Documentation
¶
Index ¶
- Variables
- type BlockTree
- func (bt *BlockTree) AddBlock(block *types.Block, arrivalTime uint64) error
- func (bt *BlockTree) Decode(in []byte) error
- func (bt *BlockTree) DeepestBlockHash() Hash
- func (bt *BlockTree) Encode() ([]byte, error)
- func (bt *BlockTree) GenesisHash() Hash
- func (bt *BlockTree) GetAllBlocksAtDepth(hash common.Hash) []common.Hash
- 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) Load() error
- func (bt *BlockTree) Store() error
- func (bt *BlockTree) String() string
- func (bt *BlockTree) SubBlockchain(start Hash, end Hash) ([]Hash, error)
- type Hash
Constants ¶
This section is empty.
Variables ¶
var ErrBlockExists = errors.New("cannot add block to blocktree that already exists")
ErrBlockExists is returned if attempting to re-add a block
var ErrDescendantNotFound = errors.New("could not find descendant node")
ErrDescendantNotFound is returned if a descendant in a subchain cannot be found
var ErrEndNodeNotFound = errors.New("end node does not exist")
ErrEndNodeNotFound is returned if the end of a subchain does not exist
var ErrNilDatabase = errors.New("blocktree database is nil")
ErrNilDatabase is returned in the database is nil
var ErrNilDescendant = errors.New("descendant node is nil")
ErrNilDescendant is returned if calling subchain with a nil node
var ErrNodeNotFound = errors.New("could not find node")
ErrNodeNotFound is returned if a node with given hash doesn't exist
var ErrParentNotFound = errors.New("cannot find parent block in blocktree")
ErrParentNotFound is returned if the parent hash does not exist in the blocktree
var ErrStartNodeNotFound = errors.New("start node does not exist")
ErrStartNodeNotFound is returned if the start of a subchain does not exist
Functions ¶
This section is empty.
Types ¶
type BlockTree ¶
type BlockTree struct {
// contains filtered or unexported fields
}
BlockTree represents the current state with all possible blocks
func NewBlockTreeFromGenesis ¶
NewBlockTreeFromGenesis initializes a blocktree with a genesis block. Currently passes in arrival time as a parameter instead of setting it as time of instantiation
func NewEmptyBlockTree ¶
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) DeepestBlockHash ¶
DeepestBlockHash returns the hash of the deepest block in the blocktree If there is multiple deepest blocks, it returns the one with the earliest arrival time.
func (*BlockTree) Encode ¶
Encode recursively encodes the block tree enc(node) = [32B block hash + 8B arrival time + 8B num children n] | enc(children[0]) | ... | enc(children[n-1])
func (*BlockTree) GenesisHash ¶
GenesisHash returns the hash of the genesis block
func (*BlockTree) GetAllBlocksAtDepth ¶
GetAllBlocksAtDepth will return all blocks hashes with the depth of the given hash plus one. To find all blocks at a depth matching a certain block, pass in that block's parent hash
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.