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 ¶
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 (e *DeSyncPermissionlessAndTrustedNodeError) Error() string
func (*DeSyncPermissionlessAndTrustedNodeError) Unwrap ¶
func (e *DeSyncPermissionlessAndTrustedNodeError) Unwrap() error
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 ¶
func NewTrustedBatchesRetrieve(batchExecutor BatchProcessor, zkEVMClient syncinterfaces.ZKEVMClientTrustedBatchesGetter, state StateInterface, sync syncinterfaces.SynchronizerFlushIDManager, TrustedStateMngr TrustedStateManager, ) *TrustedBatchesRetrieve
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 ¶
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) 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