Documentation ¶
Index ¶
- Constants
- Variables
- func Byte2Uint32(val []byte) uint32
- func CheckSum(data []byte) uint16
- func ClearData()
- func CompareFile(index int, dataMFile *MFile, hintMFile *MFile, after int64) error
- func CreateBlock(hash common.Hash, parent common.Hash, height uint32) *types.Block
- func CreateBufWithNumber(size int) ([]byte, error)
- func CreateBufWithNumberBatch(cnt int, template []byte) ([][]byte, error)
- func CreateSign(cnt int) ([]types.SignData, error)
- func GetAccount(address string, balance int64, version uint32) *types.AccountData
- func GetAccounts() []*types.AccountData
- func GetBlock0() *types.Block
- func GetBlock1() *types.Block
- func GetBlock2() *types.Block
- func GetBucketIndex(pos uint32) uint32
- func GetItemIndex(pos uint32) uint32
- func GetPos(bucketIndex uint32, itemIndex uint32) uint32
- func GetStorePath() string
- func IsExist(path string) (bool, error)
- func NewKey1() ([]byte, uint32)
- func NewKey2() ([]byte, uint32)
- func NewKey3() ([]byte, uint32)
- func ScanDataFile(index int, dataPath string, hintPath string) error
- func SetItems(pool *CachePool, items []*TItem) (uint32, error)
- func SetNodes(pool *CachePool, nodes []*Node) (uint32, error)
- func UpdateItems(pool *CachePool, start uint32, items []*TItem) error
- func UpdateNodes(pool *CachePool, header uint32, nodes []*Node) error
- type Batch
- type BatchItem
- type CacheBucket
- type CacheChain
- func (chain *CacheChain) AppendConfirmInfo(hash common.Hash, signData types.SignData) error
- func (chain *CacheChain) AppendConfirms(hash common.Hash, pack []types.SignData) error
- func (chain *CacheChain) Close() error
- func (chain *CacheChain) DelAccount(address common.Address) error
- func (chain *CacheChain) GetAccount(blockHash common.Hash, address common.Address) (*types.AccountData, error)
- func (chain *CacheChain) GetBlock(hash common.Hash, height uint32) (*types.Block, error)
- func (chain *CacheChain) GetBlockByHash(hash common.Hash) (*types.Block, error)
- func (chain *CacheChain) GetBlockByHeight(height uint32) (*types.Block, error)
- func (chain *CacheChain) GetCanonicalAccount(address common.Address) (*types.AccountData, error)
- func (chain *CacheChain) GetConfirms(hash common.Hash) ([]types.SignData, error)
- func (chain *CacheChain) GetContractCode(codeHash common.Hash) (types.Code, error)
- func (chain *CacheChain) GetTrieDatabase() *TrieDatabase
- func (chain *CacheChain) IsExistByHash(hash common.Hash) (bool, error)
- func (chain *CacheChain) LoadLatestBlock() (*types.Block, error)
- func (chain *CacheChain) SetAccounts(blockHash common.Hash, accounts []*types.AccountData) error
- func (chain *CacheChain) SetBlock(hash common.Hash, block *types.Block) error
- func (chain *CacheChain) SetConfirmInfo(hash common.Hash, signData types.SignData) error
- func (chain *CacheChain) SetConfirms(hash common.Hash, pack []types.SignData) error
- func (chain *CacheChain) SetContractCode(codeHash common.Hash, code types.Code) error
- func (chain *CacheChain) SetStableBlock(hash common.Hash) error
- type CachePool
- func (pool *CachePool) Get(header uint32, index uint32) ([]byte, error)
- func (pool *CachePool) GetUnit(header uint32) ([]byte, error)
- func (pool *CachePool) Malloc(size uint32) *bytes.Buffer
- func (pool *CachePool) SetUnit(buf []byte) (uint32, error)
- func (pool *CachePool) UpdateUnit(start uint32, buf []byte) error
- type CachedNode
- type ContextFileHeader
- type Database
- type DatabaseReader
- type HItem
- type HintItem
- type Index
- type LDBBatch
- type LDBDatabase
- func (db *LDBDatabase) Close()
- func (db *LDBDatabase) Delete(key []byte) error
- func (db *LDBDatabase) Get(key []byte) ([]byte, error)
- func (db *LDBDatabase) Has(key []byte) (bool, error)
- func (db *LDBDatabase) LDB() *LmDataBase
- func (db *LDBDatabase) NewBatch() Batch
- func (db *LDBDatabase) Put(key []byte, value []byte) error
- type LmBuffer
- type LmDataBase
- func (database *LmDataBase) Close() error
- func (database *LmDataBase) Commit(items []*BatchItem) error
- func (database *LmDataBase) CurrentBlock() []byte
- func (database *LmDataBase) Delete(key []byte) error
- func (database *LmDataBase) Get(key []byte) ([]byte, error)
- func (database *LmDataBase) Has(key []byte) (bool, error)
- func (database *LmDataBase) Put(key []byte, val []byte) error
- func (database *LmDataBase) ScanDataFiles() error
- func (database *LmDataBase) SetCurrentBlock(block []byte) error
- type MFile
- type MemDatabase
- func (db *MemDatabase) Close()
- func (db *MemDatabase) Delete(key []byte) error
- func (db *MemDatabase) Get(key []byte) ([]byte, error)
- func (db *MemDatabase) Has(key []byte) (bool, error)
- func (db *MemDatabase) Keys() [][]byte
- func (db *MemDatabase) Len() int
- func (db *MemDatabase) NewBatch() Batch
- func (db *MemDatabase) Put(key []byte, value []byte) error
- type Node
- type Putter
- type RecordHeader
- type TItem
- type Tree
- type TrieDatabase
- func (db *TrieDatabase) Commit(node common.Hash, report bool) error
- func (db *TrieDatabase) Dereference(child common.Hash, parent common.Hash)
- func (db *TrieDatabase) DiskDB() DatabaseReader
- func (db *TrieDatabase) DiskDB4Test() Database
- func (db *TrieDatabase) Insert(hash common.Hash, blob []byte)
- func (db *TrieDatabase) InsertPreimage(hash common.Hash, preimage []byte)
- func (db *TrieDatabase) Lock()
- func (db *TrieDatabase) Node(hash common.Hash) ([]byte, error)
- func (db *TrieDatabase) Nodes() []common.Hash
- func (db *TrieDatabase) Nodes4Test() map[common.Hash]*CachedNode
- func (db *TrieDatabase) Preimage(hash common.Hash) ([]byte, error)
- func (db *TrieDatabase) Reference(child common.Hash, parent common.Hash)
- func (db *TrieDatabase) Size() common.StorageSize
- func (db *TrieDatabase) UnLock()
Constants ¶
const IdealBatchSize = 100 * 1024
Code using batches should try to add this much data to the batch. The value was determined empirically.
Variables ¶
var ( ErrArgInvalid = errors.New("invalid argument") ErrExist = errors.New("item already exists") ErrNotExist = errors.New("item 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("") )
var M10 = int64(1024 * 1024 * 10)
var MbTable = []uint16{}/* 256 elements not displayed */
var OpenFileLimit = 64
Functions ¶
func Byte2Uint32 ¶
func CompareFile ¶
func CreateBlock ¶
func CreateBufWithNumber ¶
func GetAccount ¶
func GetAccount(address string, balance int64, version uint32) *types.AccountData
func GetAccounts ¶
func GetAccounts() []*types.AccountData
func GetBucketIndex ¶
func GetItemIndex ¶
func GetStorePath ¶
func GetStorePath() string
Types ¶
type Batch ¶
type Batch interface { Putter ValueSize() int // amount of data in the batch Write() error // Reset resets the batch for reuse Reset() }
Batch is a write-only database that commits changes to its host database when Write is called. Batch cannot be used concurrently.
type CacheBucket ¶
type CacheBucket struct { Index uint32 MaxCnt uint32 UsedCnt uint32 ItemLen uint8 UnitCnt uint8 Buf []byte }
func NewCacheBucket ¶
func NewCacheBucket(index uint32, maxCnt uint32, itemLen uint8) *CacheBucket
func (*CacheBucket) Remind ¶
func (bucket *CacheBucket) Remind() uint32
func (*CacheBucket) UpdateUint ¶
func (bucket *CacheBucket) UpdateUint(start uint32, buf []byte) error
type CacheChain ¶
type CacheChain struct { ConfirmNum int64 Blocks map[common.Hash]*types.Block Accounts map[common.Hash]map[common.Address]*types.AccountData LmDataBase *LmDataBase }
func NewCacheChain ¶
func NewCacheChain(path string) (*CacheChain, error)
func (*CacheChain) AppendConfirmInfo ¶
func (*CacheChain) AppendConfirms ¶
func (*CacheChain) Close ¶
func (chain *CacheChain) Close() error
func (*CacheChain) DelAccount ¶
func (chain *CacheChain) DelAccount(address common.Address) error
func (*CacheChain) GetAccount ¶
func (chain *CacheChain) GetAccount(blockHash common.Hash, address common.Address) (*types.AccountData, error)
GetAccount loads account from cache or db
func (*CacheChain) GetBlockByHash ¶
func (*CacheChain) GetBlockByHeight ¶
func (chain *CacheChain) GetBlockByHeight(height uint32) (*types.Block, error)
func (*CacheChain) GetCanonicalAccount ¶
func (chain *CacheChain) GetCanonicalAccount(address common.Address) (*types.AccountData, error)
func (*CacheChain) GetConfirms ¶
获取区块的确认包 获取不到返回:nil,原因
func (*CacheChain) GetContractCode ¶
GetContractCode loads contract's code from db.
func (*CacheChain) GetTrieDatabase ¶
func (chain *CacheChain) GetTrieDatabase() *TrieDatabase
OpenStorageTrie opens the storage trie of an account.
func (*CacheChain) IsExistByHash ¶
func (chain *CacheChain) IsExistByHash(hash common.Hash) (bool, error)
func (*CacheChain) LoadLatestBlock ¶
func (chain *CacheChain) LoadLatestBlock() (*types.Block, error)
func (*CacheChain) SetAccounts ¶
func (chain *CacheChain) SetAccounts(blockHash common.Hash, accounts []*types.AccountData) error
SetAccounts saves dirty accounts generated by a block
func (*CacheChain) SetConfirmInfo ¶
设置区块的确认信息 每次收到一个
func (*CacheChain) SetConfirms ¶
func (*CacheChain) SetContractCode ¶
SetContractCode saves contract's code
func (*CacheChain) SetStableBlock ¶
func (chain *CacheChain) SetStableBlock(hash common.Hash) error
区块得到共识
type CachePool ¶
type CachePool struct { Current uint32 MaxCnt uint32 ItemLen uint8 Buckets []*CacheBucket UintBuf *bytes.Buffer }
func NewCachePool ¶
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 ContextFileHeader ¶
type Database ¶
type Database interface { Putter Get(key []byte) ([]byte, error) Has(key []byte) (bool, error) Delete(key []byte) error Close() NewBatch() Batch }
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(key []byte) (value []byte, err error) // Has retrieves whether a key is present in the database. Has(key []byte) (bool, error) }
DatabaseReader wraps the Get and Has method of a backing store for the trie.
type LDBDatabase ¶
type LDBDatabase struct {
// contains filtered or unexported fields
}
func NewLDBDatabase ¶
func NewLDBDatabase(database *LmDataBase, cache int, handles int) *LDBDatabase
NewLDBDatabase returns a LevelDB wrapped object.
func (*LDBDatabase) Close ¶
func (db *LDBDatabase) Close()
func (*LDBDatabase) Delete ¶
func (db *LDBDatabase) Delete(key []byte) error
Delete deletes the key from the queue and database
func (*LDBDatabase) Get ¶
func (db *LDBDatabase) Get(key []byte) ([]byte, error)
Get returns the given key if it's present.
func (*LDBDatabase) LDB ¶
func (db *LDBDatabase) LDB() *LmDataBase
func (*LDBDatabase) NewBatch ¶
func (db *LDBDatabase) NewBatch() Batch
type LmBuffer ¶
type LmBuffer struct {
// contains filtered or unexported fields
}
func NewLmBuffer ¶
type LmDataBase ¶
type LmDataBase struct { HomePath string CurIndex int CurOffset int64 Tree *Tree Buf *bytes.Buffer Context [][]byte // contains filtered or unexported fields }
func NewLmDataBase ¶
func NewLmDataBase(homePath string) (*LmDataBase, error)
func (*LmDataBase) Close ¶
func (database *LmDataBase) Close() error
func (*LmDataBase) Commit ¶
func (database *LmDataBase) Commit(items []*BatchItem) error
func (*LmDataBase) CurrentBlock ¶
func (database *LmDataBase) CurrentBlock() []byte
func (*LmDataBase) Delete ¶
func (database *LmDataBase) Delete(key []byte) error
func (*LmDataBase) ScanDataFiles ¶
func (database *LmDataBase) ScanDataFiles() error
func (*LmDataBase) SetCurrentBlock ¶
func (database *LmDataBase) SetCurrentBlock(block []byte) error
type MFile ¶
type MFile struct {
// contains filtered or unexported fields
}
func OpenMFileForRead ¶
func OpenMFileForWrite ¶
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(key []byte) 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
type Putter ¶
Putter wraps the database write operation supported by both batches and regular databases.
type RecordHeader ¶
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()