Documentation ¶
Overview ¶
Package state provides a caching layer atop the utg state trie.
Index ¶
- func CommitData(s *ExtraStateDB) (common.Hash, common.Hash, error)
- func DBGet(key []byte) ([]byte, error)
- func DBPut(key, value []byte) error
- func InitExtraDB(dbpath string) error
- type Account
- type Code
- type Database
- type Dump
- type DumpAccount
- type DumpCollector
- type DumpConfig
- type ExtraStateDB
- func (s *ExtraStateDB) AddBalance(addr common.Address, amount *big.Int)
- func (s *ExtraStateDB) AddLockReward(addr common.Address, amount *big.Int)
- func (s *ExtraStateDB) BlockHash() common.Hash
- func (s *ExtraStateDB) Commit(deleteEmptyObjects bool) (common.Hash, error)
- func (s *ExtraStateDB) Copy() *ExtraStateDB
- func (s *ExtraStateDB) CreateAccount(addr common.Address)
- func (s *ExtraStateDB) Database() Database
- func (s *ExtraStateDB) Dump(opts *DumpConfig) []byte
- func (s *ExtraStateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []byte)
- func (s *ExtraStateDB) Empty(addr common.Address) bool
- func (s *ExtraStateDB) Error() error
- func (s *ExtraStateDB) Exist(addr common.Address) bool
- func (s *ExtraStateDB) Finalise(deleteEmptyObjects bool)
- func (s *ExtraStateDB) GetBalance(addr common.Address) *big.Int
- func (s *ExtraStateDB) GetGrantListHash() common.Hash
- func (s *ExtraStateDB) GetLockReward(addr common.Address) *big.Int
- func (s *ExtraStateDB) GetOrNewStateObject(addr common.Address) *stateObject
- func (s *ExtraStateDB) GetProof(addr common.Address) ([][]byte, error)
- func (s *ExtraStateDB) GetProofByHash(addrHash common.Hash) ([][]byte, error)
- func (s *ExtraStateDB) GetRefund() uint64
- func (s *ExtraStateDB) HasSuicided(addr common.Address) bool
- func (s *ExtraStateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash
- func (s *ExtraStateDB) IterativeDump(opts *DumpConfig, output *json.Encoder)
- func (s *ExtraStateDB) IteratorDump(opts *DumpConfig) IteratorDump
- func (s *ExtraStateDB) LoadLockAccounts(root common.Hash) ([]common.Address, error)
- func (s *ExtraStateDB) PayLockReward(number uint64, state *state.StateDB) []PayRecard
- func (s *ExtraStateDB) Prepare(thash, bhash common.Hash, ti int)
- func (s *ExtraStateDB) PutLockAccounts() (common.Hash, error)
- func (s *ExtraStateDB) RawDump(opts *DumpConfig) Dump
- func (s *ExtraStateDB) RevertToSnapshot(revid int)
- func (s *ExtraStateDB) SetBalance(addr common.Address, amount *big.Int)
- func (s *ExtraStateDB) SetStorage(addr common.Address, storage map[common.Hash]common.Hash)
- func (s *ExtraStateDB) Snapshot() int
- func (s *ExtraStateDB) StartPrefetcher(namespace string)
- func (s *ExtraStateDB) StopPrefetcher()
- func (s *ExtraStateDB) SubBalance(addr common.Address, amount *big.Int)
- func (s *ExtraStateDB) Suicide(addr common.Address) bool
- func (s *ExtraStateDB) TxIndex() int
- type IteratorDump
- type LockAccounts
- func (la *LockAccounts) Accounts() sort.StringSlice
- func (la *LockAccounts) Append(addr common.Address)
- func (la *LockAccounts) Commit() (common.Hash, error)
- func (la *LockAccounts) Delete(addr common.Address)
- func (la *LockAccounts) Len() int
- func (la *LockAccounts) Load(root common.Hash) error
- func (la *LockAccounts) Root() common.Hash
- type NodeIterator
- type PayRecard
- type Storage
- type Trie
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommitData ¶
func DBPut ¶
func Commi(es *ExtraStateDB,node common.Hash, report bool, callback func(common.Hash)) error { globalLdbCtrl.mutex.Lock() defer globalLdbCtrl.mutex.Unlock() return globalLdbCtrl.extradb.TrieDB().Commit(node, report, callback) }
func InitExtraDB ¶
Types ¶
type Account ¶
type Account struct { LockBalance *big.Int ReleaseQueue []*big.Int Root common.Hash // merkle root of the storage trie Balance *big.Int ReleaseIdx uint16 Number uint64 }
Account is the utg consensus representation of accounts. These objects are stored in the main account trie.
type Database ¶
type Database interface { // OpenTrie opens the main account trie. OpenTrie(root common.Hash) (Trie, error) // OpenStorageTrie opens the storage trie of an account. OpenStorageTrie(addrHash, root common.Hash) (Trie, error) // CopyTrie returns an independent copy of the given trie. CopyTrie(Trie) Trie // ContractCode retrieves a particular contract's code. ContractCode(addrHash, codeHash common.Hash) ([]byte, error) // ContractCodeSize retrieves a particular contracts code's size. ContractCodeSize(addrHash, codeHash common.Hash) (int, error) // TrieDB retrieves the low level trie database used for data storage. TrieDB() *trie.Database }
Database wraps access to tries and contract code.
func NewDatabase ¶
NewDatabase creates a backing store for state. The returned database is safe for concurrent use, but does not retain any recent trie nodes in memory. To keep some historical state in memory, use the NewDatabaseWithConfig constructor.
type Dump ¶
type Dump struct { Root string `json:"root"` Accounts map[common.Address]DumpAccount `json:"accounts"` }
Dump represents the full dump in a collected format, as one large map.
type DumpAccount ¶
type DumpAccount struct { Balance string `json:"balance"` Nonce uint64 `json:"nonce"` Root hexutil.Bytes `json:"root"` CodeHash hexutil.Bytes `json:"codeHash"` Code hexutil.Bytes `json:"code,omitempty"` Storage map[common.Hash]string `json:"storage,omitempty"` Address *common.Address `json:"address,omitempty"` // Address only present in iterative (line-by-line) mode SecureKey hexutil.Bytes `json:"key,omitempty"` // If we don't have address, we can output the key }
DumpAccount represents an account in the state.
type DumpCollector ¶
type DumpCollector interface { // OnRoot is called with the state root OnRoot(common.Hash) // OnAccount is called once for each account in the trie OnAccount(common.Address, DumpAccount) }
DumpCollector interface which the state trie calls during iteration
type DumpConfig ¶
type DumpConfig struct { SkipCode bool SkipStorage bool OnlyWithAddresses bool Start []byte Max uint64 }
DumpConfig is a set of options to control what portions of the statewill be iterated and collected.
type ExtraStateDB ¶
type ExtraStateDB struct { // Measurements gathered during execution for debugging purposes AccountReads time.Duration AccountHashes time.Duration AccountUpdates time.Duration AccountCommits time.Duration StorageReads time.Duration StorageHashes time.Duration StorageUpdates time.Duration StorageCommits time.Duration SnapshotAccountReads time.Duration SnapshotStorageReads time.Duration SnapshotCommits time.Duration // contains filtered or unexported fields }
ExtraStateDB structs within the utg protocol are used to store anything within the merkle trie. ExtraStateDBs take care of caching and storing nested states. It's the general query interface to retrieve: * Contracts * Accounts
func ExtraStateAt ¶
func ExtraStateAt(root common.Hash) (*ExtraStateDB, error)
func New ¶
func New(root common.Hash) (*ExtraStateDB, error)
New creates a new extrastate from a given trie.
func (*ExtraStateDB) AddBalance ¶
func (s *ExtraStateDB) AddBalance(addr common.Address, amount *big.Int)
AddBalance addrs amount to the account associated with addr.
func (*ExtraStateDB) AddLockReward ¶
func (s *ExtraStateDB) AddLockReward(addr common.Address, amount *big.Int)
AddLockReward addrs amount to the account lock reward with addr.
func (*ExtraStateDB) BlockHash ¶
func (s *ExtraStateDB) BlockHash() common.Hash
BlockHash returns the current block hash set by Prepare.
func (*ExtraStateDB) Commit ¶
func (s *ExtraStateDB) Commit(deleteEmptyObjects bool) (common.Hash, error)
Commit writes the state to the underlying in-memory trie database.
func (*ExtraStateDB) Copy ¶
func (s *ExtraStateDB) Copy() *ExtraStateDB
Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.
func (*ExtraStateDB) CreateAccount ¶
func (s *ExtraStateDB) CreateAccount(addr common.Address)
CreateAccount explicitly creates a state object. If a state object with the address already exists the balance is carried over to the new account.
CreateAccount is called during the EVM CREATE operation. The situation might arise that a contract does the following:
- sends funds to sha(account ++ (nonce + 1))
- tx_create(sha(account ++ nonce)) (note that this gets the address of 1)
Carrying over the balance ensures that Ether doesn't disappear.
func (*ExtraStateDB) Database ¶
func (s *ExtraStateDB) Database() Database
Database retrieves the low level database supporting the lower level trie ops.
func (*ExtraStateDB) Dump ¶
func (s *ExtraStateDB) Dump(opts *DumpConfig) []byte
Dump returns a JSON string representing the entire state as a single json-object
func (*ExtraStateDB) DumpToCollector ¶
func (s *ExtraStateDB) DumpToCollector(c DumpCollector, conf *DumpConfig) (nextKey []byte)
DumpToCollector iterates the state according to the given options and inserts the items into a collector for aggregation or serialization.
func (*ExtraStateDB) Empty ¶
func (s *ExtraStateDB) Empty(addr common.Address) bool
Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0)
func (*ExtraStateDB) Error ¶
func (s *ExtraStateDB) Error() error
func (*ExtraStateDB) Exist ¶
func (s *ExtraStateDB) Exist(addr common.Address) bool
Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.
func (*ExtraStateDB) Finalise ¶
func (s *ExtraStateDB) Finalise(deleteEmptyObjects bool)
Finalise finalises the state by removing the s destructed objects and clears the journal as well as the refunds. Finalise, however, will not push any updates into the tries just yet. Only IntermediateRoot or Commit will do that.
func (*ExtraStateDB) GetBalance ¶
func (s *ExtraStateDB) GetBalance(addr common.Address) *big.Int
GetBalance retrieves the balance from the given address or 0 if object not found
func (*ExtraStateDB) GetGrantListHash ¶
func (s *ExtraStateDB) GetGrantListHash() common.Hash
func (*ExtraStateDB) GetLockReward ¶
func (s *ExtraStateDB) GetLockReward(addr common.Address) *big.Int
GetLockReward retrieves the lockalance from the given address or 0 if object not found
func (*ExtraStateDB) GetOrNewStateObject ¶
func (s *ExtraStateDB) GetOrNewStateObject(addr common.Address) *stateObject
GetOrNewStateObject retrieves a state object or create a new state object if nil.
func (*ExtraStateDB) GetProof ¶
func (s *ExtraStateDB) GetProof(addr common.Address) ([][]byte, error)
GetProof returns the Merkle proof for a given account.
func (*ExtraStateDB) GetProofByHash ¶
func (s *ExtraStateDB) GetProofByHash(addrHash common.Hash) ([][]byte, error)
GetProofByHash returns the Merkle proof for a given account.
func (*ExtraStateDB) GetRefund ¶
func (s *ExtraStateDB) GetRefund() uint64
GetRefund returns the current value of the refund counter.
func (*ExtraStateDB) HasSuicided ¶
func (s *ExtraStateDB) HasSuicided(addr common.Address) bool
func (*ExtraStateDB) IntermediateRoot ¶
func (s *ExtraStateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash
IntermediateRoot computes the current root hash of the state trie. It is called in between transactions to get the root hash that goes into transaction receipts.
func (*ExtraStateDB) IterativeDump ¶
func (s *ExtraStateDB) IterativeDump(opts *DumpConfig, output *json.Encoder)
IterativeDump dumps out accounts as json-objects, delimited by linebreaks on stdout
func (*ExtraStateDB) IteratorDump ¶
func (s *ExtraStateDB) IteratorDump(opts *DumpConfig) IteratorDump
IteratorDump dumps out a batch of accounts starts with the given start key
func (*ExtraStateDB) LoadLockAccounts ¶
func (*ExtraStateDB) PayLockReward ¶
func (s *ExtraStateDB) PayLockReward(number uint64, state *state.StateDB) []PayRecard
func (*ExtraStateDB) Prepare ¶
func (s *ExtraStateDB) Prepare(thash, bhash common.Hash, ti int)
Prepare sets the current transaction hash and index and block hash which is used when the EVM emits new state logs.
func (*ExtraStateDB) PutLockAccounts ¶
func (s *ExtraStateDB) PutLockAccounts() (common.Hash, error)
func (*ExtraStateDB) RawDump ¶
func (s *ExtraStateDB) RawDump(opts *DumpConfig) Dump
RawDump returns the entire state an a single large object
func (*ExtraStateDB) RevertToSnapshot ¶
func (s *ExtraStateDB) RevertToSnapshot(revid int)
RevertToSnapshot reverts all state changes made since the given revision.
func (*ExtraStateDB) SetBalance ¶
func (s *ExtraStateDB) SetBalance(addr common.Address, amount *big.Int)
func (*ExtraStateDB) SetStorage ¶
SetStorage replaces the entire storage for the specified account with given storage. This function should only be used for debugging.
func (*ExtraStateDB) Snapshot ¶
func (s *ExtraStateDB) Snapshot() int
Snapshot returns an identifier for the current revision of the state.
func (*ExtraStateDB) StartPrefetcher ¶
func (s *ExtraStateDB) StartPrefetcher(namespace string)
StartPrefetcher initializes a new trie prefetcher to pull in nodes from the state trie concurrently while the state is mutated so that when we reach the commit phase, most of the needed data is already hot.
func (*ExtraStateDB) StopPrefetcher ¶
func (s *ExtraStateDB) StopPrefetcher()
StopPrefetcher terminates a running prefetcher and reports any leftover stats from the gathered metrics.
func (*ExtraStateDB) SubBalance ¶
func (s *ExtraStateDB) SubBalance(addr common.Address, amount *big.Int)
SubBalance subtracts amount from the account associated with addr.
func (*ExtraStateDB) Suicide ¶
func (s *ExtraStateDB) Suicide(addr common.Address) bool
Suicide marks the given account as suicided. This clears the account balance.
The account's state object is still available until the state is committed, getStateObject will return a non-nil account after Suicide.
func (*ExtraStateDB) TxIndex ¶
func (s *ExtraStateDB) TxIndex() int
TxIndex returns the current transaction index set by Prepare.
type IteratorDump ¶
type IteratorDump struct { Root string `json:"root"` Accounts map[common.Address]DumpAccount `json:"accounts"` Next []byte `json:"next,omitempty"` // nil if no more accounts }
IteratorDump is an implementation for iterating over data.
func (*IteratorDump) OnAccount ¶
func (d *IteratorDump) OnAccount(addr common.Address, account DumpAccount)
OnAccount implements DumpCollector interface
func (*IteratorDump) OnRoot ¶
func (d *IteratorDump) OnRoot(root common.Hash)
OnRoot implements DumpCollector interface
type LockAccounts ¶
type LockAccounts struct {
// contains filtered or unexported fields
}
func (*LockAccounts) Accounts ¶
func (la *LockAccounts) Accounts() sort.StringSlice
func (*LockAccounts) Append ¶
func (la *LockAccounts) Append(addr common.Address)
func (*LockAccounts) Delete ¶
func (la *LockAccounts) Delete(addr common.Address)
func (*LockAccounts) Len ¶
func (la *LockAccounts) Len() int
func (*LockAccounts) Root ¶
func (la *LockAccounts) Root() common.Hash
type NodeIterator ¶
type NodeIterator struct { Hash common.Hash // Hash of the current entry being iterated (nil if not standalone) Parent common.Hash // Hash of the first full ancestor node (nil if current is the root) Error error // Failure set in case of an internal error in the iterator // contains filtered or unexported fields }
NodeIterator is an iterator to traverse the entire state trie post-order, including all of the contract code and contract state tries.
func NewNodeIterator ¶
func NewNodeIterator(state *ExtraStateDB) *NodeIterator
NewNodeIterator creates an post-order state node iterator.
func (*NodeIterator) Next ¶
func (it *NodeIterator) Next() bool
Next moves the iterator to the next node, returning whether there are any further nodes. In case of an internal error this method returns false and sets the Error field to the encountered failure.
type PayRecard ¶
func LoadPayRecords ¶
func (s *ExtraStateDB) GetLockAccounts() []common.Address { return s.grantList }
type Trie ¶
type Trie interface { // GetKey returns the sha3 preimage of a hashed key that was previously used // to store a value. // // TODO(fjl): remove this when SecureTrie is removed GetKey([]byte) []byte // TryGet returns the value for key stored in the trie. The value bytes must // not be modified by the caller. If a node was not found in the database, a // trie.MissingNodeError is returned. TryGet(key []byte) ([]byte, error) // TryUpdate associates key with value in the trie. If value has length zero, any // existing value is deleted from the trie. The value bytes must not be modified // by the caller while they are stored in the trie. If a node was not found in the // database, a trie.MissingNodeError is returned. TryUpdate(key, value []byte) error // TryDelete removes any existing value for key from the trie. If a node was not // found in the database, a trie.MissingNodeError is returned. TryDelete(key []byte) error // Hash returns the root hash of the trie. It does not write to the database and // can be used even if the trie doesn't have one. Hash() common.Hash // Commit writes all nodes to the trie's memory database, tracking the internal // and external (for account tries) references. Commit(onleaf trie.LeafCallback) (common.Hash, error) // NodeIterator returns an iterator that returns nodes of the trie. Iteration // starts at the key after the given start key. NodeIterator(startKey []byte) trie.NodeIterator // Prove constructs a Merkle proof for key. The result contains all encoded nodes // on the path to the value at key. The value itself is also included in the last // node and can be retrieved by verifying the proof. // // If the trie does not contain a value for key, the returned proof contains all // nodes of the longest existing prefix of the key (at least the root), ending // with the node that proves the absence of the key. Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWriter) error }
Trie is a utg Merkle Patricia trie.