Documentation ¶
Index ¶
- Variables
- func NewContext(origin common.Address, coinbase common.Address, gasLimit uint64, ...) vm.Context
- type BaseState
- func (bs *BaseState) ApplyTransaction(tx *EVMLTransaction, txIndex int, blockHash common.Hash, ...) error
- func (bs *BaseState) Call(callMsg ethTypes.Message) ([]byte, error)
- func (bs *BaseState) Commit() (common.Hash, error)
- func (bs *BaseState) Copy() BaseState
- func (bs *BaseState) CreateAccount(address common.Address, code string, storage map[string]string, balance string, ...)
- func (bs *BaseState) GetBalance(addr common.Address) *big.Int
- func (bs *BaseState) GetCode(addr common.Address) []byte
- func (bs *BaseState) GetNonce(addr common.Address) uint64
- func (bs *BaseState) GetReceipt(txHash common.Hash) (*ethTypes.Receipt, error)
- func (bs *BaseState) GetStorage(addr common.Address) map[string]string
- func (bs *BaseState) GetTransaction(hash common.Hash) (*ethTypes.Transaction, error)
- func (bs *BaseState) Reset(root common.Hash) error
- func (bs *BaseState) WriteReceipts(txs map[common.Hash]*EVMLTransaction) error
- func (bs *BaseState) WriteTransactions(txs map[common.Hash]*EVMLTransaction) error
- type CurrentGenesis
- type EVMLTransaction
- type ReceiptPromise
- type ReceiptPromiseResponse
- type State
- func (s *State) ApplyTransaction(txBytes []byte, txIndex int, blockHash common.Hash, coinbase common.Address) error
- func (s *State) Call(callMsg ethTypes.Message) ([]byte, error)
- func (s *State) CheckAuthorised(addr common.Address) (bool, error)
- func (s *State) CheckTx(tx *EVMLTransaction) error
- func (s *State) Commit() (common.Hash, error)
- func (s *State) CreateGenesisAccounts() error
- func (s *State) CreateReceiptPromise(hash common.Hash) *ReceiptPromise
- func (s *State) DumpAllAccounts() []byte
- func (s *State) GetAuthorisingABI() string
- func (s *State) GetAuthorisingAccount() string
- func (s *State) GetBalance(addr common.Address, fromPool bool) *big.Int
- func (s *State) GetCode(addr common.Address, fromPool bool) []byte
- func (s *State) GetGasLimit() uint64
- func (s *State) GetGenesis() (bcommon.Genesis, error)
- func (s *State) GetNonce(addr common.Address, fromPool bool) uint64
- func (s *State) GetReceipt(txHash common.Hash) (*ethTypes.Receipt, error)
- func (s *State) GetSigner() ethTypes.Signer
- func (s *State) GetStorage(addr common.Address, fromPool bool) map[string]string
- func (s *State) GetTransaction(txHash common.Hash) (*ethTypes.Transaction, error)
- type TxPool
- type WriteAheadState
- func (was *WriteAheadState) ApplyTransaction(tx *EVMLTransaction, txIndex int, blockHash common.Hash, ...) error
- func (was *WriteAheadState) Commit() (common.Hash, error)
- func (was *WriteAheadState) CreateReceiptPromise(hash common.Hash) *ReceiptPromise
- func (was *WriteAheadState) Reset(root common.Hash) error
Constants ¶
This section is empty.
Variables ¶
var ( // POAABI defines the ABI of the POA smart-contract as needed by a consensus // module to check if an address is authorized POAABI abi.ABI // POAABISTRING is the string representaion of POAABI POAABISTRING string // POAADDR is the address of the POA smart-contract. POAADDR eth_common.Address )
var ( // CustomChainConfig accounts for the fact that EVM-Lite doesn't really have // a concept of Chain, or Blocks (being consensus-agnostic). The EVM is // tightly coupled with this ChainConfig object (cf interpreter.go), so this // is a workaround that treats all blocks the same. CustomChainConfig = params.ChainConfig{ ChainID: big.NewInt(1), ConstantinopleBlock: big.NewInt(0), } )
Functions ¶
Types ¶
type BaseState ¶ added in v0.3.4
BaseState is a THREAD-SAFE wrapper around a StateDB. It contains the logic to retrieve information from the DB, and apply new transactions.
func NewBaseState ¶ added in v0.3.4
func NewBaseState(db ethdb.Database, root common.Hash, signer ethTypes.Signer, chainConfig params.ChainConfig, vmConfig vm.Config, gasLimit uint64) BaseState
NewBaseState returns a BaseState initialized from a database and root hash.
func (*BaseState) ApplyTransaction ¶ added in v0.3.4
func (bs *BaseState) ApplyTransaction( tx *EVMLTransaction, txIndex int, blockHash common.Hash, coinbase common.Address, noReceipt bool) error
ApplyTransaction executes the transaction on the stateDB and sets its receipt unless noReceipt is set to true. An error indicates a consensus issue.
func (*BaseState) Call ¶ added in v0.3.4
Call executes a readonly transaction on a copy of the stateDB. This is used to call smart-contract methods. We use a copy of the stateDB because even a call transaction increments the sender's nonce.
func (*BaseState) Copy ¶ added in v0.3.4
Copy returns a copy of the BaseState with its own mutex, gp, and stateDB
func (*BaseState) CreateAccount ¶ added in v0.3.4
func (bs *BaseState) CreateAccount(address common.Address, code string, storage map[string]string, balance string, nonce uint64)
CreateAccount adds an account in the stateDB
func (*BaseState) GetBalance ¶ added in v0.3.4
GetBalance returns an account's balance from the stateDB
func (*BaseState) GetReceipt ¶ added in v0.3.4
GetReceipt fetches transaction receipts by transaction hash directly from the DB
func (*BaseState) GetStorage ¶ added in v0.3.6
GetStorage returns an account's storage from the stateDB
func (*BaseState) GetTransaction ¶ added in v0.3.4
GetTransaction fetches transactions by hash directly from the DB.
func (*BaseState) WriteReceipts ¶ added in v0.3.4
func (bs *BaseState) WriteReceipts(txs map[common.Hash]*EVMLTransaction) error
WriteReceipts writes a set of receipts directly into the DB
func (*BaseState) WriteTransactions ¶ added in v0.3.4
func (bs *BaseState) WriteTransactions(txs map[common.Hash]*EVMLTransaction) error
WriteTransactions writes a set of transactions directly into the DB
type CurrentGenesis ¶ added in v0.3.6
type CurrentGenesis struct { Alloc map[string]ethState.DumpAccount Poa bcommon.PoaMap }
CurrentGenesis is a datastructure for the export
type EVMLTransaction ¶ added in v0.3.5
type EVMLTransaction struct { *ethTypes.Transaction // contains filtered or unexported fields }
EVMLTransaction is a wrapper around an EVM transaction which contains a receipt and the sender address.
func NewEVMLTransaction ¶ added in v0.3.5
func NewEVMLTransaction(rlpBytes []byte, signer ethTypes.Signer) (*EVMLTransaction, error)
NewEVMLTransaction decodes an RLP encoded EVM transaction and returns an EVMLTransaction wrapper
func (*EVMLTransaction) From ¶ added in v0.3.5
func (t *EVMLTransaction) From() ethCommon.Address
From returns the transaction's sender address
func (*EVMLTransaction) JSONReceipt ¶ added in v0.3.5
func (t *EVMLTransaction) JSONReceipt() *common.JSONReceipt
JSONReceipt returns the JSONReceipt corresponding to an EVMLTransaction
func (*EVMLTransaction) Msg ¶ added in v0.3.5
func (t *EVMLTransaction) Msg() *ethTypes.Message
Msg returns the transaction's core.Message property
type ReceiptPromise ¶ added in v0.3.1
type ReceiptPromise struct { Hash ethCommon.Hash RespCh chan ReceiptPromiseResponse }
ReceiptPromise provides a response mechanism for transaction receipts. The Hash identifies the transaction to which the ReceiptPromise corresponds, and is used as the key in the map kept by the WAS.
func NewReceiptPromise ¶ added in v0.3.1
func NewReceiptPromise(hash ethCommon.Hash) *ReceiptPromise
NewReceiptPromise is a factory method for a ReceiptPromise
func (*ReceiptPromise) Respond ¶ added in v0.3.1
func (p *ReceiptPromise) Respond(receipt *common.JSONReceipt, err error)
Respond resolves a ReceiptPromiseResponse and passes it to the RespCh
type ReceiptPromiseResponse ¶ added in v0.3.3
type ReceiptPromiseResponse struct { Receipt *common.JSONReceipt Error error }
ReceiptPromiseResponse captures a receipt and a potential error
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is the main THREAD SAFE object that manages the application-state of evm-lite. It is used by the Service for read-only operations, and by the Consensus system to apply new transactions. It manages 3 copies of the underlying datastore:
- it's own state, which is the "official" state, that cannot be arbitrarily reverted.
- the write-ahead-state (was), where the consensus system applies transactions before committing them to the main state.
- the transaction-pool's state, where the Service verifies transactions before submitting them to the consensus system.
func NewState ¶
NewState creates and initializes a new State object. It reads the genesis file to create the initial accounts, including the POA smart-contract.
func (*State) ApplyTransaction ¶
func (s *State) ApplyTransaction( txBytes []byte, txIndex int, blockHash common.Hash, coinbase common.Address) error
ApplyTransaction decodes a transaction and applies it to the WAS. It is meant to be called by the consensus system to apply transactions sequentially.
func (*State) Call ¶
Call executes a readonly transaction on a copy of the WAS. It is called by the service handlers
func (*State) CheckAuthorised ¶
CheckAuthorised queries the POA smart-contract to check if the address is authorised. It is called by the consensus system when deciding to add or remove a peer.
func (*State) CheckTx ¶
func (s *State) CheckTx(tx *EVMLTransaction) error
CheckTx attempts to apply a transaction to the TxPool's stateDB. It is called by the Service handlers to check if a transaction is valid before submitting it to the consensus system. This also updates the sender's Nonce in the TxPool's statedb.
func (*State) Commit ¶
Commit persists all pending state changes (in the WAS) to the DB, and resets the WAS and TxPool
func (*State) CreateGenesisAccounts ¶
CreateGenesisAccounts reads the genesis.json file and creates the regular pre-funded accounts, as well as the POA smart-contract account.
func (*State) CreateReceiptPromise ¶ added in v0.3.1
func (s *State) CreateReceiptPromise(hash common.Hash) *ReceiptPromise
CreateReceiptPromise crates a new receipt promise
func (*State) DumpAllAccounts ¶ added in v0.3.6
DumpAllAccounts outputs JSON of all accounts
func (*State) GetAuthorisingABI ¶ added in v0.3.3
GetAuthorisingABI returns the abi of the smart contract which handles the list of authorized peers
func (*State) GetAuthorisingAccount ¶
GetAuthorisingAccount returns the address of the smart contract which handles the list of authorized peers
func (*State) GetBalance ¶
GetBalance returns an account's balance
func (*State) GetGasLimit ¶
GetGasLimit returns the gas limit set between commit calls
func (*State) GetGenesis ¶
GetGenesis reads and unmarshals the genesis.json file
func (*State) GetReceipt ¶
GetReceipt fetches a transaction's receipt from the WAS
func (*State) GetStorage ¶ added in v0.3.6
GetStorage returns an account's storage
func (*State) GetTransaction ¶
GetTransaction fetches a transaction from the WAS
type TxPool ¶
type TxPool struct { BaseState // contains filtered or unexported fields }
TxPool is a BaseState extension with a CheckTx function. The service requires a stateful object to check transactions, because txs might be coming it faster than the consensus system can process them.
func (*TxPool) CheckTx ¶
func (p *TxPool) CheckTx(tx *EVMLTransaction) error
CheckTx applies the transaction to the base's stateDB. It doesn't care about the transaction index, block hash, or coinbase. It is used by the service to quickly check if a transaction is valid before submitting it to the consensus system.
type WriteAheadState ¶
type WriteAheadState struct { BaseState // contains filtered or unexported fields }
WriteAheadState is a wrapper around a DB and StateBase object that applies transactions to the StateDB and only commits them to the DB upon Commit. It also handles persisting transactions, logs, and receipts to the DB. NOT THREAD SAFE
func NewWriteAheadState ¶
func NewWriteAheadState(base BaseState, logger *logrus.Entry) *WriteAheadState
NewWriteAheadState returns a new WAS based on a BaseState
func (*WriteAheadState) ApplyTransaction ¶
func (was *WriteAheadState) ApplyTransaction( tx *EVMLTransaction, txIndex int, blockHash common.Hash, coinbase common.Address) error
ApplyTransaction executes the transaction on the WAS BaseState. If the transaction returns a "consensus" error (an error that is not due to EVM execution), it will not produce a receipt, and will not be saved; if there is a promise attached to it, we quickly resolve it with an error. If the transaction did not return a "consensus" error, we record it and its receipt, even if its status is "failed".
func (*WriteAheadState) Commit ¶
func (was *WriteAheadState) Commit() (common.Hash, error)
Commit commits everything to the underlying database.
func (*WriteAheadState) CreateReceiptPromise ¶ added in v0.3.4
func (was *WriteAheadState) CreateReceiptPromise(hash common.Hash) *ReceiptPromise
CreateReceiptPromise creates and records a new ReceiptPromise for a transaction hash.