chain_state

package
v2.10.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STOP   = 0
	INITED = 1
)
View Source
const (
	ConsensusNoCache   = 0
	ConsensusReadCache = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain interface {
	IterateAccounts(iterateFunc func(addr types.Address, accountId uint64, err error) bool)

	QueryLatestSnapshotBlock() (*ledger.SnapshotBlock, error)

	GetLatestSnapshotBlock() *ledger.SnapshotBlock

	GetSnapshotHeightByHash(hash types.Hash) (uint64, error)

	GetUnconfirmedBlocks(addr types.Address) []*ledger.AccountBlock

	GetAccountBlockByHash(blockHash types.Hash) (*ledger.AccountBlock, error)

	GetSnapshotHeaderBeforeTime(timestamp *time.Time) (*ledger.SnapshotBlock, error)

	GetSnapshotHeadersAfterOrEqualTime(endHashHeight *ledger.HashHeight, startTime *time.Time, producer *types.Address) ([]*ledger.SnapshotBlock, error)

	// header without snapshot content
	GetSnapshotHeaderByHeight(height uint64) (*ledger.SnapshotBlock, error)

	StopWrite()

	RecoverWrite()
}

type Consensus

type Consensus interface {
	VerifyAccountProducer(block *ledger.AccountBlock) (bool, error)
	SBPReader() core.SBPStatReader
}

type EventListener

type EventListener interface {
	PrepareInsertAccountBlocks(blocks []*vm_db.VmAccountBlock) error
	InsertAccountBlocks(blocks []*vm_db.VmAccountBlock) error

	PrepareInsertSnapshotBlocks(snapshotBlocks []*ledger.SnapshotBlock) error
	InsertSnapshotBlocks(snapshotBlocks []*ledger.SnapshotBlock) error

	PrepareDeleteAccountBlocks(blocks []*ledger.AccountBlock) error
	DeleteAccountBlocks(blocks []*ledger.AccountBlock) error

	PrepareDeleteSnapshotBlocks(chunks []*ledger.SnapshotChunk) error
	DeleteSnapshotBlocks(chunks []*ledger.SnapshotChunk) error
}

type FlushingBatch

type FlushingBatch struct {
	Operation byte
	Batch     *leveldb.Batch
}

type LogItem

type LogItem struct {
	Storage      [][2][]byte
	BalanceMap   map[types.TokenTypeId]*big.Int
	Code         []byte
	ContractMeta map[types.Address][]byte
	VmLogList    map[types.Hash][]byte
	CallDepth    map[types.Hash]uint16
	Height       uint64 // account block height
}

type MemPool

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

func NewMemPool

func NewMemPool(byteSliceLimit int, intSliceLimit int) *MemPool

func (*MemPool) GetByteSlice

func (mp *MemPool) GetByteSlice(n int) []byte

func (*MemPool) GetIntSlice

func (mp *MemPool) GetIntSlice(n int) []int

func (*MemPool) Put

func (mp *MemPool) Put(x interface{})

type Redo

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

func NewStorageRedoWithStore

func NewStorageRedoWithStore(chain Chain, store *chain_db.Store) (*Redo, error)

func (*Redo) AddLog

func (redo *Redo) AddLog(addr types.Address, log LogItem)

func (*Redo) Close

func (redo *Redo) Close() error

func (*Redo) HasRedo

func (redo *Redo) HasRedo(snapshotHeight uint64) (bool, error)

func (*Redo) InsertSnapshotBlock

func (redo *Redo) InsertSnapshotBlock(snapshotBlock *ledger.SnapshotBlock, confirmedBlocks []*ledger.AccountBlock)

func (*Redo) QueryLog

func (redo *Redo) QueryLog(snapshotHeight uint64) (SnapshotLog, bool, error)

func (*Redo) Rollback

func (redo *Redo) Rollback(chunks []*ledger.SnapshotChunk)

func (*Redo) SetCurrentSnapshot

func (redo *Redo) SetCurrentSnapshot(snapshotHeight uint64, logMap SnapshotLog)

type RedoCache

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

func NewRedoCache

func NewRedoCache() *RedoCache

func (*RedoCache) AddLog

func (redoCache *RedoCache) AddLog(addr types.Address, log LogItem)

func (*RedoCache) Current

func (redoCache *RedoCache) Current() SnapshotLog

func (*RedoCache) Delete

func (redoCache *RedoCache) Delete(snapshotHeight uint64)

func (*RedoCache) Get

func (redoCache *RedoCache) Get(snapshotHeight uint64) (SnapshotLog, bool)

func (*RedoCache) Init

func (redoCache *RedoCache) Init(currentHeight uint64)

func (*RedoCache) Set

func (redoCache *RedoCache) Set(snapshotHeight uint64, snapshotLog SnapshotLog)

func (*RedoCache) SetCurrent

func (redoCache *RedoCache) SetCurrent(snapshotHeight uint64, snapshotLog SnapshotLog)

type RedoCacheData

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

func NewRedoCacheData

func NewRedoCacheData(roundIndex uint64, lastSnapshotBlock *ledger.SnapshotBlock, currentData *memdb.DB, redoLogs *RoundCacheRedoLogs) *RedoCacheData

type RedoInterface

type RedoInterface interface {
	Close() error
	InsertSnapshotBlock(snapshotBlock *ledger.SnapshotBlock, confirmedBlocks []*ledger.AccountBlock)
	HasRedo(snapshotHeight uint64) (bool, error)
	QueryLog(snapshotHeight uint64) (SnapshotLog, bool, error)
	SetCurrentSnapshot(snapshotHeight uint64, logMap SnapshotLog)
	AddLog(addr types.Address, log LogItem)
	Rollback(chunks []*ledger.SnapshotChunk)
	// contains filtered or unexported methods
}

type RoundCache

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

func NewRoundCache

func NewRoundCache(chain Chain, stateDB StateDBInterface, roundCount uint8) *RoundCache

func (*RoundCache) DeleteSnapshotBlocks

func (cache *RoundCache) DeleteSnapshotBlocks(snapshotBlocks []*ledger.SnapshotBlock) error

panic when return error

func (*RoundCache) GetSnapshotViteBalanceList

func (cache *RoundCache) GetSnapshotViteBalanceList(snapshotHash types.Hash, addrList []types.Address) (map[types.Address]*big.Int, []types.Address, error)

tokenId is viteTokenID

func (*RoundCache) Init

func (cache *RoundCache) Init(timeIndex core.TimeIndex) (returnErr error)

build data

func (*RoundCache) InsertSnapshotBlock

func (cache *RoundCache) InsertSnapshotBlock(snapshotBlock *ledger.SnapshotBlock, snapshotLog SnapshotLog) (returnErr error)

panic when return error

func (*RoundCache) StorageIterator

func (cache *RoundCache) StorageIterator(snapshotHash types.Hash) interfaces.StorageIterator

type RoundCacheInterface

type RoundCacheInterface interface {
	Init(timeIndex core.TimeIndex) (returnErr error)
	InsertSnapshotBlock(snapshotBlock *ledger.SnapshotBlock, snapshotLog SnapshotLog) (returnErr error)
	DeleteSnapshotBlocks(snapshotBlocks []*ledger.SnapshotBlock) error
	GetSnapshotViteBalanceList(snapshotHash types.Hash, addrList []types.Address) (map[types.Address]*big.Int, []types.Address, error)
	StorageIterator(snapshotHash types.Hash) interfaces.StorageIterator
	// contains filtered or unexported methods
}

type RoundCacheLogItem

type RoundCacheLogItem struct {
	Storage    [][2][]byte
	BalanceMap map[types.TokenTypeId]*big.Int
}

type RoundCacheRedoLogs

type RoundCacheRedoLogs struct {
	Logs []*RoundCacheSnapshotLog
}

func NewRoundCacheRedoLogs

func NewRoundCacheRedoLogs() *RoundCacheRedoLogs

func (*RoundCacheRedoLogs) Add

func (redoLogs *RoundCacheRedoLogs) Add(snapshotHeight uint64, snapshotLog SnapshotLog)

type RoundCacheSnapshotLog

type RoundCacheSnapshotLog struct {
	LogMap map[types.Address][]RoundCacheLogItem

	SnapshotHeight uint64
}

type SnapshotLog

type SnapshotLog map[types.Address][]LogItem

func (*SnapshotLog) Deserialize

func (sl *SnapshotLog) Deserialize(buf []byte) error

func (*SnapshotLog) Serialize

func (sl *SnapshotLog) Serialize() ([]byte, error)

type StateDB

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

func NewStateDB

func NewStateDB(chain Chain, chainCfg *config.Chain, chainDir string) (*StateDB, error)

func NewStateDBWithStore

func NewStateDBWithStore(chain Chain, chainCfg *config.Chain, store *chain_db.Store, redoStore *chain_db.Store) (*StateDB, error)

func (*StateDB) Close

func (sDB *StateDB) Close() error

func (*StateDB) GetBalance

func (sDB *StateDB) GetBalance(addr types.Address, tokenTypeId types.TokenTypeId) (*big.Int, error)

func (*StateDB) GetBalanceMap

func (sDB *StateDB) GetBalanceMap(addr types.Address) (map[types.TokenTypeId]*big.Int, error)

func (*StateDB) GetCallDepth

func (sDB *StateDB) GetCallDepth(sendBlockHash *types.Hash) (uint16, error)

func (*StateDB) GetCode

func (sDB *StateDB) GetCode(addr types.Address) ([]byte, error)

func (*StateDB) GetContractList

func (sDB *StateDB) GetContractList(gid *types.Gid) ([]types.Address, error)

func (*StateDB) GetContractMeta

func (sDB *StateDB) GetContractMeta(addr types.Address) (*ledger.ContractMeta, error)

func (*StateDB) GetSnapshotBalanceList

func (sDB *StateDB) GetSnapshotBalanceList(balanceMap map[types.Address]*big.Int, snapshotBlockHash types.Hash, addrList []types.Address, tokenId types.TokenTypeId) error

func (*StateDB) GetSnapshotValue

func (sDB *StateDB) GetSnapshotValue(snapshotBlockHeight uint64, addr types.Address, key []byte) ([]byte, error)

func (*StateDB) GetStatus

func (sDB *StateDB) GetStatus() []interfaces.DBStatus

func (*StateDB) GetStorageValue

func (sDB *StateDB) GetStorageValue(addr *types.Address, key []byte) ([]byte, error)

func (*StateDB) GetVmLogList

func (sDB *StateDB) GetVmLogList(logHash *types.Hash) (ledger.VmLogList, error)

func (*StateDB) HasContractMeta

func (sDB *StateDB) HasContractMeta(addr types.Address) (bool, error)

func (*StateDB) Init

func (sDB *StateDB) Init() error

func (*StateDB) InsertSnapshotBlock

func (sDB *StateDB) InsertSnapshotBlock(snapshotBlock *ledger.SnapshotBlock, confirmedBlocks []*ledger.AccountBlock) error

func (*StateDB) IterateContracts

func (sDB *StateDB) IterateContracts(iterateFunc func(addr types.Address, meta *ledger.ContractMeta, err error) bool)

func (*StateDB) NewRawSnapshotStorageIteratorByHeight

func (sDB *StateDB) NewRawSnapshotStorageIteratorByHeight(snapshotHeight uint64, addr types.Address, prefix []byte) interfaces.StorageIterator

func (*StateDB) NewSnapshotStorageIterator

func (sDB *StateDB) NewSnapshotStorageIterator(snapshotHash types.Hash, addr types.Address, prefix []byte) (interfaces.StorageIterator, error)

func (*StateDB) NewSnapshotStorageIteratorByHeight

func (sDB *StateDB) NewSnapshotStorageIteratorByHeight(snapshotHeight uint64, addr types.Address, prefix []byte) (interfaces.StorageIterator, error)

func (*StateDB) NewStorageDatabase

func (sDB *StateDB) NewStorageDatabase(snapshotHash types.Hash, addr types.Address) (StorageDatabaseInterface, error)

func (*StateDB) NewStorageIterator

func (sDB *StateDB) NewStorageIterator(addr types.Address, prefix []byte) interfaces.StorageIterator

func (*StateDB) Redo

func (sDB *StateDB) Redo() RedoInterface

func (*StateDB) RedoStore

func (sDB *StateDB) RedoStore() *chain_db.Store

func (*StateDB) RollbackAccountBlocks

func (sDB *StateDB) RollbackAccountBlocks(accountBlocks []*ledger.AccountBlock) error

func (*StateDB) RollbackSnapshotBlocks

func (sDB *StateDB) RollbackSnapshotBlocks(deletedSnapshotSegments []*ledger.SnapshotChunk, newUnconfirmedBlocks []*ledger.AccountBlock) error

func (*StateDB) SetCacheLevelForConsensus

func (sDB *StateDB) SetCacheLevelForConsensus(level uint32)

func (*StateDB) SetConsensus

func (sDB *StateDB) SetConsensus(cs Consensus) error

func (*StateDB) Store

func (sDB *StateDB) Store() *chain_db.Store

func (*StateDB) Write

func (sDB *StateDB) Write(block *vm_db.VmAccountBlock) error

func (*StateDB) WriteByRedo

func (sDB *StateDB) WriteByRedo(blockHash types.Hash, addr types.Address, redoLog LogItem)

type StateDBInterface

type StateDBInterface interface {
	NewStorageIterator(addr types.Address, prefix []byte) interfaces.StorageIterator
	NewSnapshotStorageIteratorByHeight(snapshotHeight uint64, addr types.Address, prefix []byte) (interfaces.StorageIterator, error)
	NewSnapshotStorageIterator(snapshotHash types.Hash, addr types.Address, prefix []byte) (interfaces.StorageIterator, error)
	NewRawSnapshotStorageIteratorByHeight(snapshotHeight uint64, addr types.Address, prefix []byte) interfaces.StorageIterator
	RollbackSnapshotBlocks(deletedSnapshotSegments []*ledger.SnapshotChunk, newUnconfirmedBlocks []*ledger.AccountBlock) error
	RollbackAccountBlocks(accountBlocks []*ledger.AccountBlock) error

	Init() error
	Close() error
	SetConsensus(cs Consensus) error
	GetStorageValue(addr *types.Address, key []byte) ([]byte, error)
	GetBalance(addr types.Address, tokenTypeId types.TokenTypeId) (*big.Int, error)
	GetBalanceMap(addr types.Address) (map[types.TokenTypeId]*big.Int, error)
	GetCode(addr types.Address) ([]byte, error)
	GetContractMeta(addr types.Address) (*ledger.ContractMeta, error)
	IterateContracts(iterateFunc func(addr types.Address, meta *ledger.ContractMeta, err error) bool)
	HasContractMeta(addr types.Address) (bool, error)
	GetContractList(gid *types.Gid) ([]types.Address, error)
	GetVmLogList(logHash *types.Hash) (ledger.VmLogList, error)
	GetCallDepth(sendBlockHash *types.Hash) (uint16, error)
	GetSnapshotBalanceList(balanceMap map[types.Address]*big.Int, snapshotBlockHash types.Hash, addrList []types.Address, tokenId types.TokenTypeId) error
	GetSnapshotValue(snapshotBlockHeight uint64, addr types.Address, key []byte) ([]byte, error)
	SetCacheLevelForConsensus(level uint32)
	Store() *chain_db.Store
	RedoStore() *chain_db.Store
	Redo() RedoInterface
	GetStatus() []interfaces.DBStatus

	NewStorageDatabase(snapshotHash types.Hash, addr types.Address) (StorageDatabaseInterface, error)

	Write(block *vm_db.VmAccountBlock) error
	WriteByRedo(blockHash types.Hash, addr types.Address, redoLog LogItem)
	InsertSnapshotBlock(snapshotBlock *ledger.SnapshotBlock, confirmedBlocks []*ledger.AccountBlock) error
	// contains filtered or unexported methods
}

type StorageDatabase

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

func (*StorageDatabase) Address

func (sd *StorageDatabase) Address() *types.Address

func (*StorageDatabase) GetValue

func (sd *StorageDatabase) GetValue(key []byte) ([]byte, error)

func (*StorageDatabase) NewStorageIterator

func (sd *StorageDatabase) NewStorageIterator(prefix []byte) (interfaces.StorageIterator, error)

type StorageDatabaseInterface

type StorageDatabaseInterface interface {
	GetValue(key []byte) ([]byte, error)
	NewStorageIterator(prefix []byte) (interfaces.StorageIterator, error)
	Address() *types.Address
}

func NewStorageDatabase

func NewStorageDatabase(stateDb *StateDB, hashHeight ledger.HashHeight, addr types.Address) StorageDatabaseInterface

type TimeIndex

type TimeIndex interface {
	Index2Time(index uint64) (time.Time, time.Time)
	Time2Index(t time.Time) uint64
}

type TransformIterator

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

func NewTransformIterator

func NewTransformIterator(iter iterator.Iterator, keyPrefixLength int) *TransformIterator

func (*TransformIterator) Error

func (rcIter *TransformIterator) Error() error

func (*TransformIterator) Key

func (rcIter *TransformIterator) Key() []byte

func (*TransformIterator) Last

func (rcIter *TransformIterator) Last() bool

func (*TransformIterator) Next

func (rcIter *TransformIterator) Next() bool

func (*TransformIterator) Prev

func (rcIter *TransformIterator) Prev() bool

func (*TransformIterator) Release

func (rcIter *TransformIterator) Release()

func (*TransformIterator) Seek

func (rcIter *TransformIterator) Seek(key []byte) bool

func (*TransformIterator) Value

func (rcIter *TransformIterator) Value() []byte

Jump to

Keyboard shortcuts

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