Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Fix wrong precision in calculation of gas fee #798

Merged
merged 14 commits into from
Mar 15, 2021

Conversation

KamiD
Copy link

@KamiD KamiD commented Feb 16, 2021

Closes: #799

Description


For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

For admin use:

  • Added appropriate labels to PR (ex. WIP, R4R, docs, etc)
  • Reviewers assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

KamiD and others added 10 commits December 31, 2020 10:09
evm: reset cache after csdb is committed (cosmos#676)
update development branch
rpc: fix method to calculate block hash and fix mismatch block hash i…
update branch of development to newest
@KamiD KamiD requested review from fedekunze and noot as code owners February 16, 2021 06:59
@araskachoi
Copy link
Contributor

@KamiD
This fix does not fix #799. The proposed fix here will make the multiplier into 18*10^18, which will break the default precision calculation. could you revisit this and see if it is actually an issue?

@KamiD
Copy link
Author

KamiD commented Feb 19, 2021

@KamiD
This fix does not fix #799. The proposed fix here will make the multiplier into 18*10^18, which will break the default precision calculation. could you revisit this and see if it is actually an issue?

hi, I have test this case in ut and debug in step by step, that is actually an issue here.
for math example:

  • set gas price to 1 GWEI, set gas limit to 10000
  • in AnteHandler, the code fee = price * GasLimit should be 10000000000000, that's a correct value
  • if I use old code, the result of fee will be 10000000000000 ^ 18 cause NewDecCoin will call func ToDec() and it will change the value to n ^ 18
  • if I use the new code, the result of fee will be 10000000000000

in case of using function NewDecCoinFromDec , if I set the param prec to 0, the result will be n ^ 18, if I set prec to 18, the result will be n ^ 0, after debugging and running tests case on okexchain, this pr will fix the precision error.

BTW: the function NewDecCoinFromDec was a little anti-humanity

@araskachoi
Copy link
Contributor

tested and works as intended!
@KamiD can we write a quick precision test to make sure that the fee has the correct decimal precision? looks ready to approve/merge after that. thanks!

Copy link
Contributor

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

ACK. Can you add a changelog entry?

app/ante/eth.go Show resolved Hide resolved
@araskachoi
Copy link
Contributor

@KamiD can you update the changelog file please? ready to merge afterwards. apologies on the delay

@KamiD
Copy link
Author

KamiD commented Mar 13, 2021

@KamiD can you update the changelog file please? ready to merge afterwards. apologies on the delay

hey bro, its done

@araskachoi araskachoi merged commit 2294a19 into cosmos:development Mar 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrong precision in calculation of gas fee during call AnteHandler
4 participants