forked from cerc-io/plugeth
core/txpool: reject blob txs with blob fee cap below the minimum (#29081)
* make blobpool reject blob transactions with fee below the minimum * core/txpool: some minot nitpick polishes and unified error formats * core/txpool: do less big.Int constructions with the min blob cap --------- Co-authored-by: Péter Szilágyi <peterke@gmail.com>
This commit is contained in:
parent
93c541ad56
commit
32d4d6e616
@ -402,7 +402,7 @@ func (p *BlobPool) Init(gasTip uint64, head *types.Header, reserve txpool.Addres
|
|||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
basefee = uint256.MustFromBig(eip1559.CalcBaseFee(p.chain.Config(), p.head))
|
basefee = uint256.MustFromBig(eip1559.CalcBaseFee(p.chain.Config(), p.head))
|
||||||
blobfee = uint256.MustFromBig(big.NewInt(params.BlobTxMinBlobGasprice))
|
blobfee = uint256.NewInt(params.BlobTxMinBlobGasprice)
|
||||||
)
|
)
|
||||||
if p.head.ExcessBlobGas != nil {
|
if p.head.ExcessBlobGas != nil {
|
||||||
blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*p.head.ExcessBlobGas))
|
blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*p.head.ExcessBlobGas))
|
||||||
|
@ -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
|
||||||
|
@ -30,6 +30,12 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// blobTxMinBlobGasPrice is the big.Int version of the configured protocol
|
||||||
|
// parameter to avoid constucting a new big integer for every transaction.
|
||||||
|
blobTxMinBlobGasPrice = big.NewInt(params.BlobTxMinBlobGasprice)
|
||||||
|
)
|
||||||
|
|
||||||
// ValidationOptions define certain differences between transaction validation
|
// ValidationOptions define certain differences between transaction validation
|
||||||
// across the different pools without having to duplicate those checks.
|
// across the different pools without having to duplicate those checks.
|
||||||
type ValidationOptions struct {
|
type ValidationOptions struct {
|
||||||
@ -101,15 +107,17 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if tx.Gas() < intrGas {
|
if tx.Gas() < intrGas {
|
||||||
return fmt.Errorf("%w: needed %v, allowed %v", core.ErrIntrinsicGas, intrGas, tx.Gas())
|
return fmt.Errorf("%w: gas %v, minimum needed %v", core.ErrIntrinsicGas, tx.Gas(), intrGas)
|
||||||
}
|
}
|
||||||
// Ensure the gasprice is high enough to cover the requirement of the calling
|
// Ensure the gasprice is high enough to cover the requirement of the calling pool
|
||||||
// pool and/or block producer
|
|
||||||
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: gas tip cap %v, minimum needed %v", ErrUnderpriced, tx.GasTipCap(), opts.MinTip)
|
||||||
}
|
}
|
||||||
// Ensure blob transactions have valid commitments
|
|
||||||
if tx.Type() == types.BlobTxType {
|
if tx.Type() == types.BlobTxType {
|
||||||
|
// Ensure the blob fee cap satisfies the minimum blob gas price
|
||||||
|
if tx.BlobGasFeeCapIntCmp(blobTxMinBlobGasPrice) < 0 {
|
||||||
|
return fmt.Errorf("%w: blob fee cap %v, minimum needed %v", ErrUnderpriced, tx.BlobGasFeeCap(), blobTxMinBlobGasPrice)
|
||||||
|
}
|
||||||
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 +131,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 and hashes are valid
|
||||||
if err := validateBlobSidecar(hashes, sidecar); err != nil {
|
if err := validateBlobSidecar(hashes, sidecar); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user