Documentation
¶
Index ¶
- Variables
- func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) ([]byte, uint64, *big.Int, bool, error)
- func ApplyTransaction(config *params.ChainConfig, bc DummyChain, author *common.Address, gp *GasPool, ...) (*types.Receipt, uint64, *big.Int, bool, error)
- func CanTransfer(db vm.StateDB, addr common.Address, amount *big.Int) bool
- func GenerateChain(config *params.ChainConfig, parent *EvmBlock, db ethdb.Database, n int, ...) ([]*EvmBlock, []types.Receipts, DummyChain)
- func GetHashFn(ref *EvmHeader, chain DummyChain) func(n uint64) common.Hash
- func IntrinsicGas(data []byte, contractCreation, homestead bool) (uint64, error)
- func NewEVMContext(msg Message, header *EvmHeader, chain DummyChain, author *common.Address) vm.Context
- func TransactionPreCheck(statedb *state.StateDB, msg types.Message, tx *types.Transaction) error
- func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int)
- type BlockGen
- func (b *BlockGen) AddTx(tx *types.Transaction)
- func (b *BlockGen) AddTxWithChain(bc DummyChain, tx *types.Transaction)
- func (b *BlockGen) AddUncheckedReceipt(receipt *types.Receipt)
- func (b *BlockGen) AddUncheckedTx(tx *types.Transaction)
- func (b *BlockGen) Number() *big.Int
- func (b *BlockGen) OffsetTime(seconds int64)
- func (b *BlockGen) PrevBlock(index int) *EvmBlock
- func (b *BlockGen) SetCoinbase(addr common.Address)
- func (b *BlockGen) TxNonce(addr common.Address) uint64
- type ChainHeadNotify
- type ChainNotify
- type ChainSideNotify
- type DummyChain
- type EvmBlock
- type EvmHeader
- type GasPool
- type Message
- type NewMinedBlockNotify
- type NewTxsNotify
- type PendingLogsNotify
- type Prefetcher
- type Processor
- type RemovedLogsNotify
- type StateProcessor
- type StateTransition
- type TestChain
- type TxPool
- func (pool *TxPool) AddLocal(tx *types.Transaction) error
- func (pool *TxPool) AddLocals(txs []*types.Transaction) []error
- func (pool *TxPool) AddRemote(tx *types.Transaction) errordeprecated
- func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error
- func (pool *TxPool) AddRemotesSync(txs []*types.Transaction) []error
- func (pool *TxPool) Content() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
- func (pool *TxPool) GasPrice() *big.Int
- func (pool *TxPool) Get(hash common.Hash) *types.Transaction
- func (pool *TxPool) Locals() []common.Address
- func (pool *TxPool) Nonce(addr common.Address) uint64
- func (pool *TxPool) Pending() (map[common.Address]types.Transactions, error)
- func (pool *TxPool) SetGasPrice(price *big.Int)
- func (pool *TxPool) Stats() (int, int)
- func (pool *TxPool) Status(hashes []common.Hash) []TxStatus
- func (pool *TxPool) Stop()
- func (pool *TxPool) SubscribeNewTxsNotify(ch chan<- NewTxsNotify) notify.Subscription
- type TxPoolConfig
- type TxStatus
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKnownBlock is returned when a block to import is already known locally. ErrKnownBlock = errors.New("block already known") // 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") // ErrBlacklistedHash is returned if a block to import is on the blacklist. ErrBlacklistedHash = errors.New("blacklisted hash") // 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") // ErrNoGenesis is returned when there is no Genesis Block. ErrNoGenesis = errors.New("genesis not found in chain") )
var ( // ErrInvalidSender is returned if the transaction contains an invalid signature. ErrInvalidSender = errors.New("invalid sender") // 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") // ErrUnderpriced is returned if a transaction's gas price is below the minimum // configured for the transaction pool. ErrUnderpriced = errors.New("transaction underpriced") // ErrReplaceUnderpriced is returned if a transaction is attempted to be replaced // with a different one without the required price bump. ErrReplaceUnderpriced = errors.New("replacement transaction underpriced") // 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") // 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") // ErrGasLimit is returned if a transaction's requested gas limit exceeds the // maximum allowance of the current block. ErrGasLimit = errors.New("exceeds block gas limit") // ErrNegativeValue is a sanity error to ensure noone is able to specify a // transaction with a negative value. ErrNegativeValue = errors.New("negative value") // ErrOversizedData is returned if the input data of a transaction is greater // than some meaningful limit a user might use. This is not a consensus error // making the transaction invalid, rather a DOS protection. ErrOversizedData = errors.New("oversized data") )
var BadHashes = map[common.Hash]bool{}
BadHashes represent a set of manually tracked bad hashes (usually hard forks)
Functions ¶
func ApplyMessage ¶
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.
func ApplyTransaction ¶
func ApplyTransaction( config *params.ChainConfig, bc DummyChain, author *common.Address, gp *GasPool, statedb *state.StateDB, header *EvmHeader, tx *types.Transaction, usedGas *uint64, cfg vm.Config, strict bool, ) ( *types.Receipt, uint64, *big.Int, bool, 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 CanTransfer ¶
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 GenerateChain ¶
func GenerateChain(config *params.ChainConfig, parent *EvmBlock, db ethdb.Database, n int, gen func(int, *BlockGen)) ([]*EvmBlock, []types.Receipts, DummyChain)
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 GetHashFn ¶
func GetHashFn(ref *EvmHeader, chain DummyChain) func(n uint64) common.Hash
GetHashFn returns a GetHashFunc which retrieves header hashes by number
func IntrinsicGas ¶
IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
func NewEVMContext ¶
func NewEVMContext(msg Message, header *EvmHeader, chain DummyChain, author *common.Address) vm.Context
NewEVMContext creates a new context for use in the EVM.
func TransactionPreCheck ¶
Types ¶
type BlockGen ¶
type BlockGen struct {
// contains filtered or unexported fields
}
BlockGen creates blocks for testing. See GenerateChain for a detailed explanation.
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(bc DummyChain, 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 ¶
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) OffsetTime ¶
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 ¶
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 ¶
SetCoinbase sets the coinbase of the generated block. It can be called at most once.
type ChainHeadNotify ¶
type ChainHeadNotify struct{ Block *EvmBlock }
type ChainSideNotify ¶
type ChainSideNotify struct {
Block *EvmBlock
}
type DummyChain ¶
type DummyChain interface { // GetHeader returns the hash corresponding to their hash. GetHeader(common.Hash, uint64) *EvmHeader }
DummyChain supports retrieving headers and consensus parameters from the current blockchain to be used during transaction processing.
type EvmBlock ¶
type EvmBlock struct { EvmHeader Transactions types.Transactions }
func ApplyGenesis ¶
ApplyGenesis writes or updates the genesis block in db.
func MustApplyGenesis ¶
MustApplyGenesis writes the genesis block and state to db, panicking on error.
type EvmHeader ¶
type EvmHeader struct { Number *big.Int Hash common.Hash ParentHash common.Hash Root common.Hash TxHash common.Hash Time inter.Timestamp Coinbase common.Address GasLimit uint64 GasUsed uint64 }
func ConvertFromEthHeader ¶
ConvertFromEthHeader converts ETH-formatted header to Lachesis EVM header
func ToEvmHeader ¶
ToEvmHeader converts inter.Block to EvmHeader.
type GasPool ¶
type GasPool uint64
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.
type Message ¶
type Message interface { From() common.Address //FromFrontier() (common.Address, error) To() *common.Address GasPrice() *big.Int Gas() uint64 Value() *big.Int Nonce() uint64 CheckNonce() bool Data() []byte }
Message represents a message sent to a contract.
type NewMinedBlockNotify ¶
type NewMinedBlockNotify struct{ Block *EvmBlock }
NewMinedBlockNotify is posted when a block has been imported.
type NewTxsNotify ¶
type NewTxsNotify struct{ Txs []*types.Transaction }
NewTxsNotify is posted when a batch of transactions enter the transaction pool.
type PendingLogsNotify ¶
PendingLogsNotify is posted pre mining and notifies of pending logs.
type Prefetcher ¶
type Prefetcher interface { // Prefetch processes the state changes according to the Ethereum rules by running // the transaction messages using the statedb, but any changes are discarded. The // only goal is to pre-cache transaction signatures and state trie nodes. Prefetch(block *EvmBlock, statedb *state.StateDB, cfg vm.Config, interrupt *uint32) }
Prefetcher is an interface for pre-caching transaction signatures and state.
type Processor ¶
type Processor interface { // Process processes the state changes according to the Ethereum rules by running // the transaction messages using the statedb and applying any rewards to both // the processor (coinbase) and any included uncles. Process(block *EvmBlock, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) }
Processor is an interface for processing blocks using a given initial state.
type RemovedLogsNotify ¶
RemovedLogsNotify is posted when a reorg happens
type StateProcessor ¶
type StateProcessor struct {
// contains filtered or unexported fields
}
StateProcessor is a basic Processor, which takes care of transitioning state from one point to another.
StateProcessor implements Processor.
func NewStateProcessor ¶
func NewStateProcessor(config *params.ChainConfig, bc DummyChain) *StateProcessor
NewStateProcessor initialises a new StateProcessor.
func (*StateProcessor) Process ¶
func (p *StateProcessor) Process(block *EvmBlock, statedb *state.StateDB, cfg vm.Config, strict bool) (types.Receipts, []*types.Log, uint64, *big.Int, []uint, error)
Process processes the state changes according to the Ethereum rules by running the transaction messages using the statedb and applying any rewards to both the processor (coinbase) and any included uncles.
Process returns the receipts and logs accumulated during the process and returns the amount of gas that was used in the process. If any of the transactions failed to execute due to insufficient gas it will return an error.
type StateTransition ¶
type StateTransition struct {
// contains filtered or unexported fields
}
func NewStateTransition ¶
func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
NewStateTransition initialises and returns a new state transition object.
func (*StateTransition) TransitionDb ¶
func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, fee *big.Int, failed bool, err error)
TransitionDb will transition the state by applying the current message and returning the result including the used gas. It returns an error if failed. An error indicates a consensus issue.
type TxPool ¶
type TxPool struct {
// contains filtered or unexported fields
}
TxPool contains all currently known transactions. Transactions enter the pool when they are received from the network or submitted locally. They exit the pool when they are included in the blockchain.
The pool separates processable transactions (which can be applied to the current state) and future transactions. Transactions move between those two states over time as they are received and processed.
func NewTxPool ¶
func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, chain stateReader) *TxPool
NewTxPool creates a new transaction pool to gather, sort and filter inbound transactions from the network.
func (*TxPool) AddLocal ¶
func (pool *TxPool) AddLocal(tx *types.Transaction) error
AddLocal enqueues a single local transaction into the pool if it is valid. This is a convenience wrapper aroundd AddLocals.
func (*TxPool) AddLocals ¶
func (pool *TxPool) AddLocals(txs []*types.Transaction) []error
AddLocals enqueues a batch of transactions into the pool if they are valid, marking the senders as a local ones, ensuring they go around the local pricing constraints.
This method is used to add transactions from the RPC API and performs synchronous pool reorganization and event propagation.
func (*TxPool) AddRemote
deprecated
func (pool *TxPool) AddRemote(tx *types.Transaction) error
AddRemote enqueues a single transaction into the pool if it is valid. This is a convenience wrapper around AddRemotes.
Deprecated: use AddRemotes
func (*TxPool) AddRemotes ¶
func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error
AddRemotes enqueues a batch of transactions into the pool if they are valid. If the senders are not among the locally tracked ones, full pricing constraints will apply.
This method is used to add transactions from the p2p network and does not wait for pool reorganization and internal event propagation.
func (*TxPool) AddRemotesSync ¶
func (pool *TxPool) AddRemotesSync(txs []*types.Transaction) []error
This is like AddRemotes, but waits for pool reorganization. Tests use this method.
func (*TxPool) Content ¶
func (pool *TxPool) Content() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
Content retrieves the data content of the transaction pool, returning all the pending as well as queued transactions, grouped by account and sorted by nonce.
func (*TxPool) Get ¶
func (pool *TxPool) Get(hash common.Hash) *types.Transaction
Get returns a transaction if it is contained in the pool and nil otherwise.
func (*TxPool) Nonce ¶
Nonce returns the next nonce of an account, with all transactions executable by the pool already applied on top.
func (*TxPool) Pending ¶
Pending retrieves all currently processable transactions, grouped by origin account and sorted by nonce. The returned transaction set is a copy and can be freely modified by calling code.
func (*TxPool) SetGasPrice ¶
SetGasPrice updates the minimum price required by the transaction pool for a new transaction, and drops all transactions below this threshold.
func (*TxPool) Stats ¶
Stats retrieves the current pool stats, namely the number of pending and the number of queued (non-executable) transactions.
func (*TxPool) Status ¶
Status returns the status (unknown/pending/queued) of a batch of transactions identified by their hashes.
func (*TxPool) SubscribeNewTxsNotify ¶
func (pool *TxPool) SubscribeNewTxsNotify(ch chan<- NewTxsNotify) notify.Subscription
SubscribeNewTxsNotify registers a subscription of NewTxsNotify and starts sending event to the given channel.
type TxPoolConfig ¶
type TxPoolConfig struct { Locals []common.Address // Addresses that should be treated by default as local NoLocals bool // Whether local transaction handling should be disabled Journal string // Journal of local transactions to survive node restarts Rejournal time.Duration // Time interval to regenerate the local transaction journal PriceLimit uint64 // Minimum gas price to enforce for acceptance into the pool PriceBump uint64 // Minimum price bump percentage to replace an already existing transaction (nonce) AccountSlots uint64 // Number of executable transaction slots guaranteed per account GlobalSlots uint64 // Maximum number of executable transaction slots for all accounts AccountQueue uint64 // Maximum number of non-executable transaction slots permitted per account GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts Lifetime time.Duration // Maximum amount of time non-executable transaction are queued }
TxPoolConfig are the configuration parameters of the transaction pool.
func DefaultTxPoolConfig ¶
func DefaultTxPoolConfig() TxPoolConfig
DefaultTxPoolConfig returns the default configurations for the transaction pool.
func FakeTxPoolConfig ¶
func FakeTxPoolConfig() TxPoolConfig
FakeTxPoolConfig returns the fake configurations for the transaction pool.
type TxStatus ¶
type TxStatus uint
TxStatus is the current status of a transaction as seen by the pool.
type Validator ¶
type Validator interface { // ValidateBody validates the given block's content. ValidateBody(block *EvmBlock) error // ValidateState validates the given statedb and optionally the receipts and // gas used. ValidateState(block *EvmBlock, state *state.StateDB, receipts types.Receipts, usedGas uint64) error }
Validator is an interface which defines the standard for block validation. It is only responsible for validating block contents, as the header validation is done by the specific consensus engines.