Documentation ¶
Index ¶
- Constants
- Variables
- func GetBalanceKey(address common.Address) []byte
- func GetCommitNumKey(address common.Address) []byte
- func GetContractAddrAndKey(key []byte) (common.Address, []byte)
- func GetContractFieldKey(address common.Address, key string) []byte
- func GetContractRootKey(address common.Address) []byte
- func GetDataRootKey(address common.Address) []byte
- func GetHashLockKey(address common.Address) []byte
- func GetLastElectKey(address common.Address) []byte
- func GetNonceKey(address common.Address) []byte
- func GetPerformanceKey(address common.Address) []byte
- func GetStakeKey(address common.Address) []byte
- func GetTimeLockKey(address common.Address) []byte
- func GetVerifyNumKey(address common.Address) []byte
- type AccountStateDB
- func (state *AccountStateDB) AddBalance(addr common.Address, amount *big.Int) error
- func (state *AccountStateDB) AddNonce(addr common.Address, amount uint64) error
- func (state *AccountStateDB) AddStake(addr common.Address, amount *big.Int) error
- func (state *AccountStateDB) Commit() (common.Hash, error)
- func (state *AccountStateDB) ContractExist(addr common.Address) bool
- func (state *AccountStateDB) Copy() *AccountStateDB
- func (state *AccountStateDB) DeleteAccountState(addr common.Address) error
- func (state *AccountStateDB) Finalise() (result common.Hash, err error)
- func (state *AccountStateDB) GetAccountState(addr common.Address) (*account, error)
- func (state *AccountStateDB) GetBalance(addr common.Address) (*big.Int, error)
- func (state *AccountStateDB) GetCommitNum(addr common.Address) (uint64, error)
- func (state *AccountStateDB) GetContract(addr common.Address, vType reflect.Type) (v reflect.Value, err error)
- func (state *AccountStateDB) GetDataRoot(addr common.Address) (common.Hash, error)
- func (state *AccountStateDB) GetHashLock(addr common.Address) (common.Hash, error)
- func (state *AccountStateDB) GetLastElect(addr common.Address) (uint64, error)
- func (state *AccountStateDB) GetNonce(addr common.Address) (uint64, error)
- func (state *AccountStateDB) GetPerformance(addr common.Address) (uint64, error)
- func (state *AccountStateDB) GetStake(addr common.Address) (*big.Int, error)
- func (state *AccountStateDB) GetTimeLock(addr common.Address) (*big.Int, error)
- func (state *AccountStateDB) GetVerifyNum(addr common.Address) (uint64, error)
- func (state *AccountStateDB) IsEmptyAccount(addr common.Address) bool
- func (state *AccountStateDB) MoveStakeToAddress(fromAdd common.Address, toAdd common.Address) error
- func (state *AccountStateDB) NewAccountState(addr common.Address) error
- func (state *AccountStateDB) PreStateRoot() common.Hash
- func (state *AccountStateDB) ProcessPerformance(address common.Address, amount float64) error
- func (state *AccountStateDB) ProcessTx(tx model.AbstractTransaction, height uint64) (err error)
- func (state *AccountStateDB) ProcessVerification(v model.AbstractVerification, index int) error
- func (state *AccountStateDB) ProcessVerifierNumber(address common.Address) error
- func (state *AccountStateDB) PutContract(addr common.Address, v reflect.Value) error
- func (state *AccountStateDB) RevertToSnapshot(revid int)
- func (state *AccountStateDB) SetBalance(addr common.Address, amount *big.Int) error
- func (state *AccountStateDB) SetCommitNum(addr common.Address, amount uint64) error
- func (state *AccountStateDB) SetDataRoot(addr common.Address, dataRoot common.Hash) error
- func (state *AccountStateDB) SetHashLock(addr common.Address, hashLock common.Hash) error
- func (state *AccountStateDB) SetLastElect(addr common.Address, blockID uint64) error
- func (state *AccountStateDB) SetNonce(addr common.Address, amount uint64) error
- func (state *AccountStateDB) SetPerformance(addr common.Address, amount uint64) error
- func (state *AccountStateDB) SetStake(addr common.Address, amount *big.Int) error
- func (state *AccountStateDB) SetTimeLock(addr common.Address, timeLock *big.Int) error
- func (state *AccountStateDB) SetVerifyNum(addr common.Address, amount uint64) error
- func (state *AccountStateDB) Snapshot() int
- func (state *AccountStateDB) Stake(addr common.Address, amount *big.Int) error
- func (state *AccountStateDB) SubBalance(addr common.Address, amount *big.Int) error
- func (state *AccountStateDB) SubStake(addr common.Address, amount *big.Int) error
- func (state *AccountStateDB) UnStake(addr common.Address) error
- type AccountStateProcessor
- type AccountStateReader
- type ManagedState
- func (ms *ManagedState) GetNonce(addr common.Address) uint64
- func (ms *ManagedState) HasAccount(addr common.Address) bool
- func (ms *ManagedState) NewNonce(addr common.Address) uint64
- func (ms *ManagedState) RemoveNonce(addr common.Address, n uint64)
- func (ms *ManagedState) SetNonce(addr common.Address, nonce uint64)
- func (ms *ManagedState) SetState(statedb *AccountStateDB)
- type NodeList
- type NodeSet
- func (db *NodeSet) DataSize() int
- func (db *NodeSet) Get(key []byte) ([]byte, error)
- func (db *NodeSet) Has(key []byte) (bool, error)
- func (db *NodeSet) KeyCount() int
- func (db *NodeSet) NodeList() NodeList
- func (db *NodeSet) Put(key []byte, value []byte) error
- func (db *NodeSet) Store(target ethdb.Putter)
- type StateChange
- type StateChangeList
- type StateChangeRLP
- type StateStorage
- type StateTrie
Constants ¶
const ( NewAccountChange = iota BalanceChange NonceChange HashLockChange TimeLockChange // not use this //ContractRootChange DataRootChange StakeChange CommitNumChange VerifyNumChange PerformanceChange LastElectChange DeleteAccountChange )
Variables ¶
var ( TransactionTypeError = errors.New("transaction type miss match with processor function") NotEnoughBalanceError = errors.New("not enough balance error") NotEnoughStakeErr = errors.New("target account stake not enough") SenderNotExistErr = errors.New("sender account does not exist") ReceiverNotExistErr = errors.New("receiver account does not exist") SendRegisterTxFirst = errors.New("target need to send register transaction first") SendCancelTxFirst = errors.New("target need to send cancel transaction first") )
var MaxTrieCacheGen = uint16(120)
Trie cache generation limit after which to evict trie nodes from memory.
var (
SenderOrReceiverIsEmptyErr = errors.New("sender or receiver is empty")
)
Functions ¶
func GetBalanceKey ¶
func GetCommitNumKey ¶
func GetContractAddrAndKey ¶
get the real key without hash and address
func GetContractRootKey ¶
func GetDataRootKey ¶
func GetHashLockKey ¶
func GetLastElectKey ¶
func GetNonceKey ¶
func GetPerformanceKey ¶
func GetStakeKey ¶
func GetTimeLockKey ¶
func GetVerifyNumKey ¶
Types ¶
type AccountStateDB ¶
type AccountStateDB struct {
// contains filtered or unexported fields
}
call the Process function of this struct to get the state root
func NewAccountStateDB ¶
func NewAccountStateDB(preStateRoot common.Hash, db StateStorage) (*AccountStateDB, error)
add chain reader out side
func (*AccountStateDB) AddBalance ¶
func (*AccountStateDB) AddNonce ¶
func (state *AccountStateDB) AddNonce(addr common.Address, amount uint64) error
func (*AccountStateDB) ContractExist ¶
func (state *AccountStateDB) ContractExist(addr common.Address) bool
func (*AccountStateDB) Copy ¶
func (state *AccountStateDB) Copy() *AccountStateDB
Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.
func (*AccountStateDB) DeleteAccountState ¶
func (state *AccountStateDB) DeleteAccountState(addr common.Address) error
func (*AccountStateDB) Finalise ¶
func (state *AccountStateDB) Finalise() (result common.Hash, err error)
deleteEmptyAccount bool true. Doing a trie commit logic here is more complicated, so don't consider committing for the time being. If finalised, don't change any state outside, otherwise there will be problems.
func (*AccountStateDB) GetAccountState ¶
func (state *AccountStateDB) GetAccountState(addr common.Address) (*account, error)
func (*AccountStateDB) GetBalance ¶
func (*AccountStateDB) GetCommitNum ¶
func (state *AccountStateDB) GetCommitNum(addr common.Address) (uint64, error)
func (*AccountStateDB) GetContract ¶
func (*AccountStateDB) GetDataRoot ¶
func (*AccountStateDB) GetHashLock ¶
func (*AccountStateDB) GetLastElect ¶
func (state *AccountStateDB) GetLastElect(addr common.Address) (uint64, error)
func (*AccountStateDB) GetNonce ¶
func (state *AccountStateDB) GetNonce(addr common.Address) (uint64, error)
func (*AccountStateDB) GetPerformance ¶
func (state *AccountStateDB) GetPerformance(addr common.Address) (uint64, error)
func (*AccountStateDB) GetTimeLock ¶
func (*AccountStateDB) GetVerifyNum ¶
func (state *AccountStateDB) GetVerifyNum(addr common.Address) (uint64, error)
func (*AccountStateDB) IsEmptyAccount ¶
func (state *AccountStateDB) IsEmptyAccount(addr common.Address) bool
func (*AccountStateDB) MoveStakeToAddress ¶
Move stake to some address
func (*AccountStateDB) NewAccountState ¶
func (state *AccountStateDB) NewAccountState(addr common.Address) error
func (*AccountStateDB) PreStateRoot ¶
func (state *AccountStateDB) PreStateRoot() common.Hash
func (*AccountStateDB) ProcessPerformance ¶
func (state *AccountStateDB) ProcessPerformance(address common.Address, amount float64) error
func (*AccountStateDB) ProcessTx ¶
func (state *AccountStateDB) ProcessTx(tx model.AbstractTransaction, height uint64) (err error)
todo these processes are removed afterwards。 todo Write a unit test for each transaction to cover all situations
func (*AccountStateDB) ProcessVerification ¶
func (state *AccountStateDB) ProcessVerification(v model.AbstractVerification, index int) error
func (*AccountStateDB) ProcessVerifierNumber ¶
func (state *AccountStateDB) ProcessVerifierNumber(address common.Address) error
func (*AccountStateDB) PutContract ¶
not save the return data if there is an error. only save it in DB when commit in the end
func (*AccountStateDB) RevertToSnapshot ¶
func (state *AccountStateDB) RevertToSnapshot(revid int)
RevertToSnapshot reverts all state changes made since the given revision.
func (*AccountStateDB) SetBalance ¶
func (*AccountStateDB) SetCommitNum ¶
func (state *AccountStateDB) SetCommitNum(addr common.Address, amount uint64) error
func (*AccountStateDB) SetDataRoot ¶
func (*AccountStateDB) SetHashLock ¶
func (*AccountStateDB) SetLastElect ¶
func (state *AccountStateDB) SetLastElect(addr common.Address, blockID uint64) error
func (*AccountStateDB) SetNonce ¶
func (state *AccountStateDB) SetNonce(addr common.Address, amount uint64) error
func (*AccountStateDB) SetPerformance ¶
func (state *AccountStateDB) SetPerformance(addr common.Address, amount uint64) error
func (*AccountStateDB) SetTimeLock ¶
func (*AccountStateDB) SetVerifyNum ¶
func (state *AccountStateDB) SetVerifyNum(addr common.Address, amount uint64) error
func (*AccountStateDB) Snapshot ¶
func (state *AccountStateDB) Snapshot() int
Snapshot returns an identifier for the Current revision of the state.
func (*AccountStateDB) SubBalance ¶
type AccountStateProcessor ¶
type AccountStateProcessor interface { NewAccountState(addr common.Address) (err error) GetBalance(addr common.Address) (*big.Int, error) SetBalance(addr common.Address, amount *big.Int) error Finalise() (root common.Hash, err error) Commit() (root common.Hash, err error) PutContract(addr common.Address, v reflect.Value) error GetContract(addr common.Address, vType reflect.Type) (v reflect.Value, err error) ContractExist(addr common.Address) bool }
only genesis use
func MakeGenesisAccountStateProcessor ¶
func MakeGenesisAccountStateProcessor(accountStorage StateStorage) (AccountStateProcessor, error)
type AccountStateReader ¶
type AccountStateReader interface { GetNonce(addr common.Address) (uint64, error) GetBalance(addr common.Address) (*big.Int, error) GetContractRoot(addr common.Address) (common.Hash, error) GetLastElect(addr common.Address) (uint64, error) GetStake(addr common.Address) (*big.Int, error) GetCommitNum(addr common.Address) (uint64, error) GetVerifyNum(addr common.Address) (uint64, error) GetProduceNum(addr common.Address) (uint64, error) }
type ManagedState ¶
type ManagedState struct { *AccountStateDB // contains filtered or unexported fields }
func ManageState ¶
func ManageState(statedb *AccountStateDB) *ManagedState
ManagedState returns a new managed state with the statedb as it's backing layer
func (*ManagedState) GetNonce ¶
func (ms *ManagedState) GetNonce(addr common.Address) uint64
GetNonce returns the canonical nonce for the managed or unmanaged account.
Because GetNonce mutates the DB, we must take a write lock.
func (*ManagedState) HasAccount ¶
func (ms *ManagedState) HasAccount(addr common.Address) bool
HasAccount returns whether the given address is managed or not
func (*ManagedState) NewNonce ¶
func (ms *ManagedState) NewNonce(addr common.Address) uint64
NewNonce returns the new canonical nonce for the managed account
func (*ManagedState) RemoveNonce ¶
func (ms *ManagedState) RemoveNonce(addr common.Address, n uint64)
RemoveNonce removed the nonce from the managed state and all future pending nonces
func (*ManagedState) SetNonce ¶
func (ms *ManagedState) SetNonce(addr common.Address, nonce uint64)
SetNonce sets the new canonical nonce for the managed state
func (*ManagedState) SetState ¶
func (ms *ManagedState) SetState(statedb *AccountStateDB)
SetState sets the backing layer of the managed state
type NodeList ¶
NodeList stores an ordered list of trie nodes. It implements ethdb.Putter.
type NodeSet ¶
type NodeSet struct {
// contains filtered or unexported fields
}
type StateChange ¶
type StateChange interface {
// contains filtered or unexported methods
}
journalEntry is a modification entry in the state change journal that can be reverted on demand.
type StateChangeList ¶
type StateChangeList struct {
// contains filtered or unexported fields
}
journal contains the list of state modifications applied since the last state commit. These are tracked to be able to be reverted in case of an execution exception or revertal request.
func (*StateChangeList) DecodeRLP ¶
func (scl *StateChangeList) DecodeRLP(s *rlp.Stream) (err error)
func (*StateChangeList) Len ¶
func (scl *StateChangeList) Len() int
func (*StateChangeList) Less ¶
func (scl *StateChangeList) Less(i, j int) bool
func (*StateChangeList) Swap ¶
func (scl *StateChangeList) Swap(i, j int)
type StateChangeRLP ¶
type StateStorage ¶
type StateStorage interface { // OpenTrie opens the main account trie. OpenTrie(root common.Hash) (StateTrie, error) // OpenStorageTrie opens the storage trie of an account. OpenStorageTrie(addrHash, root common.Hash) (StateTrie, error) // CopyTrie returns an independent copy of the given trie. CopyTrie(StateTrie) StateTrie // TrieDB retrieves the low level trie database used for data storage. TrieDB() *trie.Database DiskDB() ethdb.Database }
func NewStateStorageWithCache ¶
func NewStateStorageWithCache(db ethdb.Database) StateStorage
In addition to the modified state in the package will be used, other areas of the query status may also be used? Temporarily made public
type StateTrie ¶
type StateTrie interface { TryGet(key []byte) ([]byte, error) TryUpdate(key, value []byte) error TryDelete(key []byte) error Commit(onleaf trie.LeafCallback) (common.Hash, error) Hash() common.Hash NodeIterator(startKey []byte) trie.NodeIterator GetKey([]byte) []byte // TODO(fjl): remove this when SecureTrie is removed Prove(key []byte, fromLevel uint, proofDb ethdb.Putter) error }