synchronizer

package
v0.4.7-RC3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 31 Imported by: 2

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

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"
)

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]) Clear added in v0.0.990

func (c *Cache[K, T]) Clear()

Clear clears the 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

func (c *Cache[K, T]) Get(key K) (T, bool)

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]) Len added in v0.0.990

func (c *Cache[K, T]) Len() int

Len returns the number of items in the cache

func (*Cache[K, T]) RenewEntry added in v0.0.990

func (c *Cache[K, T]) RenewEntry(key K, validTime time.Time)

RenewEntry renews the entry of the key

func (*Cache[K, T]) Set added in v0.0.990

func (c *Cache[K, T]) Set(key K, value T)

Set sets the value of the key

func (*Cache[K, T]) Values added in v0.0.990

func (c *Cache[K, T]) Values() []T

Values returns the values of the cache

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

type TimeProvider interface {
	// Now returns current time
	Now() time.Time
}

TimeProvider is a interface for classes that needs time and we want to be able to unittest it

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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