Skip to content

Commit

Permalink
core/txpool: use bitmaps instead of maps for tx type filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Jun 6, 2023
1 parent e01fddc commit d779bac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions core/txpool/txpool.go
Expand Up @@ -581,11 +581,10 @@ func (pool *TxPool) local() map[common.Address]types.Transactions {
func (pool *TxPool) validateTxBasics(tx *types.Transaction, local bool) error {
opts := &ValidationOptions{
Config: pool.chainconfig,
Accept: map[uint8]struct{}{
types.LegacyTxType: {},
types.AccessListTxType: {},
types.DynamicFeeTxType: {},
},
Accept: 0 |
1<<types.LegacyTxType |
1<<types.AccessListTxType |
1<<types.DynamicFeeTxType,
MaxSize: txMaxSize,
MinTip: pool.gasTip.Load(),
}
Expand Down
10 changes: 5 additions & 5 deletions core/txpool/validation.go
Expand Up @@ -35,9 +35,9 @@ import (
type ValidationOptions struct {
Config *params.ChainConfig // Chain configuration to selectively validate based on current fork rules

Accept map[uint8]struct{} // Transaction types that should be accepted for the calling pool
MaxSize uint64 // Maximum size of a transaction that the caller can meaningfully handle
MinTip *big.Int // Minimum gas tip needed to allow a transaction into the caller pool
Accept uint8 // Bitmap of transaction types that should be accepted for the calling pool
MaxSize uint64 // Maximum size of a transaction that the caller can meaningfully handle
MinTip *big.Int // Minimum gas tip needed to allow a transaction into the caller pool
}

// ValidateTransaction is a helper method to check whether a transaction is valid
Expand All @@ -48,7 +48,7 @@ type ValidationOptions struct {
// rules without duplicating code and running the risk of missed updates.
func ValidateTransaction(tx *types.Transaction, blobs []kzg4844.Blob, commits []kzg4844.Commitment, proofs []kzg4844.Proof, head *types.Header, signer types.Signer, opts *ValidationOptions) error {
// Ensure transactions not implemented by the calling pool are rejected
if _, ok := opts.Accept[tx.Type()]; !ok {
if opts.Accept&(1<<tx.Type()) != 0 {
return fmt.Errorf("%w: tx type %v not supported by this pool", core.ErrTxTypeNotSupported, tx.Type())
}
// Before performing any expensive validations, sanity check that the tx is
Expand Down Expand Up @@ -129,7 +129,7 @@ func ValidateTransaction(tx *types.Transaction, blobs []kzg4844.Blob, commits []
return fmt.Errorf("invalid number of %d blob proofs compared to %d blob hashes", len(proofs), len(hashes))
}
// Blob quantities match up, validate that the provers match with the
// transaction hash before getting to the creyptography
// transaction hash before getting to the cryptography
hasher := sha256.New()
for i, want := range hashes {
hasher.Write(commits[i][:])
Expand Down

0 comments on commit d779bac

Please sign in to comment.