-
Notifications
You must be signed in to change notification settings - Fork 51
Precalculate the fee at on_term_open #1900
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
Conversation
4ad4a41 to
51630c5
Compare
f873804 to
66e8b2f
Compare
|
I tested it in the local network and found out that there is some problem with fee distribution. |
| }; | ||
|
|
||
| let banned = stake::Banned::load_from_state(block.state())?; | ||
| let start_of_the_current_term_header = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the header contains seal here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the related parts, and I'm pretty sure that the seal exists at this point.
`on_open_block` is called when the block is created, before processing any transactions included in the block.
66e8b2f to
f960800
Compare
At `on_term_close`, the term_common_params is not updated to the new parameters yet. But the parameters in the current block's state is updated, so we should get the `era` from there.
f960800 to
807ad63
Compare
|
Finished testing it on the local network, and the fee distribution is correctly working as I expected now. |
Depends on #1895
This PR introduces
on_term_open, and calculates the final fee distribution there.The detailed design is as follows:
1. State structure
State leaf at
makeKey("IntermediateRewards")contains[previous, current]value, and they mean the previous and current intermediate reward that the validators collected.In era=1, it now contains
[current, calculated], and they mean the current intermediate reward, and the calculated result of (reward - penalty).2.
on_term_openon_term_openis called at the first block of the term, and before any of the transactions in the block is processed.The term start is detected by the following condition:
block_number == metadata.last_term_finished_block_num() + 1When the era is zero, it does nothing.
When the era is 1, it calculates the penalty that each validator should take, and substracts it from the current reward in the state, and saves the result in calculated part.
After that, it clears the current reward.
3.
on_term_closeWhen the era is 1, the calculated fee is read from the state and CCC is distributed according to that value.
Note that although it is not strictly required to do this, the calculated part is cleared to empty map here.