core

package
v0.0.0-...-92d349b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: GPL-3.0 Imports: 53 Imported by: 0

Documentation

Overview

Package core implements the Ethereum consensus protocol.

Index

Constants

View Source
const (
	TriesInMemory = 128
)

Variables

View Source
var (
	// ErrKnownBlock is returned when a block to import is already known locally.
	ErrKnownBlock = errors.New("block already known")

	// ErrBlacklistedHash is returned if a block to import is on the blacklist.
	ErrBlacklistedHash = errors.New("blacklisted hash")

	// ErrNoGenesis is returned when there is no Genesis Block.
	ErrNoGenesis = errors.New("genesis not found in chain")

	// ErrTipAboveFeeCap is a sanity error to ensure no one is able to specify a
	// transaction with a tip higher than the total fee cap.
	ErrTipAboveFeeCap = errors.New("tip higher than fee cap")

	// ErrTipVeryHigh is a sanity error to avoid extremely big numbers specified
	// in the tip field.
	ErrTipVeryHigh = errors.New("tip higher than 2^256-1")

	// ErrFeeCapVeryHigh is a sanity error to avoid extremely big numbers specified
	// in the fee cap field.
	ErrFeeCapVeryHigh = errors.New("fee cap higher than 2^256-1")
)
View Source
var (
	// ErrNonceTooLow is returned if the nonce of a transaction is lower than the
	// one present in the local chain.
	ErrNonceTooLow = errors.New("nonce too low")

	// ErrNonceTooHigh is returned if the nonce of a transaction is higher than the
	// next one expected based on the local chain.
	ErrNonceTooHigh = errors.New("nonce too high")

	// ErrNonceMax is returned if the nonce of a transaction sender account has
	// maximum allowed value and would become invalid if incremented.
	ErrNonceMax = errors.New("nonce has max value")

	// ErrGasLimitReached is returned by the gas pool if the amount of gas required
	// by a transaction is higher than what's left in the block.
	ErrGasLimitReached = errors.New("gas limit reached")

	// ErrDataGasLimitReached is returned by the gas pool if the amount of data gas required
	// by a transaction is higher than what's left in the block.
	ErrDataGasLimitReached = errors.New("data gas limit reached")

	// ErrMaxInitCodeSizeExceeded is returned if creation transaction provides the init code bigger
	// than init code size limit.
	ErrMaxInitCodeSizeExceeded = errors.New("max initcode size exceeded")

	// ErrInsufficientFunds is returned if the total cost of executing a transaction
	// is higher than the balance of the user's account.
	ErrInsufficientFunds = errors.New("insufficient funds for gas * price + value")

	// ErrGasUintOverflow is returned when calculating gas usage.
	ErrGasUintOverflow = errors.New("gas uint64 overflow")

	// ErrIntrinsicGas is returned if the transaction is specified to use less gas
	// than required to start the invocation.
	ErrIntrinsicGas = errors.New("intrinsic gas too low")

	// ErrTxTypeNotSupported is returned if a transaction is not supported in the
	// current network configuration.
	ErrTxTypeNotSupported = types.ErrTxTypeNotSupported

	// ErrFeeCapTooLow is returned if the transaction fee cap is less than the
	// the base fee of the block.
	ErrFeeCapTooLow = errors.New("fee cap less than block base fee")

	// ErrSenderNoEOA is returned if the sender of a transaction is a contract.
	// See EIP-3607: Reject transactions from senders with deployed code.
	ErrSenderNoEOA = errors.New("sender not an eoa")
)

List of evm-call-message pre-checking errors. All state transition messages will be pre-checked before execution. If any invalidation detected, the corresponding error should be returned which is defined here.

- If the pre-checking happens in the miner, then the transaction won't be packed. - If the pre-checking happens in the block processing procedure, then a "BAD BLOCk" error should be emitted.

View Source
var BadHashes = map[libcommon.Hash]bool{
	libcommon.HexToHash("05bef30ef572270f654746da22639a7a0c97dd97a7050b9e252391996aaeb689"): true,
	libcommon.HexToHash("7d05d08cbc596a2e5e4f13b80a743e53e09221b5323c3a61946b20873e58583f"): true,
}

BadHashes represent a set of manually tracked bad hashes (usually hard forks)

View Source
var (
	BlockExecutionTimer = metrics2.GetOrCreateSummary("chain_execution_seconds")
)
View Source
var DevnetEtherbase = libcommon.HexToAddress("67b1d87101671b127f5f8714789c7192f7ad340e")
View Source
var DevnetSignPrivateKey, _ = crypto.HexToECDSA("26e86e45f6fc45ec6e2ecd128cec80fa1d1505e5507dcd2ae58c3130a7a97b48")

Pre-calculated version of:

DevnetSignPrivateKey = crypto.HexToECDSA(sha256.Sum256([]byte("erigon devnet key")))
DevnetEtherbase=crypto.PubkeyToAddress(DevnetSignPrivateKey.PublicKey)
View Source
var GenerateTrace bool

Functions

func AddFeeTransferLog

func AddFeeTransferLog(
	state evmtypes.IntraBlockState,

	sender,
	recipient libcommon.Address,

	amount,
	input1,
	input2,
	output1,
	output2 *uint256.Int,
)

AddFeeTransferLog adds transfer log into state Deprecating transfer log and will be removed in future fork. PLEASE DO NOT USE this transfer log going forward. Parameters won't get updated as expected going forward with EIP1559

func AddTransferLog

func AddTransferLog(
	state evmtypes.IntraBlockState,

	sender,
	recipient libcommon.Address,

	amount,
	input1,
	input2,
	output1,
	output2 *uint256.Int,
)

AddTransferLog adds transfer log into state

func ApplyTransaction

func ApplyTransaction(config *chain.Config, blockHashFunc func(n uint64) libcommon.Hash, engine consensus.EngineReader, author *libcommon.Address, gp *GasPool, ibs *state.IntraBlockState, stateWriter state.StateWriter, header *types.Header, tx types.Transaction, usedGas *uint64, cfg vm.Config, excessDataGas *big.Int, effectiveGasPricePercentage uint8) (*types.Receipt, []byte, error)

ApplyTransaction attempts to apply a transaction to the given state database and uses the input parameters for its environment. It returns the receipt for the transaction, gas used and an error if the transaction failed, indicating the block was invalid.

func BorDevnetGenesisBlock

func BorDevnetGenesisBlock() *types.Genesis

func BorMainnetGenesisBlock

func BorMainnetGenesisBlock() *types.Genesis

BorMainnetGenesisBlock returns the Bor Mainnet network genesis block.

func BorTransfer

func BorTransfer(db evmtypes.IntraBlockState, sender, recipient libcommon.Address, amount *uint256.Int, bailout bool)

BorTransfer transfer in Bor

func CalcGasLimit

func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64

CalcGasLimit computes the gas limit of the next block after parent. It aims to keep the baseline gas close to the provided target, and increase it towards the target if the baseline gas is lower.

func CallContract

func CallContract(contract libcommon.Address, data []byte, chainConfig chain.Config, ibs *state.IntraBlockState, header *types.Header, engine consensus.Engine, excessDataGas *big.Int) (result []byte, err error)

func CallContractTx

func CallContractTx(contract libcommon.Address, data []byte, ibs *state.IntraBlockState) (tx types.Transaction, err error)

from the null sender, with 50M gas.

func CanTransfer

func CanTransfer(db evmtypes.IntraBlockState, addr libcommon.Address, amount *uint256.Int) bool

CanTransfer checks whether there are enough funds in the address' account to make a transfer. This does not take the necessary gas in to account to make the transfer valid.

func CheckEip1559TxGasFeeCap

func CheckEip1559TxGasFeeCap(from libcommon.Address, gasFeeCap, tip, baseFee *uint256.Int, isFree bool) error

func ChiadoGenesisBlock

func ChiadoGenesisBlock() *types.Genesis

func CommitGenesisBlock

func CommitGenesisBlock(db kv.RwDB, genesis *types.Genesis, tmpDir string) (*chain.Config, *types.Block, error)

CommitGenesisBlock writes or updates the genesis block in db. The block that will be used is:

                     genesis == nil       genesis != nil
                  +------------------------------------------
db has no genesis |  main-net          |  genesis
db has genesis    |  from DB           |  genesis (if compatible)

The stored chain configuration will be updated if it is compatible (i.e. does not specify a fork block below the local head block). In case of a conflict, the error is a *params.ConfigCompatError and the new, unwritten config is returned.

The returned chain configuration is never nil.

func CommitGenesisBlockWithOverride

func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *types.Genesis, overrideShanghaiTime *big.Int, tmpDir string) (*chain.Config, *types.Block, error)

func DeveloperGenesisBlock

func DeveloperGenesisBlock(period uint64, faucet libcommon.Address) *types.Genesis

DeveloperGenesisBlock returns the 'geth --dev' genesis block.

func FinalizeBlockExecution

func FinalizeBlockExecution(
	engine consensus.Engine, stateReader state.StateReader,
	header *types.Header, txs types.Transactions, uncles []*types.Header,
	stateWriter state.WriterWithChangeSets, cc *chain.Config,
	ibs *state.IntraBlockState, receipts types.Receipts,
	withdrawals []*types.Withdrawal, headerReader consensus.ChainHeaderReader,
	isMining bool, excessDataGas *big.Int,
) (newBlock *types.Block, newTxs types.Transactions, newReceipt types.Receipts, err error)

func GenesisBlockByChainName

func GenesisBlockByChainName(chain string) *types.Genesis

func GenesisBlockForTesting

func GenesisBlockForTesting(db kv.RwDB, addr libcommon.Address, balance *big.Int, tmpDir string) *types.Block

GenesisBlockForTesting creates and writes a block in which addr has the given wei balance.

func GenesisToBlock

func GenesisToBlock(g *types.Genesis, tmpDir string) (*types.Block, *state.IntraBlockState, error)

ToBlock creates the genesis block and writes state of a genesis specification to the given database (or discards it if nil).

func GenesisWithAccounts

func GenesisWithAccounts(db kv.RwDB, accs []GenAccount, tmpDir string) *types.Block

func GetHashFn

func GetHashFn(ref *types.Header, getHeader func(hash libcommon.Hash, number uint64) *types.Header) func(n uint64) libcommon.Hash

GetHashFn returns a GetHashFunc which retrieves header hashes by number

func GnosisGenesisBlock

func GnosisGenesisBlock() *types.Genesis

func GoerliGenesisBlock

func GoerliGenesisBlock() *types.Genesis

GoerliGenesisBlock returns the Görli network genesis block.

func HermezDevnetGenesisBlock

func HermezDevnetGenesisBlock() *types.Genesis

func HermezMainnetGenesisBlock

func HermezMainnetGenesisBlock() *types.Genesis

func HermezTestnetGenesisBlock

func HermezTestnetGenesisBlock() *types.Genesis

func InitializeBlockExecution

func InitializeBlockExecution(engine consensus.Engine, chain consensus.ChainHeaderReader, header *types.Header, txs types.Transactions, uncles []*types.Header, cc *chain.Config, ibs *state.IntraBlockState, excessDataGas *big.Int) error

func IntrinsicGas

func IntrinsicGas(data []byte, accessList types2.AccessList, isContractCreation bool, isHomestead, isEIP2028, isEIP3860 bool) (uint64, error)

IntrinsicGas computes the 'intrinsic gas' for a message with the given data.

func MainnetGenesisBlock

func MainnetGenesisBlock() *types.Genesis

MainnetGenesisBlock returns the Ethereum main net genesis block.

func MakeEmptyHeader

func MakeEmptyHeader(parent *types.Header, chainConfig *chain.Config, timestamp uint64, targetGasLimit *uint64) *types.Header

func MumbaiGenesisBlock

func MumbaiGenesisBlock() *types.Genesis

func MustCommitGenesis

func MustCommitGenesis(g *types.Genesis, db kv.RwDB, tmpDir string) *types.Block

func NewEVMBlockContext

func NewEVMBlockContext(header *types.Header, blockHashFunc func(n uint64) libcommon.Hash, engine consensus.EngineReader, author *libcommon.Address, excessDataGas *big.Int) evmtypes.BlockContext

NewEVMBlockContext creates a new context for use in the EVM. excessDataGas must be set to the excessDataGas value from the *parent* block header, and can be nil if the parent block is not of EIP-4844 type. It is read only.

func NewEVMTxContext

func NewEVMTxContext(msg Message) evmtypes.TxContext

NewEVMTxContext creates a new transaction context for a single transaction.

func RinkebyGenesisBlock

func RinkebyGenesisBlock() *types.Genesis

RinkebyGenesisBlock returns the Rinkeby network genesis block.

func SepoliaGenesisBlock

func SepoliaGenesisBlock() *types.Genesis

SepoliaGenesisBlock returns the Sepolia network genesis block.

func SkipAnalysis

func SkipAnalysis(config *chain.Config, blockNumber uint64) bool

func SysCallContract

func SysCallContract(contract libcommon.Address, data []byte, chainConfig chain.Config, ibs *state.IntraBlockState, header *types.Header, engine consensus.EngineReader, constCall bool, excessDataGas *big.Int) (result []byte, err error)

func SysCreate

func SysCreate(contract libcommon.Address, data []byte, chainConfig chain.Config, ibs *state.IntraBlockState, header *types.Header, excessDataGas *big.Int) (result []byte, err error)

SysCreate is a special (system) contract creation methods for genesis constructors.

func Transfer

func Transfer(db evmtypes.IntraBlockState, sender, recipient libcommon.Address, amount *uint256.Int, bailout bool)

Transfer subtracts amount from sender and adds amount to recipient using the given Db

func WriteGenesisBlock

func WriteGenesisBlock(tx kv.RwTx, genesis *types.Genesis, overrideShanghaiTime *big.Int, tmpDir string) (*chain.Config, *types.Block, error)

func WriteGenesisState

func WriteGenesisState(g *types.Genesis, tx kv.RwTx, tmpDir string) (*types.Block, *state.IntraBlockState, error)

Types

type BlockBuilderParameters

type BlockBuilderParameters struct {
	ParentHash            libcommon.Hash
	Timestamp             uint64
	PrevRandao            libcommon.Hash
	SuggestedFeeRecipient libcommon.Address
	Withdrawals           []*types.Withdrawal
	PayloadId             uint64
}

Parameters for PoS block building See also https://github.com/ethereum/execution-apis/blob/main/src/engine/specification.md#payloadattributesv2

type BlockGen

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

BlockGen creates blocks for testing. See GenerateChain for a detailed explanation.

func (*BlockGen) AddFailedTx

func (b *BlockGen) AddFailedTx(tx types.Transaction)

func (*BlockGen) AddFailedTxWithChain

func (b *BlockGen) AddFailedTxWithChain(getHeader func(hash libcommon.Hash, number uint64) *types.Header, engine consensus.Engine, tx types.Transaction)

func (*BlockGen) AddTx

func (b *BlockGen) AddTx(tx types.Transaction)

AddTx adds a transaction to the generated block. If no coinbase has been set, the block's coinbase is set to the zero address.

AddTx panics if the transaction cannot be executed. In addition to the protocol-imposed limitations (gas limit, etc.), there are some further limitations on the content of transactions that can be added. Notably, contract code relying on the BLOCKHASH instruction will panic during execution.

func (*BlockGen) AddTxWithChain

func (b *BlockGen) AddTxWithChain(getHeader func(hash libcommon.Hash, number uint64) *types.Header, engine consensus.Engine, tx types.Transaction)

AddTxWithChain adds a transaction to the generated block. If no coinbase has been set, the block's coinbase is set to the zero address.

AddTxWithChain panics if the transaction cannot be executed. In addition to the protocol-imposed limitations (gas limit, etc.), there are some further limitations on the content of transactions that can be added. If contract code relies on the BLOCKHASH instruction, the block in chain will be returned.

func (*BlockGen) AddUncheckedReceipt

func (b *BlockGen) AddUncheckedReceipt(receipt *types.Receipt)

AddUncheckedReceipt forcefully adds a receipts to the block without a backing transaction.

AddUncheckedReceipt will cause consensus failures when used during real chain processing. This is best used in conjunction with raw block insertion.

func (*BlockGen) AddUncheckedTx

func (b *BlockGen) AddUncheckedTx(tx types.Transaction)

AddUncheckedTx forcefully adds a transaction to the block without any validation.

AddUncheckedTx will cause consensus failures when used during real chain processing. This is best used in conjunction with raw block insertion.

func (*BlockGen) AddUncle

func (b *BlockGen) AddUncle(h *types.Header)

AddUncle adds an uncle header to the generated block.

func (*BlockGen) GetHeader

func (b *BlockGen) GetHeader() *types.Header

func (*BlockGen) GetParent

func (b *BlockGen) GetParent() *types.Block

func (*BlockGen) GetReceipts

func (b *BlockGen) GetReceipts() []*types.Receipt

func (*BlockGen) Number

func (b *BlockGen) Number() *big.Int

Number returns the block number of the block being generated.

func (*BlockGen) OffsetTime

func (b *BlockGen) OffsetTime(seconds int64)

OffsetTime modifies the time instance of a block, implicitly changing its associated difficulty. It's useful to test scenarios where forking is not tied to chain length directly.

func (*BlockGen) PrevBlock

func (b *BlockGen) PrevBlock(index int) *types.Block

PrevBlock returns a previously generated block by number. It panics if num is greater or equal to the number of the block being generated. For index -1, PrevBlock returns the parent block given to GenerateChain.

func (*BlockGen) SetCoinbase

func (b *BlockGen) SetCoinbase(addr libcommon.Address)

SetCoinbase sets the coinbase of the generated block. It can be called at most once.

func (*BlockGen) SetDifficulty

func (b *BlockGen) SetDifficulty(diff *big.Int)

SetDifficulty sets the difficulty field of the generated block. This method is useful for Clique tests where the difficulty does not depend on time. For the ethash tests, please use OffsetTime, which implicitly recalculates the diff.

func (*BlockGen) SetExtra

func (b *BlockGen) SetExtra(data []byte)

SetExtra sets the extra data field of the generated block.

func (*BlockGen) SetNonce

func (b *BlockGen) SetNonce(nonce types.BlockNonce)

SetNonce sets the nonce field of the generated block.

func (*BlockGen) TxNonce

func (b *BlockGen) TxNonce(addr libcommon.Address) uint64

TxNonce returns the next valid transaction nonce for the account at addr. It panics if the account does not exist.

type ChainEvent

type ChainEvent struct {
	Block *types.Block
	Hash  libcommon.Hash
	Logs  []*types.Log
}

type ChainHeadEvent

type ChainHeadEvent struct{ Block *types.Block }

type ChainPack

type ChainPack struct {
	Headers  []*types.Header
	Blocks   []*types.Block
	Receipts []types.Receipts
	TopBlock *types.Block // Convenience field to access the last block
}

func GenerateChain

func GenerateChain(config *chain.Config, parent *types.Block, engine consensus.Engine, db kv.RwDB, n int, gen func(int, *BlockGen),
	intermediateHashes bool,
) (*ChainPack, error)

GenerateChain creates a chain of n blocks. The first block's parent will be the provided parent. db is used to store intermediate states and should contain the parent's state trie.

The generator function is called with a new block generator for every block. Any transactions and uncles added to the generator become part of the block. If gen is nil, the blocks will be empty and their coinbase will be the zero address.

Blocks created by GenerateChain do not contain valid proof of work values. Inserting them into BlockChain requires use of FakePow or a similar non-validating proof of work implementation.

func (*ChainPack) Copy

func (cp *ChainPack) Copy() *ChainPack

Copy creates a deep copy of the ChainPack.

func (*ChainPack) Length

func (cp *ChainPack) Length() int

func (*ChainPack) NumberOfPoWBlocks

func (cp *ChainPack) NumberOfPoWBlocks() int

func (*ChainPack) Slice

func (cp *ChainPack) Slice(i, j int) *ChainPack

OneBlock returns a ChainPack which contains just one block with given index

type ChainSideEvent

type ChainSideEvent struct {
	Block *types.Block
}

type EphemeralExecResult

type EphemeralExecResult struct {
	StateRoot        libcommon.Hash        `json:"stateRoot"`
	TxRoot           libcommon.Hash        `json:"txRoot"`
	ReceiptRoot      libcommon.Hash        `json:"receiptsRoot"`
	LogsHash         libcommon.Hash        `json:"logsHash"`
	Bloom            types.Bloom           `json:"logsBloom"        gencodec:"required"`
	Receipts         types.Receipts        `json:"receipts"`
	Rejected         RejectedTxs           `json:"rejected,omitempty"`
	Difficulty       *math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"`
	GasUsed          math.HexOrDecimal64   `json:"gasUsed"`
	StateSyncReceipt *types.Receipt        `json:"-"`
}

func ExecuteBlockEphemerally

func ExecuteBlockEphemerally(
	chainConfig *chain.Config, vmConfig *vm.Config,
	blockHashFunc func(n uint64) libcommon.Hash,
	engine consensus.Engine, block *types.Block,
	stateReader state.StateReader,
	stateWriter state.WriterWithChangeSets,
	chainReader consensus.ChainHeaderReader,
	getTracer func(txIndex int, txHash libcommon.Hash) (vm.EVMLogger, error),
	dbTx kv.RwTx,
	roHermezDb state.ReadOnlyHermezDb,
) (*EphemeralExecResult, error)

ExecuteBlockEphemerally runs a block from provided stateReader and writes the result to the provided stateWriter

func ExecuteBlockEphemerallyBor

func ExecuteBlockEphemerallyBor(
	chainConfig *chain.Config, vmConfig *vm.Config,
	blockHashFunc func(n uint64) libcommon.Hash,
	engine consensus.Engine, block *types.Block,
	stateReader state.StateReader, stateWriter state.WriterWithChangeSets,
	chainReader consensus.ChainHeaderReader, getTracer func(txIndex int, txHash libcommon.Hash) (vm.EVMLogger, error),
) (*EphemeralExecResult, error)

ExecuteBlockEphemerallyBor runs a block from provided stateReader and writes the result to the provided stateWriter

type ExecutionResult

type ExecutionResult struct {
	UsedGas    uint64 // Total used gas but include the refunded gas
	Err        error  // Any error encountered during the execution(listed in core/vm/errors.go)
	ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode)
}

ExecutionResult includes all output after executing given evm message no matter the execution itself is successful or not.

func ApplyMessage

func ApplyMessage(evm vm.VMInterface, msg Message, gp *GasPool, refunds bool, gasBailout bool) (*ExecutionResult, error)

ApplyMessage computes the new state by applying the given message against the old state within the environment.

ApplyMessage returns the bytes returned by any EVM execution (if it took place), the gas used (which includes gas refunds) and an error if it failed. An error always indicates a core error meaning that the message would always fail for that particular state and would never be accepted within a block. `refunds` is false when it is not required to apply gas refunds `gasBailout` is true when it is not required to fail transaction if the balance is not enough to pay gas. for trace_call to replicate OE/Pariry behaviour

func (*ExecutionResult) Failed

func (result *ExecutionResult) Failed() bool

Failed returns the indicator whether the execution is successful or not

func (*ExecutionResult) Return

func (result *ExecutionResult) Return() []byte

Return is a helper function to help caller distinguish between revert reason and function return. Return returns the data after execution if no error occurs.

func (*ExecutionResult) Revert

func (result *ExecutionResult) Revert() []byte

Revert returns the concrete revert reason if the execution is aborted by `REVERT` opcode. Note the reason can be nil if no data supplied with revert opcode.

func (*ExecutionResult) Unwrap

func (result *ExecutionResult) Unwrap() error

Unwrap returns the internal evm error which allows us for further analysis outside.

type FakeChainReader

type FakeChainReader struct {
	Cfg *chain.Config
	// contains filtered or unexported fields
}

func (*FakeChainReader) Config

func (cr *FakeChainReader) Config() *chain.Config

Config returns the chain configuration.

func (*FakeChainReader) CurrentHeader

func (cr *FakeChainReader) CurrentHeader() *types.Header

func (*FakeChainReader) GetBlock

func (cr *FakeChainReader) GetBlock(hash libcommon.Hash, number uint64) *types.Block

func (*FakeChainReader) GetHeader

func (cr *FakeChainReader) GetHeader(hash libcommon.Hash, number uint64) *types.Header

func (*FakeChainReader) GetHeaderByHash

func (cr *FakeChainReader) GetHeaderByHash(hash libcommon.Hash) *types.Header

func (*FakeChainReader) GetHeaderByNumber

func (cr *FakeChainReader) GetHeaderByNumber(number uint64) *types.Header

func (*FakeChainReader) GetTd

func (cr *FakeChainReader) GetTd(hash libcommon.Hash, number uint64) *big.Int

func (*FakeChainReader) HasBlock

func (cr *FakeChainReader) HasBlock(hash libcommon.Hash, number uint64) bool

type GasPool

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

GasPool tracks the amount of gas available during execution of the transactions in a block. The zero value is a pool with zero gas available.

func (*GasPool) AddDataGas

func (gp *GasPool) AddDataGas(amount uint64) *GasPool

AddDataGas makes data gas available for execution.

func (*GasPool) AddGas

func (gp *GasPool) AddGas(amount uint64) *GasPool

AddGas makes gas available for execution.

func (*GasPool) DataGas

func (gp *GasPool) DataGas() uint64

DataGas returns the amount of data gas remaining in the pool.

func (*GasPool) Gas

func (gp *GasPool) Gas() uint64

Gas returns the amount of gas remaining in the pool.

func (*GasPool) Reset

func (gp *GasPool) Reset(amount uint64)

func (*GasPool) String

func (gp *GasPool) String() string

func (*GasPool) SubDataGas

func (gp *GasPool) SubDataGas(amount uint64) error

SubDataGas deducts the given amount from the pool if enough data gas is available and returns an error otherwise.

func (*GasPool) SubGas

func (gp *GasPool) SubGas(amount uint64) error

SubGas deducts the given amount from the pool if enough gas is available and returns an error otherwise.

type GenAccount

type GenAccount struct {
	Addr    libcommon.Address
	Balance *big.Int
}

type Message

type Message interface {
	From() libcommon.Address
	To() *libcommon.Address

	GasPrice() *uint256.Int
	FeeCap() *uint256.Int
	Tip() *uint256.Int
	Gas() uint64
	Value() *uint256.Int

	Nonce() uint64
	CheckNonce() bool
	Data() []byte
	AccessList() types2.AccessList

	IsFree() bool
	EffectiveGasPricePercentage() uint8
}

Message represents a message sent to a contract.

type NewTxsEvent

type NewTxsEvent struct{ Txs []types.Transaction }

NewTxsEvent is posted when a batch of transactions enter the transaction pool.

type RejectedTx

type RejectedTx struct {
	Index int    `json:"index"    gencodec:"required"`
	Err   string `json:"error"    gencodec:"required"`
}

type RejectedTxs

type RejectedTxs []*RejectedTx

type RemovedLogsEvent

type RemovedLogsEvent struct{ Logs []*types.Log }

RemovedLogsEvent is posted when a reorg happens

type StateTransition

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

The State Transitioning Model

A state transition is a change made when a transaction is applied to the current world state The state transitioning model does all the necessary work to work out a valid new state root.

1) Nonce handling 2) Pre pay gas 3) Create a new state object if the recipient is \0*32 4) Value transfer == If contract creation ==

4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object

== end == 5) Run Script section 6) Derive new state root

func NewStateTransition

func NewStateTransition(evm vm.VMInterface, msg Message, gp *GasPool) *StateTransition

NewStateTransition initialises and returns a new state transition object.

func (*StateTransition) TransitionDb

func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (*ExecutionResult, error)

TransitionDb will transition the state by applying the current message and returning the evm execution result with following fields.

  • used gas: total gas used (including gas being refunded)
  • returndata: the returned data from evm
  • concrete execution error: various **EVM** error which aborts the execution, e.g. ErrOutOfGas, ErrExecutionReverted

However if any consensus issue encountered, return the error directly with nil evm execution result.

type SyncMode

type SyncMode string

type TxSenderCacher

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

TxSenderCacher is a helper structure to concurrently ecrecover transaction senders from digital signatures on background threads.

func NewTxSenderCacher

func NewTxSenderCacher(threads int) *TxSenderCacher

newTxSenderCacher creates a new transaction sender background cacher and starts as many processing goroutines as allowed by the GOMAXPROCS on construction.

func (*TxSenderCacher) Close

func (cacher *TxSenderCacher) Close()

Directories

Path Synopsis
Package asm provides support for dealing with EVM assembly instructions (e.g., disassembling them).
Package asm provides support for dealing with EVM assembly instructions (e.g., disassembling them).
Package forkid implements EIP-2124 (https://eips.ethereum.org/EIPS/eip-2124).
Package forkid implements EIP-2124 (https://eips.ethereum.org/EIPS/eip-2124).
Package state provides a caching layer atop the Ethereum state trie.
Package state provides a caching layer atop the Ethereum state trie.
Package types contains data types related to Ethereum consensus.
Package types contains data types related to Ethereum consensus.
vm
Package vm implements the Ethereum Virtual Machine.
Package vm implements the Ethereum Virtual Machine.
runtime
Package runtime provides a basic execution model for executing EVM code.
Package runtime provides a basic execution model for executing EVM code.

Jump to

Keyboard shortcuts

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