diff --git a/src/chains/ethereum/ethereum/src/transaction-pool.ts b/src/chains/ethereum/ethereum/src/transaction-pool.ts index 035e9dc140..b0267c832e 100644 --- a/src/chains/ethereum/ethereum/src/transaction-pool.ts +++ b/src/chains/ethereum/ethereum/src/transaction-pool.ts @@ -9,11 +9,13 @@ import { UNDERPRICED, REPLACED, TRANSACTION_LOCKED, - INSUFFICIENT_FUNDS + INSUFFICIENT_FUNDS, + ERROR_FEE_CAP_TOO_LOW } from "@ganache/ethereum-utils"; import { EthereumInternalOptions } from "@ganache/ethereum-options"; import { Executables } from "./miner/executables"; import { TypedTransaction } from "@ganache/ethereum-transaction"; +import {Block} from "@ganache/ethereum-block"; /** * Checks if the `replacer` is eligible to replace the `replacee` transaction @@ -474,6 +476,18 @@ export default class TransactionPool extends Emittery<{ drain: undefined }> { ); } + // transaction maxGasPerFee must be greater or equal to baseFeePerGas _of the pending block_ + if ("maxFeePerGas" in transaction && !transaction.maxFeePerGas.isNull()) { + console.log(this.#blockchain.blocks.latest); + const nextBaseFee = Block.calcNextBaseFee(this.#blockchain.blocks.latest); + if (transaction.maxFeePerGas.toBigInt() < nextBaseFee) { + return new CodedError( + ERROR_FEE_CAP_TOO_LOW, + JsonRpcErrorCode.TRANSACTION_REJECTED + ); + } + } + return null; }; } diff --git a/src/chains/ethereum/utils/src/errors/errors.ts b/src/chains/ethereum/utils/src/errors/errors.ts index e653f48f53..382759621b 100644 --- a/src/chains/ethereum/utils/src/errors/errors.ts +++ b/src/chains/ethereum/utils/src/errors/errors.ts @@ -49,3 +49,8 @@ export const TRANSACTION_LOCKED = * Returned if a transaction may require more funds than than account currently has available. */ export const INSUFFICIENT_FUNDS = "insufficient funds for gas * price + value"; + +/** + * Returns in a transaction has maxFeePerGas less than the block base fee of the pending transaction. +*/ +export const ERROR_FEE_CAP_TOO_LOW = "max fee per gas less than block base fee";