blocktree

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: LGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlockExists = errors.New("cannot add block to blocktree that already exists")

ErrBlockExists is returned if attempting to re-add a block

View Source
var ErrDescendantNotFound = errors.New("could not find descendant node")

ErrDescendantNotFound is returned if a descendant in a subchain cannot be found

View Source
var ErrEndNodeNotFound = errors.New("end node does not exist")

ErrEndNodeNotFound is returned if the end of a subchain does not exist

View Source
var ErrNilDatabase = errors.New("blocktree database is nil")

ErrNilDatabase is returned in the database is nil

View Source
var ErrNilDescendant = errors.New("descendant node is nil")

ErrNilDescendant is returned if calling subchain with a nil node

View Source
var ErrNodeNotFound = errors.New("could not find node")

ErrNodeNotFound is returned if a node with given hash doesn't exist

View Source
var ErrParentNotFound = errors.New("cannot find parent block in blocktree")

ErrParentNotFound is returned if the parent hash does not exist in the blocktree

View Source
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 {
	sync.RWMutex
	// contains filtered or unexported fields
}

BlockTree represents the current state with all possible blocks

func NewBlockTreeFromRoot added in v0.3.1

func NewBlockTreeFromRoot(root *types.Header, db database.Database) *BlockTree

NewBlockTreeFromRoot initializes a blocktree with a root block. The root block is always the most recently finalized block (ie the genesis block if the node is just starting.)

func NewEmptyBlockTree

func NewEmptyBlockTree(db database.Database) *BlockTree

NewEmptyBlockTree creates a BlockTree with a nil head

func (*BlockTree) AddBlock

func (bt *BlockTree) AddBlock(block *types.Block, arrivalTime uint64) error

AddBlock inserts the block as child of its parent node Note: Assumes block has no children

func (*BlockTree) Decode

func (bt *BlockTree) Decode(in []byte) error

Decode recursively decodes an encoded block tree

func (*BlockTree) DeepCopy added in v0.3.0

func (bt *BlockTree) DeepCopy() *BlockTree

DeepCopy returns a copy of the BlockTree

func (*BlockTree) DeepestBlockHash

func (bt *BlockTree) DeepestBlockHash() Hash

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

func (bt *BlockTree) Encode() ([]byte, error)

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

func (bt *BlockTree) GenesisHash() Hash

GenesisHash returns the hash of the genesis block

func (*BlockTree) GetAllBlocks added in v0.2.0

func (bt *BlockTree) GetAllBlocks() []Hash

GetAllBlocks returns all the blocks in the tree

func (*BlockTree) GetAllBlocksAtDepth

func (bt *BlockTree) GetAllBlocksAtDepth(hash common.Hash) []common.Hash

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

func (bt *BlockTree) HighestCommonAncestor(a, b Hash) (Hash, error)

HighestCommonAncestor returns the highest block that is a Ancestor to both a and b

func (*BlockTree) IsDescendantOf

func (bt *BlockTree) IsDescendantOf(parent, child Hash) (bool, error)

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

func (bt *BlockTree) Leaves() []Hash

Leaves returns the leaves of the blocktree as an array

func (*BlockTree) Load

func (bt *BlockTree) Load() error

Load loads the blocktree from the underlying db

func (*BlockTree) Prune added in v0.2.0

func (bt *BlockTree) Prune(finalized Hash) (pruned []Hash)

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) Rewind added in v0.3.1

func (bt *BlockTree) Rewind(numBlocks int)

Rewind rewinds the block tree by the given height. If the blocktree is less than the given height, it will only rewind until the blocktree has one node.

func (*BlockTree) Store

func (bt *BlockTree) Store() error

Store stores the blocktree in the underlying db

func (*BlockTree) String

func (bt *BlockTree) String() string

String utilizes github.com/disiqueira/gotree to create a printable tree

func (*BlockTree) SubBlockchain

func (bt *BlockTree) SubBlockchain(start Hash, end Hash) ([]Hash, error)

SubBlockchain returns the path from the node with Hash start to the node with Hash end

type Hash

type Hash = common.Hash

Hash common.Hash

Jump to

Keyboard shortcuts

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