Documentation ¶
Index ¶
- Variables
- func AggregateOrangeTree(result []byte, coding []byte, codingSize, nShards uint32)
- type SparseMerkleTree
- func (tree *SparseMerkleTree) CatalanNumbersCoding() (coding []byte, bitsCoded uint32, err error)
- func (tree *SparseMerkleTree) DropShardHash(position uint32) (err error)
- func (tree *SparseMerkleTree) Height() uint16
- func (tree *SparseMerkleTree) HeightWithoutRoot() uint16
- func (tree *SparseMerkleTree) MarshalOrangeTreeLeafs() (data []chainhash.Hash)
- func (tree *SparseMerkleTree) MerkleProofPath(position uint32) (pathData []chainhash.Hash, err error)
- func (tree *SparseMerkleTree) Root() (root chainhash.Hash, err error)
- func (tree *SparseMerkleTree) SetShardHash(position uint32, hash [32]byte) (err error)
- func (tree *SparseMerkleTree) ValidateOrangeTree(codingBitsSize uint32, coding []byte, hashes []chainhash.Hash, mmNumber uint32, ...) (err error)
- func (tree *SparseMerkleTree) ValidateShardMerkleProofPath(position, shardsCount uint32, shardMerkleProof []chainhash.Hash, ...) (err error)
Constants ¶
This section is empty.
Variables ¶
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") ErrInvalidMerkleProofPath = errors.New("invalid merkle proof path") )
var ( // MH - MagicHash. // Used to bound the orange tree. // See the WP for the details. MH = chainhash.Hash{} )
Functions ¶
func AggregateOrangeTree ¶
Types ¶
type SparseMerkleTree ¶
type SparseMerkleTree struct {
// contains filtered or unexported fields
}
func NewSparseMerkleTree ¶
func NewSparseMerkleTree(shardsCount uint32) (tree *SparseMerkleTree)
func (*SparseMerkleTree) CatalanNumbersCoding ¶
func (tree *SparseMerkleTree) CatalanNumbersCoding() (coding []byte, bitsCoded uint32, err 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.
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) (pathData []chainhash.Hash, err error)
func (*SparseMerkleTree) Root ¶
func (tree *SparseMerkleTree) Root() (root chainhash.Hash, err error)
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.