Skip to content

Commit

Permalink
Merge pull request #2145 from AntelopeIO/gh_2028
Browse files Browse the repository at this point in the history
IF: make qc_info in instant_finality_extension non-optional
  • Loading branch information
greg7mdp authored Jan 29, 2024
2 parents 7d9bb58 + 297d059 commit 0fb7f5d
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 172 deletions.
37 changes: 24 additions & 13 deletions libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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

block_header_state_core block_header_state_core::next(qc_info_t incoming) const {
block_header_state_core block_header_state_core::next(qc_claim_t incoming) const {
// no state change if last_qc_block_num is the same
if (incoming.last_qc_block_num == this->last_qc_block_num) {
return {*this};
Expand Down Expand Up @@ -88,10 +88,6 @@ block_header_state block_header_state::next(block_header_state_input& input) con
result.activated_protocol_features = activated_protocol_features;
}

// block_header_state_core
// -----------------------
result.core = input.qc_info ? core.next(*input.qc_info) : core;

// proposal_mtree and finality_mtree
// ---------------------------------
// [greg todo] ??
Expand Down Expand Up @@ -127,17 +123,32 @@ block_header_state block_header_state::next(block_header_state_input& input) con
// ++input.new_finalizer_policy->generation;


// add IF block header extension
// -----------------------------
qc_claim_t qc_claim;
uint16_t if_ext_id = instant_finality_extension::extension_id();
auto if_entry = header_exts.lower_bound(if_ext_id);
auto& if_ext = std::get<instant_finality_extension>(if_entry->second);

instant_finality_extension new_if_ext {if_ext.qc_info,
if (input.qc_claim) {
qc_claim = *input.qc_claim;
dlog("qc_claim from input -> final value: ${qci}",("qci", qc_claim));
} else {
// copy previous qc_claim if we are not provided with a new one
// ------------------------------------------------------------
auto if_entry = header_exts.lower_bound(if_ext_id);
if (if_entry != header_exts.end()) {
const auto& qci = std::get<instant_finality_extension>(if_entry->second).qc_claim;
qc_claim = qci;
dlog("qc_claim from existing extension -> final value: ${qci}",("qci",qc_claim));
} else {
assert(0); // we should always get a previous if extension when in IF mode.
}
}

instant_finality_extension new_if_ext {qc_claim,
std::move(input.new_finalizer_policy),
std::move(input.new_proposer_policy)};
if (input.qc_info)
new_if_ext.qc_info = *input.qc_info;

// block_header_state_core
// -----------------------
result.core = core.next(new_if_ext.qc_claim);

emplace_extension(result.header.header_extensions, if_ext_id, fc::raw::pack(new_if_ext));
result.header_exts.emplace(if_ext_id, std::move(new_if_ext));
Expand Down Expand Up @@ -202,7 +213,7 @@ block_header_state block_header_state::next(const signed_block_header& h, const

block_header_state_input bhs_input{
bb_input, h.transaction_mroot, h.action_mroot, if_ext.new_proposer_policy, if_ext.new_finalizer_policy,
if_ext.qc_info };
if_ext.qc_claim };

return next(bhs_input);
}
Expand Down
5 changes: 3 additions & 2 deletions libraries/chain/block_header_state_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,10 @@ namespace eosio::chain {
}

if (new_finalizer_policy) {
new_finalizer_policy->generation = 1; // TODO: do we allow more than one set during transition
new_finalizer_policy->generation = 1;
// set current block_num as qc_claim.last_qc_block_num in the IF extension
emplace_extension(h.header_extensions, instant_finality_extension::extension_id(),
fc::raw::pack(instant_finality_extension{ {}, std::move(new_finalizer_policy), {} }));
fc::raw::pack(instant_finality_extension{ { block_num, false }, std::move(new_finalizer_policy), {} }));
}

return h;
Expand Down
4 changes: 3 additions & 1 deletion libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ block_state::block_state(const block_state_legacy& bsp) {
header = bsp.header;
core.last_final_block_num = bsp.block_num(); // [if todo] instant transition is not acceptable
activated_protocol_features = bsp.activated_protocol_features;
std::optional<block_header_extension> ext = bsp.block->extract_header_extension(instant_finality_extension::extension_id());

auto if_ext_id = instant_finality_extension::extension_id();
std::optional<block_header_extension> ext = bsp.block->extract_header_extension(if_ext_id);
assert(ext); // required by current transition mechanism
const auto& if_extension = std::get<instant_finality_extension>(*ext);
assert(if_extension.new_finalizer_policy); // required by current transition mechanism
Expand Down
Loading

0 comments on commit 0fb7f5d

Please sign in to comment.