state

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2019 License: MIT Imports: 23 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
)
View Source
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

func NewContext

func NewContext(origin common.Address,
	coinbase common.Address,
	gasLimit uint64,
	gasPrice *big.Int) vm.Context

NewContext returns a custom Context suitable from evm-lite

Types

type BaseState added in v0.3.4

type BaseState struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

func (bs *BaseState) Call(callMsg ethTypes.Message) ([]byte, error)

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) Commit added in v0.3.4

func (bs *BaseState) Commit() (common.Hash, error)

Commit commits everything to the underlying database

func (*BaseState) Copy added in v0.3.4

func (bs *BaseState) Copy() BaseState

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

func (bs *BaseState) GetBalance(addr common.Address) *big.Int

GetBalance returns an account's balance from the stateDB

func (*BaseState) GetCode added in v0.3.4

func (bs *BaseState) GetCode(addr common.Address) []byte

GetCode returns an account's bytecode from the stateDB

func (*BaseState) GetNonce added in v0.3.4

func (bs *BaseState) GetNonce(addr common.Address) uint64

GetNonce returns an account's nonce from the stateDB

func (*BaseState) GetReceipt added in v0.3.4

func (bs *BaseState) GetReceipt(txHash common.Hash) (*ethTypes.Receipt, error)

GetReceipt fetches transaction receipts by transaction hash directly from the DB

func (*BaseState) GetStorage added in v0.3.6

func (bs *BaseState) GetStorage(addr common.Address) map[string]string

GetStorage returns an account's storage from the stateDB

func (*BaseState) GetTransaction added in v0.3.4

func (bs *BaseState) GetTransaction(hash common.Hash) (*ethTypes.Transaction, error)

GetTransaction fetches transactions by hash directly from the DB.

func (*BaseState) Reset added in v0.3.4

func (bs *BaseState) Reset(root common.Hash) error

Reset resets the stateDB and the gas counters.

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:

  1. it's own state, which is the "official" state, that cannot be arbitrarily reverted.
  2. the write-ahead-state (was), where the consensus system applies transactions before committing them to the main state.
  3. the transaction-pool's state, where the Service verifies transactions before submitting them to the consensus system.

func NewState

func NewState(dbFile string, dbCache int, genesisFile string, logger *logrus.Entry) (*State, error)

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

func (s *State) Call(callMsg ethTypes.Message) ([]byte, error)

Call executes a readonly transaction on a copy of the WAS. It is called by the service handlers

func (*State) CheckAuthorised

func (s *State) CheckAuthorised(addr common.Address) (bool, error)

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

func (s *State) Commit() (common.Hash, error)

Commit persists all pending state changes (in the WAS) to the DB, and resets the WAS and TxPool

func (*State) CreateGenesisAccounts

func (s *State) CreateGenesisAccounts() error

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

func (s *State) DumpAllAccounts() []byte

DumpAllAccounts outputs JSON of all accounts

func (*State) GetAuthorisingABI added in v0.3.3

func (s *State) GetAuthorisingABI() string

GetAuthorisingABI returns the abi of the smart contract which handles the list of authorized peers

func (*State) GetAuthorisingAccount

func (s *State) GetAuthorisingAccount() string

GetAuthorisingAccount returns the address of the smart contract which handles the list of authorized peers

func (*State) GetBalance

func (s *State) GetBalance(addr common.Address, fromPool bool) *big.Int

GetBalance returns an account's balance

func (*State) GetCode

func (s *State) GetCode(addr common.Address, fromPool bool) []byte

GetCode returns an account's bytecode

func (*State) GetGasLimit

func (s *State) GetGasLimit() uint64

GetGasLimit returns the gas limit set between commit calls

func (*State) GetGenesis

func (s *State) GetGenesis() (bcommon.Genesis, error)

GetGenesis reads and unmarshals the genesis.json file

func (*State) GetNonce

func (s *State) GetNonce(addr common.Address, fromPool bool) uint64

GetNonce returns an account's nonce

func (*State) GetReceipt

func (s *State) GetReceipt(txHash common.Hash) (*ethTypes.Receipt, error)

GetReceipt fetches a transaction's receipt from the WAS

func (*State) GetSigner added in v0.3.3

func (s *State) GetSigner() ethTypes.Signer

GetSigner returns the state's signer

func (*State) GetStorage added in v0.3.6

func (s *State) GetStorage(addr common.Address, fromPool bool) map[string]string

GetStorage returns an account's storage

func (*State) GetTransaction

func (s *State) GetTransaction(txHash common.Hash) (*ethTypes.Transaction, error)

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 NewTxPool

func NewTxPool(base BaseState, logger *logrus.Entry) *TxPool

NewTxPool creates a new TxPool object

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.

func (*WriteAheadState) Reset

func (was *WriteAheadState) Reset(root common.Hash) error

Reset overrides BaseState Reset. It calls reset on the BaseState and clears the transactions, receipts, and logs caches.

Jump to

Keyboard shortcuts

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