-
Notifications
You must be signed in to change notification settings - Fork 26
Increment finalizer policy generation on each block that proposes a new finalizer policy; also log when finalizer policy changes #84
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
Changes from all commits
ea951d7
d9d935f
a2de799
0a6f1f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,13 +78,18 @@ const vector<digest_type>& block_header_state::get_new_protocol_feature_activati | |
|
|
||
| #warning Add last_proposed_finalizer_policy_generation to snapshot_block_header_state_v3, see header file TODO | ||
|
|
||
| // ------------------------------------------------------------------------------------------------- | ||
| // `finish_next` updates the next `block_header_state` according to the contents of the | ||
| // header extensions (either new protocol_features or instant_finality_extension) applicable to this | ||
| // next block . | ||
| // | ||
| // These extensions either result from the execution of the previous block (in case this node | ||
| // was the block producer) or were received from the network in a `signed_block`. | ||
| // ------------------------------------------------------------------------------------------------- | ||
| void finish_next(const block_header_state& prev, | ||
| block_header_state& next_header_state, | ||
| vector<digest_type> new_protocol_feature_activations, | ||
| std::shared_ptr<proposer_policy> new_proposer_policy, | ||
| std::optional<finalizer_policy> new_finalizer_policy, | ||
| qc_claim_t qc_claim) { | ||
|
|
||
| instant_finality_extension if_ext) { | ||
| // activated protocol features | ||
| // --------------------------- | ||
| if (!new_protocol_feature_activations.empty()) { | ||
|
|
@@ -98,7 +103,7 @@ void finish_next(const block_header_state& prev, | |
| // --------------- | ||
| next_header_state.active_proposer_policy = prev.active_proposer_policy; | ||
|
|
||
| if(!prev.proposer_policies.empty()) { | ||
| if (!prev.proposer_policies.empty()) { | ||
| auto it = prev.proposer_policies.begin(); | ||
| // +1 since this is called after the block is built, this will be the active schedule for the next block | ||
| if (it->first.slot <= next_header_state.header.timestamp.slot + 1) { | ||
|
|
@@ -109,9 +114,10 @@ void finish_next(const block_header_state& prev, | |
| } | ||
| } | ||
|
|
||
| if (new_proposer_policy) { | ||
| if (if_ext.new_proposer_policy) { | ||
| // called when assembling the block | ||
| next_header_state.proposer_policies[new_proposer_policy->active_time] = std::move(new_proposer_policy); | ||
| next_header_state.proposer_policies[if_ext.new_proposer_policy->active_time] = | ||
| std::move(if_ext.new_proposer_policy); | ||
| } | ||
|
|
||
| // finality_core | ||
|
|
@@ -120,54 +126,77 @@ void finish_next(const block_header_state& prev, | |
| .block_id = prev.block_id, | ||
| .timestamp = prev.timestamp() | ||
| }; | ||
| next_header_state.core = prev.core.next(parent_block, qc_claim); | ||
| next_header_state.core = prev.core.next(parent_block, if_ext.qc_claim); | ||
|
|
||
| // finalizer policy | ||
| // ---------------- | ||
| next_header_state.active_finalizer_policy = prev.active_finalizer_policy; | ||
|
|
||
| if(!prev.finalizer_policies.empty()) { | ||
| if (!prev.finalizer_policies.empty()) { | ||
| auto lib = next_header_state.core.last_final_block_num(); | ||
| auto it = prev.finalizer_policies.begin(); | ||
| if (it->first > lib) { | ||
| // we have at least one `finalizer_policy` in our map, but none of these is | ||
| // due to become active of this block because lib has not advanced enough, so | ||
| // we just copy the multimap and keep using the same `active_finalizer_policy` | ||
| // --------------------------------------------------------------------------- | ||
| next_header_state.finalizer_policies = prev.finalizer_policies; | ||
| } else { | ||
| while (it != prev.finalizer_policies.end() && it->first <= lib) { | ||
| const finalizer_policy_tracker& tracker = it->second; | ||
| if (tracker.state == finalizer_policy_tracker::state_t::pending) { | ||
| // new finalizer_policy becones active | ||
| // ----------------------------------- | ||
| next_header_state.active_finalizer_policy.reset(new finalizer_policy(*tracker.policy)); | ||
| next_header_state.active_finalizer_policy->generation = prev.active_finalizer_policy->generation + 1; | ||
| } else { | ||
| assert(tracker.state == finalizer_policy_tracker::state_t::proposed); | ||
| // block where finalizer_policy was proposed became final. The finalizer policy will | ||
| // become active when next block becomes final. | ||
| // --------------------------------------------------------------------------------- | ||
| finalizer_policy_tracker t { finalizer_policy_tracker::state_t::pending, tracker.policy }; | ||
| next_header_state.finalizer_policies.emplace(next_header_state.block_num(), std::move(t)); | ||
| } | ||
| ++it; | ||
| } | ||
| if (it != prev.finalizer_policies.end()) { | ||
| // copy remainder of pending finalizer_policy changes | ||
| // -------------------------------------------------- | ||
| next_header_state.finalizer_policies.insert(boost::container::ordered_unique_range_t(), | ||
| it, prev.finalizer_policies.end()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (new_finalizer_policy) { | ||
| if (if_ext.new_finalizer_policy) { | ||
| // a new `finalizer_policy` was proposed in the previous block, and is present in the previous | ||
| // block's header extensions. | ||
| // Add this new proposal to the `finalizer_policies` multimap which tracks the in-flight proposals, | ||
| // increment the generation number, and log that proposal (debug level). | ||
| // ------------------------------------------------------------------------------------------------ | ||
| dlog("New finalizer policy proposed in block ${id}: ${pol}", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we log block number instead?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue specifies that ids should be logged, which makes sense as these blocks are not final, so we may have the same block number in different forks. |
||
| ("id", prev.block_id)("pol", *if_ext.new_finalizer_policy)); | ||
| next_header_state.finalizer_policy_generation = if_ext.new_finalizer_policy->generation; | ||
| next_header_state.finalizer_policies.emplace( | ||
| next_header_state.block_num(), | ||
| finalizer_policy_tracker{finalizer_policy_tracker::state_t::proposed, | ||
| std::make_shared<finalizer_policy>(std::move(*new_finalizer_policy))}); | ||
| std::make_shared<finalizer_policy>(std::move(*if_ext.new_finalizer_policy))}); | ||
|
|
||
| } else { | ||
| next_header_state.finalizer_policy_generation = prev.finalizer_policy_generation; | ||
| } | ||
|
|
||
| // Finally update block id from header | ||
| // ----------------------------------- | ||
| next_header_state.block_id = next_header_state.header.calculate_id(); | ||
|
|
||
| // Now that we have the block id of the new block, log what changed. | ||
| // ----------------------------------------------------------------- | ||
| if (next_header_state.active_finalizer_policy != prev.active_finalizer_policy) { | ||
| const auto& act = next_header_state.active_finalizer_policy; | ||
| ilog("Finalizer policy generation change: ${old_gen} -> ${new_gen}", | ||
| ("old_gen", prev.active_finalizer_policy->generation)("new_gen",act->generation)); | ||
| ilog("New finalizer policy becoming active in block ${id}: ${pol}",("id", next_header_state.block_id)("pol", *act)); | ||
| } | ||
| } | ||
|
|
||
| block_header_state block_header_state::next(block_header_state_input& input) const { | ||
|
|
@@ -187,13 +216,13 @@ block_header_state block_header_state::next(block_header_state_input& input) con | |
|
|
||
| // finality extension | ||
| // ------------------ | ||
| instant_finality_extension new_if_ext {input.most_recent_ancestor_with_qc, | ||
| input.new_finalizer_policy, | ||
| input.new_proposer_policy}; | ||
| instant_finality_extension new_if_ext { input.most_recent_ancestor_with_qc, | ||
| std::move(input.new_finalizer_policy), | ||
| std::move(input.new_proposer_policy) }; | ||
|
|
||
| uint16_t if_ext_id = instant_finality_extension::extension_id(); | ||
| emplace_extension(next_header_state.header.header_extensions, if_ext_id, fc::raw::pack(new_if_ext)); | ||
| next_header_state.header_exts.emplace(if_ext_id, std::move(new_if_ext)); | ||
| next_header_state.header_exts.emplace(if_ext_id, new_if_ext); | ||
|
|
||
| // add protocol_feature_activation extension | ||
| // ----------------------------------------- | ||
|
|
@@ -205,9 +234,7 @@ block_header_state block_header_state::next(block_header_state_input& input) con | |
| next_header_state.header_exts.emplace(ext_id, std::move(pfa_ext)); | ||
| } | ||
|
|
||
| finish_next(*this, next_header_state, std::move(input.new_protocol_feature_activations), | ||
| std::move(input.new_proposer_policy), std::move(input.new_finalizer_policy), | ||
| input.most_recent_ancestor_with_qc); | ||
| finish_next(*this, next_header_state, std::move(input.new_protocol_feature_activations), std::move(new_if_ext)); | ||
|
|
||
| return next_header_state; | ||
| } | ||
|
|
@@ -230,6 +257,8 @@ block_header_state block_header_state::next(const signed_block_header& h, valida | |
| block_header_state next_header_state; | ||
| next_header_state.header = static_cast<const block_header&>(h); | ||
| next_header_state.header_exts = h.validate_and_extract_header_extensions(); | ||
| next_header_state.finalizer_policy_generation = finalizer_policy_generation; | ||
|
|
||
| const auto& exts = next_header_state.header_exts; | ||
|
|
||
| // retrieve protocol_feature_activation from incoming block header extension | ||
|
|
@@ -262,8 +291,7 @@ block_header_state block_header_state::next(const signed_block_header& h, valida | |
| ("f", next_core_metadata.final_on_strong_qc_block_num)); | ||
| }; | ||
|
|
||
| finish_next(*this, next_header_state, std::move(new_protocol_feature_activations), if_ext.new_proposer_policy, | ||
| if_ext.new_finalizer_policy, if_ext.qc_claim); | ||
| finish_next(*this, next_header_state, std::move(new_protocol_feature_activations), if_ext); | ||
|
|
||
| return next_header_state; | ||
| } | ||
|
|
||
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.
Like those descriptions!
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.
Thanks!