Documentation ¶
Overview ¶
Package statesync implements module for the P2P state synchronisation process. The module manages state synchronisation for non-archival nodes which are joining the network and don't have the ability to resync from the genesis block.
Given the currently available state synchronisation point P, sate sync process includes the following stages:
1. Fetching headers starting from height 0 up to P+1. 2. Fetching MPT nodes for height P stating from the corresponding state root. 3. Fetching blocks starting from height P-MaxTraceableBlocks (or 0) up to P.
Steps 2 and 3 are being performed in parallel. Once all the data are collected and stored in the db, an atomic state jump is occurred to the state sync point P. Further node operation process is performed using standard sync mechanism until the node reaches synchronised state.
Index ¶
- func TemporaryPrefix(currPrefix storage.KeyPrefix) storage.KeyPrefix
- type Ledger
- type Module
- func (s *Module) AddBlock(block *block.Block) error
- func (s *Module) AddHeaders(hdrs ...*block.Header) error
- func (s *Module) AddMPTNodes(nodes [][]byte) error
- func (s *Module) BlockHeight() uint32
- func (s *Module) GetUnknownMPTNodesBatch(limit int) []util.Uint256
- func (s *Module) Init(currChainHeight uint32) error
- func (s *Module) IsActive() bool
- func (s *Module) IsInitialized() bool
- func (s *Module) NeedHeaders() bool
- func (s *Module) NeedMPTNodes() bool
- func (s *Module) Traverse(root util.Uint256, process func(node mpt.Node, nodeBytes []byte) bool) error
- type Pool
- func (mp *Pool) Add(hash util.Uint256, path []byte)
- func (mp *Pool) ContainsKey(hash util.Uint256) bool
- func (mp *Pool) Count() int
- func (mp *Pool) GetAll() map[util.Uint256][][]byte
- func (mp *Pool) GetBatch(limit int) []util.Uint256
- func (mp *Pool) Remove(hash util.Uint256)
- func (mp *Pool) TryGet(hash util.Uint256) ([][]byte, bool)
- func (mp *Pool) Update(remove map[util.Uint256][][]byte, add map[util.Uint256][][]byte)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Ledger ¶ added in v0.98.1
type Ledger interface { AddHeaders(...*block.Header) error BlockHeight() uint32 GetConfig() config.ProtocolConfiguration GetHeader(hash util.Uint256) (*block.Header, error) GetHeaderHash(int) util.Uint256 HeaderHeight() uint32 }
Ledger is the interface required from Blockchain for Module to operate.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module represents state sync module and aimed to gather state-related data to perform an atomic state jump.
func NewModule ¶
func NewModule(bc Ledger, stateMod *stateroot.Module, log *zap.Logger, s *dao.Simple, jumpCallback func(p uint32) error) *Module
NewModule returns new instance of statesync module.
func (*Module) AddHeaders ¶
AddHeaders validates and adds specified headers to the chain.
func (*Module) AddMPTNodes ¶
AddMPTNodes tries to add provided set of MPT nodes to the MPT billet if they are not yet collected.
func (*Module) BlockHeight ¶
BlockHeight returns index of the last stored block.
func (*Module) GetUnknownMPTNodesBatch ¶
GetUnknownMPTNodesBatch returns set of currently unknown MPT nodes (`limit` at max).
func (*Module) Init ¶
Init initializes state sync module for the current chain's height with given callback for MPT nodes requests.
func (*Module) IsActive ¶
IsActive tells whether state sync module is on and still gathering state synchronisation data (headers, blocks or MPT nodes).
func (*Module) IsInitialized ¶
IsInitialized tells whether state sync module does not require initialization. If `false` is returned then Init can be safely called.
func (*Module) NeedHeaders ¶
NeedHeaders tells whether the module hasn't completed headers synchronisation.
func (*Module) NeedMPTNodes ¶
NeedMPTNodes returns whether the module hasn't completed MPT synchronisation.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool stores unknown MPT nodes along with the corresponding paths (single node is allowed to have multiple MPT paths).
func (*Pool) ContainsKey ¶
ContainsKey checks if MPT node with the specified hash is in the Pool.