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, the state sync process includes the following stages:
1. Fetching headers starting from height 0 up to P+1. 2. Fetching state data for height P, starting from the corresponding state root. It can either be raw contract storage items or MPT nodes depending on the StorageSyncMode. 3. Fetching blocks starting from height P-MaxTraceableBlocks(P) (or 0) up to P.
All steps are being performed sequentially. 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) AddContractStorageItems(kvs []storage.KeyValue, syncHeight uint32, expectedRoot util.Uint256) error
- func (s *Module) AddHeaders(hdrs ...*block.Header) error
- func (s *Module) AddMPTNodes(nodes [][]byte) error
- func (s *Module) BlockHeight() uint32
- func (s *Module) GetConfig() config.Blockchain
- func (s *Module) GetLastStoredKey() []byte
- func (s *Module) GetStateSyncPoint() uint32
- func (s *Module) GetUnknownMPTNodesBatch(limit int) []util.Uint256
- func (s *Module) HeaderHeight() uint32
- func (s *Module) Init(currChainHeight uint32) error
- func (s *Module) IsActive() bool
- func (s *Module) IsInitialized() bool
- func (s *Module) NeedBlocks() bool
- func (s *Module) NeedHeaders() bool
- func (s *Module) NeedStorageData() bool
- func (s *Module) SetOnStageChanged(cb func())
- 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)
- type StorageSyncMode
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
IsHardforkEnabled(hf *config.Hardfork, blockHeight uint32) bool
GetConfig() config.Blockchain
GetHeader(hash util.Uint256) (*block.Header, error)
GetHeaderHash(uint32) 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) AddContractStorageItems ¶ added in v0.110.0
func (s *Module) AddContractStorageItems(kvs []storage.KeyValue, syncHeight uint32, expectedRoot util.Uint256) error
AddContractStorageItems adds a batch of key-value pairs for storage-based sync.
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. It's a no-op to call this method until MPT is in sync since block height initialization requires access to the node state at state synchronisation point.
func (*Module) GetConfig ¶ added in v0.108.0
func (s *Module) GetConfig() config.Blockchain
GetConfig returns current blockchain configuration.
func (*Module) GetLastStoredKey ¶ added in v0.110.0
GetLastStoredKey returns the last processed storage key iff operating in ContractStorageBased mode.
func (*Module) GetStateSyncPoint ¶ added in v0.110.0
GetStateSyncPoint returns the current state synchronisation point P.
func (*Module) GetUnknownMPTNodesBatch ¶
GetUnknownMPTNodesBatch returns set of currently unknown MPT nodes (`limit` at max).
func (*Module) HeaderHeight ¶ added in v0.108.0
HeaderHeight returns the height of the latest stored header.
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) NeedBlocks ¶ added in v0.108.0
NeedBlocks returns whether the module hasn't completed blocks synchronisation.
func (*Module) NeedHeaders ¶
NeedHeaders tells whether the module hasn't completed headers synchronisation.
func (*Module) NeedStorageData ¶ added in v0.110.0
NeedStorageData returns whether the module hasn't completed contract storage state synchronization.
func (*Module) SetOnStageChanged ¶ added in v0.108.0
func (s *Module) SetOnStageChanged(cb func())
SetOnStageChanged sets callback that is triggered whenever the sync stage changes.
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.
type StorageSyncMode ¶ added in v0.110.0
type StorageSyncMode byte
StorageSyncMode is an enum that denotes the operation mode of contract storage synchronisation. It can be either ContractStorageBased or MPTBased.
const ( // MPTBased denotes that the Module recovers contract storage state based on // the MPT state at the state synchronisation point. MPTBased StorageSyncMode = iota // ContractStorageBased denotes that the Module recovers contract storage state // based on the raw contract storage items at the state synchronisation point. ContractStorageBased )
func (StorageSyncMode) String ¶ added in v0.110.0
func (i StorageSyncMode) String() string