Documentation ¶
Overview ¶
package synchronizer This file contains common struct definitions and functions used by L1 sync. l1DataMessage : struct to hold L1 rollup info data package send from producer to consumer
This packages could contain data or control information. - data is a real rollup info - control send actions to consumer
Constructors: - newL1PackageDataControl: create a l1PackageData with only control information - newL1PackageData: create a l1PackageData with data and control information
Index ¶
- Constants
- type Cache
- func (c *Cache[K, T]) Clear()
- func (c *Cache[K, T]) Delete(key K)
- func (c *Cache[K, T]) DeleteOutdated()
- func (c *Cache[K, T]) Get(key K) (T, bool)
- func (c *Cache[K, T]) Keys() []K
- func (c *Cache[K, T]) Len() int
- func (c *Cache[K, T]) RenewEntry(key K, validTime time.Time)
- func (c *Cache[K, T]) Set(key K, value T)
- func (c *Cache[K, T]) Values() []T
- type ClientFlushIDControl
- type ClientSynchronizer
- type Config
- type DefaultTimeProvider
- type EthermanInterface
- type FlushIDController
- type L1ParallelSynchronizationConfig
- type L1PerformanceCheckConfig
- type Synchronizer
- type TimeProvider
Constants ¶
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" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶ added in v0.0.990
type Cache[K comparable, T any] struct { // contains filtered or unexported fields }
Cache is a generic cache implementation with TOL (time of live) for each item
func NewCache ¶ added in v0.0.990
func NewCache[K comparable, T any](timerProvider TimeProvider, timeOfLiveItems time.Duration) *Cache[K, T]
NewCache creates a new cache
func (*Cache[K, T]) Delete ¶ added in v0.0.990
func (c *Cache[K, T]) Delete(key K)
Delete deletes the key from the cache
func (*Cache[K, T]) DeleteOutdated ¶ added in v0.0.990
func (c *Cache[K, T]) DeleteOutdated()
DeleteOutdated deletes the outdated items from the cache
func (*Cache[K, T]) Get ¶ added in v0.0.990
Get returns the value of the key and true if the key exists and is not outdated
func (*Cache[K, T]) Keys ¶ added in v0.0.990
func (c *Cache[K, T]) Keys() []K
Keys returns the keys of the cache
func (*Cache[K, T]) RenewEntry ¶ added in v0.0.990
RenewEntry renews the entry of the key
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 stateInterface, 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) 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"` // 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 }
Config represents the configuration of the synchronizer
type DefaultTimeProvider ¶ added in v0.0.990
type DefaultTimeProvider struct{}
DefaultTimeProvider is the default implementation of TimeProvider
func (DefaultTimeProvider) Now ¶ added in v0.0.990
func (d DefaultTimeProvider) Now() time.Time
Now returns current time
type EthermanInterface ¶ added in v0.0.990
type EthermanInterface interface { HeaderByNumber(ctx context.Context, number *big.Int) (*ethTypes.Header, error) GetRollupInfoByBlockRange(ctx context.Context, fromBlock uint64, toBlock *uint64) ([]etherman.Block, map[common.Hash][]etherman.Order, error) EthBlockByNumber(ctx context.Context, blockNumber uint64) (*ethTypes.Block, error) GetLatestBatchNumber() (uint64, error) GetTrustedSequencerURL() (string, error) VerifyGenBlockNumber(ctx context.Context, genBlockNumber uint64) (bool, error) GetLatestVerifiedBatchNum() (uint64, error) }
EthermanInterface contains the methods required to interact with ethereum.
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 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 ¶
func NewSynchronizer( isTrustedSequencer bool, ethMan EthermanInterface, etherManForL1 []EthermanInterface, st stateInterface, pool poolInterface, ethTxManager ethTxManager, zkEVMClient zkEVMClientInterface, eventLog *event.EventLog, genesis state.Genesis, cfg Config, runInDevelopmentMode bool) (Synchronizer, error)
NewSynchronizer creates and initializes an instance of Synchronizer
type TimeProvider ¶ added in v0.0.990
TimeProvider is a interface for classes that needs time and we want to be able to unittest it
Source Files ¶
- block_range.go
- config.go
- control_flush_id.go
- ext_control.go
- generic_cache.go
- interfaces.go
- l1_common.go
- l1_data_message.go
- l1_filter_send_orderer_results_to_synchronizer.go
- l1_live_block_ranges.go
- l1_rollup_info_consumer.go
- l1_rollup_info_consumer_statistics.go
- l1_rollup_info_producer.go
- l1_rollup_info_producer_statistics.go
- l1_sync_orchestration.go
- l1_syncstatus.go
- l1_worker_etherman.go
- l1_workers.go
- l1_workers_decorator_limit_retries_by_time.go
- mock_dbtx.go
- mock_etherman.go
- mock_ethtxmanager.go
- mock_l1_rollup_consumer_interface.go
- mock_l1_rollup_producer_interface.go
- mock_l1_worker.go
- mock_pool.go
- mock_state.go
- mock_synchronizer_process_block_range.go
- mock_workers.go
- mock_zkevmclient.go
- synchronizer.go
- time_provider.go