Skip to content

Commit

Permalink
Fix gas-provider when there's empty blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
LEAFERx committed Apr 11, 2023
1 parent bf949f1 commit ae97f87
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
rpcQuantityToNumber,
rpcQuantityToBigInt,
} from "../jsonrpc/types/base-types";
import * as BigIntUtils from "../../util/bigint";

import { ProviderWrapper } from "./wrapper";

Expand Down Expand Up @@ -268,7 +269,10 @@ export class AutomaticGasPriceProvider extends ProviderWrapper {
(AutomaticGasPriceProvider.EIP1559_BASE_FEE_MAX_FULL_BLOCKS_PREFERENCE -
1n),

maxPriorityFeePerGas: rpcQuantityToBigInt(response.reward[0][0]),
maxPriorityFeePerGas: BigIntUtils.max(
rpcQuantityToBigInt(response.reward[0][0]),
1n
),
};
} catch {
this._nodeHasFeeHistory = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,44 @@ describe("AutomaticGasPriceProvider", () => {
});
});

describe("When eth_feeHistory is available and EIP1559 is supported but recent block is empty", function () {
const latestBaseFeeInMockedProvider = 80;

beforeEach(function () {
mockedProvider.setReturnValue("eth_feeHistory", {
baseFeePerGas: [
numberToRpcQuantity(latestBaseFeeInMockedProvider),
numberToRpcQuantity(
Math.floor((latestBaseFeeInMockedProvider * 9) / 8)
),
],
reward: [["0x0"]],
});

mockedProvider.setReturnValue("eth_getBlockByNumber", {
baseFeePerGas: "0x1",
});
});

it("should set maxPriorityFeePerGas to at least 1 to avoid FeeTooLow error", async function () {
await provider.request({
method: "eth_sendTransaction",
params: [
{
from: "0x0000000000000000000000000000000000000011",
to: "0x0000000000000000000000000000000000000011",
value: 1,
maxFeePerGas: "0x99",
},
],
});

const [tx] = mockedProvider.getLatestParams("eth_sendTransaction");
assert.equal(tx.maxPriorityFeePerGas, "0x1");
assert.equal(tx.maxFeePerGas, "0x99");
});
});

describe("When eth_feeHistory is available and EIP1559 is not supported", function () {
const latestBaseFeeInMockedProvider = 80;

Expand Down

0 comments on commit ae97f87

Please sign in to comment.