make blobpool reject blob transactions with fee below the minimum

This commit is contained in:
Roberto Bayardo 2024-02-25 17:09:24 -08:00
parent 93c541ad56
commit 398d860a8a
No known key found for this signature in database
GPG key ID: BAD75F1206851CC1
2 changed files with 24 additions and 1 deletions

View file

@ -1228,6 +1228,24 @@ func TestAdd(t *testing.T) {
}, },
}, },
}, },
// Blob transactions that don't meet the min blob gas price should be rejected
{
seeds: map[string]seed{
"alice": {balance: 10000000},
},
adds: []addtx{
{ // New account, no previous txs, nonce 0, but blob fee cap too low
from: "alice",
tx: makeUnsignedTx(0, 1, 1, 0),
err: txpool.ErrUnderpriced,
},
{ // Same as above but blob fee cap equals minimum, should be accepted
from: "alice",
tx: makeUnsignedTx(0, 1, 1, params.BlobTxMinBlobGasprice),
err: nil,
},
},
},
} }
for i, tt := range tests { for i, tt := range tests {
// Create a temporary folder for the persistent backend // Create a temporary folder for the persistent backend

View file

@ -108,8 +108,12 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
if tx.GasTipCapIntCmp(opts.MinTip) < 0 { if tx.GasTipCapIntCmp(opts.MinTip) < 0 {
return fmt.Errorf("%w: tip needed %v, tip permitted %v", ErrUnderpriced, opts.MinTip, tx.GasTipCap()) return fmt.Errorf("%w: tip needed %v, tip permitted %v", ErrUnderpriced, opts.MinTip, tx.GasTipCap())
} }
// Ensure blob transactions have valid commitments
if tx.Type() == types.BlobTxType { if tx.Type() == types.BlobTxType {
// Ensure the blob fee cap cap satisfies the minimum blob gas price
minBlobGasPrice := big.NewInt(params.BlobTxMinBlobGasprice)
if tx.BlobGasFeeCapIntCmp(minBlobGasPrice) < 0 {
return fmt.Errorf("%w: blob transaction has too low BlobFeeCap: %v, need: %v", ErrUnderpriced, tx.BlobGasFeeCap(), minBlobGasPrice)
}
sidecar := tx.BlobTxSidecar() sidecar := tx.BlobTxSidecar()
if sidecar == nil { if sidecar == nil {
return fmt.Errorf("missing sidecar in blob transaction") return fmt.Errorf("missing sidecar in blob transaction")
@ -123,6 +127,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
if len(hashes) > params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob { if len(hashes) > params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob {
return fmt.Errorf("too many blobs in transaction: have %d, permitted %d", len(hashes), params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob) return fmt.Errorf("too many blobs in transaction: have %d, permitted %d", len(hashes), params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob)
} }
// Ensure commitments, proofs, & hashes are valid
if err := validateBlobSidecar(hashes, sidecar); err != nil { if err := validateBlobSidecar(hashes, sidecar); err != nil {
return err return err
} }