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) 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) HighestCommonAncestor(a, b Hash) (Hash, error)
- func (bt *BlockTree) IsDescendantOf(parent, child Hash) (bool, error)
- func (bt *BlockTree) Leaves() []Hash
- func (bt *BlockTree) Prune(finalised Hash) (pruned []Hash)
- func (bt *BlockTree) StoreRuntime(hash common.Hash, in runtime.Instance)
- func (bt *BlockTree) String() string
- func (bt *BlockTree) SubBlockchain(start, end Hash) ([]Hash, error)
- 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") // ErrNilDatabase is returned in the database is nil ErrNilDatabase = errors.New("blocktree database is nil") // 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
Functions ¶
This section is empty.
Types ¶
type BlockTree ¶
BlockTree represents the current state with all possible blocks
func NewBlockTreeFromRoot ¶
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 ¶
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 ¶
GetAllBlocks returns all the blocks in the tree
func (*BlockTree) GetAllBlocksAtNumber ¶
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) GetArrivalTime ¶
GetArrivalTime returns the arrival time of a block
func (*BlockTree) GetBlockRuntime ¶
GetBlockRuntime returns block runtime for corresponding block hash.
func (*BlockTree) GetHashByNumber ¶
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) HighestCommonAncestor ¶
HighestCommonAncestor returns the highest block that is a Ancestor to both a and b
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.
func (*BlockTree) Prune ¶
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) StoreRuntime ¶
StoreRuntime stores the runtime for corresponding block hash.