state

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const NewRootKey = "root"

Variables

View Source
var (
	ErrOrigin = "origin account doesnt exist"
	ErrFunds  = "insufficient funds"
	ErrNonce  = "incorrect nonce"
)
View Source
var MaxTrieCacheGen = uint16(120)

Trie cache generation limit after which to evict trie nodes from memory.

Functions

func PublicKeyToAccountAddress

func PublicKeyToAccountAddress(pub ed25519.PublicKey) types.Address

Types

type Account

type Account struct {
	Nonce   uint64
	Balance *big.Int
}

type AccountState

type AccountState interface {
	GetBalance() *big.Int
	GetNonce() uint64
	SetNonce(newNonce uint64)
	AddBalance(amount *big.Int)
	SubBalance(amount *big.Int)
	SetBalance(amount *big.Int)
	GetAddress() types.Address
}

type Database

type Database interface {
	// OpenTrie opens the main account trie.
	OpenTrie(root types.Hash32) (Trie, error)

	// OpenStorageTrie opens the storage trie of an account.
	OpenStorageTrie(addrHash, root types.Hash32) (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 and contract code.

func NewDatabase

func NewDatabase(db database.Database) Database

NewDatabase creates a backing store for state. The returned database is safe for concurrent use and retains cached trie nodes in memory. The pool is an optional intermediate trie-node memory pool between the low level storage layer and the high level trie abstraction.

type Dump

type Dump struct {
	Root     string                 `json:"root"`
	Accounts map[string]DumpAccount `json:"accounts"`
}

type DumpAccount

type DumpAccount struct {
	Balance string `json:"balance"`
	Nonce   uint64 `json:"nonce"`
}

type GlobalStateDB

type GlobalStateDB interface {
	Exist(addr types.Address) bool
	Empty(addr types.Address) bool
	GetBalance(addr types.Address) uint64
	GetNonce(addr types.Address) uint64
	AddBalance(addr types.Address, amount *big.Int)
	SubBalance(addr types.Address, amount *big.Int)
	SetNonce(addr types.Address, nonce uint64)
	GetOrNewStateObj(addr types.Address) *StateObj
	CreateAccount(addr types.Address)
	Commit(deleteEmptyObjects bool) (root types.Hash32, err error)
	//Copy() *GlobalStateDB
	IntermediateRoot(deleteEmptyObjects bool) types.Hash32
	TrieDB() *trie.Database
}

type Projector

type Projector interface {
	GetProjection(addr types.Address, prevNonce, prevBalance uint64) (nonce, balance uint64, err error)
}

type StateDB

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

func New

func New(root types.Hash32, db Database) (*StateDB, error)

Create a new state from a given trie.

func (*StateDB) AddBalance

func (self *StateDB) AddBalance(addr types.Address, amount *big.Int)

AddBalance adds amount to the account associated with addr.

func (*StateDB) Commit

func (s *StateDB) Commit(deleteEmptyObjects bool) (root types.Hash32, err error)

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

func (*StateDB) Copy

func (self *StateDB) Copy() *StateDB

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

func (*StateDB) CreateAccount

func (self *StateDB) CreateAccount(addr types.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:

  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 (*StateDB) Dump

func (self *StateDB) Dump() []byte

func (*StateDB) Empty

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

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

func (*StateDB) Error

func (self *StateDB) Error() error

func (*StateDB) Exist

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

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

func (*StateDB) Finalise

func (s *StateDB) Finalise(deleteEmptyObjects bool)

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

func (*StateDB) GetBalance

func (self *StateDB) GetBalance(addr types.Address) uint64

Retrieve the balance from the given address or 0 if object not found

func (*StateDB) GetNonce

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

func (*StateDB) GetOrNewStateObj

func (self *StateDB) GetOrNewStateObj(addr types.Address) *StateObj

Retrieve a state object or create a new state object if nil.

func (*StateDB) IntermediateRoot

func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) types.Hash32

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 (*StateDB) RawDump

func (self *StateDB) RawDump() Dump

func (*StateDB) SetBalance

func (self *StateDB) SetBalance(addr types.Address, amount *big.Int)

func (*StateDB) SetNonce

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

func (*StateDB) SubBalance

func (self *StateDB) SubBalance(addr types.Address, amount *big.Int)

SubBalance subtracts amount from the account associated with addr.

func (*StateDB) TrieDB

func (s *StateDB) TrieDB() *trie.Database

TrieDB retrieves the low level trie database used for data storage.

type StateObj

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

func (*StateObj) AddBalance

func (c *StateObj) AddBalance(amount *big.Int)

AddBalance removes amount from c's balance. It is used to add funds to the destination account of a transfer.

func (*StateObj) Address

func (c *StateObj) Address() types.Address

Returns the address of the contract/account

func (*StateObj) Balance

func (self *StateObj) Balance() *big.Int

func (*StateObj) EncodeRLP

func (c *StateObj) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*StateObj) Nonce

func (self *StateObj) Nonce() uint64

func (*StateObj) ReturnGas

func (c *StateObj) ReturnGas(gas *big.Int)

Return the gas back to the origin. Used by the Virtual machine or Closures

func (*StateObj) SetBalance

func (self *StateObj) SetBalance(amount *big.Int)

func (*StateObj) SetNonce

func (self *StateObj) SetNonce(nonce uint64)

func (*StateObj) SubBalance

func (c *StateObj) SubBalance(amount *big.Int)

SubBalance removes amount from c's balance. It is used to remove funds from the origin account of a transfer.

func (*StateObj) Value

func (self *StateObj) Value() *big.Int

Never called, but must be present to allow StateObj to be used as a vm.Account interface that also satisfies the vm.ContractRef interface. Interfaces are awesome.

type StatePreImages

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

type TransactionProcessor

type TransactionProcessor struct {
	log.Log
	*StateDB
	// contains filtered or unexported fields
}

func NewTransactionProcessor

func NewTransactionProcessor(allStates, processorDb database.Database, projector Projector, logger log.Log) *TransactionProcessor

func (*TransactionProcessor) AddressExists

func (tp *TransactionProcessor) AddressExists(addr types.Address) bool

AddressExists checks if an account address exists in this node's global state

func (*TransactionProcessor) ApplyRewards

func (tp *TransactionProcessor) ApplyRewards(layer types.LayerID, miners []types.Address, reward *big.Int)

func (*TransactionProcessor) ApplyTransaction

func (tp *TransactionProcessor) ApplyTransaction(trans *types.Transaction, layerId types.LayerID) error

func (*TransactionProcessor) ApplyTransactions

func (tp *TransactionProcessor) ApplyTransactions(layer types.LayerID, txs []*types.Transaction) (int, error)

ApplyTransaction receives a batch of transaction to apply on state. Returns the number of transaction that failed to apply.

func (*TransactionProcessor) GetLayerApplied

func (tp *TransactionProcessor) GetLayerApplied(txId types.TransactionId) *types.LayerID

func (*TransactionProcessor) GetStateRoot

func (tp *TransactionProcessor) GetStateRoot() types.Hash32

func (*TransactionProcessor) LoadState

func (tp *TransactionProcessor) LoadState(layer types.LayerID) error

func (*TransactionProcessor) Process

func (tp *TransactionProcessor) Process(txs []*types.Transaction, layerId types.LayerID) (remaining []*types.Transaction)

func (*TransactionProcessor) ValidateNonceAndBalance

func (tp *TransactionProcessor) ValidateNonceAndBalance(tx *types.Transaction) error

func (*TransactionProcessor) ValidateSignature

func (tp *TransactionProcessor) ValidateSignature(s types.Signed) (types.Address, error)

Validate the signature by extracting the source account and validating its existence. Return the src acount address and error in case of failure

type Trie

type Trie interface {
	TryGet(key []byte) ([]byte, error)
	TryUpdate(key, value []byte) error
	TryDelete(key []byte) error
	Commit(onleaf trie.LeafCallback) (types.Hash32, error)
	Hash() types.Hash32
	NodeIterator(startKey []byte) trie.NodeIterator
	GetKey([]byte) []byte // TODO(fjl): remove this when SecureTrie is removed
	Prove(key []byte, fromLevel uint, proofDb database.Putter) error
}

Trie is a Ethereum Merkle Trie.

Jump to

Keyboard shortcuts

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