statesync

package
v0.98.4-pre Latest Latest
Warning

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

Go to latest
Published: May 7, 2022 License: MIT Imports: 15 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func TemporaryPrefix added in v0.98.0

func TemporaryPrefix(currPrefix storage.KeyPrefix) storage.KeyPrefix

TemporaryPrefix accepts current storage prefix and returns prefix to use for storing intermediate items during synchronization.

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) AddBlock

func (s *Module) AddBlock(block *block.Block) error

AddBlock verifies and saves block skipping executable scripts.

func (*Module) AddHeaders

func (s *Module) AddHeaders(hdrs ...*block.Header) error

AddHeaders validates and adds specified headers to the chain.

func (*Module) AddMPTNodes

func (s *Module) AddMPTNodes(nodes [][]byte) error

AddMPTNodes tries to add provided set of MPT nodes to the MPT billet if they are not yet collected.

func (*Module) BlockHeight

func (s *Module) BlockHeight() uint32

BlockHeight returns index of the last stored block.

func (*Module) GetUnknownMPTNodesBatch

func (s *Module) GetUnknownMPTNodesBatch(limit int) []util.Uint256

GetUnknownMPTNodesBatch returns set of currently unknown MPT nodes (`limit` at max).

func (*Module) Init

func (s *Module) Init(currChainHeight uint32) error

Init initializes state sync module for the current chain's height with given callback for MPT nodes requests.

func (*Module) IsActive

func (s *Module) IsActive() bool

IsActive tells whether state sync module is on and still gathering state synchronisation data (headers, blocks or MPT nodes).

func (*Module) IsInitialized

func (s *Module) IsInitialized() bool

IsInitialized tells whether state sync module does not require initialization. If `false` is returned then Init can be safely called.

func (*Module) NeedHeaders

func (s *Module) NeedHeaders() bool

NeedHeaders tells whether the module hasn't completed headers synchronisation.

func (*Module) NeedMPTNodes

func (s *Module) NeedMPTNodes() bool

NeedMPTNodes returns whether the module hasn't completed MPT synchronisation.

func (*Module) Traverse

func (s *Module) Traverse(root util.Uint256, process func(node mpt.Node, nodeBytes []byte) bool) error

Traverse traverses local MPT nodes starting from the specified root down to its children calling `process` for each serialised node until stop condition is satisfied.

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 NewPool

func NewPool() *Pool

NewPool returns new MPT node hashes pool.

func (*Pool) Add

func (mp *Pool) Add(hash util.Uint256, path []byte)

Add adds path to the set of paths for the specified node.

func (*Pool) ContainsKey

func (mp *Pool) ContainsKey(hash util.Uint256) bool

ContainsKey checks if MPT node with the specified hash is in the Pool.

func (*Pool) Count

func (mp *Pool) Count() int

Count returns the number of nodes in the pool.

func (*Pool) GetAll

func (mp *Pool) GetAll() map[util.Uint256][][]byte

GetAll returns all MPT nodes with the corresponding paths from the pool.

func (*Pool) GetBatch

func (mp *Pool) GetBatch(limit int) []util.Uint256

GetBatch returns set of unknown MPT nodes hashes (`limit` at max).

func (*Pool) Remove

func (mp *Pool) Remove(hash util.Uint256)

Remove removes MPT node from the pool by the specified hash.

func (*Pool) TryGet

func (mp *Pool) TryGet(hash util.Uint256) ([][]byte, bool)

TryGet returns a set of MPT paths for the specified HashNode.

func (*Pool) Update

func (mp *Pool) Update(remove map[util.Uint256][][]byte, add map[util.Uint256][][]byte)

Update is an atomic operation and removes/adds specified nodes from/to the pool.

Jump to

Keyboard shortcuts

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