bmt

package
v0.0.0-...-77b6ffe Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Bucket merkle tree implementaion

Index

Constants

View Source
const (
	NodeKeyPrefix      = "n" // "n" + node hash
	HashTableKeyPrefix = "t" // "t" + root node hash
	BucketKeyPrefix    = "s" // "s" + slot hash
)

Variables

View Source
var (
	ErrDbNotOpen = errors.New("db not open")
)

Functions

func Commit

func Commit(set WriteSet, db tdb.Database) error

func Hash

func Hash(set WriteSet) (common.Hash, error)

Types

type BmtDB

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

func NewBmtDB

func NewBmtDB(db tdb.Database) *BmtDB

func (*BmtDB) GetBucket

func (bdb *BmtDB) GetBucket(key common.Hash) (*Bucket, error)

func (*BmtDB) GetHashTable

func (bdb *BmtDB) GetHashTable(key common.Hash) (*HashTable, error)

func (*BmtDB) GetNode

func (bdb *BmtDB) GetNode(key common.Hash) (*MerkleNode, error)

func (*BmtDB) PutBucket

func (bdb *BmtDB) PutBucket(batch tdb.Batch, key common.Hash, bucket *Bucket) error

func (*BmtDB) PutHashTable

func (bdb *BmtDB) PutHashTable(batch tdb.Batch, key common.Hash, ht *HashTable) error

func (*BmtDB) PutNode

func (bdb *BmtDB) PutNode(batch tdb.Batch, key common.Hash, node *MerkleNode) error

type Bucket

type Bucket struct {
	H     common.Hash       `json:"hash"`
	Slots map[string][]byte `json:"slots"`
	Keys  []string          `json:"keys"` // store the order of map key
	// contains filtered or unexported fields
}

func NewBucket

func NewBucket() *Bucket

func (*Bucket) Hash

func (bk *Bucket) Hash() common.Hash

type BucketTree

type BucketTree struct {
	Capacity   int
	Aggreation int
	// contains filtered or unexported fields
}

func NewBucketTree

func NewBucketTree(db tdb.Database) *BucketTree

func (*BucketTree) Commit

func (bt *BucketTree) Commit(batch tdb.Batch) error

commit commits all data in memory to db.Batch. At this time, data is not really stored in db, so you should explicitly invoke batch.Write().

func (*BucketTree) Copy

func (bt *BucketTree) Copy() *BucketTree

func (*BucketTree) Get

func (bt *BucketTree) Get(key []byte) ([]byte, error)

Get data from hash table by key

func (*BucketTree) Hash

func (bt *BucketTree) Hash() common.Hash

func (*BucketTree) Init

func (bt *BucketTree) Init(rootHash []byte) error

Init constructing the tree structure

func (*BucketTree) LowestLevel

func (bt *BucketTree) LowestLevel() int

func (*BucketTree) Prepare

func (bt *BucketTree) Prepare(dirty WriteSet) error

func (*BucketTree) Process

func (bt *BucketTree) Process() (common.Hash, error)

func (*BucketTree) Purge

func (bt *BucketTree) Purge()

Purge release the cache memory to avoid mem peak

func (*BucketTree) Verify

func (bt *BucketTree) Verify(data []byte)

type HashTable

type HashTable struct {
	Cap        int           `json:"cap"`
	BucketHash []common.Hash `json:"bucket_hash"`
	// contains filtered or unexported fields
}

Wrapper of buckets

func NewHashTable

func NewHashTable(db *BmtDB, cap int) *HashTable

type MerkleNode

type MerkleNode struct {
	H        common.Hash   `json:"hash"`
	Pos      *Position     `json:"pos"`      // position of the node
	Children []common.Hash `json:"children"` // children hash, for locating in db
	// contains filtered or unexported fields
}

func NewMerkleNode

func NewMerkleNode(db *BmtDB, pos *Position, aggre int) *MerkleNode

func (*MerkleNode) Hash

func (node *MerkleNode) Hash() common.Hash

type Position

type Position struct {
	Level int `json:"level"` // the level of the node in tree
	Index int `json:"index"` // the index of the node in current level
}

type WriteSet

type WriteSet map[string][]byte

Write set for tree prepare

func NewWriteSet

func NewWriteSet() WriteSet

Jump to

Keyboard shortcuts

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