Skip to content

Conversation

@remagpie
Copy link
Contributor

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_open

on_term_open is 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() + 1

When 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_close

When 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.

@remagpie remagpie force-pushed the on-term-open branch 2 times, most recently from f873804 to 66e8b2f Compare November 29, 2019 03:15
@remagpie remagpie added do-not-merge Do not merge (for mergify.io) and removed do-not-merge Do not merge (for mergify.io) labels Nov 29, 2019
@remagpie
Copy link
Contributor Author

I tested it in the local network and found out that there is some problem with fee distribution.
The distributed amount should be the same with before, but fee-monitor says there are some difference.
I'll try to figure out what's going on.

};

let banned = stake::Banned::load_from_state(block.state())?;
let start_of_the_current_term_header =
Copy link
Contributor

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?

Copy link
Contributor Author

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.
@remagpie remagpie changed the title Precalculate the fee at on_term_open [WIP] Precalculate the fee at on_term_open Dec 3, 2019
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.
@remagpie remagpie changed the title [WIP] Precalculate the fee at on_term_open Precalculate the fee at on_term_open Dec 3, 2019
@remagpie remagpie removed the do-not-merge Do not merge (for mergify.io) label Dec 3, 2019
@remagpie
Copy link
Contributor Author

remagpie commented Dec 3, 2019

Finished testing it on the local network, and the fee distribution is correctly working as I expected now.
Please review the changed parts again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants