sync_stages

package
v0.0.0-...-92d349b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Metrics = map[SyncStage]*metrics.Counter{}

Functions

func GetStageData

func GetStageData(db kv.Getter, stage SyncStage) ([]byte, error)

func GetStageProgress

func GetStageProgress(db kv.Getter, stage SyncStage) (uint64, error)

GetStageProgress retrieves saved progress of given sync stage from the database

func GetStagePruneProgress

func GetStagePruneProgress(db kv.Getter, stage SyncStage) (uint64, error)

GetStagePruneProgress retrieves saved progress of given sync stage from the database

func PrintTables

func PrintTables(db kv.RoDB, tx kv.RwTx) []interface{}

func SaveStageData

func SaveStageData(db kv.Putter, stage SyncStage, data []byte) error

func SaveStageProgress

func SaveStageProgress(db kv.Putter, stage SyncStage, progress uint64) error

func SaveStagePruneProgress

func SaveStagePruneProgress(db kv.Putter, stage SyncStage, progress uint64) error

func UpdateMetrics

func UpdateMetrics(tx kv.Tx) error

UpdateMetrics - need update metrics manually because current "metrics" package doesn't support labels need to fix it in future

Types

type ExecFunc

type ExecFunc func(firstCycle bool, badBlockUnwind bool, s *StageState, unwinder Unwinder, tx kv.RwTx, quiet bool) error

ExecFunc is the execution function for the stage to move forward. * state - is the current state of the stage and contains stage data. * unwinder - if the stage needs to cause unwinding, `unwinder` methods can be used.

type PruneFunc

type PruneFunc func(firstCycle bool, p *PruneState, tx kv.RwTx) error

PruneFunc is the execution function for the stage to prune old data. * state - is the current state of the stage and contains stage data.

type PruneOrder

type PruneOrder []SyncStage

type PruneState

type PruneState struct {
	ID              SyncStage
	ForwardProgress uint64 // progress of stage forward move
	PruneProgress   uint64 // progress of stage prune move. after sync cycle it become equal to ForwardProgress by Done() method
	// contains filtered or unexported fields
}

func (*PruneState) Done

func (s *PruneState) Done(db kv.Putter) error

func (*PruneState) DoneAt

func (s *PruneState) DoneAt(db kv.Putter, blockNum uint64) error

func (*PruneState) LogPrefix

func (s *PruneState) LogPrefix() string

type Stage

type Stage struct {
	// Description is a string that is shown in the logs.
	Description string
	// DisabledDescription shows in the log with a message if the stage is disabled. Here, you can show which command line flags should be provided to enable the page.
	DisabledDescription string
	// Forward is called when the stage is executed. The main logic of the stage should be here. Should always end with `s.Done()` to allow going to the next stage. MUST NOT be nil!
	Forward ExecFunc
	// Unwind is called when the stage should be unwound. The unwind logic should be there. MUST NOT be nil!
	Unwind UnwindFunc
	Prune  PruneFunc
	// ID of the sync stage. Should not be empty and should be unique. It is recommended to prefix it with reverse domain to avoid clashes (`com.example.my-stage`).
	ID SyncStage
	// Disabled defines if the stage is disabled. It sets up when the stage is build by its `StageBuilder`.
	Disabled bool
}

Stage is a single sync stage in staged sync.

type StageState

type StageState struct {
	ID          SyncStage
	BlockNumber uint64 // BlockNumber is the current block number of the stage at the beginning of the state execution.
	// contains filtered or unexported fields
}

StageState is the state of the stage.

func (*StageState) ExecutionAt

func (s *StageState) ExecutionAt(db kv.Getter) (uint64, error)

ExecutionAt gets the current state of the "Execution" stage, which block is currently executed.

func (*StageState) IntermediateHashesAt

func (s *StageState) IntermediateHashesAt(db kv.Getter) (uint64, error)

IntermediateHashesAt gets the current state of the "IntermediateHashes" stage. A block is fully validated after the IntermediateHashes stage is passed successfully.

func (*StageState) LogPrefix

func (s *StageState) LogPrefix() string

func (*StageState) Update

func (s *StageState) Update(db kv.Putter, newBlockNum uint64) error

Update updates the stage state (current block number) in the database. Can be called multiple times during stage execution.

func (*StageState) UpdatePrune

func (s *StageState) UpdatePrune(db kv.Putter, blockNum uint64) error

type Sync

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

func New

func New(stagesList []*Stage, unwindOrder UnwindOrder, pruneOrder PruneOrder) *Sync

func (*Sync) DisableAllStages

func (s *Sync) DisableAllStages() []SyncStage

DisableAllStages - including their unwinds

func (*Sync) DisableStages

func (s *Sync) DisableStages(ids ...SyncStage)

func (*Sync) EnableStages

func (s *Sync) EnableStages(ids ...SyncStage)

func (*Sync) IsAfter

func (s *Sync) IsAfter(stage1, stage2 SyncStage) bool

IsAfter returns true if stage1 goes after stage2 in staged sync

func (*Sync) IsBefore

func (s *Sync) IsBefore(stage1, stage2 SyncStage) bool

IsBefore returns true if stage1 goes before stage2 in staged sync

func (*Sync) IsDone

func (s *Sync) IsDone() bool

func (*Sync) Len

func (s *Sync) Len() int

func (*Sync) LogPrefix

func (s *Sync) LogPrefix() string

func (*Sync) MockExecFunc

func (s *Sync) MockExecFunc(id SyncStage, f ExecFunc)

func (*Sync) NewUnwindState

func (s *Sync) NewUnwindState(id SyncStage, unwindPoint, currentProgress uint64) *UnwindState

func (*Sync) NextStage

func (s *Sync) NextStage()

func (*Sync) PrevUnwindPoint

func (s *Sync) PrevUnwindPoint() *uint64

func (*Sync) PrintTimings

func (s *Sync) PrintTimings() []interface{}

func (*Sync) PruneStageState

func (s *Sync) PruneStageState(id SyncStage, forwardProgress uint64, tx kv.Tx, db kv.RwDB) (*PruneState, error)

func (*Sync) Run

func (s *Sync) Run(db kv.RwDB, tx kv.RwTx, firstCycle bool, quiet bool) error

func (*Sync) RunPrune

func (s *Sync) RunPrune(db kv.RwDB, tx kv.RwTx, firstCycle bool) error

func (*Sync) RunUnwind

func (s *Sync) RunUnwind(db kv.RwDB, tx kv.RwTx) error

func (*Sync) SetCurrentStage

func (s *Sync) SetCurrentStage(id SyncStage) error

func (*Sync) StageState

func (s *Sync) StageState(stage SyncStage, tx kv.Tx, db kv.RoDB) (*StageState, error)

func (*Sync) UnwindTo

func (s *Sync) UnwindTo(unwindPoint uint64, badBlock libcommon.Hash)

type SyncStage

type SyncStage string

SyncStage represents the stages of syncronisation in the Mode.StagedSync mode It is used to persist the information about the stage state into the database. It should not be empty and should be unique.

var (
	Snapshots           SyncStage = "Snapshots"       // Snapshots
	Headers             SyncStage = "Headers"         // Headers are downloaded, their Proof-Of-Work validity and chaining is verified
	CumulativeIndex     SyncStage = "CumulativeIndex" // Calculate how much gas has been used up to each block.
	BlockHashes         SyncStage = "BlockHashes"     // Headers Number are written, fills blockHash => number bucket
	Bodies              SyncStage = "Bodies"          // Block bodies are downloaded, TxHash and UncleHash are getting verified
	Senders             SyncStage = "Senders"         // "From" recovered from signatures, bodies re-written
	Execution           SyncStage = "Execution"       // Executing each block w/o buildinf a trie
	Translation         SyncStage = "Translation"     // Translation each marked for translation contract (from EVM to TEVM)
	VerkleTrie          SyncStage = "VerkleTrie"
	IntermediateHashes  SyncStage = "IntermediateHashes"  // Generate intermediate hashes, calculate the state root hash
	HashState           SyncStage = "HashState"           // Apply Keccak256 to all the keys in the state
	AccountHistoryIndex SyncStage = "AccountHistoryIndex" // Generating history index for accounts
	StorageHistoryIndex SyncStage = "StorageHistoryIndex" // Generating history index for storage
	LogIndex            SyncStage = "LogIndex"            // Generating logs index (from receipts)
	CallTraces          SyncStage = "CallTraces"          // Generating call traces index
	TxLookup            SyncStage = "TxLookup"            // Generating transactions lookup index
	Finish              SyncStage = "Finish"              // Nominal stage after all other stages

	MiningCreateBlock SyncStage = "MiningCreateBlock"
	MiningExecution   SyncStage = "MiningExecution"
	MiningFinish      SyncStage = "MiningFinish"
	// Beacon chain stages
	BeaconHistoryReconstruction SyncStage = "BeaconHistoryReconstruction" // BeaconHistoryReconstruction reconstruct missing history.
	BeaconBlocks                SyncStage = "BeaconBlocks"                // BeaconBlocks are downloaded, no verification
	BeaconState                 SyncStage = "BeaconState"                 // Beacon blocks are sent to the state transition function
	BeaconIndexes               SyncStage = "BeaconIndexes"               // Fills up Beacon indexes

	// ZK stages
	L1Syncer                    SyncStage = "L1Syncer"
	L1VerificationsBatchNo      SyncStage = "L1VerificationsBatchNo"
	Batches                     SyncStage = "Batches"
	HighestHashableL2BlockNo    SyncStage = "HighestHashableL2BlockNo"
	VerificationsStateRootCheck SyncStage = "VerificationStateRootCheck"
	ForkId                      SyncStage = "ForkId"
)

type Timing

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

type UnwindFunc

type UnwindFunc func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error

UnwindFunc is the unwinding logic of the stage. * unwindState - contains information about the unwind itself. * stageState - represents the state of this stage at the beginning of unwind.

type UnwindOrder

type UnwindOrder []SyncStage

UnwindOrder represents the order in which the stages needs to be unwound. The unwind order is important and not always just stages going backwards. Let's say, there is tx pool can be unwound only after execution. It's ok to remove some stage from here to disable only unwind of stage

type UnwindState

type UnwindState struct {
	ID SyncStage
	// UnwindPoint is the block to unwind to.
	UnwindPoint        uint64
	CurrentBlockNumber uint64
	// If unwind is caused by a bad block, this hash is not empty
	BadBlock libcommon.Hash
	// contains filtered or unexported fields
}

UnwindState contains the information about unwind.

func (*UnwindState) Done

func (u *UnwindState) Done(db kv.Putter) error

Done updates the DB state of the stage.

func (*UnwindState) LogPrefix

func (u *UnwindState) LogPrefix() string

type Unwinder

type Unwinder interface {
	// UnwindTo begins staged sync unwind to the specified block.
	UnwindTo(unwindPoint uint64, badBlock libcommon.Hash)
}

Unwinder allows the stage to cause an unwind.

Jump to

Keyboard shortcuts

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