Documentation ¶
Index ¶
- Variables
- type BlockTree
- func (bt *BlockTree) AddBlock(header *types.Header, arrivalTime time.Time) (err error)
- func (bt *BlockTree) BestBlockHash() Hash
- func (bt *BlockTree) DeepCopy() *BlockTree
- func (bt *BlockTree) GetAllBlocks() []Hash
- func (bt *BlockTree) GetAllBlocksAtNumber(hash common.Hash) (hashes []common.Hash)
- func (bt *BlockTree) GetAllDescendants(hash common.Hash) ([]Hash, error)
- func (bt *BlockTree) GetArrivalTime(hash common.Hash) (time.Time, error)
- func (bt *BlockTree) GetBlockRuntime(hash common.Hash) (runtime.Instance, error)
- func (bt *BlockTree) GetHashByNumber(num uint) (common.Hash, error)
- func (bt *BlockTree) IsDescendantOf(parent, child Hash) (bool, error)
- func (bt *BlockTree) Leaves() []Hash
- func (bt *BlockTree) LowestCommonAncestor(a, b Hash) (Hash, error)
- func (bt *BlockTree) Prune(finalised Hash) (pruned []Hash)
- func (bt *BlockTree) Range(startHash common.Hash, endHash common.Hash) (hashes []common.Hash, err error)
- func (bt *BlockTree) RangeInMemory(startHash common.Hash, endHash common.Hash) (hashes []common.Hash, err error)
- func (bt *BlockTree) StoreRuntime(hash common.Hash, instance runtime.Instance)
- func (bt *BlockTree) String() string
- type Hash
Constants ¶
This section is empty.
Variables ¶
var ( ErrParentNotFound = errors.New("cannot find parent block in blocktree") // ErrBlockExists is returned if attempting to re-add a block ErrBlockExists = errors.New("cannot add block to blocktree that already exists") // ErrStartNodeNotFound is returned if the start of a subchain does not exist ErrStartNodeNotFound = errors.New("start node does not exist") // ErrEndNodeNotFound is returned if the end of a subchain does not exist ErrEndNodeNotFound = errors.New("end node does not exist") ErrKeyNotFound = errors.New("key not found") // ErrNilDescendant is returned if calling subchain with a nil node ErrNilDescendant = errors.New("descendant node is nil") // ErrDescendantNotFound is returned if a descendant in a subchain cannot be found ErrDescendantNotFound = errors.New("could not find descendant node") // ErrNodeNotFound is returned if a node with given hash doesn't exist ErrNodeNotFound = errors.New("could not find node") // ErrFailedToGetRuntime is returned when runtime doesn't exist in blockTree for corresponding block. ErrFailedToGetRuntime = errors.New("failed to get runtime instance") // ErrNumGreaterThanHighest is returned when attempting to get a // hash by number that is higher than any in the blocktree ErrNumGreaterThanHighest = errors.New("cannot find node with number greater than highest in blocktree") // ErrNumLowerThanRoot is returned when attempting to get a hash by number that is lower than the root node ErrNumLowerThanRoot = errors.New("cannot find node with number lower than root node") // ErrNoCommonAncestor is returned when a common ancestor cannot be found between two nodes ErrNoCommonAncestor = errors.New("no common ancestor between two nodes") )
ErrParentNotFound is returned if the parent hash does not exist in the blocktree
var ErrNilBlockInRange = errors.New("nil block in range")
var (
ErrRuntimeNotFound = errors.New("runtime not found")
)
var ErrStartGreaterThanEnd = errors.New("start greater than end")
Functions ¶
This section is empty.
Types ¶
type BlockTree ¶
BlockTree represents the current state with all possible blocks
func NewBlockTreeFromRoot ¶ added in v0.3.1
NewBlockTreeFromRoot initialises a blocktree with a root block. The root block is always the most recently finalised block (ie the genesis block if the node is just starting.)
func NewEmptyBlockTree ¶
func NewEmptyBlockTree() *BlockTree
NewEmptyBlockTree creates a BlockTree with a nil head
func (*BlockTree) AddBlock ¶
AddBlock inserts the block as child of its parent node Note: Assumes block has no children
func (*BlockTree) BestBlockHash ¶ added in v0.7.0
BestBlockHash returns the hash of the block that is considered "best" based on the fork-choice rule. It returns the head of the chain with the most primary blocks. If there are multiple chains with the same number of primaries, it returns the one with the highest head number. If there are multiple chains with the same number of primaries and the same height, it returns the one with the head block that arrived the earliest.
func (*BlockTree) GetAllBlocks ¶ added in v0.2.0
GetAllBlocks returns all the blocks in the tree
func (*BlockTree) GetAllBlocksAtNumber ¶ added in v0.7.0
GetAllBlocksAtNumber will return all blocks hashes with the number of the given hash plus one. To find all blocks at a number matching a certain block, pass in that block's parent hash
func (*BlockTree) GetAllDescendants ¶ added in v0.7.0
GetAllDescendants returns all block hashes that are descendants of the given block hash (including itself).
func (*BlockTree) GetArrivalTime ¶ added in v0.7.0
GetArrivalTime returns the arrival time of a block
func (*BlockTree) GetBlockRuntime ¶ added in v0.7.0
GetBlockRuntime returns the runtime corresponding to the given block hash. If there is no instance for the given block hash it will lookup an instance of an ancestor and return it.
func (*BlockTree) GetHashByNumber ¶ added in v0.7.0
GetHashByNumber returns the block hash with the given number that is on the best chain. If the number is lower or higher than the numbers in the blocktree, an error is returned.
func (*BlockTree) IsDescendantOf ¶
IsDescendantOf returns true if the child is a descendant of parent, false otherwise. it returns an error if either the child or parent are not in the blocktree. If parent and child are the same, we return true.
func (*BlockTree) LowestCommonAncestor ¶ added in v0.7.0
LowestCommonAncestor returns the lowest common ancestor block hash between two blocks in the tree.
func (*BlockTree) Prune ¶ added in v0.2.0
Prune sets the given hash as the new blocktree root, removing all nodes that are not the new root node or its descendant It returns an array of hashes that have been pruned
func (*BlockTree) Range ¶ added in v0.8.0
func (bt *BlockTree) Range(startHash common.Hash, endHash common.Hash) (hashes []common.Hash, err error)
Range will return all the blocks between the start and end hash inclusive. If the end hash does not exist in the blocktree then an error is returned. If the start hash does not exist in the blocktree then we will return all blocks between the end and the blocktree root inclusive
func (*BlockTree) RangeInMemory ¶ added in v0.8.0
func (bt *BlockTree) RangeInMemory(startHash common.Hash, endHash common.Hash) (hashes []common.Hash, err error)
RangeInMemory returns the path from the node with Hash start to the node with Hash end. If the end hash does not exist in the blocktree then an error is returned. Different from blocktree.Range, if the start node is not found in the in memory blocktree
func (*BlockTree) StoreRuntime ¶ added in v0.7.0
StoreRuntime stores the runtime for corresponding block hash.