store

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: LGPL-3.0 Imports: 21 Imported by: 2

Documentation

Index

Examples

Constants

View Source
const IdealBatchSize = 100 * 1024

Code using batches should try to add this much data to the batch. The value was determined empirically.

Variables

View Source
var (
	ErrArgInvalid           = errors.New("invalid argument")
	ErrExist                = errors.New("item already exists")
	ErrNotExist             = errors.New("item does not exist")
	ErrContractCodeNotExist = errors.New("contract code does not exist")
	ErrBlockNotExist        = errors.New("block does not exist")
	ErrStableBlockNotExist  = errors.New("stable block does not exist")
	ErrAccountNotExist      = errors.New("account does not exist")
	ErrAncestorsNotExist    = errors.New("the block's ancestors does not exist")
	ErrEOF                  = errors.New("file EOF")
	ErrRlpEncode            = errors.New("rlp encode err")
	ErrOutOfMemory          = errors.New("out of memory")
	ErrUnKnown              = errors.New("")
)
View Source
var MbTable = []uint16{}/* 256 elements not displayed */
View Source
var RecordHeadLength = binary.Size(RecordHead{})

Functions

func Byte2Uint32

func Byte2Uint32(val []byte) uint32

func CheckSum

func CheckSum(data []byte) uint16

func FileUtilsAlign added in v1.2.0

func FileUtilsAlign(length uint32) uint32

func FileUtilsCreateFile added in v1.2.0

func FileUtilsCreateFile(path string) error

func FileUtilsEncode added in v1.2.0

func FileUtilsEncode(flag uint32, key []byte, val []byte) ([]byte, error)

func FileUtilsFlush added in v1.2.0

func FileUtilsFlush(path string, offset int64, data []byte) (int64, error)

func FileUtilsIsExist added in v1.2.0

func FileUtilsIsExist(path string) (bool, error)

func FileUtilsRead added in v1.2.0

func FileUtilsRead(file *os.File, offset int64) (*RecordHead, *RecordBody, error)

func GetBucketIndex

func GetBucketIndex(pos uint32) uint32

func GetItemIndex

func GetItemIndex(pos uint32) uint32

func GetPos

func GetPos(bucketIndex uint32, itemIndex uint32) uint32

func SerializeForks added in v1.3.0

func SerializeForks(unconfirmedBlocks map[common.Hash]*CBlock, currentHash common.Hash) string
Example
package main

import (
	"fmt"
	"github.com/LemoFoundationLtd/lemochain-core/chain/types"
	"github.com/LemoFoundationLtd/lemochain-core/common"
)

// makeForkBlocks make blocks and setup the tree struct like this:
//
//	┌─2
//
// 0───1─┼─3───6
//
//	├─4─┬─7───9
//	│   └─8
//	└─5
func makeForkBlocks() []*CBlock {
	rawBlock0 := &types.Block{Header: &types.Header{Height: 99}}
	block0 := &CBlock{Block: rawBlock0}
	rawBlock1 := &types.Block{Header: &types.Header{Height: 100}}
	block1 := &CBlock{Block: rawBlock1}
	rawBlock2 := &types.Block{Header: &types.Header{Height: 101, Time: 1}}
	block2 := &CBlock{Block: rawBlock2}
	rawBlock3 := &types.Block{Header: &types.Header{Height: 101, Time: 2}}
	block3 := &CBlock{Block: rawBlock3}
	rawBlock4 := &types.Block{Header: &types.Header{Height: 101, Time: 3}}
	block4 := &CBlock{Block: rawBlock4}
	rawBlock5 := &types.Block{Header: &types.Header{Height: 101, Time: 4}}
	block5 := &CBlock{Block: rawBlock5}
	rawBlock6 := &types.Block{Header: &types.Header{Height: 102, Time: 5}}
	block6 := &CBlock{Block: rawBlock6}
	rawBlock7 := &types.Block{Header: &types.Header{Height: 102, Time: 6}}
	block7 := &CBlock{Block: rawBlock7}
	rawBlock8 := &types.Block{Header: &types.Header{Height: 102, Time: 7}}
	block8 := &CBlock{Block: rawBlock8}
	rawBlock9 := &types.Block{Header: &types.Header{Height: 103, Time: 8}}
	block9 := &CBlock{Block: rawBlock9}

	block1.BeChildOf(block0)
	block2.BeChildOf(block1)
	block3.BeChildOf(block1)
	block4.BeChildOf(block1)
	block5.BeChildOf(block1)
	block6.BeChildOf(block3)
	block7.BeChildOf(block4)
	block8.BeChildOf(block4)
	block9.BeChildOf(block7)
	return []*CBlock{block0, block1, block2, block3, block4, block5, block6, block7, block8, block9}
}

func main() {
	blocks := makeForkBlocks()
	blockMap := make(map[common.Hash]*CBlock, len(blocks))
	for _, block := range blocks {
		blockMap[block.Block.Hash()] = block
	}

	fmt.Printf(SerializeForks(blockMap, blocks[9].Block.Hash()))

}
Output:

─[ 99]5bd69f─[100]757227┬[101]1ba62c
                        ├[101]1dc055
                        ├[101]1f5603┬[102]44ae7c
                        │           └[102]6490a0─[103]db4799 <-Current
                        └[101]29d8a5─[102]379da9

func UtilsGetAccount added in v1.2.0

func UtilsGetAccount(db *BeansDB, address common.Address) (*types.AccountData, error)

func UtilsGetAssetCode added in v1.2.0

func UtilsGetAssetCode(db *BeansDB, code common.Hash) (common.Address, error)

func UtilsGetAssetId added in v1.2.0

func UtilsGetAssetId(db *BeansDB, id common.Hash) (common.Hash, error)

func UtilsGetBlockByHash added in v1.2.0

func UtilsGetBlockByHash(db *BeansDB, hash common.Hash) (*types.Block, error)

不会返回ErrNotExist

func UtilsGetBlockByHeight added in v1.2.0

func UtilsGetBlockByHeight(db *BeansDB, height uint32) (*types.Block, error)

func UtilsHashBlock added in v1.2.0

func UtilsHashBlock(db *BeansDB, hash common.Hash) (bool, error)

func UtilsSetAssetCode added in v1.2.0

func UtilsSetAssetCode(db *BeansDB, code common.Hash, address common.Address) error

func UtilsSetAssetId added in v1.2.0

func UtilsSetAssetId(db *BeansDB, id common.Hash, code common.Hash) error

Types

type AccountTrieDB added in v1.1.1

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

AccountAPI

func NewAccountTrieDB added in v1.1.1

func NewAccountTrieDB(trie *PatriciaTrie, beansdb *BeansDB) *AccountTrieDB

func NewEmptyAccountTrieDB added in v1.1.1

func NewEmptyAccountTrieDB(beansdb *BeansDB) *AccountTrieDB

func (*AccountTrieDB) Clone added in v1.1.1

func (db *AccountTrieDB) Clone() *AccountTrieDB

func (*AccountTrieDB) Collect added in v1.1.1

func (db *AccountTrieDB) Collect(dye uint32) []*types.AccountData

func (*AccountTrieDB) Get added in v1.1.1

func (db *AccountTrieDB) Get(address common.Address) (*types.AccountData, error)

func (*AccountTrieDB) GetReader added in v1.1.1

func (db *AccountTrieDB) GetReader() *BeansDB

func (*AccountTrieDB) GetTrie added in v1.1.1

func (db *AccountTrieDB) GetTrie() *PatriciaTrie

func (*AccountTrieDB) Put added in v1.1.1

func (db *AccountTrieDB) Put(account *types.AccountData, dye uint32)

func (*AccountTrieDB) Set added in v1.1.1

func (db *AccountTrieDB) Set(account *types.AccountData)

func (*AccountTrieDB) SetReader added in v1.1.1

func (db *AccountTrieDB) SetReader(beansdb *BeansDB)

func (*AccountTrieDB) SetTrie added in v1.1.1

func (db *AccountTrieDB) SetTrie(trie *PatriciaTrie)

type Batch

type Batch interface {
	Put(flg uint32, key, value []byte) error
	Commit() error
	Items() []*BatchItem
	ValueSize() int
	Reset()
}

Batch is a write-only database that commits changes to its host database when Write is called. Batch cannot be used concurrently.

type BatchItem

type BatchItem struct {
	Flg uint32
	Key []byte
	Val []byte
}

type BeansDB added in v1.1.0

type BeansDB struct {
	Home    string
	LevelDB *leveldb.LevelDBDatabase
	Queue   *FileQueue
}

func NewBeansDB added in v1.1.0

func NewBeansDB(home string, levelDB *leveldb.LevelDBDatabase) *BeansDB

func (*BeansDB) After added in v1.2.0

func (beansdb *BeansDB) After(flg uint32, key []byte, val []byte) error

func (*BeansDB) Close added in v1.1.0

func (beansdb *BeansDB) Close()

func (*BeansDB) Commit added in v1.1.0

func (beansdb *BeansDB) Commit(batch Batch) error

func (*BeansDB) Delete added in v1.2.0

func (beansdb *BeansDB) Delete(flg uint32, key []byte) error

func (*BeansDB) Get added in v1.1.0

func (beansdb *BeansDB) Get(flg uint32, key []byte) ([]byte, error)

func (*BeansDB) Has added in v1.1.0

func (beansdb *BeansDB) Has(flag uint32, key []byte) (bool, error)

func (*BeansDB) NewBatch added in v1.1.0

func (beansdb *BeansDB) NewBatch() Batch

func (*BeansDB) Put added in v1.1.0

func (beansdb *BeansDB) Put(flag uint32, key []byte, val []byte) error

func (*BeansDB) Start added in v1.2.0

func (beansdb *BeansDB) Start()

type BitCask added in v1.1.0

type BitCask struct {
	RW   sync.RWMutex
	Home string

	BitCaskIndex int
	CurIndex     int
	CurOffset    int64
	LevelDB      *leveldb.LevelDBDatabase
}

func NewBitCask added in v1.1.0

func NewBitCask(home string, index int, levelDB *leveldb.LevelDBDatabase) (*BitCask, error)

func (*BitCask) Delete added in v1.1.0

func (bitcask *BitCask) Delete(flag uint32, key []byte) error

func (*BitCask) Get added in v1.1.0

func (bitcask *BitCask) Get(flag uint32, key []byte) ([]byte, error)

func (*BitCask) Put added in v1.1.0

func (bitcask *BitCask) Put(flag uint32, key []byte, val []byte) error

type BizDatabase added in v1.1.0

type BizDatabase struct {
	Reader  Reader
	LevelDB *leveldb.LevelDBDatabase
}

func NewBizDatabase added in v1.1.0

func NewBizDatabase(reader Reader, levelDB *leveldb.LevelDBDatabase) *BizDatabase

func (*BizDatabase) AfterCommit added in v1.1.0

func (db *BizDatabase) AfterCommit(flag uint32, key []byte, val []byte) error

func (*BizDatabase) GetTxByAddr added in v1.1.0

func (db *BizDatabase) GetTxByAddr(src common.Address, index int, size int) ([]*VTransaction, uint32, error)

func (*BizDatabase) GetTxByHash added in v1.1.0

func (db *BizDatabase) GetTxByHash(hash common.Hash) (*VTransactionDetail, error)

type BizDb added in v1.1.0

type BizDb interface {
	GetTxByHash(hash common.Hash) (*VTransactionDetail, error)

	GetTxByAddr(src common.Address, index int, size int) ([]*VTransaction, uint32, error)
}

type CBlock added in v1.1.0

type CBlock struct {
	Block           *types.Block
	AccountTrieDB   *AccountTrieDB
	CandidateTrieDB *CandidateTrieDB
	Top             *VoteTop
	Parent          *CBlock
	Children        []*CBlock
}

func NewGenesisBlock added in v1.1.1

func NewGenesisBlock(block *types.Block, beansdb *BeansDB) *CBlock

func NewNormalBlock added in v1.1.1

func NewNormalBlock(block *types.Block, accountTrieDB *AccountTrieDB, candidateTrieDB *CandidateTrieDB, top *VoteTop) *CBlock

func (*CBlock) BeChildOf added in v1.2.0

func (block *CBlock) BeChildOf(parent *CBlock)

func (*CBlock) CollectToParent added in v1.2.0

func (block *CBlock) CollectToParent(end *CBlock) []*CBlock

CollectToParent collect blocks from parent to parent, include itself and exclude the end block

func (*CBlock) IsSameBlock added in v1.2.0

func (block *CBlock) IsSameBlock(b *CBlock) bool

func (*CBlock) Ranking added in v1.1.1

func (block *CBlock) Ranking(voteLogs types.ChangeLogSlice)

func (*CBlock) Walk added in v1.2.0

func (block *CBlock) Walk(fn func(*CBlock), exclude *CBlock)

Walk iterate every child recursively. Not include itself

type CachedNode

type CachedNode struct {
	Blob     []byte              // Cached data block of the trie node
	Parents  int                 // Number of live nodes referencing this one
	Children map[common.Hash]int // Children referenced by this nodes
}

CachedNode is all the information we know about a single cached node in the memory database write layer.

type Candidate added in v1.1.0

type Candidate struct {
	Address common.Address
	Total   *big.Int
}

func (*Candidate) Clone added in v1.1.0

func (candidate *Candidate) Clone() types.NodeData

func (*Candidate) Copy added in v1.1.1

func (candidate *Candidate) Copy() *Candidate

func (*Candidate) GetAddress added in v1.1.0

func (candidate *Candidate) GetAddress() common.Address

func (*Candidate) GetTotal added in v1.1.0

func (candidate *Candidate) GetTotal() *big.Int

type CandidateCache added in v1.1.1

type CandidateCache struct {
	Candidates   map[common.Address]CandidatePos
	ItemMaxSize  int
	Cap          int
	Cur          int
	CandidateBuf []byte
}

func NewCandidateCache added in v1.1.1

func NewCandidateCache() *CandidateCache

func (*CandidateCache) Decode added in v1.1.1

func (cache *CandidateCache) Decode(buf []byte, length int) error

func (*CandidateCache) Encode added in v1.1.1

func (cache *CandidateCache) Encode() ([]byte, int)

func (*CandidateCache) GetCandidatePage added in v1.1.1

func (cache *CandidateCache) GetCandidatePage(index int, size int) ([]common.Address, uint32, error)

func (*CandidateCache) GetCandidates added in v1.1.1

func (cache *CandidateCache) GetCandidates() ([]*Candidate, error)

func (*CandidateCache) IsExist added in v1.1.1

func (cache *CandidateCache) IsExist(address common.Address) bool

func (*CandidateCache) Set added in v1.1.1

func (cache *CandidateCache) Set(candidate *Candidate) error

type CandidatePos added in v1.1.1

type CandidatePos struct {
	Pos uint32
	Len uint32
}

type CandidateTrieDB added in v1.1.1

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

CandidateAPI

func NewEmptyCandidateTrieDB added in v1.1.1

func NewEmptyCandidateTrieDB() *CandidateTrieDB

func (*CandidateTrieDB) Clone added in v1.1.1

func (db *CandidateTrieDB) Clone() *CandidateTrieDB

func (*CandidateTrieDB) Get added in v1.1.1

func (db *CandidateTrieDB) Get(address common.Address) (*Candidate, error)

func (*CandidateTrieDB) GetAll added in v1.1.1

func (db *CandidateTrieDB) GetAll() []*Candidate

func (*CandidateTrieDB) GetTrie added in v1.1.1

func (db *CandidateTrieDB) GetTrie() *PatriciaTrie

func (*CandidateTrieDB) Put added in v1.1.1

func (db *CandidateTrieDB) Put(candidate *Candidate, dye uint32)

func (*CandidateTrieDB) Set added in v1.1.1

func (db *CandidateTrieDB) Set(candidate *Candidate)

func (*CandidateTrieDB) SetTrie added in v1.1.1

func (db *CandidateTrieDB) SetTrie(trie *PatriciaTrie)

type ChainDatabase added in v1.1.0

type ChainDatabase struct {
	LastConfirm     *CBlock                 // the newest confirm block, and the root of unconfirmed block tree
	UnConfirmBlocks map[common.Hash]*CBlock // unconfirmed block tree nodes
	Context         *RunContext
	LevelDB         *leveldb.LevelDBDatabase
	Beansdb         *BeansDB
	BizDB           *BizDatabase
	RW              sync.RWMutex
	BizRW           sync.RWMutex
}

func NewChainDataBase added in v1.1.0

func NewChainDataBase(home string) *ChainDatabase

func (*ChainDatabase) AfterScan added in v1.1.0

func (database *ChainDatabase) AfterScan(flag uint32, key []byte, val []byte) error

func (*ChainDatabase) CandidatesRanking added in v1.1.0

func (database *ChainDatabase) CandidatesRanking(hash common.Hash, voteLogs types.ChangeLogSlice)

func (*ChainDatabase) Close added in v1.1.0

func (database *ChainDatabase) Close() error

func (*ChainDatabase) GetAccount added in v1.1.0

func (database *ChainDatabase) GetAccount(addr common.Address) (*types.AccountData, error)

GetAccount loads account from cache or db

func (*ChainDatabase) GetActDatabase added in v1.1.0

func (database *ChainDatabase) GetActDatabase(hash common.Hash) (*AccountTrieDB, error)

func (*ChainDatabase) GetAllCandidates added in v1.4.0

func (database *ChainDatabase) GetAllCandidates() ([]common.Address, error)

func (*ChainDatabase) GetAssetCode added in v1.2.0

func (database *ChainDatabase) GetAssetCode(code common.Hash) (common.Address, error)

func (*ChainDatabase) GetAssetID added in v1.2.0

func (database *ChainDatabase) GetAssetID(id common.Hash) (common.Address, error)

func (*ChainDatabase) GetBlockByHash added in v1.1.0

func (database *ChainDatabase) GetBlockByHash(hash common.Hash) (*types.Block, error)

func (*ChainDatabase) GetBlockByHeight added in v1.1.0

func (database *ChainDatabase) GetBlockByHeight(height uint32) (*types.Block, error)

func (*ChainDatabase) GetCandidatesPage added in v1.1.0

func (database *ChainDatabase) GetCandidatesPage(index int, size int) ([]common.Address, uint32, error)

func (*ChainDatabase) GetCandidatesTop added in v1.1.0

func (database *ChainDatabase) GetCandidatesTop(hash common.Hash) []*Candidate

func (*ChainDatabase) GetConfirms added in v1.1.0

func (database *ChainDatabase) GetConfirms(hash common.Hash) ([]types.SignData, error)

func (*ChainDatabase) GetContractCode added in v1.1.0

func (database *ChainDatabase) GetContractCode(hash common.Hash) (types.Code, error)

GetContractCode loads contract's code from db.

func (*ChainDatabase) GetLastConfirm added in v1.1.0

func (database *ChainDatabase) GetLastConfirm() *CBlock

func (*ChainDatabase) GetStableBlock added in v1.2.0

func (database *ChainDatabase) GetStableBlock() (*types.Block, error)

func (*ChainDatabase) GetTrieDatabase added in v1.1.0

func (database *ChainDatabase) GetTrieDatabase() *TrieDatabase

func (*ChainDatabase) GetUnConfirmByHeight added in v1.3.0

func (database *ChainDatabase) GetUnConfirmByHeight(height uint32, leafBlockHash common.Hash) (*types.Block, error)

GetUnConfirmByHeight find unconfirmed block by height. The leafBlockHash is a son block on the fork

func (*ChainDatabase) IsExistByHash added in v1.1.0

func (database *ChainDatabase) IsExistByHash(hash common.Hash) (bool, error)

func (*ChainDatabase) IterateUnConfirms added in v1.3.0

func (database *ChainDatabase) IterateUnConfirms(fn func(*types.Block))

func (*ChainDatabase) LoadLatestBlock added in v1.1.0

func (database *ChainDatabase) LoadLatestBlock() (*types.Block, error)

func (*ChainDatabase) SerializeForks added in v1.3.0

func (database *ChainDatabase) SerializeForks(currentHash common.Hash) string

func (*ChainDatabase) SetBlock added in v1.1.0

func (database *ChainDatabase) SetBlock(hash common.Hash, block *types.Block) error

func (*ChainDatabase) SetConfirms added in v1.1.0

func (database *ChainDatabase) SetConfirms(hash common.Hash, pack []types.SignData) (*types.Block, error)

SetConfirms 设置区块的确认信息

func (*ChainDatabase) SetContractCode added in v1.1.0

func (database *ChainDatabase) SetContractCode(hash common.Hash, code types.Code) error

SetContractCode saves contract's code

func (*ChainDatabase) SetStableBlock added in v1.1.0

func (database *ChainDatabase) SetStableBlock(hash common.Hash) ([]*types.Block, error)

SetStableBlock set the state of the block to stable, then return pruned uncle blocks

func (*ChainDatabase) SizeOfValue added in v1.1.0

func (database *ChainDatabase) SizeOfValue(hash common.Hash) (int, error)

type Commit added in v1.1.0

type Commit interface {
	Commit(batch Batch) error
}

type Database

type Database interface {
	NewBatch
	Put(flg uint32, key, value []byte) error
	Get(flg uint32, key []byte) ([]byte, error)
	Has(flg uint32, key []byte) (bool, error)
	Delete(flg uint32, key []byte) error
	Close()
}

Database wraps all database operations. All methods are safe for concurrent use.

type DatabaseReader

type DatabaseReader interface {
	// Get retrieves the value associated with key form the database.
	Get(flg uint32, key []byte) (value []byte, err error)

	// Has retrieves whether a key is present in the database.
	Has(flg uint32, key []byte) (bool, error)
}

DatabaseReader wraps the Get and Has method of a backing store for the trie.

type FileQueue added in v1.2.0

type FileQueue struct {
	Home   string
	Offset int64

	IndexRW sync.RWMutex
	Index   map[string]*item

	LevelDB *leveldb.LevelDBDatabase

	SyncFileDB *SyncFileDB
	DoneChan   chan *Inject
	ErrChan    chan *Inject
	Quit       chan struct{}
}

func NewFileQueue added in v1.2.0

func NewFileQueue(home string, levelDB *leveldb.LevelDBDatabase, extend WriteExtend) *FileQueue

func (*FileQueue) Close added in v1.2.0

func (queue *FileQueue) Close()

func (*FileQueue) Get added in v1.2.0

func (queue *FileQueue) Get(flag uint32, key []byte) ([]byte, error)

func (*FileQueue) Put added in v1.2.0

func (queue *FileQueue) Put(flag uint32, key []byte, val []byte) error

func (*FileQueue) PutBatch added in v1.2.0

func (queue *FileQueue) PutBatch(items []*BatchItem) error

func (*FileQueue) Start added in v1.2.0

func (queue *FileQueue) Start()

type Index

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

func (*Index) Bak

func (index *Index) Bak() int

func (*Index) Cur

func (index *Index) Cur() int

func (*Index) Init

func (index *Index) Init()

func (*Index) Swap

func (index *Index) Swap()

type Inject added in v1.2.0

type Inject struct {
	Flg uint32
	Key []byte
	Val []byte
}

type LmBuffer

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

func NewLmBuffer

func NewLmBuffer(buf []byte) *LmBuffer

func (*LmBuffer) Read

func (buf *LmBuffer) Read(p []byte) (n int, err error)

func (*LmBuffer) Write

func (buf *LmBuffer) Write(p []byte) (n int, err error)

type LmDBBatch added in v1.1.0

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

func (*LmDBBatch) Commit added in v1.1.0

func (batch *LmDBBatch) Commit() error

func (*LmDBBatch) Items added in v1.1.0

func (batch *LmDBBatch) Items() []*BatchItem

func (*LmDBBatch) Put added in v1.1.0

func (batch *LmDBBatch) Put(flg uint32, key, value []byte) error

func (*LmDBBatch) Reset added in v1.1.0

func (batch *LmDBBatch) Reset()

func (*LmDBBatch) ValueSize added in v1.1.0

func (batch *LmDBBatch) ValueSize() int

type MemDatabase

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

* This is a test memory database. Do not use for any production it does not get persisted

func NewMemDatabase

func NewMemDatabase() (*MemDatabase, error)

func NewMemDatabaseWithCap

func NewMemDatabaseWithCap(size int) (*MemDatabase, error)

func (*MemDatabase) Close

func (db *MemDatabase) Close()

func (*MemDatabase) Delete

func (db *MemDatabase) Delete(flag uint32, key []byte) error

func (*MemDatabase) Get

func (db *MemDatabase) Get(flag uint32, key []byte) ([]byte, error)

func (*MemDatabase) Has

func (db *MemDatabase) Has(flag uint32, key []byte) (bool, error)

func (*MemDatabase) Keys

func (db *MemDatabase) Keys() [][]byte

func (*MemDatabase) Len

func (db *MemDatabase) Len() int

func (*MemDatabase) NewBatch

func (db *MemDatabase) NewBatch() Batch

func (*MemDatabase) Put

func (db *MemDatabase) Put(flag uint32, key []byte, value []byte) error

type NewBatch added in v1.1.0

type NewBatch interface {
	NewBatch() Batch
}

type Offset added in v1.4.0

type Offset struct {
	IndexRW sync.RWMutex

	Home string

	/** 当前刷到磁盘的位置 */
	FlushOffset int64

	/** 当前文件追加写的位置,还未写入的长度为:AppendOffset - FlushOffset */
	AppendOffset int64
}

type OffsetItem added in v1.4.0

type OffsetItem struct {
	FlushOffset  uint64
	AppendOffset uint64
}

type PatriciaNode added in v1.1.0

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

func (*PatriciaNode) Clone added in v1.1.0

func (node *PatriciaNode) Clone() *PatriciaNode

type PatriciaTrie added in v1.1.0

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

func NewActDatabase added in v1.1.0

func NewActDatabase(root *PatriciaTrie) *PatriciaTrie

func NewEmptyDatabase added in v1.1.0

func NewEmptyDatabase() *PatriciaTrie

func (*PatriciaTrie) All added in v1.1.1

func (trie *PatriciaTrie) All() []types.NodeData

func (*PatriciaTrie) Clone added in v1.1.0

func (trie *PatriciaTrie) Clone() *PatriciaTrie

func (*PatriciaTrie) Collected added in v1.1.0

func (trie *PatriciaTrie) Collected(dye uint32) []types.NodeData

func (*PatriciaTrie) DelDye added in v1.1.0

func (trie *PatriciaTrie) DelDye(dye uint32)

func (*PatriciaTrie) Find added in v1.1.0

func (trie *PatriciaTrie) Find(key string) types.NodeData

func (*PatriciaTrie) Insert added in v1.1.0

func (trie *PatriciaTrie) Insert(key string, data types.NodeData) error

func (*PatriciaTrie) Put added in v1.1.0

func (trie *PatriciaTrie) Put(key string, data types.NodeData, dye uint32)

dye the node's path

type Putter

type Putter interface {
	Put(flg uint32, key, value []byte) error
}

Putter wraps the database write operation supported by both batches and regular databases.

type Reader added in v1.1.0

type Reader interface {
	GetLastConfirm() *CBlock

	GetBlockByHash(hash common.Hash) (*types.Block, error)
}

type RecordBody added in v1.2.0

type RecordBody struct {
	Key []byte
	Val []byte
}

type RecordHead added in v1.2.0

type RecordHead struct {
	Flg       uint32
	Len       uint32
	TimeStamp uint64
	Crc       uint16
}

type RunContext added in v1.1.0

type RunContext struct {
	Path       string
	Candidates *CandidateCache
}

func NewRunContext added in v1.1.0

func NewRunContext(path string) *RunContext

func (*RunContext) CandidateIsExist added in v1.1.0

func (context *RunContext) CandidateIsExist(address common.Address) bool

func (*RunContext) Flush added in v1.1.0

func (context *RunContext) Flush() error

func (*RunContext) GetCandidatePage added in v1.1.0

func (context *RunContext) GetCandidatePage(index int, size int) ([]common.Address, uint32, error)

func (*RunContext) GetCandidates added in v1.1.1

func (context *RunContext) GetCandidates() ([]*Candidate, error)

func (*RunContext) Load added in v1.1.0

func (context *RunContext) Load() error

func (*RunContext) SetCandidate added in v1.1.0

func (context *RunContext) SetCandidate(candidate *Candidate) error

func (*RunContext) SetCandidates added in v1.1.1

func (context *RunContext) SetCandidates(candidates []*Candidate) error

type SyncFileDB added in v1.2.0

type SyncFileDB struct {
	Home string

	Height   uint
	BitCasks []*BitCask

	LevelDB *leveldb.LevelDBDatabase
	Extend  WriteExtend

	DoneChan  chan *Inject
	ErrChan   chan *Inject
	WriteChan chan *Inject
	Quit      chan struct{}
}

func NewSyncFileDB added in v1.2.0

func NewSyncFileDB(home string, levelDB *leveldb.LevelDBDatabase, doneChan chan *Inject, errChan chan *Inject, quit chan struct{}, extend WriteExtend) *SyncFileDB

func (*SyncFileDB) Get added in v1.2.0

func (db *SyncFileDB) Get(flag uint32, key []byte) ([]byte, error)

func (*SyncFileDB) Open added in v1.2.0

func (db *SyncFileDB) Open()

func (*SyncFileDB) Put added in v1.2.0

func (db *SyncFileDB) Put(flag uint32, key []byte, val []byte)

type TrieDatabase

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

Database is an intermediate write layer between the trie data structures and the disk database. The aim is to accumulate trie writes in-memory and only periodically flush a couple tries to disk, garbage collecting the remainder.

func NewTrieDatabase

func NewTrieDatabase(diskdb Database) *TrieDatabase

NewTrieDatabase creates a new trie database to store ephemeral trie content before its written out to disk or garbage collected.

func (*TrieDatabase) Commit

func (db *TrieDatabase) Commit(node common.Hash, report bool) error

Commit iterates over all the Children of a particular node, writes them out to disk, forcefully tearing down all references in both directions.

As a side effect, all pre-images accumulated up to this point are also written.

func (*TrieDatabase) Dereference

func (db *TrieDatabase) Dereference(child common.Hash, parent common.Hash)

Dereference removes an existing reference from a parent node to a child node.

func (*TrieDatabase) DiskDB

func (db *TrieDatabase) DiskDB() DatabaseReader

DiskDB retrieves the persistent storage backing the trie database.

func (*TrieDatabase) DiskDB4Test

func (db *TrieDatabase) DiskDB4Test() Database

func (*TrieDatabase) Insert

func (db *TrieDatabase) Insert(hash common.Hash, blob []byte)

Insert writes a new trie node to the memory database if it's yet unknown. The method will make a copy of the slice.

func (*TrieDatabase) InsertPreimage

func (db *TrieDatabase) InsertPreimage(hash common.Hash, preimage []byte)

insertPreimage writes a new trie node pre-image to the memory database if it's yet unknown. The method will make a copy of the slice.

Note, this method assumes that the database's lock is held!

func (*TrieDatabase) Lock

func (db *TrieDatabase) Lock()

func (*TrieDatabase) Node

func (db *TrieDatabase) Node(hash common.Hash) ([]byte, error)

Node retrieves a cached trie node from memory. If it cannot be found cached, the method queries the persistent database for the content.

func (*TrieDatabase) Nodes

func (db *TrieDatabase) Nodes() []common.Hash

Nodes retrieves the hashes of all the nodes cached within the memory database. This method is extremely expensive and should only be used to validate internal states in test code.

func (*TrieDatabase) Nodes4Test

func (db *TrieDatabase) Nodes4Test() map[common.Hash]*CachedNode

func (*TrieDatabase) Preimage

func (db *TrieDatabase) Preimage(hash common.Hash) ([]byte, error)

preimage retrieves a cached trie node pre-image from memory. If it cannot be found cached, the method queries the persistent database for the content.

func (*TrieDatabase) Reference

func (db *TrieDatabase) Reference(child common.Hash, parent common.Hash)

Reference adds a new reference from a parent node to a child node.

func (*TrieDatabase) Size

func (db *TrieDatabase) Size() common.StorageSize

Size returns the current storage size of the memory cache in front of the persistent database layer.

func (*TrieDatabase) UnLock

func (db *TrieDatabase) UnLock()

type VTransaction added in v1.1.0

type VTransaction struct {
	Tx          *types.Transaction `json:"tx" gencodec:"required"`
	PHash       common.Hash        `json:"pHash" gencodec:"required"`
	PackageTime uint32             `json:"time" gencodec:"required"`
	AssetCode   common.Hash        `json:"assetCode"`
	AssetId     common.Hash        `json:"assetId"`
}

func (VTransaction) MarshalJSON added in v1.1.0

func (v VTransaction) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*VTransaction) UnmarshalJSON added in v1.1.0

func (v *VTransaction) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type VTransactionDetail added in v1.1.0

type VTransactionDetail struct {
	BlockHash   common.Hash        `json:"blockHash" gencodec:"required"`
	PHash       common.Hash        `json:"pHash" gencodec:"required"`
	Height      uint32             `json:"height" gencodec:"required"`
	Tx          *types.Transaction `json:"tx"  gencodec:"required"`
	PackageTime uint32             `json:"time" gencodec:"required"`
	AssetCode   common.Hash        `json:"assetCode"`
	AssetId     common.Hash        `json:"assetId"`
}

func (VTransactionDetail) MarshalJSON added in v1.1.0

func (v VTransactionDetail) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*VTransactionDetail) UnmarshalJSON added in v1.1.0

func (v *VTransactionDetail) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type VoteTop added in v1.1.0

type VoteTop struct {
	Top []*Candidate
}

func NewEmptyVoteTop added in v1.1.1

func NewEmptyVoteTop() *VoteTop

func NewVoteTop added in v1.1.0

func NewVoteTop(top []*Candidate) *VoteTop

func (*VoteTop) Clear added in v1.1.0

func (top *VoteTop) Clear()

func (*VoteTop) Clone added in v1.1.0

func (top *VoteTop) Clone() *VoteTop

func (*VoteTop) Count added in v1.1.0

func (top *VoteTop) Count() int

func (*VoteTop) GetTop added in v1.1.0

func (top *VoteTop) GetTop() []*Candidate

func (*VoteTop) Max added in v1.1.0

func (top *VoteTop) Max() *Candidate

func (*VoteTop) MergeCandidates added in v1.4.0

func (top *VoteTop) MergeCandidates(candidates []*Candidate)

MergeCandidates merge candidates together

func (*VoteTop) Min added in v1.1.0

func (top *VoteTop) Min() *Candidate

func (*VoteTop) Rank added in v1.1.0

func (top *VoteTop) Rank(topSize int, candidates []*Candidate)

func (*VoteTop) RemoveCandidates added in v1.4.0

func (top *VoteTop) RemoveCandidates(candidates []*Candidate)

MergeCandidates merge candidates together

func (*VoteTop) Reset added in v1.1.0

func (top *VoteTop) Reset(candidates []*Candidate)

type WriteExtend added in v1.2.0

type WriteExtend interface {
	After(flg uint32, key []byte, val []byte) error
}

Directories

Path Synopsis
Package trie implements Merkle Patricia Tries.
Package trie implements Merkle Patricia Tries.

Jump to

Keyboard shortcuts

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