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

Exclude BNB Chain from zero fee configuration in gas fee logic #755

Merged
merged 3 commits into from
May 9, 2024

Conversation

magicsih
Copy link
Contributor

@magicsih magicsih commented May 9, 2024

This commit updates the gas fee configuration logic to accommodate the BNB Chain (chainId 56). While the BNB Network supports EIP-1559, it reports a baseFeePerGas of zero(bnb-chain/bsc#2062). This adjustment ensures that transactions on the BNB Chain do not mistakenly receive a max fee configuration of zero, which is not appropriate despite the reported base fee. This change maintains the functionality for other chains such as Polygon (chainId 137) that require legacy gasPrice fees, and excludes only BNB Chain from the zero max fee logic. This is crucial for proper transaction fee handling on networks supporting EIP-1559 but reporting a base fee of zero.

Deployments on the BNB Chain were failing. The required tip for transactions should be n wei, but because the baseFeePerGas was mistakenly set to 0, the actual tip was also calculated as 0. This resulted in deployment errors that prevented successful transaction submissions. This commit corrects this misconfiguration, ensuring that the correct transaction fees are applied, thus enabling proper deployments on the BNB Chain.

This commit updates the gas fee configuration logic to accommodate the BNB Chain (chainId 56). While the BNB Network supports EIP-1559, it reports a `baseFeePerGas` of zero. This adjustment ensures that transactions on the BNB Chain do not mistakenly receive a max fee configuration of zero, which is not appropriate despite the reported base fee. This change maintains the functionality for other chains such as Polygon (chainId 137) that require legacy gasPrice fees, and excludes only BNB Chain from the zero max fee logic. This is crucial for proper transaction fee handling on networks supporting EIP-1559 but reporting a base fee of zero.
@kanej
Copy link
Member

kanej commented May 9, 2024

Thanks @magicsih, could you add a test based on this example:

it("Should return zero gas fees when deploying to a network with a zero base fee per gas (e.g. private Besu instances)", async function () {

@@ -640,7 +640,7 @@ export class EIP1193JsonRpcClient implements JsonRpcClient {
// We prioritize EIP-1559 fees over legacy gasPrice fees, however,
// polygon (chainId 137) requires legacy gasPrice fees so we skip EIP-1559 logic in that case
if (latestBlock.baseFeePerGas !== undefined && chainId !== 137) {
if (latestBlock.baseFeePerGas === 0n) {
if (latestBlock.baseFeePerGas === 0n && chainId != 56) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (latestBlock.baseFeePerGas === 0n && chainId != 56) {
if (latestBlock.baseFeePerGas === 0n && chainId !== 56) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will satisfy our eslint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for letting me know. I should have read contribution guide carefully. Today was the contract deployment day. We handled this problem with downgrading version to v0.15.0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you been able to test the change with a deployment against BNB?

Copy link
Contributor Author

@magicsih magicsih May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. by modifying the line, I confirmed that BNB distribution was successful.

this was original stacktrace.

√ Confirm deploy to network bnb (56)? ... yes
Hardhat Ignition 🚀

Deploying [ TestTokenModule ]

Batch #1
  Executing TestTokenModule#TestToken...

An unexpected error occurred:

ProviderError: transaction underpriced: tip needed 1000000000, tip permitted 0
    at HttpProvider.request (node_modules\hardhat\src\internal\core\providers\http.ts:90:21)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async EIP1193JsonRpcClient.sendTransaction (node_modules\@nomicfoundation\ignition-core\src\internal\execution\jsonrpc-client.ts:418:24)
    at async sendTransactionForOnchainInteraction (node_modules\@nomicfoundation\ignition-core\src\internal\execution\future-processor\helpers\network-interaction-execution.ts:181:18)
    at async sendTransaction (node_modules\@nomicfoundation\ignition-core\src\internal\execution\future-processor\handlers\send-transaction.ts:86:18)
    at async FutureProcessor.processFuture (node_modules\@nomicfoundation\ignition-core\src\internal\execution\future-processor\future-processor.ts:114:9)
    at async ExecutionEngine._executeBatch (node_modules\@nomicfoundation\ignition-core\src\internal\execution\execution-engine.ts:153:30)
    at async ExecutionEngine.executeModule (node_modules\@nomicfoundation\ignition-core\src\internal\execution\execution-engine.ts:114:25)
    at async Deployer.deploy (node_modules\@nomicfoundation\ignition-core\src\internal\deployer.ts:194:25)
    at async SimpleTaskDefinition.action (node_modules\@nomicfoundation\hardhat-ignition\src\index.ts:302:24)

after the change

√ Confirm deploy to network bnb (56)? ... yes
Hardhat Ignition 🚀

Resuming existing deployment from .\ignition\deployments\chain-56

Deploying [ TestTokenModule ]

Batch #1
  Executed TestTokenModule#TestToken

Batch #2
  Executed TestTokenModule#TestToken.mint

[ TestTokenModule ] successfully deployed 🚀

Deployed Addresses

TestTokenModule#TestToken - (hide)

in gas fee logic

This commit updates the gas fee configuration logic to accommodate the BNB Chain (chainId 56).
While the BNB Network supports EIP-1559, it reports a `baseFeePerGas` of zero.
This adjustment ensures that transactions on the BNB Chain do not mistakenly receive a max fee configuration of zero, which is not appropriate despite the reported base fee.
This change maintains the functionality for other chains such as Polygon (chainId 137) that require legacy gasPrice fees, and excludes only BNB Chain from the zero max fee logic.
This is crucial for proper transaction fee handling on networks supporting EIP-1559 but reporting a base fee of zero.
Correct the indentation in the test files to resolve linting errors.
Copy link
Member

@kanej kanej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @magicsih

@kanej kanej merged commit 42ccfc7 into NomicFoundation:development May 9, 2024
5 checks passed
zoeyTM pushed a commit that referenced this pull request May 10, 2024
* fix: Exclude BNB Chain from zero fee configuration in gas fee logic

This commit updates the gas fee configuration logic to accommodate the BNB Chain (chainId 56). While the BNB Network supports EIP-1559, it reports a `baseFeePerGas` of zero. This adjustment ensures that transactions on the BNB Chain do not mistakenly receive a max fee configuration of zero, which is not appropriate despite the reported base fee. This change maintains the functionality for other chains such as Polygon (chainId 137) that require legacy gasPrice fees, and excludes only BNB Chain from the zero max fee logic. This is crucial for proper transaction fee handling on networks supporting EIP-1559 but reporting a base fee of zero.
@blackbear10000
Copy link

Hi. Should we also fix the same issue for BNB Testnet Chain? It's chainId is 97. Thanks.

@kanej
Copy link
Member

kanej commented May 23, 2024

BNB Testnet Chain? It's chainId is 97

Hey @blackbear10000, yes we should add the testnet, I have opened a separate issue for this: #763

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants