statedb

package
v0.0.0-...-3b47f62 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FromMem  KeyOrigin = iota
	FromBack           = iota
	FromBoth           = iota
)

Variables

View Source
var (
	ErrNotFound     = errors.ErrNotFound
	ErrIterReleased = errors.New("leveldb/memdb: iterator released")
)

Common errors.

Functions

This section is empty.

Types

type CacheDB

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

CacheDB is smart contract execute cache, it contains transaction cache and block cache When smart contract execute finish, need to commit transaction cache to block cache

func NewCacheDB

func NewCacheDB(store storage.PersistStore) *CacheDB

NewCacheDB return a new contract cache

func (*CacheDB) CleanContractStorage

func (self *CacheDB) CleanContractStorage(addr common.Address, height uint32) error

func (*CacheDB) CleanContractStorageData

func (self *CacheDB) CleanContractStorageData(addr common.Address) error

func (*CacheDB) Commit

func (self *CacheDB) Commit()

Commit current transaction cache to block cache

func (*CacheDB) DelEthAccount

func (self *CacheDB) DelEthAccount(addr ethcomm.Address)

func (*CacheDB) Delete

func (self *CacheDB) Delete(key []byte)

func (*CacheDB) DeleteContract

func (self *CacheDB) DeleteContract(address common.Address, height uint32)

func (*CacheDB) GenAccountStateKey

func (self *CacheDB) GenAccountStateKey(addr common.Address, key []byte) []byte

func (*CacheDB) Get

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

func (*CacheDB) GetEthAccount

func (self *CacheDB) GetEthAccount(addr ethcomm.Address) (val EthAccount, err error)

func (*CacheDB) GetEthCode

func (self *CacheDB) GetEthCode(codeHash ethcomm.Hash) (val []byte, err error)

func (*CacheDB) IsContractDestroyed

func (self *CacheDB) IsContractDestroyed(addr common.Address) (bool, error)

func (*CacheDB) MigrateContractStorage

func (self *CacheDB) MigrateContractStorage(oldAddress, newAddress common.Address, height uint32) error

func (*CacheDB) NewIterator

func (self *CacheDB) NewIterator(key []byte) storage.StoreIterator

func (*CacheDB) Put

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

func (*CacheDB) PutEthAccount

func (self *CacheDB) PutEthAccount(addr ethcomm.Address, val EthAccount)

func (*CacheDB) PutEthCode

func (self *CacheDB) PutEthCode(codeHash ethcomm.Hash, val []byte)

func (*CacheDB) Reset

func (self *CacheDB) Reset()

func (*CacheDB) SetContractDestroyed

func (self *CacheDB) SetContractDestroyed(addr common.Address, height uint32)

func (*CacheDB) SetDbErr

func (self *CacheDB) SetDbErr(err error)

func (*CacheDB) UnsetContractDestroyed

func (self *CacheDB) UnsetContractDestroyed(addr common.Address, height uint32)

type Dummy

type Dummy struct {
	Val map[common.Address]*big.Int
}

TODO 待实现

func NewDummy

func NewDummy() Dummy

func (Dummy) AddBalance

func (d Dummy) AddBalance(cache *CacheDB, addr common.Address, val *big.Int) error

func (Dummy) GetBalance

func (d Dummy) GetBalance(cache *CacheDB, addr common.Address) (*big.Int, error)

func (Dummy) SetBalance

func (d Dummy) SetBalance(cache *CacheDB, addr common.Address, val *big.Int) error

func (Dummy) SubBalance

func (d Dummy) SubBalance(cache *CacheDB, addr common.Address, val *big.Int) error

type EthAccount

type EthAccount struct {
	Nonce    uint64
	CodeHash ethcomm.Hash
}

func (*EthAccount) Deserialization

func (self *EthAccount) Deserialization(source *common.ZeroCopySource) error

func (*EthAccount) IsEmpty

func (self *EthAccount) IsEmpty() bool

func (*EthAccount) IsEmptyContract

func (self *EthAccount) IsEmptyContract() bool

func (*EthAccount) Serialization

func (self *EthAccount) Serialization(sink *common.ZeroCopySink)

type Iter

type Iter struct {
	*JoinIter
}

func (*Iter) Key

func (self *Iter) Key() []byte

type JoinIter

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

func NewJoinIter

func NewJoinIter(memIter, backendIter storage.StoreIterator) *JoinIter

func (*JoinIter) Error

func (iter *JoinIter) Error() error

func (*JoinIter) First

func (iter *JoinIter) First() bool

func (*JoinIter) Key

func (iter *JoinIter) Key() []byte

func (*JoinIter) Next

func (iter *JoinIter) Next() bool

func (*JoinIter) Release

func (iter *JoinIter) Release()

func (*JoinIter) Value

func (iter *JoinIter) Value() []byte

type KeyOrigin

type KeyOrigin byte

type MemDB

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

MemDB is an in-memdb key/value database.

func NewMemDB

func NewMemDB(capacity int, kvNum int) *MemDB

NewMemDB creates a new initialized in-memdb key/value MemDB. The capacity is the initial key/value buffer capacity. The capacity is advisory, not enforced.

This MemDB is append-only, deleting an entry would remove entry node but not reclaim KV buffer.

The returned MemDB instance is safe for concurrent use.

func (*MemDB) Capacity

func (p *MemDB) Capacity() int

Capacity returns keys/values buffer capacity.

func (*MemDB) DeepClone

func (self *MemDB) DeepClone() *MemDB

func (*MemDB) Delete

func (p *MemDB) Delete(key []byte)

Delete deletes the value for the given key.

It is safe to modify the contents of the arguments after Delete returns.

func (*MemDB) Find

func (p *MemDB) Find(key []byte) (rkey, value []byte, err error)

Find finds key/value pair whose key is greater than or equal to the given key. It returns ErrNotFound if the table doesn't contain such pair.

The caller should not modify the contents of the returned slice, but it is safe to modify the contents of the argument after Find returns.

func (*MemDB) ForEach

func (p *MemDB) ForEach(f func(key, val []byte))

func (*MemDB) Free

func (p *MemDB) Free() int

Free returns keys/values free buffer before need to grow.

func (*MemDB) Get

func (p *MemDB) Get(key []byte) (value []byte, unkown bool)

Get gets the value for the given key. It returns unkown == true if the MemDB does not contain the key. It returns nil, false if MemDB has deleted the key

The caller should not modify the contents of the returned slice, but it is safe to modify the contents of the argument after Get returns.

func (*MemDB) Len

func (p *MemDB) Len() int

Len returns the number of entries in the MemDB.

func (*MemDB) NewIterator

func (p *MemDB) NewIterator(slice *util.Range) iterator.Iterator

NewIterator returns an iterator of the MemDB. The returned iterator is not safe for concurrent use, but it is safe to use multiple iterators concurrently, with each in a dedicated goroutine. It is also safe to use an iterator concurrently with modifying its underlying MemDB. However, the resultant key/value pairs are not guaranteed to be a consistent snapshot of the MemDB at a particular point in time.

Slice allows slicing the iterator to only contains keys in the given range. A nil Range.Start is treated as a key before all keys in the MemDB. And a nil Range.Limit is treated as a key after all keys in the MemDB.

The iterator must be released after use, by calling Release method.

Also read Iterator documentation of the leveldb/iterator package.

func (*MemDB) Put

func (p *MemDB) Put(key []byte, value []byte)

Put sets the value for the given key. It overwrites any previous value for that key; a MemDB is not a multi-map.

It is safe to modify the contents of the arguments after Put returns.

func (*MemDB) Reset

func (p *MemDB) Reset()

Reset resets the MemDB to initial empty state. Allows reuse the buffer.

func (*MemDB) Size

func (p *MemDB) Size() int

Size returns sum of keys and values length. Note that deleted key/value will not be accounted for, but it will still consume the buffer, since the buffer is append only.

type OngBalanceHandle

type OngBalanceHandle interface {
	SubBalance(cache *CacheDB, addr common.Address, val *big.Int) error
	AddBalance(cache *CacheDB, addr common.Address, val *big.Int) error
	SetBalance(cache *CacheDB, addr common.Address, val *big.Int) error
	GetBalance(cache *CacheDB, addr common.Address) (*big.Int, error)
}

type StateDB

type StateDB struct {
	Suicided map[ethcomm.Address]bool

	OngBalanceHandle OngBalanceHandle
	// contains filtered or unexported fields
}

func NewStateDB

func NewStateDB(cacheDB *CacheDB, thash, bhash ethcomm.Hash, balanceHandle OngBalanceHandle) *StateDB

func (*StateDB) AddBalance

func (self *StateDB) AddBalance(addr ethcomm.Address, val *big.Int)

func (*StateDB) AddLog

func (self *StateDB) AddLog(log *common.StorageLog)

func (*StateDB) AddPreimage

func (self *StateDB) AddPreimage(ethcomm.Hash, []byte)

func (*StateDB) AddRefund

func (self *StateDB) AddRefund(gas uint64)

func (*StateDB) BlockHash

func (self *StateDB) BlockHash() ethcomm.Hash

func (*StateDB) Commit

func (self *StateDB) Commit() error

func (*StateDB) CommitToCacheDB

func (self *StateDB) CommitToCacheDB() error

func (*StateDB) CreateAccount

func (self *StateDB) CreateAccount(address ethcomm.Address)

func (*StateDB) Empty

func (self *StateDB) Empty(addr ethcomm.Address) bool

func (*StateDB) Exist

func (self *StateDB) Exist(addr ethcomm.Address) bool

func (*StateDB) ForEachStorage

func (self *StateDB) ForEachStorage(ethcomm.Address, func(ethcomm.Hash, ethcomm.Hash) bool) error

func (*StateDB) GetBalance

func (self *StateDB) GetBalance(addr ethcomm.Address) *big.Int

func (*StateDB) GetCode

func (self *StateDB) GetCode(addr ethcomm.Address) []byte

func (*StateDB) GetCodeHash

func (self *StateDB) GetCodeHash(addr ethcomm.Address) (hash ethcomm.Hash)

func (*StateDB) GetCodeSize

func (self *StateDB) GetCodeSize(addr ethcomm.Address) int

func (*StateDB) GetCommittedState

func (self *StateDB) GetCommittedState(addr ethcomm.Address, key ethcomm.Hash) ethcomm.Hash

func (*StateDB) GetLogs

func (self *StateDB) GetLogs() []*common.StorageLog

func (*StateDB) GetNonce

func (self *StateDB) GetNonce(addr ethcomm.Address) uint64

func (*StateDB) GetRefund

func (self *StateDB) GetRefund() uint64

GetRefund returns the current value of the refund counter.

func (*StateDB) GetState

func (self *StateDB) GetState(contract ethcomm.Address, key ethcomm.Hash) ethcomm.Hash

func (*StateDB) HasSuicided

func (self *StateDB) HasSuicided(addr ethcomm.Address) bool

func (*StateDB) Prepare

func (self *StateDB) Prepare(thash, bhash ethcomm.Hash)

func (*StateDB) RevertToSnapshot

func (self *StateDB) RevertToSnapshot(idx int)

func (*StateDB) SetCode

func (self *StateDB) SetCode(addr ethcomm.Address, code []byte)

func (*StateDB) SetNonce

func (self *StateDB) SetNonce(addr ethcomm.Address, nonce uint64)

func (*StateDB) SetState

func (self *StateDB) SetState(contract ethcomm.Address, key, value ethcomm.Hash)

func (*StateDB) Snapshot

func (self *StateDB) Snapshot() int

func (*StateDB) SubBalance

func (self *StateDB) SubBalance(addr ethcomm.Address, val *big.Int)

func (*StateDB) SubRefund

func (self *StateDB) SubRefund(gas uint64)

SubRefund removes gas from the refund counter. This method will panic if the refund counter goes below zero

func (*StateDB) Suicide

func (self *StateDB) Suicide(addr ethcomm.Address) bool

Jump to

Keyboard shortcuts

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