Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider.getFeeData().maxPriorityFeePerGas vs eth_maxPriorityFeePerGas different values #5093

Closed
JeremyX2022 opened this issue Apr 7, 2024 · 5 comments · Fixed by #5157
Closed
Assignees
Labels
status:ready This issue is ready to be worked on

Comments

@JeremyX2022
Copy link

Version of Hardhat

2.20

What happened?

Why the value of maxPriorityFeePerGas are different by using these two methods?
I tested it on the Ethereum mainnet

Minimal reproduction steps

  1. config hardhat network:
  networks: {
    mainnet: {
      url: "https://eth.llamarpc.com",
    },
  }
  1. goto hardhat console: npx hardhat console --network mainnet

  2. using following codes:

const p = new ethers.JsonRpcProvider("https://eth.llamarpc.com")

console.log([(await ethers.provider.getFeeData()), Number(await ethers.provider.send('eth_maxPriorityFeePerGas', []))]);
console.log([(await p.getFeeData()), Number(await p.send('eth_maxPriorityFeePerGas', []))]);

output:

> [
  FeeData {
    gasPrice: 16951633560n,
    maxFeePerGas: 34883267120n,
    maxPriorityFeePerGas: 1000000000n
  },
  10000000
]


> [
  FeeData {
    gasPrice: 16951633560n,
    maxFeePerGas: 33893267120n,
    maxPriorityFeePerGas: 10000000n
  },
  10000000
]

You can see 'maxPriorityFeePerGas' in 'getFeeData' is different from the value of 'eth_maxPriorityFeePerGas' by using ethers.provider.

Search terms

No response

@kanej
Copy link
Member

kanej commented Apr 8, 2024

Hey @JeremyX2022, can I confirm the version of ethers you are using here?

@JeremyX2022
Copy link
Author

Hey @JeremyX2022, can I confirm the version of ethers you are using here?

ethers.version
'6.11.1'

@JeremyX2022
Copy link
Author

I also post in ethers: ethers-io/ethers.js#4656
but the issue seems more related to hardhat

@kanej kanej added status:ready This issue is ready to be worked on and removed status:triaging labels Apr 18, 2024
@kanej
Copy link
Member

kanej commented Apr 22, 2024

I can reproduce this locally. It appears that ethers delegates to eth_maxPriorityFeePerGas RPC call for calculating gas falling back to a default of 1_000_000_000n and the Harhdat hardhat-ethers-provider always returns the default:

public async getFeeData(): Promise<ethers.FeeData> {
let gasPrice: bigint | undefined;
let maxFeePerGas: bigint | undefined;
let maxPriorityFeePerGas: bigint | undefined;
try {
gasPrice = BigInt(await this._hardhatProvider.send("eth_gasPrice"));
} catch {}
const latestBlock = await this.getBlock("latest");
const baseFeePerGas = latestBlock?.baseFeePerGas;
if (baseFeePerGas !== undefined && baseFeePerGas !== null) {
maxPriorityFeePerGas = 1_000_000_000n;
maxFeePerGas = 2n * baseFeePerGas + maxPriorityFeePerGas;
}

We should update this logic to match the ethers logic.

kanej added a commit that referenced this issue Apr 22, 2024
Update `getFeeData` to match the `ethers` algorithm, specifically don't
just assume `1_000_000_000n` as the `maxPriorityFeePerGas`. Instead call
`eth_maxPriorityFeePerGas`, and only fall back to `1_000_000_000n`, if
there is no response.

Fixes #5093
@sambacha
Copy link
Contributor

it should be noted that eth_maxPriorityFeePerGas was not originally part of the official Ethereum JSON-RPC specification and originally a go-ethereum only RPC method. It is now part of the execution api spec.

kanej added a commit that referenced this issue May 7, 2024
Update `getFeeData` to match the `ethers` algorithm, specifically don't
just assume `1_000_000_000n` as the `maxPriorityFeePerGas`. Instead call
`eth_maxPriorityFeePerGas`, and only fall back to `1_000_000_000n`, if
there is no response.

Fixes #5093
kanej added a commit that referenced this issue May 7, 2024
Update `getFeeData` to match the `ethers` algorithm, specifically don't
just assume `1_000_000_000n` as the `maxPriorityFeePerGas`. Instead call
`eth_maxPriorityFeePerGas`, and only fall back to `1_000_000_000n`, if
there is no response.

Fixes #5093
kanej added a commit that referenced this issue May 7, 2024
Update `getFeeData` to match the `ethers` algorithm, specifically don't
just assume `1_000_000_000n` as the `maxPriorityFeePerGas`. Instead call
`eth_maxPriorityFeePerGas`, and only fall back to `1_000_000_000n`, if
there is no response.

Fixes #5093
kanej added a commit that referenced this issue May 7, 2024
Update `getFeeData` to match the `ethers` algorithm, specifically don't
just assume `1_000_000_000n` as the `maxPriorityFeePerGas`. Instead call
`eth_maxPriorityFeePerGas`, and only fall back to `1_000_000_000n` if
there is no response.

Fixes #5093
kanej added a commit that referenced this issue May 9, 2024
Update `getFeeData` to match the `ethers` algorithm, specifically don't
just assume `1_000_000_000n` as the `maxPriorityFeePerGas`. Instead call
`eth_maxPriorityFeePerGas`, and only fall back to `1_000_000_000n` if
there is no response.

Fixes #5093
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants