Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix: reject transaction if maxFeePerGas is less than blockBaseFeePerG…
Browse files Browse the repository at this point in the history
…as of the pending transaction #2831
  • Loading branch information
jeffsmale90 committed Apr 6, 2022
1 parent 8f8feb4 commit 0139abd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/chains/ethereum/ethereum/src/transaction-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};
}
5 changes: 5 additions & 0 deletions src/chains/ethereum/utils/src/errors/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 0139abd

Please sign in to comment.