Documentation ¶
Index ¶
- Constants
- Variables
- func ByteCount(b uint64) string
- func CompareBlockByHash(a *types.Block, b *types.Block) int
- func CompareSyncPeerConfigByblockHashes(a *SyncPeerConfig, b *SyncPeerConfig) int
- func CreateView(ctx context.Context, db kv.RwDB, tx kv.Tx, f func(tx kv.Tx) error) error
- func GetBucketName(bucketName string, isBeacon bool) string
- func GetHowManyMaxConsensus(blocks []*types.Block) (int, int)
- func GetStageCleanUpProgress(db kv.Getter, stage SyncStageID, isBeacon bool) (uint64, error)
- func GetStageID(stage SyncStageID, isBeacon bool, prune bool) []byte
- func GetStageName(stage string, isBeacon bool, prune bool) string
- func GetStageProgress(db kv.Getter, stage SyncStageID, isBeacon bool) (uint64, error)
- func GetSyncingPort(nodePort string) string
- func NewSyncStatus(role nodeconfig.Role) syncStatus
- func ParseResult(res SyncCheckResult) (IsSynchronized bool, OtherHeight uint64, HeightDiff uint64)
- func RlpDecodeBlockOrBlockWithSig(payload []byte) (*types.Block, error)
- func SaveStageCleanUpProgress(db kv.Putter, stage SyncStageID, isBeacon bool, progress uint64) error
- func SaveStageProgress(db kv.Putter, stage SyncStageID, isBeacon bool, progress uint64) error
- func WrapStagedSyncError(context string) error
- type BlockWithSig
- type CleanUpOrder
- type CleanUpState
- type ExecFunc
- type ForwardOrder
- type RevertOrder
- type RevertState
- type Reverter
- type Stage
- type StageBlockHashes
- func (bh *StageBlockHashes) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
- func (bh *StageBlockHashes) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, ...) (err error)
- func (bh *StageBlockHashes) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
- type StageBlockHashesCfg
- type StageBodies
- func (b *StageBodies) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
- func (b *StageBodies) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, ...) (err error)
- func (b *StageBodies) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
- type StageBodiesCfg
- type StageFinish
- func (finish *StageFinish) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
- func (finish *StageFinish) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, ...) error
- func (finish *StageFinish) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
- type StageFinishCfg
- type StageHandler
- type StageHeads
- func (heads *StageHeads) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
- func (heads *StageHeads) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, ...) error
- func (heads *StageHeads) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
- type StageHeadsCfg
- type StageLastMile
- func (lm *StageLastMile) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
- func (lm *StageLastMile) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, ...) (err error)
- func (lm *StageLastMile) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
- type StageLastMileCfg
- type StageState
- func (s *StageState) CurrentStageProgress(db kv.Getter) (uint64, error)
- func (s *StageState) LogPrefix() string
- func (s *StageState) StageProgress(db kv.Getter, id SyncStageID) (uint64, error)
- func (s *StageState) Update(db kv.Putter, newBlockNum uint64) error
- func (s *StageState) UpdateCleanUp(db kv.Putter, blockNum uint64) error
- type StageStates
- func (stg *StageStates) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
- func (stg *StageStates) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, ...) (err error)
- func (stg *StageStates) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
- type StageStatesCfg
- type StagedSync
- func (s *StagedSync) AddBlocks(blks map[uint64][]byte) error
- func (ss *StagedSync) AddLastMileBlock(block *types.Block)
- func (ss *StagedSync) AddNewBlock(peerHash []byte, block *types.Block)
- func (s *StagedSync) Blockchain() core.BlockChain
- func (s *StagedSync) CleanUpStageState(id SyncStageID, forwardProgress uint64, tx kv.Tx, db kv.RwDB) (*CleanUpState, error)
- func (s *StagedSync) Context() context.Context
- func (ss *StagedSync) CreateSyncConfig(peers []p2p.Peer, shardID uint32, selfPeerID libp2p_peer.ID, ...) error
- func (s *StagedSync) DB() kv.RwDB
- func (s *StagedSync) DisableAllStages() []SyncStageID
- func (s *StagedSync) DisableStages(ids ...SyncStageID)
- func (s *StagedSync) Done()
- func (s *StagedSync) EnableStages(ids ...SyncStageID)
- func (ss *StagedSync) GetActivePeerNumber() int
- func (s *StagedSync) GetDownloadedBlocks() map[uint64][]byte
- func (ss *StagedSync) GetMaxPeerHeight() (uint64, error)
- func (ss *StagedSync) GetParsedSyncStatus() (IsSynchronized bool, OtherHeight uint64, HeightDiff uint64)
- func (ss *StagedSync) GetParsedSyncStatusDoubleChecked() (IsSynchronized bool, OtherHeight uint64, HeightDiff uint64)
- func (ss *StagedSync) GetSyncStatus() SyncCheckResult
- func (ss *StagedSync) GetSyncStatusDoubleChecked() SyncCheckResult
- func (s *StagedSync) InitDownloadedBlocksMap() error
- func (s *StagedSync) IsAfter(stage1, stage2 SyncStageID) bool
- func (s *StagedSync) IsBeacon() bool
- func (s *StagedSync) IsBefore(stage1, stage2 SyncStageID) bool
- func (s *StagedSync) IsDone() bool
- func (s *StagedSync) IsExplorer() bool
- func (ss *StagedSync) IsSameBlockchainHeight(bc core.BlockChain) (uint64, bool)
- func (ss *StagedSync) IsSynchronized() bool
- func (s *StagedSync) Len() int
- func (s *StagedSync) LogPrefix() string
- func (s *StagedSync) NewRevertState(id SyncStageID, revertPoint, currentProgress uint64) *RevertState
- func (s *StagedSync) NextStage()
- func (s *StagedSync) PrevRevertPoint() *uint64
- func (ss *StagedSync) RegisterNodeInfo() int
- func (s *StagedSync) RevertTo(revertPoint uint64, invalidBlock common.Hash)
- func (s *StagedSync) Run(db kv.RwDB, tx kv.RwTx, firstCycle bool) error
- func (s *StagedSync) SetCurrentStage(id SyncStageID) error
- func (s *StagedSync) StageState(stage SyncStageID, tx kv.Tx, db kv.RwDB) (*StageState, error)
- func (s *StagedSync) SyncLoop(bc core.BlockChain, isBeacon bool, consensus *consensus.Consensus, ...)
- func (ss *StagedSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChain) error
- type SyncBlockTask
- type SyncCheckResult
- type SyncConfig
- func (sc *SyncConfig) AddPeer(peer *SyncPeerConfig)
- func (sc *SyncConfig) CloseConnections()
- func (sc *SyncConfig) FindPeerByHash(peerHash []byte) *SyncPeerConfig
- func (sc *SyncConfig) ForEachPeer(f func(peer *SyncPeerConfig) (brk bool))
- func (sc *SyncConfig) GetBlockHashesConsensusAndCleanUp(bgMode bool) error
- func (sc *SyncConfig) InitForTesting(client *downloader.Client, blockHashes [][]byte)
- func (sc *SyncConfig) RemovePeer(peer *SyncPeerConfig, reason string)
- func (sc *SyncConfig) ReplacePeerWithReserved(peer *SyncPeerConfig, reason string)
- func (sc *SyncConfig) SelectRandomPeers(peers []p2p.Peer, randSeed int64) int
- type SyncCycle
- type SyncPeerConfig
- type SyncStageID
- type Timing
Constants ¶
const ( RegistrationNumber = 3 SyncingPortDifference = 3000 SyncLoopBatchSize uint32 = 30 // maximum size for one query of block hashes LastMileBlocksSize = 50 // after cutting off a number of connected peers, the result number of peers // shall be between numPeersLowBound and numPeersHighBound NumPeersLowBound = 3 // NumPeersReserved is the number reserved peers which will be replaced with any broken peer NumPeersReserved = 2 )
Constants for syncing.
const ( BlockHashesBucket = "BlockHashes" BeaconBlockHashesBucket = "BeaconBlockHashes" DownloadedBlocksBucket = "BlockBodies" BeaconDownloadedBlocksBucket = "BeaconBlockBodies" // Beacon Block bodies are downloaded, TxHash and UncleHash are getting verified LastMileBlocksBucket = "LastMileBlocks" // last mile blocks to catch up with the consensus StageProgressBucket = "StageProgress" // cache db keys LastBlockHeight = "LastBlockHeight" LastBlockHash = "LastBlockHash" // cache db names BlockHashesCacheDB = "cache_block_hashes" BlockCacheDB = "cache_blocks" )
Variables ¶
var ( ErrRegistrationFail = WrapStagedSyncError("registration failed") ErrGetBlock = WrapStagedSyncError("get block failed") ErrGetBlockHash = WrapStagedSyncError("get block hash failed") ErrGetConsensusHashes = WrapStagedSyncError("get consensus hashes failed") ErrGenStateSyncTaskQueue = WrapStagedSyncError("generate state sync task queue failed") ErrDownloadBlocks = WrapStagedSyncError("get download blocks failed") ErrUpdateBlockAndStatus = WrapStagedSyncError("update block and status failed") ErrGenerateNewState = WrapStagedSyncError("get generate new state failed") ErrFetchBlockHashProgressFail = WrapStagedSyncError("fetch cache progress for block hashes stage failed") ErrFetchCachedBlockHashFail = WrapStagedSyncError("fetch cached block hashes failed") ErrNotEnoughBlockHashes = WrapStagedSyncError("peers haven't sent all requested block hashes") ErrRetrieveCachedProgressFail = WrapStagedSyncError("retrieving cache progress for block hashes stage failed") ErrRetrieveCachedHashProgressFail = WrapStagedSyncError("retrieving cache progress for block hashes stage failed") ErrSaveBlockHashesProgressFail = WrapStagedSyncError("saving progress for block hashes stage failed") ErrSaveCachedBlockHashesProgressFail = WrapStagedSyncError("saving cache progress for block hashes stage failed") ErrSavingCacheLastBlockHashFail = WrapStagedSyncError("saving cache last block hash for block hashes stage failed") ErrCachingBlockHashFail = WrapStagedSyncError("caching downloaded block hashes failed") ErrCommitTransactionFail = WrapStagedSyncError("failed to write db commit") ErrUnexpectedNumberOfBlocks = WrapStagedSyncError("unexpected number of block delivered") ErrSavingBodiesProgressFail = WrapStagedSyncError("saving progress for block bodies stage failed") ErrAddTasksToQueueFail = WrapStagedSyncError("cannot add task to queue") ErrSavingCachedBodiesProgressFail = WrapStagedSyncError("saving cache progress for blocks stage failed") ErrRetrievingCachedBodiesProgressFail = WrapStagedSyncError("retrieving cache progress for blocks stage failed") ErrNoConnectedPeers = WrapStagedSyncError("haven't connected to any peer yet!") ErrNotEnoughConnectedPeers = WrapStagedSyncError("not enough connected peers") ErrSaveStateProgressFail = WrapStagedSyncError("saving progress for block States stage failed") ErrPruningCursorCreationFail = WrapStagedSyncError("failed to create cursor for pruning") ErrInvalidBlockNumber = WrapStagedSyncError("invalid block number") ErrInvalidBlockBytes = WrapStagedSyncError("invalid block bytes to insert into chain") ErrAddTaskFailed = WrapStagedSyncError("cannot add task to queue") ErrNodeNotEnoughBlockHashes = WrapStagedSyncError("some of the nodes didn't provide all block hashes") ErrCachingBlocksFail = WrapStagedSyncError("caching downloaded block bodies failed") ErrSaveBlocksFail = WrapStagedSyncError("save downloaded block bodies failed") ErrStageNotFound = WrapStagedSyncError("stage not found") ErrSomeNodesNotReady = WrapStagedSyncError("some nodes are not ready") ErrSomeNodesBlockHashFail = WrapStagedSyncError("some nodes failed to download block hashes") ErrMaxPeerHeightFail = WrapStagedSyncError("get max peer height failed") )
Errors ...
var Buckets = []string{ BlockHashesBucket, BeaconBlockHashesBucket, DownloadedBlocksBucket, BeaconDownloadedBlocksBucket, LastMileBlocksBucket, StageProgressBucket, }
var DefaultCleanUpOrder = CleanUpOrder{ Finish, LastMile, States, BlockBodies, BlockHashes, Heads, }
var DefaultForwardOrder = ForwardOrder{ Heads, BlockHashes, BlockBodies, States, LastMile, Finish, }
var DefaultRevertOrder = RevertOrder{ Finish, LastMile, States, BlockBodies, BlockHashes, Heads, }
Functions ¶
func CompareBlockByHash ¶
CompareBlockByHash compares two block by hash, it will be used in sort the blocks
func CompareSyncPeerConfigByblockHashes ¶
func CompareSyncPeerConfigByblockHashes(a *SyncPeerConfig, b *SyncPeerConfig) int
CompareSyncPeerConfigByblockHashes compares two SyncPeerConfig by blockHashes.
func CreateView ¶
func GetBucketName ¶
func GetHowManyMaxConsensus ¶
GetHowManyMaxConsensus will get the most common blocks and the first such blockID
func GetStageCleanUpProgress ¶
GetStageCleanUpProgress retrieves saved progress of given sync stage from the database
func GetStageID ¶
func GetStageID(stage SyncStageID, isBeacon bool, prune bool) []byte
func GetStageProgress ¶
GetStageProgress retrieves saved progress of given sync stage from the database
func GetSyncingPort ¶
GetSyncingPort returns the syncing port.
func NewSyncStatus ¶
func NewSyncStatus(role nodeconfig.Role) syncStatus
func ParseResult ¶
func ParseResult(res SyncCheckResult) (IsSynchronized bool, OtherHeight uint64, HeightDiff uint64)
func RlpDecodeBlockOrBlockWithSig ¶
RlpDecodeBlockOrBlockWithSig decodes payload to types.Block or BlockWithSig. Return the block with commitSig if set.
func SaveStageProgress ¶
SaveStageProgress saves progress of given sync stage
func WrapStagedSyncError ¶
WrapStagedSyncError wraps errors for staged sync and returns error object
Types ¶
type BlockWithSig ¶
BlockWithSig the serialization structure for request DownloaderRequest_BLOCKWITHSIG The block is encoded as block + commit signature
type CleanUpOrder ¶
type CleanUpOrder []SyncStageID
type CleanUpState ¶
type CleanUpState struct { ID SyncStageID ForwardProgress uint64 // progress of stage forward move CleanUpProgress uint64 // progress of stage prune move. after sync cycle it become equal to ForwardProgress by Done() method // contains filtered or unexported fields }
func (*CleanUpState) LogPrefix ¶
func (s *CleanUpState) LogPrefix() string
type ForwardOrder ¶
type ForwardOrder []SyncStageID
type RevertOrder ¶
type RevertOrder []SyncStageID
type RevertState ¶
type RevertState struct { ID SyncStageID // RevertPoint is the block to revert to. RevertPoint uint64 CurrentBlockNumber uint64 // If revert is caused by a bad block, this hash is not empty InvalidBlock common.Hash // contains filtered or unexported fields }
RevertState contains the information about revert.
func (*RevertState) Done ¶
func (u *RevertState) Done(db kv.Putter) error
Done updates the DB state of the stage.
func (*RevertState) LogPrefix ¶
func (u *RevertState) LogPrefix() string
type Reverter ¶
type Reverter interface { // RevertTo begins staged sync revert to the specified block. RevertTo(revertPoint uint64, invalidBlock common.Hash) }
Reverter allows the stage to cause an revert.
type Stage ¶
type Stage struct { // 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 SyncStageID // Handler handles the logic for the stage Handler StageHandler // 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 // 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.
func DefaultStages ¶
func DefaultStages(ctx context.Context, headsCfg StageHeadsCfg, blockHashesCfg StageBlockHashesCfg, bodiesCfg StageBodiesCfg, statesCfg StageStatesCfg, lastMileCfg StageLastMileCfg, finishCfg StageFinishCfg) []*Stage
type StageBlockHashes ¶
type StageBlockHashes struct {
// contains filtered or unexported fields
}
func NewStageBlockHashes ¶
func NewStageBlockHashes(cfg StageBlockHashesCfg) *StageBlockHashes
func (*StageBlockHashes) CleanUp ¶
func (bh *StageBlockHashes) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
func (*StageBlockHashes) Exec ¶
func (bh *StageBlockHashes) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, tx kv.RwTx) (err error)
func (*StageBlockHashes) Revert ¶
func (bh *StageBlockHashes) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
type StageBlockHashesCfg ¶
type StageBlockHashesCfg struct {
// contains filtered or unexported fields
}
func NewStageBlockHashesCfg ¶
type StageBodies ¶
type StageBodies struct {
// contains filtered or unexported fields
}
func NewStageBodies ¶
func NewStageBodies(cfg StageBodiesCfg) *StageBodies
func (*StageBodies) CleanUp ¶
func (b *StageBodies) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
func (*StageBodies) Exec ¶
func (b *StageBodies) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, tx kv.RwTx) (err error)
Exec progresses Bodies stage in the forward direction
func (*StageBodies) Revert ¶
func (b *StageBodies) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
type StageBodiesCfg ¶
type StageBodiesCfg struct {
// contains filtered or unexported fields
}
func NewStageBodiesCfg ¶
type StageFinish ¶
type StageFinish struct {
// contains filtered or unexported fields
}
func NewStageFinish ¶
func NewStageFinish(cfg StageFinishCfg) *StageFinish
func (*StageFinish) CleanUp ¶
func (finish *StageFinish) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
func (*StageFinish) Exec ¶
func (finish *StageFinish) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, tx kv.RwTx) error
func (*StageFinish) Revert ¶
func (finish *StageFinish) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
type StageFinishCfg ¶
type StageFinishCfg struct {
// contains filtered or unexported fields
}
func NewStageFinishCfg ¶
func NewStageFinishCfg(ctx context.Context, db kv.RwDB) StageFinishCfg
type StageHandler ¶
type StageHandler interface { // Exec is the execution function for the stage to move forward. // * firstCycle - is it the first cycle of syncing. // * invalidBlockRevert - whether the execution is to solve the invalid block // * s - is the current state of the stage and contains stage data. // * reverter - if the stage needs to cause reverting, `reverter` methods can be used. Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, tx kv.RwTx) error // Revert is the reverting logic of the stage. // * firstCycle - is it the first cycle of syncing. // * u - contains information about the revert itself. // * s - represents the state of this stage at the beginning of revert. Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) error // CleanUp is the execution function for the stage to prune old data. // * firstCycle - is it the first cycle of syncing. // * p - is the current state of the stage and contains stage data. CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) error }
type StageHeads ¶
type StageHeads struct {
// contains filtered or unexported fields
}
func NewStageHeads ¶
func NewStageHeads(cfg StageHeadsCfg) *StageHeads
func (*StageHeads) CleanUp ¶
func (heads *StageHeads) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
func (*StageHeads) Exec ¶
func (heads *StageHeads) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, tx kv.RwTx) error
func (*StageHeads) Revert ¶
func (heads *StageHeads) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
type StageHeadsCfg ¶
type StageHeadsCfg struct {
// contains filtered or unexported fields
}
func NewStageHeadersCfg ¶
func NewStageHeadersCfg(ctx context.Context, bc core.BlockChain, db kv.RwDB) StageHeadsCfg
type StageLastMile ¶
type StageLastMile struct {
// contains filtered or unexported fields
}
func NewStageLastMile ¶
func NewStageLastMile(cfg StageLastMileCfg) *StageLastMile
func (*StageLastMile) CleanUp ¶
func (lm *StageLastMile) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
func (*StageLastMile) Exec ¶
func (lm *StageLastMile) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, tx kv.RwTx) (err error)
func (*StageLastMile) Revert ¶
func (lm *StageLastMile) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
type StageLastMileCfg ¶
type StageLastMileCfg struct {
// contains filtered or unexported fields
}
func NewStageLastMileCfg ¶
func NewStageLastMileCfg(ctx context.Context, bc core.BlockChain, db kv.RwDB) StageLastMileCfg
type StageState ¶
type StageState struct { ID SyncStageID 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) CurrentStageProgress ¶
func (s *StageState) CurrentStageProgress(db kv.Getter) (uint64, error)
func (*StageState) LogPrefix ¶
func (s *StageState) LogPrefix() string
func (*StageState) StageProgress ¶
func (s *StageState) StageProgress(db kv.Getter, id SyncStageID) (uint64, error)
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) UpdateCleanUp ¶
func (s *StageState) UpdateCleanUp(db kv.Putter, blockNum uint64) error
type StageStates ¶
type StageStates struct {
// contains filtered or unexported fields
}
func NewStageStates ¶
func NewStageStates(cfg StageStatesCfg) *StageStates
func (*StageStates) CleanUp ¶
func (stg *StageStates) CleanUp(firstCycle bool, p *CleanUpState, tx kv.RwTx) (err error)
func (*StageStates) Exec ¶
func (stg *StageStates) Exec(firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, tx kv.RwTx) (err error)
Exec progresses States stage in the forward direction
func (*StageStates) Revert ¶
func (stg *StageStates) Revert(firstCycle bool, u *RevertState, s *StageState, tx kv.RwTx) (err error)
type StageStatesCfg ¶
type StageStatesCfg struct {
// contains filtered or unexported fields
}
func NewStageStatesCfg ¶
func NewStageStatesCfg(ctx context.Context, bc core.BlockChain, db kv.RwDB, logProgress bool) StageStatesCfg
type StagedSync ¶
type StagedSync struct { // if set to true, it will double check the block hashes // so, only blocks are sent by 2/3 of peers are considered as valid DoubleCheckBlockHashes bool // Maximum number of blocks per each cycle. if set to zero, all blocks will be // downloaded and synced in one full cycle. MaxBlocksPerSyncCycle uint64 // maximum number of blocks which can be downloaded in background. MaxBackgroundBlocks uint64 // max number of blocks to use a single transaction for staged sync MaxMemSyncCycleSize uint64 // number of blocks to build a batch and insert to chain in staged sync InsertChainBatchSize int // verify signature for all blocks regardless of height or batch size VerifyAllSig bool // batch size to verify header before insert to chain VerifyHeaderBatchSize uint64 // use mem db for staged sync, set to false to use disk UseMemDB bool // use turbo mode for staged sync StagedSyncTurboMode bool // log the full sync progress in console LogProgress bool // log every single process and error to help to debug the syncing // DebugMode is not accessible to the end user and is only an aid for development DebugMode bool // contains filtered or unexported fields }
func CreateStagedSync ¶
func CreateStagedSync( ip string, port string, peerHash [20]byte, bc core.BlockChain, dbDir string, role nodeconfig.Role, isExplorer bool, TurboMode bool, UseMemDB bool, doubleCheckBlockHashes bool, maxBlocksPerCycle uint64, maxBackgroundBlocks uint64, maxMemSyncCycleSize uint64, verifyAllSig bool, verifyHeaderBatchSize uint64, insertChainBatchSize int, logProgress bool, debugMode bool, ) (*StagedSync, error)
CreateStagedSync creates an instance of staged sync
func New ¶
func New(ctx context.Context, ip string, port string, peerHash [20]byte, bc core.BlockChain, role nodeconfig.Role, isBeacon bool, isExplorer bool, db kv.RwDB, stagesList []*Stage, revertOrder RevertOrder, pruneOrder CleanUpOrder, TurboMode bool, UseMemDB bool, doubleCheckBlockHashes bool, maxBlocksPerCycle uint64, maxBackgroundBlocks uint64, maxMemSyncCycleSize uint64, verifyAllSig bool, verifyHeaderBatchSize uint64, insertChainBatchSize int, logProgress bool, debugMode bool) *StagedSync
func (*StagedSync) AddLastMileBlock ¶
func (ss *StagedSync) AddLastMileBlock(block *types.Block)
AddLastMileBlock adds the latest a few block into queue for syncing only keep the latest blocks with size capped by LastMileBlocksSize
func (*StagedSync) AddNewBlock ¶
func (ss *StagedSync) AddNewBlock(peerHash []byte, block *types.Block)
AddNewBlock will add newly received block into state syncing queue
func (*StagedSync) Blockchain ¶
func (s *StagedSync) Blockchain() core.BlockChain
func (*StagedSync) CleanUpStageState ¶
func (s *StagedSync) CleanUpStageState(id SyncStageID, forwardProgress uint64, tx kv.Tx, db kv.RwDB) (*CleanUpState, error)
func (*StagedSync) Context ¶
func (s *StagedSync) Context() context.Context
func (*StagedSync) CreateSyncConfig ¶
func (ss *StagedSync) CreateSyncConfig(peers []p2p.Peer, shardID uint32, selfPeerID libp2p_peer.ID, waitForEachPeerToConnect bool) error
CreateSyncConfig creates SyncConfig for StateSync object.
func (*StagedSync) DB ¶
func (s *StagedSync) DB() kv.RwDB
func (*StagedSync) DisableAllStages ¶
func (s *StagedSync) DisableAllStages() []SyncStageID
DisableAllStages - including their reverts
func (*StagedSync) DisableStages ¶
func (s *StagedSync) DisableStages(ids ...SyncStageID)
func (*StagedSync) Done ¶
func (s *StagedSync) Done()
func (*StagedSync) EnableStages ¶
func (s *StagedSync) EnableStages(ids ...SyncStageID)
func (*StagedSync) GetActivePeerNumber ¶
func (ss *StagedSync) GetActivePeerNumber() int
GetActivePeerNumber returns the number of active peers
func (*StagedSync) GetDownloadedBlocks ¶
func (s *StagedSync) GetDownloadedBlocks() map[uint64][]byte
func (*StagedSync) GetMaxPeerHeight ¶
func (ss *StagedSync) GetMaxPeerHeight() (uint64, error)
GetMaxPeerHeight returns maximum block height of connected peers
func (*StagedSync) GetParsedSyncStatus ¶
func (ss *StagedSync) GetParsedSyncStatus() (IsSynchronized bool, OtherHeight uint64, HeightDiff uint64)
func (*StagedSync) GetParsedSyncStatusDoubleChecked ¶
func (ss *StagedSync) GetParsedSyncStatusDoubleChecked() (IsSynchronized bool, OtherHeight uint64, HeightDiff uint64)
func (*StagedSync) GetSyncStatus ¶
func (ss *StagedSync) GetSyncStatus() SyncCheckResult
GetSyncStatus get the last sync status for other modules (E.g. RPC, explorer). If the last sync result is not expired, return the sync result immediately. If the last result is expired, ask the remote DNS nodes for latest height and return the result.
func (*StagedSync) GetSyncStatusDoubleChecked ¶
func (ss *StagedSync) GetSyncStatusDoubleChecked() SyncCheckResult
GetSyncStatusDoubleChecked returns the sync status when enforcing a immediate query on DNS nodes with a double check to avoid false alarm.
func (*StagedSync) InitDownloadedBlocksMap ¶
func (s *StagedSync) InitDownloadedBlocksMap() error
func (*StagedSync) IsAfter ¶
func (s *StagedSync) IsAfter(stage1, stage2 SyncStageID) bool
IsAfter returns true if stage1 goes after stage2 in staged sync
func (*StagedSync) IsBeacon ¶
func (s *StagedSync) IsBeacon() bool
func (*StagedSync) IsBefore ¶
func (s *StagedSync) IsBefore(stage1, stage2 SyncStageID) bool
IsBefore returns true if stage1 goes before stage2 in staged sync
func (*StagedSync) IsDone ¶
func (s *StagedSync) IsDone() bool
func (*StagedSync) IsExplorer ¶
func (s *StagedSync) IsExplorer() bool
func (*StagedSync) IsSameBlockchainHeight ¶
func (ss *StagedSync) IsSameBlockchainHeight(bc core.BlockChain) (uint64, bool)
IsSameBlockchainHeight checks whether the node is out of sync from other peers
func (*StagedSync) IsSynchronized ¶
func (ss *StagedSync) IsSynchronized() bool
func (*StagedSync) Len ¶
func (s *StagedSync) Len() int
func (*StagedSync) LogPrefix ¶
func (s *StagedSync) LogPrefix() string
func (*StagedSync) NewRevertState ¶
func (s *StagedSync) NewRevertState(id SyncStageID, revertPoint, currentProgress uint64) *RevertState
func (*StagedSync) NextStage ¶
func (s *StagedSync) NextStage()
func (*StagedSync) PrevRevertPoint ¶
func (s *StagedSync) PrevRevertPoint() *uint64
func (*StagedSync) RegisterNodeInfo ¶
func (ss *StagedSync) RegisterNodeInfo() int
RegisterNodeInfo will register node to peers to accept future new block broadcasting return number of successful registration
func (*StagedSync) RevertTo ¶
func (s *StagedSync) RevertTo(revertPoint uint64, invalidBlock common.Hash)
RevertTo reverts the stage to a specific height
func (*StagedSync) SetCurrentStage ¶
func (s *StagedSync) SetCurrentStage(id SyncStageID) error
func (*StagedSync) StageState ¶
func (s *StagedSync) StageState(stage SyncStageID, tx kv.Tx, db kv.RwDB) (*StageState, error)
func (*StagedSync) SyncLoop ¶
func (s *StagedSync) SyncLoop(bc core.BlockChain, isBeacon bool, consensus *consensus.Consensus, loopMinTime time.Duration)
SyncLoop will keep syncing with peers until catches up
func (*StagedSync) UpdateBlockAndStatus ¶
func (ss *StagedSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChain) error
UpdateBlockAndStatus updates block and its status in db
type SyncBlockTask ¶
type SyncBlockTask struct {
// contains filtered or unexported fields
}
SyncBlockTask is the task struct to sync a specific block.
type SyncCheckResult ¶
type SyncConfig ¶
type SyncConfig struct {
// contains filtered or unexported fields
}
SyncConfig contains an array of SyncPeerConfig.
func (*SyncConfig) AddPeer ¶
func (sc *SyncConfig) AddPeer(peer *SyncPeerConfig)
AddPeer adds the given sync peer.
func (*SyncConfig) CloseConnections ¶
func (sc *SyncConfig) CloseConnections()
CloseConnections close grpc connections for state sync clients
func (*SyncConfig) FindPeerByHash ¶
func (sc *SyncConfig) FindPeerByHash(peerHash []byte) *SyncPeerConfig
FindPeerByHash returns the peer with the given hash, or nil if not found.
func (*SyncConfig) ForEachPeer ¶
func (sc *SyncConfig) ForEachPeer(f func(peer *SyncPeerConfig) (brk bool))
ForEachPeer calls the given function with each peer. It breaks the iteration iff the function returns true.
func (*SyncConfig) GetBlockHashesConsensusAndCleanUp ¶
func (sc *SyncConfig) GetBlockHashesConsensusAndCleanUp(bgMode bool) error
GetBlockHashesConsensusAndCleanUp selects the most common peer config based on their block hashes to download/sync. Note that choosing the most common peer config does not guarantee that the blocks to be downloaded are the correct ones. The subsequent node syncing steps of verifying the block header chain will give such confirmation later. If later block header verification fails with the sync peer config chosen here, the entire sync loop gets retried with a new peer set.
func (*SyncConfig) InitForTesting ¶
func (sc *SyncConfig) InitForTesting(client *downloader.Client, blockHashes [][]byte)
InitForTesting used for testing.
func (*SyncConfig) RemovePeer ¶
func (sc *SyncConfig) RemovePeer(peer *SyncPeerConfig, reason string)
RemovePeer removes a peer from SyncConfig
func (*SyncConfig) ReplacePeerWithReserved ¶
func (sc *SyncConfig) ReplacePeerWithReserved(peer *SyncPeerConfig, reason string)
ReplacePeerWithReserved tries to replace a peer from reserved peer list
func (*SyncConfig) SelectRandomPeers ¶
func (sc *SyncConfig) SelectRandomPeers(peers []p2p.Peer, randSeed int64) int
SelectRandomPeers limits number of peers to release some server end sources.
type SyncPeerConfig ¶
type SyncPeerConfig struct {
// contains filtered or unexported fields
}
SyncPeerConfig is peer config to sync.
func (*SyncPeerConfig) AddFailedTime ¶
func (peerConfig *SyncPeerConfig) AddFailedTime(maxFailures uint64) (mustStop bool)
AddFailedTime considers one more peer failure and checks against max allowed failed times
func (*SyncPeerConfig) GetBlocks ¶
func (peerConfig *SyncPeerConfig) GetBlocks(hashes [][]byte) ([][]byte, error)
GetBlocks gets blocks by calling grpc request to the corresponding peer.
func (*SyncPeerConfig) GetClient ¶
func (peerConfig *SyncPeerConfig) GetClient() *downloader.Client
GetClient returns client pointer of downloader.Client
func (*SyncPeerConfig) IsEqual ¶
func (peerConfig *SyncPeerConfig) IsEqual(pc2 *SyncPeerConfig) bool
IsEqual checks the equality between two sync peers
type SyncStageID ¶
type SyncStageID string
SyncStageID represents the stages in the Mode.StagedSync mode
const ( Heads SyncStageID = "Heads" // Heads are downloaded BlockHashes SyncStageID = "BlockHashes" // block hashes are downloaded from peers BlockBodies SyncStageID = "BlockBodies" // Block bodies are downloaded, TxHash and UncleHash are getting verified States SyncStageID = "States" // will construct most recent state from downloaded blocks LastMile SyncStageID = "LastMile" // update blocks after sync and update last mile blocks as well Finish SyncStageID = "Finish" // Nominal stage after all other stages )