mempool

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrFeeTooLow = iota
	ErrMinStake
	ErrDuplicateCoinbase
	ErrTreasuryWhitelist
)

Variables

View Source
var (
	ErrDuplicateTx = errors.New("tx already in mempool")
	ErrNotFound    = errors.New("tx not found in pool")
)

Functions

func CalcFeePerKilobyte

func CalcFeePerKilobyte(tx *transactions.Transaction) (types.Amount, bool, error)

func UpdateLogger

func UpdateLogger()

Types

type AssertError

type AssertError string

AssertError identifies an error that indicates an internal code consistency issue and should be treated as a critical and unrecoverable error.

func (AssertError) Error

func (e AssertError) Error() string

Error returns the assertion error as a human-readable string and satisfies the error interface.

type ChainView

type ChainView interface {
	// TreasuryBalance returns current balance of the treasury.
	TreasuryBalance() (types.Amount, error)

	//TxoRootExists returns whether the given txo root exists
	// in the txo root set.
	TxoRootExists(txoRoot types.ID) (bool, error)

	// NullifierExists returns whether the given nullifier exists
	// in the nullifier set.
	NullifierExists(n types.Nullifier) (bool, error)

	// GetValidator returns the validator for the given ID
	GetValidator(validatorID peer.ID) (*blockchain.Validator, error)
}

ChainView is an interface of methods that provide the blockchain context that the mempool needs to validate transactions.

type ErrorCode

type ErrorCode int

func (ErrorCode) String

func (e ErrorCode) String() string

String returns the ErrorCode as a human-readable name.

type Mempool

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

Mempool holds valid transactions that have been relayed around the network but have not yet made it into a block. The pool will validate transactions before admitting them. The block generation package uses the mempool transactions to generate blocks.

func NewMempool

func NewMempool(opts ...Option) (*Mempool, error)

NewMempool returns a new mempool with the configuration options.

The options include local node policy for determining which (valid) transactions to admit into the mempool.

func (*Mempool) Close

func (m *Mempool) Close()

Close shuts down the validationHandlder and stops the mempool.

func (*Mempool) DecodeXthinner

func (m *Mempool) DecodeXthinner(blk *blocks.XThinnerBlock) (*blocks.Block, []uint32)

DecodeXthinner decodes an XThinnerBlock using the transactions in the mempool. There are two possible decode failures:

  1. There are no transactions in the mempool with the given prefix (missing tx).
  2. There are one or more transactions in the mempool with the same prefix (collision).

In both scenarios nil is returned for that transaction and the missing index is appended to the returned []uint32

The caller should request the missing transaction(s) from the remote peer before proceeding to block validation.

The final failure case is the block's tx merkle root may fail to validate. This could mean one of two things:

  1. We had a transaction in the mempool that collided with a transaction in the block, but the block's transaction was not in the mempool. This is very unlikely but possible.
  2. The peer maliciously sent us an invalid block.

In both cases the solution is to download the full list of txids from the remote peer.

func (*Mempool) EncodeXthinner

func (m *Mempool) EncodeXthinner(blkIds []types.ID) (*blocks.XThinnerBlock, error)

EncodeXthinner replaces the full transactions from a block.Block with short transaction prefixes and returns an XThinnerBlock. The idea being that the receiving node can use the prefixes and their own mempool to reconstruct the full block. Because block transactions are sorted by txid by consensus rule, we can send just the minimum number of bytes needed to disambiguate between transactions in our mempool.

The Xthinner spec calls for the XthinnerBlock to have a checksum attached that can be used to detect collisions. However, in illium blocks come quickly and typically have few transactions. With such a small number of transactions collisions are less likely. In the event a collision happens the validation of the txRoot will fail and we will just request the full list of block txids from the relaying peer.

If checksums were included we could use them to narrow down the range in block where the collision occurred and just request a smaller range of txids from our peer instead of the full list. This would save bandwidth. However, for it to be worth it the bandwidth savings needs to exceed the extra bandwidth cost of the checksums. At small block sizes this isn't worth it. So we omit the checksums.

func (*Mempool) GetTransaction

func (m *Mempool) GetTransaction(txid types.ID) (*transactions.Transaction, error)

GetTransaction returns a transaction given the ID if it exists in the pool.

func (*Mempool) GetTransactions

func (m *Mempool) GetTransactions() map[types.ID]*transactions.Transaction

GetTransactions returns the full list of transactions from the pool.

func (*Mempool) ProcessTransaction

func (m *Mempool) ProcessTransaction(tx *transactions.Transaction) error

ProcessTransaction evaluates a transaction and accepts it into the mempool if it passes all validation checks.

This method is safe for concurrent access. It will attempt to do all the static validation, such as the expensive signature and proof checks, without locking. The rest of validation, such as nullifier checks, duplicate mempool checks, etc. are done in a single threaded channel.

func (*Mempool) RemoveBlockTransactions

func (m *Mempool) RemoveBlockTransactions(txs []*transactions.Transaction)

RemoveBlockTransactions should be called when a block is connected. It will remove the block's transactions from the mempool and update the rest of the mempool state.

This method is safe for concurrent access.

type Option

type Option func(cfg *config) error

Option is configuration option function for the mempool

func BlockchainView

func BlockchainView(cv ChainView) Option

BlockchainView is an interface that is used to access data from the blockchain needed for mempool validation.

This option is required.

func DefaultOptions

func DefaultOptions() Option

DefaultOptions returns a blockchain configure option that fills in the default settings. You will almost certainly want to override some of the defaults, such as parameters and datastore, etc.

func FeePerKilobyte

func FeePerKilobyte(fpkb types.Amount) Option

FeePerKilobyte is the minimum fee per byte to use when admitting transactions into the mempool. By extension the node will only relay transactions with a fee above this level as well.

func MinStake

func MinStake(minStake types.Amount) Option

MinStake is the minimum amount of stake that a stake transaction must post to be admitted into the mempool. By extension the node will only relay transactions with a stake above this level as well.

func Params

func Params(params *params.NetworkParams) Option

Params identifies which chain parameters the mempool is associated with.

This option is required.

func ProofCache

func ProofCache(proofCache *blockchain.ProofCache) Option

ProofCache caches proof validation so we don't need to expend extra CPU to validate zero knowledge proofs more than once.

If this is not provided a new instance will be used.

func SignatureCache

func SignatureCache(sigCache *blockchain.SigCache) Option

SignatureCache caches signature validation so we don't need to expend extra CPU to validate signatures more than once.

If this is not provided a new instance will be used.

func TransactionTTL

func TransactionTTL(ttl time.Duration) Option

TransactionTTL represents the amount of time a transaction remains in the mempool without being included in a block before we discard it.

func TreasuryWhitelist

func TreasuryWhitelist(whitelist []types.ID) Option

TreasuryWhitelist is a map of transactions ID that this node approves of for treasury withdrawls. Only this IDs will be accepted into the mempool.

type PolicyError

type PolicyError struct {
	ErrorCode   ErrorCode // Describes the kind of error
	Description string    // Human-readable description of the issue
}

PolicyError identifies a mempool policy violation. It is used to indicate that the transaction met the consensus validity rules but the node chose not to accept it because it violated its own policy rule

func (PolicyError) Error

func (e PolicyError) Error() string

Error satisfies the error interface and prints human-readable errors.

type TxSorter

type TxSorter []*transactions.Transaction

TxSorter implements sort.Interface to allow a slice of transactions to be sorted lexicographically.

func (TxSorter) Len

func (s TxSorter) Len() int

Len returns the number of txs in the slice. It is part of the sort.Interface implementation.

func (TxSorter) Less

func (s TxSorter) Less(i, j int) bool

Less returns whether the txs with index i should sort before the tx with index j. It is part of the sort.Interface implementation.

func (TxSorter) Swap

func (s TxSorter) Swap(i, j int)

Swap swaps the txs at the passed indices. It is part of the sort.Interface implementation.

type TxidSorter

type TxidSorter []types.ID

TxidSorter implements sort.Interface to allow a slice of transaction ids to be sorted lexicographically.

func (TxidSorter) Len

func (s TxidSorter) Len() int

Len returns the number of txs in the slice. It is part of the sort.Interface implementation.

func (TxidSorter) Less

func (s TxidSorter) Less(i, j int) bool

Less returns whether the txs with index i should sort before the tx with index j. It is part of the sort.Interface implementation.

func (TxidSorter) Swap

func (s TxidSorter) Swap(i, j int)

Swap swaps the txs at the passed indices. It is part of the sort.Interface implementation.

Jump to

Keyboard shortcuts

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