state

package
v0.0.0-...-97e54d3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TxGas                 uint64 = 21000 // Per transaction not creating a contract
	TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract
)

Variables

View Source
var (
	ErrNonceIncorrect        = fmt.Errorf("incorrect nonce")
	ErrNotEnoughFundsForGas  = fmt.Errorf("not enough funds to cover gas costs")
	ErrBlockLimitReached     = fmt.Errorf("gas limit reached in the pool")
	ErrIntrinsicGasOverflow  = fmt.Errorf("overflow in intrinsic gas calculation")
	ErrNotEnoughIntrinsicGas = fmt.Errorf("not enough gas supplied for intrinsic gas costs")
	ErrNotEnoughFunds        = fmt.Errorf("not enough funds for transfer with given value")
)

Functions

func TestState

func TestState(t *testing.T, buildPreState buildPreState)

TestState tests a set of tests on a state

func TransactionGasCost

func TransactionGasCost(msg *types.Transaction, isHomestead, isIstanbul bool) (uint64, error)

Types

type Account

type Account struct {
	Nonce    uint64
	Balance  *big.Int
	Root     types.Hash
	CodeHash []byte
	Trie     accountTrie
}

Account is the account reference in the ethereum state

func (*Account) Copy

func (a *Account) Copy() *Account

func (*Account) MarshalWith

func (a *Account) MarshalWith(ar *fastrlp.Arena) *fastrlp.Value

func (*Account) String

func (a *Account) String() string

func (*Account) UnmarshalRlp

func (a *Account) UnmarshalRlp(b []byte) error

type BlockResult

type BlockResult struct {
	Root     types.Hash
	Receipts []*types.Receipt
	TotalGas uint64
}

type Executor

type Executor struct {
	GetHash GetHashByNumberHelper

	PostHook func(txn *Transition)
	// contains filtered or unexported fields
}

Executor is the main entity

func NewExecutor

func NewExecutor(config *chain.Params, s State, logger hclog.Logger) *Executor

NewExecutor creates a new executor

func (*Executor) BeginTxn

func (e *Executor) BeginTxn(
	parentRoot types.Hash,
	header *types.Header,
	coinbaseReceiver types.Address,
) (*Transition, error)

func (*Executor) GetForksInTime

func (e *Executor) GetForksInTime(blockNumber uint64) chain.ForksInTime

GetForksInTime returns the active forks at the given block height

func (*Executor) ProcessBlock

func (e *Executor) ProcessBlock(
	parentRoot types.Hash,
	block *types.Block,
	blockCreator types.Address,
) (*Transition, error)

ProcessBlock already does all the handling of the whole process

func (*Executor) SetRuntime

func (e *Executor) SetRuntime(r runtime.Runtime)

SetRuntime adds a runtime to the runtime set

func (*Executor) State

func (e *Executor) State() State

StateAt returns snapshot at given root

func (*Executor) StateAt

func (e *Executor) StateAt(root types.Hash) (Snapshot, error)

StateAt returns snapshot at given root

func (*Executor) WriteGenesis

func (e *Executor) WriteGenesis(alloc map[types.Address]*chain.GenesisAccount) types.Hash

type GasLimitReachedTransitionApplicationError

type GasLimitReachedTransitionApplicationError struct {
	TransitionApplicationError
}

func NewGasLimitReachedTransitionApplicationError

func NewGasLimitReachedTransitionApplicationError(err error) *GasLimitReachedTransitionApplicationError

type GetHashByNumber

type GetHashByNumber = func(i uint64) types.Hash

GetHashByNumber returns the hash function of a block number

type GetHashByNumberHelper

type GetHashByNumberHelper = func(*types.Header) GetHashByNumber

type Object

type Object struct {
	Address  types.Address
	CodeHash types.Hash
	Balance  *big.Int
	Root     types.Hash
	Nonce    uint64
	Deleted  bool

	// TODO: Move this to executor
	DirtyCode bool
	Code      []byte

	Storage []*StorageObject
}

Object is the serialization of the radix object (can be merged to StateObject?).

type PreState

type PreState struct {
	Nonce   uint64
	Balance uint64
	State   map[types.Hash]types.Hash
}

PreState is the account prestate

type PreStates

type PreStates map[types.Address]*PreState

PreStates is a set of pre states

type Snapshot

type Snapshot interface {
	Get(k []byte) ([]byte, bool)
	Commit(objs []*Object) (Snapshot, []byte)
}

type State

type State interface {
	NewSnapshotAt(types.Hash) (Snapshot, error)
	NewSnapshot() Snapshot
	GetCode(hash types.Hash) ([]byte, bool)
}

type StateObject

type StateObject struct {
	Account   *Account
	Code      []byte
	Suicide   bool
	Deleted   bool
	DirtyCode bool
	Txn       *iradix.Txn
}

StateObject is the internal representation of the account

func (*StateObject) Copy

func (s *StateObject) Copy() *StateObject

Copy makes a copy of the state object

func (*StateObject) Empty

func (s *StateObject) Empty() bool

func (*StateObject) GetCommitedState

func (s *StateObject) GetCommitedState(key types.Hash) types.Hash

type StorageObject

type StorageObject struct {
	Deleted bool
	Key     []byte
	Val     []byte
}

StorageObject is an entry in the storage

type Transition

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

func (*Transition) AccountExists

func (t *Transition) AccountExists(addr types.Address) bool

func (*Transition) Apply

Apply applies a new transaction

func (*Transition) Call2

func (t *Transition) Call2(
	caller types.Address,
	to types.Address,
	input []byte,
	value *big.Int,
	gas uint64,
) *runtime.ExecutionResult

func (*Transition) Callx

func (*Transition) Commit

func (t *Transition) Commit() (Snapshot, types.Hash)

Commit commits the final result

func (*Transition) ContextPtr

func (t *Transition) ContextPtr() *runtime.TxContext

ContextPtr returns reference of context This method is called only by test

func (*Transition) Create2

func (t *Transition) Create2(
	caller types.Address,
	code []byte,
	value *big.Int,
	gas uint64,
) *runtime.ExecutionResult

func (*Transition) EmitLog

func (t *Transition) EmitLog(addr types.Address, topics []types.Hash, data []byte)

func (*Transition) Empty

func (t *Transition) Empty(addr types.Address) bool

func (*Transition) GetBalance

func (t *Transition) GetBalance(addr types.Address) *big.Int

func (*Transition) GetBlockHash

func (t *Transition) GetBlockHash(number int64) (res types.Hash)

func (*Transition) GetCode

func (t *Transition) GetCode(addr types.Address) []byte

func (*Transition) GetCodeHash

func (t *Transition) GetCodeHash(addr types.Address) (res types.Hash)

func (*Transition) GetCodeSize

func (t *Transition) GetCodeSize(addr types.Address) int

func (*Transition) GetNonce

func (t *Transition) GetNonce(addr types.Address) uint64

func (*Transition) GetStorage

func (t *Transition) GetStorage(addr types.Address, key types.Hash) types.Hash

func (*Transition) GetTxContext

func (t *Transition) GetTxContext() runtime.TxContext

func (*Transition) GetTxnHash

func (t *Transition) GetTxnHash() types.Hash

func (*Transition) Receipts

func (t *Transition) Receipts() []*types.Receipt

func (*Transition) Selfdestruct

func (t *Transition) Selfdestruct(addr types.Address, beneficiary types.Address)

func (*Transition) SetAccountDirectly

func (t *Transition) SetAccountDirectly(addr types.Address, account *chain.GenesisAccount) error

SetAccountDirectly sets an account to the given address NOTE: SetAccountDirectly changes the world state without a transaction

func (*Transition) SetStorage

func (t *Transition) SetStorage(
	addr types.Address,
	key types.Hash,
	value types.Hash,
	config *chain.ForksInTime,
) runtime.StorageStatus

func (*Transition) SetTxn

func (t *Transition) SetTxn(txn *Txn)

func (*Transition) TotalGas

func (t *Transition) TotalGas() uint64

func (*Transition) Txn

func (t *Transition) Txn() *Txn

func (*Transition) Write

func (t *Transition) Write(txn *types.Transaction) error

Write writes another transaction to the executor

func (*Transition) WriteFailedReceipt

func (t *Transition) WriteFailedReceipt(txn *types.Transaction) error

type TransitionApplicationError

type TransitionApplicationError struct {
	Err           error
	IsRecoverable bool // Should the transaction be discarded, or put back in the queue.
}

func NewTransitionApplicationError

func NewTransitionApplicationError(err error, isRecoverable bool) *TransitionApplicationError

func (*TransitionApplicationError) Error

type Txn

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

Txn is a reference of the state

func NewTxn

func NewTxn(state State, snapshot Snapshot) *Txn

func (*Txn) AddBalance

func (txn *Txn) AddBalance(addr types.Address, balance *big.Int)

AddBalance adds balance

func (*Txn) AddLog

func (txn *Txn) AddLog(log *types.Log)

AddLog adds a new log

func (*Txn) AddRefund

func (txn *Txn) AddRefund(gas uint64)

Refund

func (*Txn) AddSealingReward

func (txn *Txn) AddSealingReward(addr types.Address, balance *big.Int)

func (*Txn) CleanDeleteObjects

func (txn *Txn) CleanDeleteObjects(deleteEmptyObjects bool)

func (*Txn) Commit

func (txn *Txn) Commit(deleteEmptyObjects bool) (Snapshot, []byte)

func (*Txn) CreateAccount

func (txn *Txn) CreateAccount(addr types.Address)

func (*Txn) EmitLog

func (txn *Txn) EmitLog(addr types.Address, topics []types.Hash, data []byte)

func (*Txn) Empty

func (txn *Txn) Empty(addr types.Address) bool

func (*Txn) Exist

func (txn *Txn) Exist(addr types.Address) bool

func (*Txn) GetAccount

func (txn *Txn) GetAccount(addr types.Address) (*Account, bool)

GetAccount returns an account

func (*Txn) GetBalance

func (txn *Txn) GetBalance(addr types.Address) *big.Int

GetBalance returns the balance of an address

func (*Txn) GetCode

func (txn *Txn) GetCode(addr types.Address) []byte

func (*Txn) GetCodeHash

func (txn *Txn) GetCodeHash(addr types.Address) types.Hash

func (*Txn) GetCodeSize

func (txn *Txn) GetCodeSize(addr types.Address) int

func (*Txn) GetCommittedState

func (txn *Txn) GetCommittedState(addr types.Address, key types.Hash) types.Hash

GetCommittedState returns the state of the address in the trie

func (*Txn) GetNonce

func (txn *Txn) GetNonce(addr types.Address) uint64

GetNonce returns the nonce of an addr

func (*Txn) GetRefund

func (txn *Txn) GetRefund() uint64

func (*Txn) GetState

func (txn *Txn) GetState(addr types.Address, key types.Hash) types.Hash

GetState returns the state of the address at a given key

func (*Txn) HasSuicided

func (txn *Txn) HasSuicided(addr types.Address) bool

HasSuicided returns true if the account suicided

func (*Txn) IncrNonce

func (txn *Txn) IncrNonce(addr types.Address)

IncrNonce increases the nonce of the address

func (*Txn) Logs

func (txn *Txn) Logs() []*types.Log

func (*Txn) RevertToSnapshot

func (txn *Txn) RevertToSnapshot(id int)

RevertToSnapshot reverts to a given snapshot

func (*Txn) SetBalance

func (txn *Txn) SetBalance(addr types.Address, balance *big.Int)

SetBalance sets the balance

func (*Txn) SetCode

func (txn *Txn) SetCode(addr types.Address, code []byte)

SetCode sets the code for an address

func (*Txn) SetNonce

func (txn *Txn) SetNonce(addr types.Address, nonce uint64)

SetNonce reduces the balance

func (*Txn) SetState

func (txn *Txn) SetState(
	addr types.Address,
	key,
	value types.Hash,
)

SetState change the state of an address

func (*Txn) SetStorage

func (txn *Txn) SetStorage(
	addr types.Address,
	key types.Hash,
	value types.Hash,
	config *chain.ForksInTime,
) runtime.StorageStatus

func (*Txn) Snapshot

func (txn *Txn) Snapshot() int

Snapshot takes a snapshot at this point in time

func (*Txn) SubBalance

func (txn *Txn) SubBalance(addr types.Address, amount *big.Int) error

SubBalance reduces the balance at address addr by amount

func (*Txn) SubRefund

func (txn *Txn) SubRefund(gas uint64)

func (*Txn) Suicide

func (txn *Txn) Suicide(addr types.Address) bool

Suicide marks the given account as suicided

func (*Txn) TouchAccount

func (txn *Txn) TouchAccount(addr types.Address)

Directories

Path Synopsis
evm

Jump to

Keyboard shortcuts

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