-
Notifications
You must be signed in to change notification settings - Fork 10
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
IF: Update new proposer policy algorithm #74
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
That was an error, corrected in this PR. |
The same block is handled in the |
If set in e.g. If one is set in |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Added additional test cases and added a fix. Ultimately, it is rather complicated to calculate what the version will be ahead of time. If you can think of additional test cases please let me know. |
This comment was marked as resolved.
This comment was marked as resolved.
… placed in a block header extension
libraries/chain/controller.cpp
Outdated
|
||
auto [version, should_propose] = pending->get_next_proposer_schedule_version(gpo.proposed_schedule.producers); | ||
if (should_propose) { | ||
new_proposer_policy = std::make_unique<proposer_policy>(); | ||
new_proposer_policy->active_time = detail::get_next_next_round_block_time(bb.timestamp()); | ||
new_proposer_policy->proposer_schedule = producer_authority_schedule::from_shared(gpo.proposed_schedule); | ||
new_proposer_policy->proposer_schedule.version = version; | ||
ilog("Scheduling proposer schedule change at ${t}: ${s}", | ||
("t", new_proposer_policy->active_time)("s", new_proposer_policy->proposer_schedule)); | ||
} |
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.
No need to change if you don't want to, but I kinda like this more functional
style where the lambda returns the new proposer_policy
(if any) , and we use the return value directly without an intermediate variable.
// Any proposer policy?
auto process_new_proposer_policy = [&](auto&) -> std::unique_ptr<proposer_policy> {
std::unique_ptr<proposer_policy> new_proposer_policy;
const auto& gpo = db.get<global_property_object>();
if (gpo.proposed_schedule_block_num) {
auto [version, should_propose] = pending->get_next_proposer_schedule_version(gpo.proposed_schedule.producers);
if (should_propose) {
new_proposer_policy = std::make_unique<proposer_policy>();
new_proposer_policy->active_time = detail::get_next_next_round_block_time(bb.timestamp());
new_proposer_policy->proposer_schedule = producer_authority_schedule::from_shared(gpo.proposed_schedule);
new_proposer_policy->proposer_schedule.version = version;
ilog("Scheduling proposer schedule change at ${t}: ${s}",
("t", new_proposer_policy->active_time)("s", new_proposer_policy->proposer_schedule));
}
db.modify( gpo, [&]( auto& gp ) {
gp.proposed_schedule_block_num = std::optional<block_num_type>();
gp.proposed_schedule.version = 0;
gp.proposed_schedule.producers.clear();
});
}
return new_proposer_policy;
};
auto assembled_block =
bb.assemble_block(thread_pool.get_executor(), protocol_features.get_protocol_feature_set(), fork_db,
apply_s<std::unique_ptr<proposer_policy>>(chain_head, process_new_proposer_policy),
validating, std::move(validating_qc_data), validating_bsp);
libraries/chain/controller.cpp
Outdated
// if producers is not different then returns the current schedule version (or next schedule version) | ||
std::tuple<uint32_t, bool> get_next_proposer_schedule_version(const vector<producer_authority>& producers) const { | ||
std::tuple<uint32_t, bool> get_next_proposer_schedule_version(const shared_vector<shared_producer_authority>& producers) const { |
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.
This could return std::optional<uint32_t>
, i.e. return a new version if one is needed.
Note:start |
set_proposed_producers[_ex]
host functions after Savanna activation check to see if the policy to be proposed is different than the last proposal policy in the queue (not the currently active one). If it is the same, it avoids adding the policy to the queue (it acts like a no-op).The host functions now return uint32_t max as the version number if the proposed policy is valid. If it is invalid (e.g. empty producers in the policy) it returns
-1
; this is the only time is returns-1
. This means that if the caller of the host function proposes a policy that is identical to the one it last proposed, the host function will still return successfully (not with a -1 return value, but with a uint32_t max).The diff in the block extension is relative to the previous policy proposed and represented in a block extension (as a diff) in the history of the chain. (diff is begin worked under #5).
Resolves #6