Skip to content
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: make qc_info in instant_finality_extension non-optional #2145

Merged
merged 18 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c3f700a
Always include `qc_info` in IF extension.
greg7mdp Jan 25, 2024
a2e9cc6
Merge branch 'hotstuff_integration' of github.com:AntelopeIO/leap int…
greg7mdp Jan 25, 2024
84aeb00
Make it work by updating the ih header extension in the block_state a…
greg7mdp Jan 26, 2024
0c4deb5
Merge branch 'hotstuff_integration' of github.com:AntelopeIO/leap int…
greg7mdp Jan 26, 2024
7b28ddd
Indentation and typo.
greg7mdp Jan 26, 2024
8b3b02b
change `qc_info` -> `qc_claim` and `block_height` -> `block_num`.
greg7mdp Jan 26, 2024
5779b6d
Remove no longer necessary check in `verify_qc_claim`.
greg7mdp Jan 26, 2024
7368768
Revert "Remove no longer necessary check in `verify_qc_claim`."
greg7mdp Jan 26, 2024
ba9b519
Fix eror text.
greg7mdp Jan 26, 2024
4cbdb1e
Update `verify_qc_claim` as discussed with Areg.
greg7mdp Jan 26, 2024
2e0783a
Fix `verify_qc_claim` according to Areg's feedback, and store correct…
greg7mdp Jan 27, 2024
d47e0c2
Update test accordingly to change for first finalizer generation == 0.
greg7mdp Jan 27, 2024
7fc28e4
Revert "Update test accordingly to change for first finalizer generat…
greg7mdp Jan 27, 2024
ed97bf6
Revert initial finalizer generation to 1, as we don't want to change …
greg7mdp Jan 27, 2024
2b3f787
Simplify redundent error message in `FC_ASSERT`, and other formatting…
greg7mdp Jan 29, 2024
68f3f3e
Remove `.clang-format` which I added by mistake.
greg7mdp Jan 29, 2024
1454a5f
Merge branch 'hotstuff_integration' of github.com:AntelopeIO/leap int…
greg7mdp Jan 29, 2024
297d059
Merge branch 'hotstuff_integration' of github.com:AntelopeIO/leap int…
greg7mdp Jan 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading