synchronizer

package
v0.5.11-RC2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 30 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) IsTrustedSequencer added in v0.5.0

func (s *ClientSynchronizer) IsTrustedSequencer() bool

IsTrustedSequencer returns true is a running in a trusted sequencer

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

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_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