state

package
v0.0.0-...-168a2c3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package state provides a caching layer atop the state trie.

Index

Constants

View Source
const (
	// TO delegation direction
	TO direction = iota
	// FROM delegation direction
	FROM
)

Variables

View Source
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) Descriptor() ([]byte, []int)

func (*Account) GetBalance

func (m *Account) GetBalance() uint64

func (*Account) GetDelegatedFrom

func (m *Account) GetDelegatedFrom() uint64

func (*Account) GetDelegatedTo

func (m *Account) GetDelegatedTo() uint64

func (*Account) GetDelegatingFrom

func (m *Account) GetDelegatingFrom() map[string]*Borrow

func (*Account) GetDelegatingTo

func (m *Account) GetDelegatingTo() map[string]*Borrow

func (*Account) GetRawRoot

func (m *Account) GetRawRoot() []byte

func (*Account) ProtoMessage

func (*Account) ProtoMessage()

func (*Account) Reset

func (m *Account) Reset()

func (*Account) Root

func (a *Account) Root() (h hash.Hash)

Root converts bytes to hash.

func (*Account) SetRoot

func (a *Account) SetRoot(h hash.Hash)

SetRoot converts hash to bytes.

func (*Account) String

func (m *Account) String() string

func (*Account) XXX_DiscardUnknown

func (m *Account) XXX_DiscardUnknown()

func (*Account) XXX_Marshal

func (m *Account) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Account) XXX_Merge

func (m *Account) XXX_Merge(src proto.Message)

func (*Account) XXX_Size

func (m *Account) XXX_Size() int

func (*Account) XXX_Unmarshal

func (m *Account) XXX_Unmarshal(b []byte) error

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) Descriptor() ([]byte, []int)

func (*Borrow) GetRecs

func (m *Borrow) GetRecs() map[uint64]uint64

func (*Borrow) ProtoMessage

func (*Borrow) ProtoMessage()

func (*Borrow) Reset

func (m *Borrow) Reset()

func (*Borrow) String

func (m *Borrow) String() string

func (*Borrow) XXX_DiscardUnknown

func (m *Borrow) XXX_DiscardUnknown()

func (*Borrow) XXX_Marshal

func (m *Borrow) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Borrow) XXX_Merge

func (m *Borrow) XXX_Merge(src proto.Message)

func (*Borrow) XXX_Size

func (m *Borrow) XXX_Size() int

func (*Borrow) XXX_Unmarshal

func (m *Borrow) XXX_Unmarshal(b []byte) error

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 New

func New(root hash.Hash, db Database) (*DB, error)

New creates a new state from a given trie.

func (*DB) AddPreimage

func (s *DB) AddPreimage(hash hash.Hash, preimage []byte)

AddPreimage records a SHA3 preimage seen by the VM.

func (*DB) Commit

func (s *DB) Commit(deleteEmptyObjects bool) (root hash.Hash, err error)

Commit writes the state to the underlying in-memory trie database.

func (*DB) Copy

func (s *DB) Copy() *DB

Copy creates a deep, independent copy of the state. Snapshots of the copied state cannot be applied to the copy.

func (*DB) CreateAccount

func (s *DB) CreateAccount(addr hash.Peer)

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:

  1. sends funds to sha(account ++ (nonce + 1))
  2. 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

func (s *DB) Database() Database

Database retrieves the low level database supporting the lower level trie ops.

func (*DB) Delegate

func (s *DB) Delegate(from, to hash.Peer, amount, until uint64)

Delegate writes delegation records.

func (*DB) Empty

func (s *DB) Empty(addr hash.Peer) bool

Empty returns whether the state object is either non-existent or empty according to the EIP161 specification (balance = nonce = code = 0).

func (*DB) Error

func (s *DB) Error() error

Error returns the first non-nil database error

func (*DB) Exist

func (s *DB) Exist(addr hash.Peer) bool

Exist reports whether the given account address exists in the state. Notably this also returns true for suicided accounts.

func (*DB) ExpireDelegations

func (s *DB) ExpireDelegations(addr hash.Peer, now uint64)

ExpireDelegations erases data about expired delegations.

func (*DB) Finalise

func (s *DB) Finalise(deleteEmptyObjects bool)

Finalise finalises the state by removing the self destructed objects and clears the journal as well as the refunds.

func (*DB) ForEachStorage

func (s *DB) ForEachStorage(addr hash.Peer, cb func(key, value hash.Hash) bool)

ForEachStorage calls func for each key-value of node.

func (*DB) FreeBalance

func (s *DB) FreeBalance(addr hash.Peer) uint64

FreeBalance returns the free balance from the given address or 0 if object not found.

func (*DB) GetCommittedState

func (s *DB) GetCommittedState(addr hash.Peer, h hash.Hash) hash.Hash

GetCommittedState retrieves a value from the given account's committed storage trie.

func (*DB) GetDelegations

func (s *DB) GetDelegations(addr hash.Peer) [2]map[hash.Peer]uint64

GetDelegations returns delegation records.

func (*DB) GetOrNewStateObject

func (s *DB) GetOrNewStateObject(addr hash.Peer) *stateObject

GetOrNewStateObject returns a state object or create a new state object if nil.

func (*DB) GetProof

func (s *DB) GetProof(a hash.Peer) ([][]byte, error)

GetProof returns the MerkleProof for a given Account.

func (*DB) GetState

func (s *DB) GetState(addr hash.Peer, h hash.Hash) hash.Hash

GetState retrieves a value from the given account's storage trie.

func (*DB) GetStorageProof

func (s *DB) GetStorageProof(a hash.Peer, key hash.Hash) ([][]byte, error)

GetStorageProof returns the StorageProof for given key.

func (*DB) HasSuicided

func (s *DB) HasSuicided(addr hash.Peer) bool

HasSuicided checks if stateObject is suicided by address.

func (*DB) IntermediateRoot

func (s *DB) IntermediateRoot(deleteEmptyObjects bool) hash.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 (*DB) Preimages

func (s *DB) Preimages() map[hash.Hash][]byte

Preimages returns a list of SHA3 preimages that have been submitted.

func (*DB) Prepare

func (s *DB) Prepare(thash, bhash hash.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 (*DB) Reset

func (s *DB) Reset(root hash.Hash) error

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

func (s *DB) RevertToSnapshot(revID int)

RevertToSnapshot reverts all state changes made since the given revision.

func (*DB) SetBalance

func (s *DB) SetBalance(addr hash.Peer, amount uint64)

SetBalance sets stateObject's balance by address.

func (*DB) SetState

func (s *DB) SetState(addr hash.Peer, key, value hash.Hash)

SetState sets stateObject's kv-state by address.

func (*DB) Snapshot

func (s *DB) Snapshot() int

Snapshot returns an identifier for the current revision of the state.

func (*DB) StorageTrie

func (s *DB) StorageTrie(addr hash.Peer) Trie

StorageTrie returns the storage trie of an account. The return value is a copy and is nil for non-existent accounts.

func (*DB) Suicide

func (s *DB) Suicide(addr hash.Peer) 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 (*DB) Transfer

func (s *DB) Transfer(from, to hash.Peer, amount uint64)

Transfer moves amount.

func (*DB) VoteBalance

func (s *DB) VoteBalance(addr hash.Peer) uint64

VoteBalance returns the vote balance from the given address or 0 if object not found.

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

func NewDatabase(db kvdb.Database) Database

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

func NewDatabaseWithCache(db kvdb.Database, cache int) Database

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

type Storage map[hash.Hash]hash.Hash

Storage of entries.

func (Storage) Copy

func (s Storage) Copy() Storage

Copy creates a deep, independent copy of the state.

func (Storage) String

func (self Storage) String() (str string)

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.

Jump to

Keyboard shortcuts

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