Skip to content

Commit 41221da

Browse files
committed
core/txpool: use bitmaps instead of maps for tx type filtering
1 parent e01fddc commit 41221da

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

core/txpool/txpool.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,10 @@ func (pool *TxPool) local() map[common.Address]types.Transactions {
581581
func (pool *TxPool) validateTxBasics(tx *types.Transaction, local bool) error {
582582
opts := &ValidationOptions{
583583
Config: pool.chainconfig,
584-
Accept: map[uint8]struct{}{
585-
types.LegacyTxType: {},
586-
types.AccessListTxType: {},
587-
types.DynamicFeeTxType: {},
588-
},
584+
Accept: 0 |
585+
1<<types.LegacyTxType |
586+
1<<types.AccessListTxType |
587+
1<<types.DynamicFeeTxType,
589588
MaxSize: txMaxSize,
590589
MinTip: pool.gasTip.Load(),
591590
}

core/txpool/validation.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import (
3535
type ValidationOptions struct {
3636
Config *params.ChainConfig // Chain configuration to selectively validate based on current fork rules
3737

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

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

0 commit comments

Comments
 (0)