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

Fix reward distribution and getRewards API on deferredTxfee = false #1886

Merged
merged 10 commits into from Jul 26, 2023

Conversation

JayChoi1736
Copy link
Contributor

@JayChoi1736 JayChoi1736 commented Jul 20, 2023

Proposed changes

Problems
Reward distribution has problems from the first version of Klaytn code when deferredTxfee = false

  1. total transaction fee goes to block proposer(in ApplyTransactions), instead of rewardbase
    - condition : all
  2. gasPrice value for total reward calculation is not set properly. gasPrice from userInput was used, instead of gasPrice in header(in ApplyTransactions)
    - condition : after Magma hardfork
  3. total transaction fee is added to block proposer(in ApplyTransactions) and rewardbase(in Block.Finalize) duplicatively. Additionally, magma hardfork content(halft of fee burn) was applied only to totaltxfee in block.finalize process
    - condition : policy = simple = 0, before Kore Hardfork

Solutions

  1. total transaction fee goes to rewardBase in ApplyTransaction. For this, I have to put rewardbase in evm context. Please let me know if you find any issues with this or if you know of a better way.
  2. gasPrice value is now properly set after Magma Hardfork. I've checked servicechains, and they didn't proceed Magma hardfork.( I checked MBX and cocone, but still waiting for reply for bora servicechain)
  3. now total transaction fee only goes to rewardbase, from after Magma Hardfork( same reason as 2. )
  4. Now half of txfee is burnt after Magma hardfork
  5. Now half of txfee is burnt also after Kore hardfork and not proceed additional burn which is defined in KIP82. This is the same logic when DeferredTxfee = true, policy = simple.

Additional
I found problems with testcases in test/ folder, which uses GenABlockWithTransactions, GenABlockWithTxPool

  • this is the function which compares accountmaps' balance in mock environment and stateDB's balance after insertChain
  • they uses deferredTxfee = false environment
  • gasUsed in mock environment was wrong, but the problems didn't revealed because deferredTxfee=false, and tx sender = rewardBase in testcases
  • I deactivated one testcase first, and will fix every testcases with next PR

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@JayChoi1736 JayChoi1736 self-assigned this Jul 20, 2023
@JayChoi1736 JayChoi1736 marked this pull request as ready for review July 21, 2023 04:15
@aidan-kwon aidan-kwon added the need to merge Need to merge for the next time label Jul 24, 2023
@JayChoi1736 JayChoi1736 mentioned this pull request Jul 24, 2023
20 tasks
ian0371
ian0371 previously approved these changes Jul 24, 2023
hyunsooda
hyunsooda previously approved these changes Jul 25, 2023
blukat29
blukat29 previously approved these changes Jul 25, 2023
Comment on lines 308 to 311
if err := bcdata.GenABlockWithTransactions(accountMap, txs, prof); err != nil {
t.Fatal(err)
}

Copy link
Member

Choose a reason for hiding this comment

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

You will change back to the original code after fixing all related bug, right? Can you just comment out and add TODO tag for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved by e24351e

@JayChoi1736 JayChoi1736 dismissed stale reviews from blukat29, hyunsooda, and ian0371 via e24351e July 25, 2023 16:10
@JayChoi1736 JayChoi1736 merged commit 599aa04 into klaytn:dev Jul 26, 2023
11 checks passed
@blukat29 blukat29 removed the need to merge Need to merge for the next time label Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants