light

package
v0.0.0-...-21186a8 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TxPool

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

TxPool implements the transaction pool for light clients, which keeps track of the status of locally created transactions, detecting if they are included in a block (mined) or rolled back. There are no queued transactions since we always receive all locally signed transactions in the same order as they are created.

func NewTxPool

func NewTxPool(config *params.ChainConfig, chain *LightChain, relay TxRelayBackend) *TxPool

NewTxPool creates a new light transaction pool

func (*TxPool) Add

func (pool *TxPool) Add(ctx context.Context, tx *types.Transaction) error

Add adds a transaction to the pool if valid and passes it to the tx relay backend

func (*TxPool) AddBatch

func (pool *TxPool) AddBatch(ctx context.Context, txs []*types.Transaction)

AddBatch adds all valid transactions to the pool and passes them to the tx relay backend

func (*TxPool) Content

func (pool *TxPool) Content() (map[common.Address][]*types.Transaction, map[common.Address][]*types.Transaction)

Content retrieves the data content of the transaction pool, returning all the pending as well as queued transactions, grouped by account and nonce.

func (*TxPool) ContentFrom

func (pool *TxPool) ContentFrom(addr common.Address) ([]*types.Transaction, []*types.Transaction)

ContentFrom retrieves the data content of the transaction pool, returning the pending as well as queued transactions of this address, grouped by nonce.

func (*TxPool) ContentMatches

func (pool *TxPool) ContentMatches(src string) (map[common.Address]types.Transactions, map[common.Address]types.Transactions)

EP-1 START ***

func (*TxPool) GetNonce

func (pool *TxPool) GetNonce(ctx context.Context, addr common.Address) (uint64, error)

GetNonce returns the "pending" nonce of a given address. It always queries the nonce belonging to the latest header too in order to detect if another client using the same key sent a transaction.

func (*TxPool) GetTransaction

func (pool *TxPool) GetTransaction(hash common.Hash) *types.Transaction

GetTransaction returns a transaction if it is contained in the pool and nil otherwise.

func (*TxPool) GetTransactions

func (pool *TxPool) GetTransactions() (txs types.Transactions, err error)

GetTransactions returns all currently processable transactions. The returned slice may be modified by the caller.

func (*TxPool) RemoveTransactions

func (pool *TxPool) RemoveTransactions(txs types.Transactions)

RemoveTransactions removes all given transactions from the pool.

func (*TxPool) RemoveTx

func (pool *TxPool) RemoveTx(hash common.Hash)

RemoveTx removes the transaction with the given hash from the pool.

func (*TxPool) Stats

func (pool *TxPool) Stats() (pending int)

Stats returns the number of currently pending (locally created) transactions

func (*TxPool) Stop

func (pool *TxPool) Stop()

Stop stops the light transaction pool

func (*TxPool) SubscribeNewTxsEvent

func (pool *TxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription

SubscribeNewTxsEvent registers a subscription of core.NewTxsEvent and starts sending event to the given channel.

type TxRelayBackend

type TxRelayBackend interface {
	Send(txs types.Transactions)
	NewHead(head common.Hash, mined []common.Hash, rollback []common.Hash)
	Discard(hashes []common.Hash)
}

TxRelayBackend provides an interface to the mechanism that forwards transactions to the ETH network. The implementations of the functions should be non-blocking.

Send instructs backend to forward new transactions NewHead notifies backend about a new head after processed by the tx pool, including mined and rolled back transactions since the last event.

Discard notifies backend about transactions that should be discarded either because they have been replaced by a re-send or because they have been mined long ago and no rollback is expected.

Jump to

Keyboard shortcuts

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