Documentation
¶
Overview ¶
Package state provides a caching layer atop the state trie.
Index ¶
- Constants
- Variables
- type Account
- func (*Account) Descriptor() ([]byte, []int)
- func (m *Account) GetBalance() uint64
- func (m *Account) GetDelegatedFrom() uint64
- func (m *Account) GetDelegatedTo() uint64
- func (m *Account) GetDelegatingFrom() map[string]*Borrow
- func (m *Account) GetDelegatingTo() map[string]*Borrow
- func (m *Account) GetRawRoot() []byte
- func (*Account) ProtoMessage()
- func (m *Account) Reset()
- func (a *Account) Root() (h hash.Hash)
- func (a *Account) SetRoot(h hash.Hash)
- func (m *Account) String() string
- func (m *Account) XXX_DiscardUnknown()
- func (m *Account) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Account) XXX_Merge(src proto.Message)
- func (m *Account) XXX_Size() int
- func (m *Account) XXX_Unmarshal(b []byte) error
- type Borrow
- func (*Borrow) Descriptor() ([]byte, []int)
- func (m *Borrow) GetRecs() map[uint64]uint64
- func (*Borrow) ProtoMessage()
- func (m *Borrow) Reset()
- func (m *Borrow) String() string
- func (m *Borrow) XXX_DiscardUnknown()
- func (m *Borrow) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Borrow) XXX_Merge(src proto.Message)
- func (m *Borrow) XXX_Size() int
- func (m *Borrow) XXX_Unmarshal(b []byte) error
- type DB
- func (s *DB) AddPreimage(hash hash.Hash, preimage []byte)
- func (s *DB) Commit(deleteEmptyObjects bool) (root hash.Hash, err error)
- func (s *DB) Copy() *DB
- func (s *DB) CreateAccount(addr hash.Peer)
- func (s *DB) Database() Database
- func (s *DB) Delegate(from, to hash.Peer, amount, until uint64)
- func (s *DB) Empty(addr hash.Peer) bool
- func (s *DB) Error() error
- func (s *DB) Exist(addr hash.Peer) bool
- func (s *DB) ExpireDelegations(addr hash.Peer, now uint64)
- func (s *DB) Finalise(deleteEmptyObjects bool)
- func (s *DB) ForEachStorage(addr hash.Peer, cb func(key, value hash.Hash) bool)
- func (s *DB) FreeBalance(addr hash.Peer) uint64
- func (s *DB) GetCommittedState(addr hash.Peer, h hash.Hash) hash.Hash
- func (s *DB) GetDelegations(addr hash.Peer) [2]map[hash.Peer]uint64
- func (s *DB) GetOrNewStateObject(addr hash.Peer) *stateObject
- func (s *DB) GetProof(a hash.Peer) ([][]byte, error)
- func (s *DB) GetState(addr hash.Peer, h hash.Hash) hash.Hash
- func (s *DB) GetStorageProof(a hash.Peer, key hash.Hash) ([][]byte, error)
- func (s *DB) HasSuicided(addr hash.Peer) bool
- func (s *DB) IntermediateRoot(deleteEmptyObjects bool) hash.Hash
- func (s *DB) Preimages() map[hash.Hash][]byte
- func (s *DB) Prepare(thash, bhash hash.Hash, ti int)
- func (s *DB) Reset(root hash.Hash) error
- func (s *DB) RevertToSnapshot(revID int)
- func (s *DB) SetBalance(addr hash.Peer, amount uint64)
- func (s *DB) SetState(addr hash.Peer, key, value hash.Hash)
- func (s *DB) Snapshot() int
- func (s *DB) StorageTrie(addr hash.Peer) Trie
- func (s *DB) Suicide(addr hash.Peer) bool
- func (s *DB) Transfer(from, to hash.Peer, amount uint64)
- func (s *DB) VoteBalance(addr hash.Peer) uint64
- type Database
- type Storage
- type Trie
Constants ¶
const ( // TO delegation direction TO direction = iota // FROM delegation direction FROM )
Variables ¶
var MaxTrieCacheGen = uint16(120)
MaxTrieCacheGen is a trie cache generation limit after which to evict trie nodes from memory.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { Balance uint64 `protobuf:"varint,1,opt,name=Balance,proto3" json:"Balance,omitempty"` RawRoot []byte `protobuf:"bytes,2,opt,name=RawRoot,proto3" json:"RawRoot,omitempty"` DelegatedFrom uint64 `protobuf:"varint,3,opt,name=DelegatedFrom,proto3" json:"DelegatedFrom,omitempty"` DelegatingFrom map[string]*Borrow `` /* 169-byte string literal not displayed */ DelegatedTo uint64 `protobuf:"varint,5,opt,name=DelegatedTo,proto3" json:"DelegatedTo,omitempty"` DelegatingTo map[string]*Borrow `` /* 165-byte string literal not displayed */ XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Account) Descriptor ¶
func (*Account) GetBalance ¶
func (*Account) GetDelegatedFrom ¶
func (*Account) GetDelegatedTo ¶
func (*Account) GetDelegatingFrom ¶
func (*Account) GetDelegatingTo ¶
func (*Account) GetRawRoot ¶
func (*Account) ProtoMessage ¶
func (*Account) ProtoMessage()
func (*Account) XXX_DiscardUnknown ¶
func (m *Account) XXX_DiscardUnknown()
func (*Account) XXX_Marshal ¶
func (*Account) XXX_Unmarshal ¶
type Borrow ¶
type Borrow struct { Recs map[uint64]uint64 `` /* 151-byte string literal not displayed */ XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Borrow) Descriptor ¶
func (*Borrow) ProtoMessage ¶
func (*Borrow) ProtoMessage()
func (*Borrow) XXX_DiscardUnknown ¶
func (m *Borrow) XXX_DiscardUnknown()
func (*Borrow) XXX_Marshal ¶
func (*Borrow) XXX_Unmarshal ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is used to store anything within the merkle trie. It takes care of caching and storing nested states. It's the general query interface to retrieve Accounts
func (*DB) AddPreimage ¶
AddPreimage records a SHA3 preimage seen by the VM.
func (*DB) Copy ¶
Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.
func (*DB) CreateAccount ¶
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 (*DB) Database ¶
Database retrieves the low level database supporting the lower level trie ops.
func (*DB) Empty ¶
Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0).
func (*DB) Exist ¶
Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.
func (*DB) ExpireDelegations ¶
ExpireDelegations erases data about expired delegations.
func (*DB) Finalise ¶
Finalise finalises the state by removing the self destructed objects and clears the journal as well as the refunds.
func (*DB) ForEachStorage ¶
ForEachStorage calls func for each key-value of node.
func (*DB) FreeBalance ¶
FreeBalance returns the free balance from the given address or 0 if object not found.
func (*DB) GetCommittedState ¶
GetCommittedState retrieves a value from the given account's committed storage trie.
func (*DB) GetDelegations ¶
GetDelegations returns delegation records.
func (*DB) GetOrNewStateObject ¶
GetOrNewStateObject returns a state object or create a new state object if nil.
func (*DB) GetStorageProof ¶
GetStorageProof returns the StorageProof for given key.
func (*DB) HasSuicided ¶
HasSuicided checks if stateObject is suicided by address.
func (*DB) IntermediateRoot ¶
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 (*DB) Prepare ¶
Prepare sets the current transaction hash and index and block hash which is used when the EVM emits new state logs.
func (*DB) Reset ¶
Reset clears out all ephemeral state objects from the state db, but keeps the underlying state trie to avoid reloading data for the next operations.
func (*DB) RevertToSnapshot ¶
RevertToSnapshot reverts all state changes made since the given revision.
func (*DB) SetBalance ¶
SetBalance sets stateObject's balance by address.
func (*DB) StorageTrie ¶
StorageTrie returns the storage trie of an account. The return value is a copy and is nil for non-existent accounts.
func (*DB) Suicide ¶
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.
type Database ¶
type Database interface { // OpenTrie opens the main account trie. OpenTrie(root hash.Hash) (Trie, error) // OpenStorageTrie opens the storage trie of an account. OpenStorageTrie(addrHash, root hash.Hash) (Trie, error) // CopyTrie returns an independent copy of the given trie. CopyTrie(Trie) Trie // TrieDB retrieves the low level trie database used for data storage. TrieDB() *trie.Database }
Database wraps access to tries.
func NewDatabase ¶
NewDatabase creates a backing store for state. The returned database is safe for concurrent use and retains a few recent expanded trie nodes in memory. To keep more historical state in memory, use the NewDatabaseWithCache constructor.
func NewDatabaseWithCache ¶
NewDatabaseWithCache creates a backing store for state. The returned database is safe for concurrent use and retains both a few recent expanded trie nodes in memory, as well as a lot of collapsed RLP trie nodes in a large memory cache.
type Storage ¶
Storage of entries.
type Trie ¶
type Trie interface { TryGet(key []byte) ([]byte, error) TryUpdate(key, value []byte) error TryDelete(key []byte) error Commit(onleaf trie.LeafCallback) (hash.Hash, error) Hash() hash.Hash NodeIterator(startKey []byte) trie.NodeIterator GetKey([]byte) []byte // TODO: remove this when SecureTrie is removed Prove(key []byte, fromLevel uint, proofDb kvdb.Putter) error }
Trie is a Merkle Trie.