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

fixes maxPriorityFeePerGas in _handleTxPricing #5018

Closed

Conversation

mathewmeconry
Copy link

@mathewmeconry mathewmeconry commented May 10, 2022

Description

web3-core-method._handleTxPricing uses now eth_feeHistory for priority fee calculation on EIP-1559 compatible chains

I have no idea to get the Deploy Preview to check if it looks correct...

Fixes #4857

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run dtslint with success and extended the tests and types if necessary.
  • I ran npm run test:cov and my test cases cover all the lines and branches of the added code.
  • I ran npm run build with success.
  • I have tested the built dist/web3.min.js in a browser.
  • I have tested my code on the live network.
  • I have checked the Deploy Preview and it looks correct.
  • I have updated the CHANGELOG.md file in the root folder.

@jdevcs jdevcs added 1.x 1.0 related issues Review Needed Maintainer(s) need to review labels May 11, 2022
Copy link
Contributor

@jdevcs jdevcs left a comment

Choose a reason for hiding this comment

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

@mathewmeconry Thanks for your contributions, could you check and fix as following tests are failing:

  2 failing

  1) typical usage
       with methods
         should sendTransaction and fill in default gasPrice:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/web3.js/web3.js/test/contract.js)
      at listOnTimeout (internal/timers.js:557:17)
      at processTimers (internal/timers.js:500:7)

  2) standalone usage
       with methods
         should sendTransaction and fill in default gasPrice:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/web3.js/web3.js/test/contract.js)
      at listOnTimeout (internal/timers.js:557:17)
      at processTimers (internal/timers.js:500:7)

@mathewmeconry
Copy link
Author

@mathewmeconry Thanks for your contributions, could you check and fix as following tests are failing:

  2 failing

  1) typical usage
       with methods
         should sendTransaction and fill in default gasPrice:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/web3.js/web3.js/test/contract.js)
      at listOnTimeout (internal/timers.js:557:17)
      at processTimers (internal/timers.js:500:7)

  2) standalone usage
       with methods
         should sendTransaction and fill in default gasPrice:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/web3.js/web3.js/test/contract.js)
      at listOnTimeout (internal/timers.js:557:17)
      at processTimers (internal/timers.js:500:7)

hey @jdevcs
the issues should be fixed. the tests run successfully local

@coveralls
Copy link

Pull Request Test Coverage Report for Build 2305841789

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 434 unchanged lines in 8 files lost coverage.
  • Overall coverage decreased (-2.3%) to 72.24%

Files with Coverage Reduction New Missed Lines %
packages/web3-core-requestmanager/src/jsonrpc.js 1 88.0%
packages/web3-core-method/lib/index.js 5 93.55%
packages/web3-core-helpers/src/formatters.js 25 81.07%
packages/web3-core-helpers/src/errors.js 31 4.41%
packages/web3-utils/src/soliditySha3.js 55 5.13%
packages/web3-utils/src/index.js 62 29.31%
packages/web3-utils/src/utils.js 92 12.86%
packages/web3-eth-accounts/src/index.js 163 23.77%
Totals Coverage Status
Change from base Build 2270215922: -2.3%
Covered Lines: 3379
Relevant Lines: 4408

💛 - Coveralls

@mathewmeconry mathewmeconry requested a review from jdevcs May 11, 2022 13:41

// if no priority fee is set in the tx try to get it from the rpc
if(maxPriorityFeePerGas === '0x9502F900') {
const feeHistory = await getFeeHistory(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

There can be optimized maxPriorityFeePerGas calculation, and users can always calculate and set it explicitly via tx.maxPriorityFeePerGas . We always defaults to 2.5 Gwei if user is not setting it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would second @jdevcs comment, we should not make these changes. We can develop a feature to inject custom fee calculation algorithm to the library but in some 4.x releases.

Copy link
Author

Choose a reason for hiding this comment

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

personally, I think the hardcoded value of 2.5 gwei is a mistake because the chains differ and as we see on polygon mainnet the transactions fail because of underpricing.
The same thing would from my point of view also apply to the gas calculation which could be done by the user and set with maxFeePerGas but this is done in this library to make the usage easier.
If you don't agree then please close the pull request and we make the change for all of our clients

Copy link
Contributor

Choose a reason for hiding this comment

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

As there can be several ways of estimation of maxPriorityFeePerGas based on how fast user want his tx to include in next block. So instead of defaulting to single way of estimation in this function, another path could be adding a standalone function for maxPriorityFeePerGas estimation for users facilitation, and allowing users to use that function for explicitly doing estimation and setting tx.maxPriorityFeePerGas @mathewmeconry ?

Copy link
Author

Choose a reason for hiding this comment

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

not a bad idea and would make total sense.
but as I have seen in the code so far there is also only one way implemented for the gas estimation and this one also defines how "fast" a transaction goes through.
I just try to understand why the code change isn't ok for the priority fee but doing the same with the gas estimation is fine....

Copy link
Contributor

Choose a reason for hiding this comment

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

@mathewmeconry our team is occupied for 4.x work so if you have time could you go ahead and add maxPriorityFeePerGas estimation function? Thanks

Copy link
Author

Choose a reason for hiding this comment

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

@jdevcs sure. in which package should this function live?
so I am gonna remove this improvement again and only add a function to return the estimated priority fee?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, web3.eth package, once its added in 1.x could you also add this in 4.x for future use.

Copy link
Author

Choose a reason for hiding this comment

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

so I guess we can close this pull request cause the eth_feeHistory is already exported by the web3-eth module
https://github.com/ChainSafe/web3.js/blob/2c0324af2da467ee1acb72452f20000e916e4306/packages/web3-eth/src/index.js#L426
?


// if no priority fee is set in the tx try to get it from the rpc
if(maxPriorityFeePerGas === '0x9502F900') {
const feeHistory = await getFeeHistory(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would second @jdevcs comment, we should not make these changes. We can develop a feature to inject custom fee calculation algorithm to the library but in some 4.x releases.

@jdevcs jdevcs closed this May 20, 2022
Copy link
Contributor

@jdevcs jdevcs left a comment

Choose a reason for hiding this comment

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

Closing this PR in favor of using https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getfeehistory for estimation of maxPriorityFeePerGas and setting Priority Fee via tx.maxPriorityFeePerGas explicitly if user dnt want to default 2.5 Gwei.

@mathewmeconry mathewmeconry deleted the fix/priority_fee_calculation branch May 22, 2022 15:13
@Barukimang
Copy link

Hej guys! We followed your advice to create a 'local fix' for the issue of tx's failing on Polygon with a fixed 2.5 gwei priorityFee. Here's the PR of @mathewmeconry: aragon/client#1753

Thanks for your input and feedback, and looking forward to 4.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Review Needed Maintainer(s) need to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Polygon chain trades gas price insufficient - 1.7.1
5 participants