l2_shared

package
v0.5.0-RC1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2023 License: AGPL-3.0, AGPL-3.0-or-later Imports: 13 Imported by: 0

Documentation

Overview

// https://www.digitalocean.com/community/tutorials/how-to-add-extra-information-to-errors-in-go

This error DeSyncPermissionlessAndTrustedNodeError have a field L1BlockNumber that contains the block number where the discrepancy is.

object TrustedBatchesRetrieve: - It get all pending batches from trusted node to be synchronized

You must implements BatchProcessor with the code to process the batches

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchProcessMode

type BatchProcessMode string

BatchProcessMode is the mode for process a batch (full, incremental, reprocess, nothing)

const (
	// FullProcessMode This batch is not on database, so is the first time we process it
	FullProcessMode BatchProcessMode = "full"
	// IncrementalProcessMode We have processed this batch before, and we have the intermediate state root, so is going to be process only new Tx
	IncrementalProcessMode BatchProcessMode = "incremental"
	// ReprocessProcessMode We have processed this batch before, but we don't have the intermediate state root, so we need to reprocess it
	ReprocessProcessMode BatchProcessMode = "reprocess"
	// NothingProcessMode The batch is already synchronized, so we don't need to process it
	NothingProcessMode BatchProcessMode = "nothing"
)

type BatchProcessor

type BatchProcessor interface {
	// ProcessTrustedBatch processes a trusted batch
	ProcessTrustedBatch(ctx context.Context, trustedBatch *types.Batch, status TrustedState, dbTx pgx.Tx, debugPrefix string) (*TrustedState, error)
}

BatchProcessor is a interface with the ProcessTrustedBatch methor

this method is responsible to process a trusted batch

type DeSyncPermissionlessAndTrustedNodeError

type DeSyncPermissionlessAndTrustedNodeError struct {
	L1BlockNumber uint64
	Err           error
}

DeSyncPermissionlessAndTrustedNodeError is an error type that contains the Block where is the discrepancy

func NewDeSyncPermissionlessAndTrustedNodeError

func NewDeSyncPermissionlessAndTrustedNodeError(L1BlockNumber uint64) *DeSyncPermissionlessAndTrustedNodeError

NewDeSyncPermissionlessAndTrustedNodeError returns a new instance of DeSyncPermissionlessAndTrustedNodeError

func (*DeSyncPermissionlessAndTrustedNodeError) Error

func (*DeSyncPermissionlessAndTrustedNodeError) Unwrap

type ProcessData

type ProcessData struct {
	BatchNumber       uint64
	Mode              BatchProcessMode
	OldStateRoot      common.Hash
	OldAccInputHash   common.Hash
	BatchMustBeClosed bool
	// The batch in trusted node, it NEVER will be nil
	TrustedBatch *types.Batch
	// Current batch in state DB, it could be nil
	StateBatch  *state.Batch
	Now         time.Time
	Description string
	// DebugPrefix is used to log, must prefix all logs entries
	DebugPrefix string
}

ProcessData contains the data required to process a batch

type ProcessResponse

type ProcessResponse struct {
	// ProcessBatchResponse have the NewStateRoot
	ProcessBatchResponse *state.ProcessBatchResponse
	// ClearCache force to clear cache for next execution
	ClearCache bool
	// UpdateBatch  update the batch for next execution
	UpdateBatch *state.Batch
	// UpdateBatchWithProcessBatchResponse update the batch (if not nil) with the data in ProcessBatchResponse
	UpdateBatchWithProcessBatchResponse bool
}

ProcessResponse contains the response of the process of a batch

type ProcessorTrustedBatchSync

type ProcessorTrustedBatchSync struct {
	Steps SyncTrustedBatchExecutor
	// contains filtered or unexported fields
}

ProcessorTrustedBatchSync is a template to sync trusted state. It classify what kind of update is needed and call to SyncTrustedStateBatchExecutorSteps

  that is the one that execute the sync process

	the real implementation of the steps is in the SyncTrustedStateBatchExecutorSteps interface that known how to process a batch

func NewProcessorTrustedBatchSync

func NewProcessorTrustedBatchSync(steps SyncTrustedBatchExecutor,
	timeProvider syncCommon.TimeProvider) *ProcessorTrustedBatchSync

NewProcessorTrustedBatchSync creates a new SyncTrustedStateBatchExecutorTemplate

func (*ProcessorTrustedBatchSync) ProcessTrustedBatch

func (s *ProcessorTrustedBatchSync) ProcessTrustedBatch(ctx context.Context, trustedBatch *types.Batch, status TrustedState, dbTx pgx.Tx, debugPrefix string) (*TrustedState, error)

ProcessTrustedBatch processes a trusted batch and return the new state

type StateInterface

type StateInterface interface {
	BeginStateTransaction(ctx context.Context) (pgx.Tx, error)
	GetBatchByNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.Batch, error)
}

StateInterface contains the methods required to interact with the state.

type SyncTrustedBatchExecutor

type SyncTrustedBatchExecutor interface {
	// FullProcess process a batch that is not on database, so is the first time we process it
	FullProcess(ctx context.Context, data *ProcessData, dbTx pgx.Tx) (*ProcessResponse, error)
	// IncrementalProcess process a batch that we have processed before, and we have the intermediate state root, so is going to be process only new Tx
	IncrementalProcess(ctx context.Context, data *ProcessData, dbTx pgx.Tx) (*ProcessResponse, error)
	// ReProcess process a batch that we have processed before, but we don't have the intermediate state root, so we need to reprocess it
	ReProcess(ctx context.Context, data *ProcessData, dbTx pgx.Tx) (*ProcessResponse, error)
	// NothingProcess process a batch that is already synchronized, so we don't need to process it
	NothingProcess(ctx context.Context, data *ProcessData, dbTx pgx.Tx) (*ProcessResponse, error)
}

SyncTrustedBatchExecutor is the interface that known how to process a batch

type TrustedBatchesRetrieve

type TrustedBatchesRetrieve struct {
	TrustedStateMngr TrustedStateManager
	// contains filtered or unexported fields
}

TrustedBatchesRetrieve it gets pending batches from Trusted node. It calls for each batch to BatchExecutor

and for each new batch calls the ProcessTrustedBatch method of the BatchExecutor interface

func NewTrustedBatchesRetrieve

NewTrustedBatchesRetrieve creates a new SyncTrustedStateTemplate

func (*TrustedBatchesRetrieve) CleanTrustedState

func (s *TrustedBatchesRetrieve) CleanTrustedState()

CleanTrustedState Clean cache of TrustedBatches and StateRoot

func (*TrustedBatchesRetrieve) SyncTrustedState

func (s *TrustedBatchesRetrieve) SyncTrustedState(ctx context.Context, latestSyncedBatch uint64) error

SyncTrustedState sync trusted state from latestSyncedBatch to lastTrustedStateBatchNumber

type TrustedState

type TrustedState struct {
	// LastTrustedBatches [0] -> Current  batch, [1] -> previous batch
	LastTrustedBatches []*state.Batch
}

TrustedState is the trusted state, basically contains the batch cache for a concrete batch

type TrustedStateManager

type TrustedStateManager struct {
	Cache *common.Cache[uint64, *state.Batch]
}

TrustedStateManager is the trusted state manager, basically contains the batch cache and create the TrustedState

func NewTrustedStateManager

func NewTrustedStateManager(timerProvider common.TimeProvider, timeOfLiveItems time.Duration) *TrustedStateManager

NewTrustedStateManager creates a new TrustedStateManager

func (*TrustedStateManager) Clear

func (ts *TrustedStateManager) Clear()

Clear clears the cache

func (*TrustedStateManager) GetStateForWorkingBatch

func (ts *TrustedStateManager) GetStateForWorkingBatch(ctx context.Context, batchNumber uint64, stateGetBatch syncinterfaces.StateGetBatchByNumberInterface, dbTx pgx.Tx) (*TrustedState, error)

GetStateForWorkingBatch returns the trusted state for the working batch

func (*TrustedStateManager) Set

func (ts *TrustedStateManager) Set(resultBatch *state.Batch)

Set sets the result batch in the cache

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL