legacysync

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: LGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
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

	//LoopMinTime sync loop must take at least as this value, otherwise it waits for it
	LoopMinTime = 0
)

Constants for syncing.

Variables

View Source
var (
	ErrRegistrationFail      = errors.New("[SYNC]: registration failed")
	ErrGetBlock              = errors.New("[SYNC]: get block failed")
	ErrGetBlockHash          = errors.New("[SYNC]: get blockhash failed")
	ErrProcessStateSync      = errors.New("[SYNC]: get blockhash failed")
	ErrGetConsensusHashes    = errors.New("[SYNC]: get consensus hashes failed")
	ErrGenStateSyncTaskQueue = errors.New("[SYNC]: generate state sync task queue failed")
	ErrDownloadBlocks        = errors.New("[SYNC]: get download blocks failed")
	ErrUpdateBlockAndStatus  = errors.New("[SYNC]: update block and status failed")
	ErrGenerateNewState      = errors.New("[SYNC]: get generate new state failed")
)

Errors ...

Functions

func CompareBlockByHash

func CompareBlockByHash(a *types.Block, b *types.Block) int

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 GetHowManyMaxConsensus

func GetHowManyMaxConsensus(blocks []*types.Block) (int, int)

GetHowManyMaxConsensus will get the most common blocks and the first such blockID

func GetSyncingPort

func GetSyncingPort(nodePort string) string

GetSyncingPort returns the syncing port.

func ParseResult

func ParseResult(res SyncCheckResult) (IsSynchronized bool, OtherHeight uint64, HeightDiff uint64)

func ProcessStateSync

func ProcessStateSync(syncConfig *SyncConfig, heights []uint64, bc core.BlockChain) error

ProcessStateSync processes state sync from the blocks received but not yet processed so far

func RlpDecodeBlockOrBlockWithSig

func RlpDecodeBlockOrBlockWithSig(payload []byte) (*types.Block, error)

RlpDecodeBlockOrBlockWithSig decode payload to types.Block or BlockWithSig. Return the block with commitSig if set.

Types

type BlockWithSig

type BlockWithSig struct {
	Block              *types.Block
	CommitSigAndBitmap []byte
}

BlockWithSig the serialization structure for request DownloaderRequest_BLOCKWITHSIG The block is encoded as block + commit signature

type EpochSync

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

func (*EpochSync) CreateSyncConfig

func (ss *EpochSync) CreateSyncConfig(peers []p2p.Peer, shardID uint32, selfPeerID libp2p_peer.ID, waitForEachPeerToConnect bool) error

CreateSyncConfig creates SyncConfig for StateSync object.

func (*EpochSync) GetActivePeerNumber

func (ss *EpochSync) GetActivePeerNumber() int

GetActivePeerNumber returns the number of active peers

func (*EpochSync) GetSyncStatus

func (ss *EpochSync) 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 (*EpochSync) SyncLoop

func (ss *EpochSync) SyncLoop(bc core.BlockChain, consensus *consensus.Consensus) time.Duration

SyncLoop will keep syncing with peers until catches up

type StateSync

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

StateSync is the struct that implements StateSyncInterface.

func CreateStateSync

func CreateStateSync(bc blockChain, ip string, port string, peerHash [20]byte, peerID libp2p_peer.ID, isExplorer bool, role nodeconfig.Role) *StateSync

CreateStateSync returns the implementation of StateSyncInterface interface.

func (*StateSync) AddLastMileBlock

func (ss *StateSync) AddLastMileBlock(block *types.Block)

AddLastMileBlock add the latest a few block into queue for syncing only keep the latest blocks with size capped by LastMileBlocksSize

func (*StateSync) AddNewBlock

func (ss *StateSync) AddNewBlock(peerHash []byte, block *types.Block)

AddNewBlock will add newly received block into state syncing queue

func (*StateSync) CreateSyncConfig

func (ss *StateSync) CreateSyncConfig(peers []p2p.Peer, shardID uint32, selfPeerID libp2p_peer.ID, waitForEachPeerToConnect bool) error

CreateSyncConfig creates SyncConfig for StateSync object.

func (*StateSync) GetActivePeerNumber

func (ss *StateSync) GetActivePeerNumber() int

GetActivePeerNumber returns the number of active peers

func (*StateSync) GetMaxPeerHeight

func (ss *StateSync) GetMaxPeerHeight() (uint64, error)

GetMaxPeerHeight ..

func (*StateSync) GetParsedSyncStatus

func (ss *StateSync) GetParsedSyncStatus() (IsSynchronized bool, OtherHeight uint64, HeightDiff uint64)

func (*StateSync) GetParsedSyncStatusDoubleChecked

func (ss *StateSync) GetParsedSyncStatusDoubleChecked() (IsSynchronized bool, OtherHeight uint64, HeightDiff uint64)

func (*StateSync) GetSyncStatus

func (ss *StateSync) 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 (*StateSync) GetSyncStatusDoubleChecked

func (ss *StateSync) GetSyncStatusDoubleChecked() SyncCheckResult

GetSyncStatusDoubleChecked return the sync status when enforcing a immediate query on DNS nodes with a double check to avoid false alarm.

func (*StateSync) IntoEpochSync

func (ss *StateSync) IntoEpochSync() *EpochSync

func (*StateSync) IsSameBlockchainHeight

func (ss *StateSync) IsSameBlockchainHeight(bc core.BlockChain) (uint64, bool)

IsSameBlockchainHeight checks whether the node is out of sync from other peers

func (*StateSync) IsSynchronized

func (ss *StateSync) IsSynchronized() bool

func (*StateSync) ProcessStateSync

func (ss *StateSync) ProcessStateSync(startHash []byte, size uint32, bc core.BlockChain) error

ProcessStateSync processes state sync from the blocks received but not yet processed so far

func (*StateSync) RegisterNodeInfo

func (ss *StateSync) RegisterNodeInfo() int

RegisterNodeInfo will register node to peers to accept future new block broadcasting return number of successful registration

func (*StateSync) SyncLoop

func (ss *StateSync) SyncLoop(bc core.BlockChain, isBeacon bool, consensus *consensus.Consensus, loopMinTime time.Duration)

SyncLoop will keep syncing with peers until catches up

func (*StateSync) UpdateBlockAndStatus

func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChain) error

UpdateBlockAndStatus ...

type SyncBlockTask

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

SyncBlockTask is the task struct to sync a specific block.

type SyncCheckResult

type SyncCheckResult struct {
	IsSynchronized bool
	OtherHeight    uint64
	HeightDiff     uint64
}

type SyncConfig

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

SyncConfig contains an array of SyncPeerConfig.

func NewSyncConfig

func NewSyncConfig(shardID uint32, selfPeerID libp2p_peer.ID, peers []*SyncPeerConfig) *SyncConfig

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

func (sc *SyncConfig) GetPeers() []*SyncPeerConfig

func (*SyncConfig) InitForTesting

func (sc *SyncConfig) InitForTesting(client *downloader.Client, blockHashes [][]byte)

InitForTesting used for testing.

func (*SyncConfig) PeersCount

func (sc *SyncConfig) PeersCount() int

func (*SyncConfig) RemovePeer

func (sc *SyncConfig) RemovePeer(peer *SyncPeerConfig, reason string)

RemovePeer removes a peer from SyncConfig

func (*SyncConfig) ShardID

func (sc *SyncConfig) ShardID() uint32

type SyncPeerConfig

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

SyncPeerConfig is peer config to sync.

func CreateTestSyncPeerConfig

func CreateTestSyncPeerConfig(client *downloader.Client, blockHashes [][]byte) *SyncPeerConfig

CreateTestSyncPeerConfig used for testing.

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

func (*SyncPeerConfig) String

func (peerConfig *SyncPeerConfig) String() interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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