Documentation ¶
Index ¶
- Variables
- type BlocksMMRTree
- func (t *BlocksMMRTree) ActualRootForLeafByHash(blockHash chainhash.Hash) (chainhash.Hash, bool)
- func (t *BlocksMMRTree) AddBlockWithoutRebuild(hash, actualMMR chainhash.Hash, height int32, difficulty big.Int)
- func (t *BlocksMMRTree) AppendBlock(hash chainhash.Hash, difficulty big.Int) error
- func (t *BlocksMMRTree) Block(height int32) TreeNode
- func (t *BlocksMMRTree) CurrenWeight() *big.Int
- func (t *BlocksMMRTree) Current() *TreeNode
- func (t *BlocksMMRTree) CurrentRoot() chainhash.Hash
- func (t *BlocksMMRTree) LookupNodeByRoot(mmrRoot chainhash.Hash) (TreeNode, bool)
- func (t *BlocksMMRTree) MarshalJSON() ([]byte, error)
- func (t *BlocksMMRTree) PreAllocateTree(blockCount int)
- func (t *BlocksMMRTree) RebuildTreeAndAssert() error
- func (t *BlocksMMRTree) ResetRootTo(hash chainhash.Hash, height int32) error
- func (t *BlocksMMRTree) RmBlock(height int32)
- func (t *BlocksMMRTree) RootForHeight(height int32) chainhash.Hash
- func (t *BlocksMMRTree) SetBlock(hash chainhash.Hash, difficulty big.Int, height int32)
- type TreeContainer
- type TreeNode
Constants ¶
This section is empty.
Variables ¶
var ( ErrNodeNotFound = errors.New("node not found") ErrNodeNoParent = errors.New("node has no parent") ErrNodeDuplicate = errors.New("node duplicate") ErrHeightMismatch = errors.New("node height does not match") ErrHeightAndHashMismatch = errors.New("node height and hash do not match") )
Functions ¶
This section is empty.
Types ¶
type BlocksMMRTree ¶
func (*BlocksMMRTree) ActualRootForLeafByHash ¶
func (*BlocksMMRTree) AddBlockWithoutRebuild ¶
func (t *BlocksMMRTree) AddBlockWithoutRebuild(hash, actualMMR chainhash.Hash, height int32, difficulty big.Int)
AddBlockWithoutRebuild adds block as latest leaf, increases height and weight, but without tree rebuild.
IMPORTANT! This function is not safe!
AddBlockWithoutRebuild should be used only for quick block adding.
Quick Block Adding must be done like this:
tree := NewTree() tree.PreAllocateTree(n) for _, block := range blocks { tree.AddBlockWithoutRebuild(....) } err := tree.RebuildTreeAndAssert()
func (*BlocksMMRTree) AppendBlock ¶
AppendBlock adds block as latest leaf, increases height and rebuild tree.
func (*BlocksMMRTree) Block ¶
func (t *BlocksMMRTree) Block(height int32) TreeNode
func (*BlocksMMRTree) CurrenWeight ¶
func (t *BlocksMMRTree) CurrenWeight() *big.Int
func (*BlocksMMRTree) Current ¶
func (t *BlocksMMRTree) Current() *TreeNode
func (*BlocksMMRTree) CurrentRoot ¶
func (t *BlocksMMRTree) CurrentRoot() chainhash.Hash
func (*BlocksMMRTree) LookupNodeByRoot ¶
func (t *BlocksMMRTree) LookupNodeByRoot(mmrRoot chainhash.Hash) (TreeNode, bool)
func (*BlocksMMRTree) MarshalJSON ¶
func (t *BlocksMMRTree) MarshalJSON() ([]byte, error)
func (*BlocksMMRTree) PreAllocateTree ¶
func (t *BlocksMMRTree) PreAllocateTree(blockCount int)
PreAllocateTree allocates tree containers to hold expected number of blocks.
IMPORTANT! this function is not safe!
PreAllocateTree should be used only on empty tree instances and only for quick block adding. Quick Block Adding must be done like this:
tree := NewTree() tree.PreAllocateTree(n) for _, block := range blocks { tree.AddBlockWithoutRebuild(....) } err := tree.RebuildTreeAndAssert()
func (*BlocksMMRTree) RebuildTreeAndAssert ¶
func (t *BlocksMMRTree) RebuildTreeAndAssert() error
RebuildTreeAndAssert just rebuild the whole tree and checks is root match with actual.
func (*BlocksMMRTree) ResetRootTo ¶
func (t *BlocksMMRTree) ResetRootTo(hash chainhash.Hash, height int32) error
ResetRootTo sets provided block with <hash, height> as latest and drops all blocks after this.
func (*BlocksMMRTree) RmBlock ¶
func (t *BlocksMMRTree) RmBlock(height int32)
RmBlock drops all block from latest to (including) provided block with <hash, height>.
func (*BlocksMMRTree) RootForHeight ¶
func (t *BlocksMMRTree) RootForHeight(height int32) chainhash.Hash
type TreeContainer ¶
type TreeContainer struct { *BlocksMMRTree // RootToBlock stores all known pairs of the mmr_root and corresponding block, // which was the last leaf in the tree for this root. // Here is stored all roots for the main chain and orphans. RootToBlock map[chainhash.Hash]chainhash.Hash }
func (*TreeContainer) SetNodeQuick ¶
func (mmrTree *TreeContainer) SetNodeQuick(node blocknodes.IBlockNode)
func (*TreeContainer) SetNodeToMmrWithReorganization ¶
func (mmrTree *TreeContainer) SetNodeToMmrWithReorganization(blockNode blocknodes.IBlockNode) (*chainhash.Hash, error)