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 ¶
- Variables
- func AreEqualStateBatchAndTrustedBatch(stateBatch *state.Batch, trustedBatch *types.Batch, flags CompareBatchFlags) (bool, string)
- func ThereAreNewBatchL2Data(previousData []byte, incommingData types.ArgBytes) (bool, error)
- type BatchProcessMode
- type BatchProcessor
- type CompareBatchFlags
- type DeSyncPermissionlessAndTrustedNodeError
- type ProcessData
- type ProcessResponse
- type ProcessorTrustedBatchSync
- func (s *ProcessorTrustedBatchSync) ExecuteProcessBatch(ctx context.Context, processMode *ProcessData, dbTx pgx.Tx) (*ProcessResponse, error)
- func (s *ProcessorTrustedBatchSync) GetCurrentAndPreviousBatchFromCache(status *TrustedState) (*state.Batch, *state.Batch)
- func (s *ProcessorTrustedBatchSync) GetModeForProcessBatch(trustedNodeBatch *types.Batch, stateBatch *state.Batch, ...) (ProcessData, error)
- func (s *ProcessorTrustedBatchSync) GetNextStatus(status TrustedState, processBatchResp *ProcessResponse, closedBatch bool, ...) (*TrustedState, error)
- func (s *ProcessorTrustedBatchSync) ProcessTrustedBatch(ctx context.Context, trustedBatch *types.Batch, status TrustedState, ...) (*TrustedState, error)
- type StateInterface
- type SyncTrustedBatchExecutor
- type TrustedBatchesRetrieve
- type TrustedState
- type TrustedStateManager
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBatchDataIsNotIncremental is returned when the new batch has different data than the one in node and is not possible to sync ErrBatchDataIsNotIncremental = errors.New("the new batch has different data than the one in node") )
var ( // ErrFatalBatchDesynchronized is the error when the batch is desynchronized ErrFatalBatchDesynchronized = fmt.Errorf("batch desynchronized") )
Functions ¶
func AreEqualStateBatchAndTrustedBatch ¶
func AreEqualStateBatchAndTrustedBatch(stateBatch *state.Batch, trustedBatch *types.Batch, flags CompareBatchFlags) (bool, string)
AreEqualStateBatchAndTrustedBatch check is are equal, it response true|false and a debug string you could pass some flags to ignore some fields
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 CompareBatchFlags ¶
type CompareBatchFlags int
CompareBatchFlags is a flag to ignore some fields when comparing batches
const ( CMP_BATCH_NONE CompareBatchFlags = 0x0 // CMP_BATCH_NONE No flag CMP_BATCH_IGNORE_WIP CompareBatchFlags = 0x1 // CMP_BATCH_IGNORE_WIP Ignore WIP field CMP_BATCH_IGNORE_TSTAMP CompareBatchFlags = 0x2 // CMP_BATCH_IGNORE_TSTAMP Ignore Timestamp field )
func (CompareBatchFlags) IsSet ¶
func (c CompareBatchFlags) IsSet(f CompareBatchFlags) bool
IsSet check if a flag is set. example of usage: v.IsSet(CMP_BATCH_IGNORE_WIP)
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 // TrustedBatch The batch in trusted node, it NEVER will be nil TrustedBatch *types.Batch // StateBatch Current batch in state DB, it could be nil StateBatch *state.Batch // PreviousStateBatch Previous batch in state DB (BatchNumber - 1), it could be nil PreviousStateBatch *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
func NewProcessResponse ¶
func NewProcessResponse() ProcessResponse
NewProcessResponse creates a new ProcessResponse
func (*ProcessResponse) CheckSanity ¶
func (p *ProcessResponse) CheckSanity() error
CheckSanity check the sanity of the response
func (*ProcessResponse) DiscardCache ¶
func (p *ProcessResponse) DiscardCache()
DiscardCache set to discard cache for next execution
func (*ProcessResponse) UpdateCurrentBatch ¶
func (p *ProcessResponse) UpdateCurrentBatch(UpdateBatch *state.Batch)
UpdateCurrentBatch update the current batch for next execution
func (*ProcessResponse) UpdateCurrentBatchWithExecutionResult ¶
func (p *ProcessResponse) UpdateCurrentBatchWithExecutionResult(UpdateBatch *state.Batch, ProcessBatchResponse *state.ProcessBatchResponse)
UpdateCurrentBatchWithExecutionResult update the current batch for next execution with the data in ProcessBatchResponse
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) ExecuteProcessBatch ¶
func (s *ProcessorTrustedBatchSync) ExecuteProcessBatch(ctx context.Context, processMode *ProcessData, dbTx pgx.Tx) (*ProcessResponse, error)
ExecuteProcessBatch execute the batch and process it
func (*ProcessorTrustedBatchSync) GetCurrentAndPreviousBatchFromCache ¶
func (s *ProcessorTrustedBatchSync) GetCurrentAndPreviousBatchFromCache(status *TrustedState) (*state.Batch, *state.Batch)
GetCurrentAndPreviousBatchFromCache returns the current and previous batch from cache
func (*ProcessorTrustedBatchSync) GetModeForProcessBatch ¶
func (s *ProcessorTrustedBatchSync) GetModeForProcessBatch(trustedNodeBatch *types.Batch, stateBatch *state.Batch, statePreviousBatch *state.Batch, debugPrefix string) (ProcessData, error)
GetModeForProcessBatch returns the mode for process a batch
func (*ProcessorTrustedBatchSync) GetNextStatus ¶
func (s *ProcessorTrustedBatchSync) GetNextStatus(status TrustedState, processBatchResp *ProcessResponse, closedBatch bool, debugPrefix string) (*TrustedState, error)
GetNextStatus returns the next cache for use in the next run it could be nil, that means discard current cache
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
func (*TrustedState) IsEmpty ¶
func (ts *TrustedState) IsEmpty() bool
IsEmpty returns true if the trusted state is empty
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