synchronizer

package
v0.7.0-fork11 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 33 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ParallelMode is the value for L1SynchronizationMode to run in parallel mode
	ParallelMode = "parallel"
	// SequentialMode is the value for L1SynchronizationMode to run in sequential mode
	SequentialMode = "sequential"
)
View Source
const (
	//L2BlockHeaderForGenesis = "0b73e6af6f00000000"
	L2BlockHeaderForGenesis = "0b0000000000000000"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientFlushIDControl added in v0.0.990

type ClientFlushIDControl struct {
	// contains filtered or unexported fields
}

ClientFlushIDControl is a struct to control the flushID and ProverID, implements FlushIDController interface

func NewFlushIDController added in v0.0.990

func NewFlushIDController(state syncinterfaces.StateFullInterface, ctx context.Context, eventLog *event.EventLog) *ClientFlushIDControl

NewFlushIDController create a new struct ClientFlushIDControl

func (*ClientFlushIDControl) BlockUntilLastFlushIDIsWritten added in v0.0.990

func (s *ClientFlushIDControl) BlockUntilLastFlushIDIsWritten(dbTx pgx.Tx) error

BlockUntilLastFlushIDIsWritten blocks until the last flushID is written in DB. It keep in a loop asking to executor the flushid written, also check ProverID

func (*ClientFlushIDControl) SetPendingFlushIDAndCheckProverID added in v0.0.990

func (s *ClientFlushIDControl) SetPendingFlushIDAndCheckProverID(flushID uint64, proverID string, callDescription string)

SetPendingFlushIDAndCheckProverID set the pending flushID to be written in DB and check proverID

func (*ClientFlushIDControl) UpdateAndCheckProverID added in v0.0.990

func (s *ClientFlushIDControl) UpdateAndCheckProverID(proverID string)

UpdateAndCheckProverID check the incomming proverID from executor with the last one, if no match finalize synchronizer if there are no previous one it keep this value as the current one

type ClientSynchronizer

type ClientSynchronizer struct {
	// contains filtered or unexported fields
}

ClientSynchronizer connects L1 and L2

func (*ClientSynchronizer) CheckFlushID added in v0.5.0

func (s *ClientSynchronizer) CheckFlushID(dbTx pgx.Tx) error

CheckFlushID is called when a flushID is pending to be stored in the db

func (*ClientSynchronizer) CleanTrustedState added in v0.5.0

func (s *ClientSynchronizer) CleanTrustedState()

CleanTrustedState Clean cache of TrustedBatches and StateRoot

func (*ClientSynchronizer) ExecuteReorgFromMismatchBlock added in v0.6.6

func (s *ClientSynchronizer) ExecuteReorgFromMismatchBlock(blockNumber uint64, reason string) error

ExecuteReorgFromMismatchBlock function will reset the state to the block before the bad block

func (*ClientSynchronizer) IsTrustedSequencer added in v0.5.0

func (s *ClientSynchronizer) IsTrustedSequencer() bool

IsTrustedSequencer returns true is a running in a trusted sequencer

func (*ClientSynchronizer) OnDetectedMismatchL1BlockReorg added in v0.6.6

func (s *ClientSynchronizer) OnDetectedMismatchL1BlockReorg()

OnDetectedMismatchL1BlockReorg function will be called when a reorg is detected (asynchronous call)

func (*ClientSynchronizer) PendingFlushID added in v0.5.0

func (s *ClientSynchronizer) PendingFlushID(flushID uint64, proverID string)

PendingFlushID is called when a flushID is pending to be stored in the db

func (*ClientSynchronizer) ProcessBlockRange added in v0.5.0

func (s *ClientSynchronizer) ProcessBlockRange(blocks []etherman.Block, order map[common.Hash][]etherman.Order) error

ProcessBlockRange process the L1 events and stores the information in the db

func (*ClientSynchronizer) RequestAndProcessRollupGenesisBlock added in v0.6.0

func (s *ClientSynchronizer) RequestAndProcessRollupGenesisBlock(dbTx pgx.Tx, lastEthBlockSynced *state.Block) error

RequestAndProcessRollupGenesisBlock it requests the rollup genesis block and processes it

and execute it

func (*ClientSynchronizer) Stop

func (s *ClientSynchronizer) Stop()

Stop function stops the synchronizer

func (*ClientSynchronizer) Sync

func (s *ClientSynchronizer) Sync() error

Sync function will read the last state synced and will continue from that point. Sync() will read blockchain events to detect rollup updates

type Config

type Config struct {
	// SyncInterval is the delay interval between reading new rollup information
	SyncInterval types.Duration `mapstructure:"SyncInterval"`
	// SyncChunkSize is the number of blocks to sync on each chunk
	SyncChunkSize uint64 `mapstructure:"SyncChunkSize"`
	// TrustedSequencerURL is the rpc url to connect and sync the trusted state
	TrustedSequencerURL string `mapstructure:"TrustedSequencerURL"`
	// SyncBlockProtection specify the state to sync (lastest, finalized or safe)
	SyncBlockProtection string `mapstructure:"SyncBlockProtection"`

	// L1SyncCheckL2BlockHash if is true when a batch is closed is force to check  L2Block hash against trustedNode (only apply for permissionless)
	L1SyncCheckL2BlockHash bool `mapstructure:"L1SyncCheckL2BlockHash"`
	// L1SyncCheckL2BlockNumberhModulus is the modulus used to choose the l2block to check
	// a modules 5, for instance, means check all l2block multiples of 5 (10,15,20,...)
	L1SyncCheckL2BlockNumberhModulus uint64 `mapstructure:"L1SyncCheckL2BlockNumberhModulus"`

	L1BlockCheck L1BlockCheckConfig `mapstructure:"L1BlockCheck"`
	// L1SynchronizationMode define how to synchronize with L1:
	// - parallel: Request data to L1 in parallel, and process sequentially. The advantage is that executor is not blocked waiting for L1 data
	// - sequential: Request data to L1 and execute
	L1SynchronizationMode string `jsonschema:"enum=sequential,enum=parallel"`
	// L1ParallelSynchronization Configuration for parallel mode (if L1SynchronizationMode equal to 'parallel')
	L1ParallelSynchronization L1ParallelSynchronizationConfig
	// L2Synchronization Configuration for L2 synchronization
	L2Synchronization l2_sync.Config `mapstructure:"L2Synchronization"`
}

Config represents the configuration of the synchronizer

type ExtCmdArgs added in v0.6.1

type ExtCmdArgs []string

ExtCmdArgs is the type of the arguments of the command

type ExtControlCmd added in v0.6.1

type ExtControlCmd interface {
	// FunctionName returns the name of the function to be called example: "l1_producer_stop"
	FunctionName() string
	// ValidateArguments validates the arguments of the command, returns nil if ok, error if not
	ValidateArguments(ExtCmdArgs) error
	// Process the command
	// args: the arguments of the command
	// return: string with the output and an error
	Process(ExtCmdArgs) (string, error)
	// Help returns the help of the command
	Help() string
}

ExtControlCmd is the interface of the external command

type FlushIDController added in v0.0.990

type FlushIDController interface {
	// UpdateAndCheckProverID check the incomming proverID from executor with the last one, if no match finalize synchronizer
	// if there are no previous one it keep this value as the current one
	UpdateAndCheckProverID(proverID string)
	// BlockUntilLastFlushIDIsWritten blocks until the last flushID is written in DB. It keep in a loop asking to executor
	// the flushid written, also check ProverID
	BlockUntilLastFlushIDIsWritten(dbTx pgx.Tx) error
	// SetPendingFlushIDAndCheckProverID set the pending flushID to be written in DB and check proverID
	SetPendingFlushIDAndCheckProverID(flushID uint64, proverID string, callDescription string)
}

FlushIDController is an interface to control the flushID and ProverID

type L1BlockCheckConfig added in v0.6.6

type L1BlockCheckConfig struct {
	// If enabled then the check l1 Block Hash is active
	Enabled bool `mapstructure:"Enabled"`
	// L1SafeBlockPoint is the point that a block is considered safe enough to be checked
	// it can be: finalized, safe,pending or latest
	L1SafeBlockPoint string `mapstructure:"L1SafeBlockPoint" jsonschema:"enum=finalized,enum=safe, enum=pending,enum=latest"`
	// L1SafeBlockOffset is the offset to add to L1SafeBlockPoint as a safe point
	// it can be positive or negative
	// Example: L1SafeBlockPoint= finalized, L1SafeBlockOffset= -10, then the safe block ten blocks before the finalized block
	L1SafeBlockOffset int `mapstructure:"L1SafeBlockOffset"`
	// ForceCheckBeforeStart if is true then the first time the system is started it will force to check all pending blocks
	ForceCheckBeforeStart bool `mapstructure:"ForceCheckBeforeStart"`

	// If enabled then the pre-check is active, will check blocks between L1SafeBlock and L1PreSafeBlock
	PreCheckEnabled bool `mapstructure:"PreCheckEnabled"`
	// L1PreSafeBlockPoint is the point that a block is considered safe enough to be checked
	// it can be: finalized, safe,pending or latest
	L1PreSafeBlockPoint string `mapstructure:"L1PreSafeBlockPoint" jsonschema:"enum=finalized,enum=safe, enum=pending,enum=latest"`
	// L1PreSafeBlockOffset is the offset to add to L1PreSafeBlockPoint as a safe point
	// it can be positive or negative
	// Example: L1PreSafeBlockPoint= finalized, L1PreSafeBlockOffset= -10, then the safe block ten blocks before the finalized block
	L1PreSafeBlockOffset int `mapstructure:"L1PreSafeBlockOffset"`
}

L1BlockCheckConfig Configuration for L1 Block Checker

func (*L1BlockCheckConfig) String added in v0.6.6

func (c *L1BlockCheckConfig) String() string

type L1ParallelSynchronizationConfig added in v0.0.990

type L1ParallelSynchronizationConfig struct {
	// MaxClients Number of clients used to synchronize with L1
	MaxClients uint64
	// MaxPendingNoProcessedBlocks Size of the buffer used to store rollup information from L1, must be >= to NumberOfEthereumClientsToSync
	// sugested twice of NumberOfParallelOfEthereumClients
	MaxPendingNoProcessedBlocks uint64

	// RequestLastBlockPeriod is the time to wait to request the
	// last block to L1 to known if we need to retrieve more data.
	// This value only apply when the system is synchronized
	RequestLastBlockPeriod types.Duration

	// Consumer Configuration for the consumer of rollup information from L1
	PerformanceWarning L1PerformanceCheckConfig

	// RequestLastBlockTimeout Timeout for request LastBlock On L1
	RequestLastBlockTimeout types.Duration
	// RequestLastBlockMaxRetries Max number of retries to request LastBlock On L1
	RequestLastBlockMaxRetries int
	// StatisticsPeriod how ofter show a log with statistics (0 is disabled)
	StatisticsPeriod types.Duration
	// TimeOutMainLoop is the timeout for the main loop of the L1 synchronizer when is not updated
	TimeOutMainLoop types.Duration
	// RollupInfoRetriesSpacing is the minimum time between retries to request rollup info (it will sleep for fulfill this time) to avoid spamming L1
	RollupInfoRetriesSpacing types.Duration
	// FallbackToSequentialModeOnSynchronized if true switch to sequential mode if the system is synchronized
	FallbackToSequentialModeOnSynchronized bool
}

L1ParallelSynchronizationConfig Configuration for parallel mode (if UL1SynchronizationMode equal to 'parallel')

type L1PerformanceCheckConfig added in v0.0.990

type L1PerformanceCheckConfig struct {
	// AceptableInacctivityTime is the expected maximum time that the consumer
	// could wait until new data is produced. If the time is greater it emmit a log to warn about
	// that. The idea is keep working the consumer as much as possible, so if the producer is not
	// fast enought then you could increse the number of parallel clients to sync with L1
	AceptableInacctivityTime types.Duration
	// ApplyAfterNumRollupReceived is the number of iterations to
	// start checking the time waiting for new rollup info data
	ApplyAfterNumRollupReceived int
}

L1PerformanceCheckConfig Configuration for the consumer of rollup information from L1

type Synchronizer

type Synchronizer interface {
	Sync() error
	Stop()
}

Synchronizer connects L1 and L2

func NewSynchronizer

NewSynchronizer creates and initializes an instance of Synchronizer

type TrustedState added in v0.5.0

type TrustedState struct {
	LastTrustedBatches []*state.Batch
	LastStateRoot      *common.Hash
}

TrustedState is the struct that contains the last trusted state root and the last trusted batches

Directories

Path Synopsis
package synchronizer This file contains common struct definitions and functions used by L1 sync.
package synchronizer This file contains common struct definitions and functions used by L1 sync.
l2_shared
// https://www.digitalocean.com/community/tutorials/how-to-add-extra-information-to-errors-in-go
// https://www.digitalocean.com/community/tutorials/how-to-add-extra-information-to-errors-in-go

Jump to

Keyboard shortcuts

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