mergedminingtree

package
v0.4.10-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: ISC, ISC Imports: 6 Imported by: 3

Documentation

Overview

nolint: gomnd

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidShardPosition = errors.New("specified shard position does not correspond to the expected tree conf")
	ErrValidation           = errors.New("validation error")
	ErrRootIsNil            = errors.New("root is nil")
	ErrLeafIsNil            = errors.New("leaf is nil")
)

MH - MagicHash. Used to bound the orange tree. See the WP for the details.

Functions

func AggregateOrangeTree

func AggregateOrangeTree(result []byte, coding []byte, codingSize, nShards uint32)

nolint: unconvert

Types

type SparseMerkleTree

type SparseMerkleTree struct {
	// contains filtered or unexported fields
}

func NewSparseMerkleTree

func NewSparseMerkleTree(shardsCount uint32) *SparseMerkleTree

nolint: revive

func (*SparseMerkleTree) CatalanNumbersCoding

func (tree *SparseMerkleTree) CatalanNumbersCoding() ([]byte, uint32, error)

CatalanNumbersCoding returns binary (BigEndian) coded orange tree, that is a subset of the current merkle tree. The coding format is the next: <orange tree structure coding>, <sequence of hashes of the orange tree>. Orange tree structure consists of ~2 bits info per node and 1 bit that defines if the node is MH or not.

This data is packed into bits slice and is aligned to the 8 bits (one byte).

Sequence of hashes of the orange tree is a simple bytes slice which is filled with the hashes of the nodes of the orange tree in the same order as they are located in the structure coding sequence. nolint: gocritic

func (*SparseMerkleTree) DropShardHash

func (tree *SparseMerkleTree) DropShardHash(position uint32) (err error)

DropShardHash deletes shard's hash into slot with position = "position", making slot empty. Returns ErrInvalidShardPosition in case if passed position does not correspond to current tree structure.

Note: this method is lazy. Setting the shard's hash would not lead to root recalculation until Root() would not be called.

func (*SparseMerkleTree) Height

func (tree *SparseMerkleTree) Height() uint16

Height returns height of the tree including root level.

func (*SparseMerkleTree) HeightWithoutRoot

func (tree *SparseMerkleTree) HeightWithoutRoot() uint16

func (*SparseMerkleTree) MarshalOrangeTreeLeafs

func (tree *SparseMerkleTree) MarshalOrangeTreeLeafs() (data []chainhash.Hash)

func (*SparseMerkleTree) MerkleProofPath

func (tree *SparseMerkleTree) MerkleProofPath(position uint32) ([]chainhash.Hash, error)

func (*SparseMerkleTree) Root

func (tree *SparseMerkleTree) Root() (chainhash.Hash, error)

nolint: revive

func (*SparseMerkleTree) SetShardHash

func (tree *SparseMerkleTree) SetShardHash(position uint32, hash [32]byte) (err error)

SetShardHash copies shard's hash into slot with position = "position". Returns ErrInvalidShardPosition in case if passed position does not correspond to current tree structure.

Note: this method is lazy. Setting the shard's hash would not lead to root recalculation until Root() would not be called.

func (*SparseMerkleTree) ValidateOrangeTree

func (tree *SparseMerkleTree) ValidateOrangeTree(codingBitsSize uint32, coding []byte, hashes []chainhash.Hash,
	mmNumber uint32, expectedRoot chainhash.Hash, beacon bool) error

func (*SparseMerkleTree) ValidateShardMerkleProofPath

func (tree *SparseMerkleTree) ValidateShardMerkleProofPath(position, shardsCount uint32,
	shardMerkleProof []chainhash.Hash, expectedShardHash, expectedRootHash chainhash.Hash) error

Jump to

Keyboard shortcuts

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