storage

package
v0.0.0-...-fb4f826 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const BITSPERKEY = 10

used to compute the size of bloom filter bits array . too small will lead to high false positive rate.

Variables

View Source
var DefaultConfig = Config{
	MerkleBranchFactor: 8,
	ConcurrentLimit:    20,
}

Functions

This section is empty.

Types

type CommitData

type CommitData struct {
	Block        *core.Block
	Transactions []*core.Transaction
	BlockCommit  *core.BlockCommit
	TxCommits    []*core.TxCommit
	// contains filtered or unexported fields
}

type Config

type Config struct {
	MerkleBranchFactor uint8
	ConcurrentLimit    int
}

type DataEntryPrefix

type DataEntryPrefix byte
const (
	BLOCK_BY_HASH             DataEntryPrefix = iota + 1 // block by hash
	BLOCK_HASH_BY_HEIGHT                                 // block hash by height
	BLOCK_HEIGHT                                         // last block height
	QC_BY_BLOCK_HASH                                     // qc by block hash
	LAST_QC_BLOCK_HASH                                   // qc for last committed block to be used on restart
	BLOCK_COMMIT_BY_HASH                                 // block commit by block hash
	TX_COUNT                                             // total committed tx count
	TX_BY_HASH                                           // tx by hash
	TX_COMMIT_BY_HASH                                    // tx commit info by tx hash
	STATE_VALUE_BY_KEY                                   // state value by state key
	MERKLE_INDEX_BY_STATE_KEY                            // tree leaf index by state key
	MERKLE_TREE_HEIGHT                                   // tree height
	MERKLE_LEAF_COUNT                                    // tree leaf count
	MERKLE_NODE_BY_POSITION                              // tree node value by position
	BOOK_KEEPER                                          // BookKeeper state key prefix
	CONTRACT                                             // Smart contract deploy code key prefix
	STORAGE                                              // Smart contract storage key prefix
	DESTROYED                                            // record destroyed smart contract: prefix+address -> height
	ETH_CODE                                             // eth contract code:hash -> bytes
	ETH_ACCOUNT                                          // eth account: address -> [nonce, codeHash]
	ETH_FILTER_START                                     // support eth filter height
)

data collection prefixes for different data collections

type Getter

type Getter interface {
	Get(key []byte) ([]byte, error)
	Has(key []byte) (bool, error) // Whether the key is exist in store
}

type LevelDBStore

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

LevelDB store

func NewLevelDBStore

func NewLevelDBStore(file string) (*LevelDBStore, error)

NewLevelDBStore return LevelDBStore instance

func NewMemLevelDBStore

func NewMemLevelDBStore() *LevelDBStore

func (*LevelDBStore) BatchCommit

func (self *LevelDBStore) BatchCommit() error

BatchCommit commit batch to leveldb

func (*LevelDBStore) BatchDelete

func (self *LevelDBStore) BatchDelete(key []byte)

BatchDelete delete a key to leveldb batch

func (*LevelDBStore) BatchPut

func (self *LevelDBStore) BatchPut(key []byte, value []byte)

BatchPut put a key-value pair to leveldb batch

func (*LevelDBStore) Close

func (self *LevelDBStore) Close() error

Close leveldb

func (*LevelDBStore) Delete

func (self *LevelDBStore) Delete(key []byte) error

Delete the key in leveldb

func (*LevelDBStore) Get

func (self *LevelDBStore) Get(key []byte) ([]byte, error)

Get the value of a key from leveldb

func (*LevelDBStore) Has

func (self *LevelDBStore) Has(key []byte) (bool, error)

Has return whether the key exists in leveldb

func (*LevelDBStore) NewBatch

func (self *LevelDBStore) NewBatch()

NewBatch start commit batch

func (*LevelDBStore) NewIterator

func (self *LevelDBStore) NewIterator(prefix []byte) StoreIterator

NewIterator return a iterator of leveldb with the key prefix

func (*LevelDBStore) Put

func (self *LevelDBStore) Put(key []byte, value []byte) error

Put a key-value pair to leveldb

type PersistStore

type PersistStore interface {
	Put(key []byte, value []byte) error      // Put the key-value pair to store
	Get(key []byte) ([]byte, error)          // Get the value if key in store
	Has(key []byte) (bool, error)            // Whether the key is exist in store
	Delete(key []byte) error                 // Delete the key in store
	NewBatch()                               // Start commit batch
	BatchPut(key []byte, value []byte)       // Put a key-value pair to batch
	BatchDelete(key []byte)                  // Delete the key in batch
	BatchCommit() error                      // Commit batch to store
	Close() error                            // Close store
	NewIterator(prefix []byte) StoreIterator // Return the iterator of store
}

PersistStore of ledger

type Setter

type Setter interface {
	Put(key []byte, value []byte) error // Put the key-value pair to store
}

type Storage

type Storage struct {
	PersistStore PersistStore
	// contains filtered or unexported fields
}

func New

func New(path string, config Config) *Storage

func (*Storage) Commit

func (strg *Storage) Commit(data *CommitData) error

func (*Storage) GetBlock

func (strg *Storage) GetBlock(hash []byte) (*core.Block, error)

func (*Storage) GetBlockByHeight

func (strg *Storage) GetBlockByHeight(height uint64) (*core.Block, error)

func (*Storage) GetBlockCommit

func (strg *Storage) GetBlockCommit(hash []byte) (*core.BlockCommit, error)

func (*Storage) GetBlockHeight

func (strg *Storage) GetBlockHeight() uint64

func (*Storage) GetLastBlock

func (strg *Storage) GetLastBlock() (*core.Block, error)

func (*Storage) GetLastQC

func (strg *Storage) GetLastQC() (*core.QuorumCert, error)

func (*Storage) GetMerkleRoot

func (strg *Storage) GetMerkleRoot() []byte

func (*Storage) GetQC

func (strg *Storage) GetQC(blkHash []byte) (*core.QuorumCert, error)

func (*Storage) GetState

func (strg *Storage) GetState(key []byte) []byte

func (*Storage) GetTx

func (strg *Storage) GetTx(hash []byte) (*core.Transaction, error)

func (*Storage) GetTxCommit

func (strg *Storage) GetTxCommit(hash []byte) (*core.TxCommit, error)

func (*Storage) HasTx

func (strg *Storage) HasTx(hash []byte) bool

func (*Storage) StoreBlock

func (strg *Storage) StoreBlock(blk *core.Block) error

func (*Storage) StoreQC

func (strg *Storage) StoreQC(qc *core.QuorumCert) error

func (*Storage) VerifyState

func (strg *Storage) VerifyState(key []byte) []byte

type StoreIterator

type StoreIterator interface {
	Next() bool    // Next item. If item available return true, otherwise return false
	First() bool   // First item. If item available return true, otherwise return false
	Key() []byte   // Return the current item key
	Value() []byte // Return the current item value
	Release()      // Close iterator
	Error() error  // Error returns any accumulated error.
}

Jump to

Keyboard shortcuts

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