Skip to content

Commit

Permalink
GH-376 Avoid finality_extension copy
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Jul 24, 2024
1 parent e90f89b commit fea71ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,7 @@ struct controller_impl {

// extract current block extension and previous header extension
auto block_exts = b->validate_and_extract_extensions();
std::optional<finality_extension> prev_header_ext = prev.header_extension<finality_extension>();
const finality_extension* prev_finality_ext = prev.header_extension<finality_extension>();
std::optional<block_header_extension> header_ext = b->extract_header_extension(f_ext_id);

bool qc_extension_present = block_exts.count(qc_ext_id) != 0;
Expand All @@ -3769,7 +3769,7 @@ struct controller_impl {
"Block #${b} includes a QC block extension, but doesn't have a finality header extension",
("b", block_num) );

EOS_ASSERT( !prev_header_ext,
EOS_ASSERT( !prev_finality_ext,
invalid_qc_claim,
"Block #${b} doesn't have a finality header extension even though its predecessor does.",
("b", block_num) );
Expand All @@ -3784,7 +3784,7 @@ struct controller_impl {
// ensure the block does not have a QC and the QC claim of the current block has a block_num
// of the current block’s number and that it is a claim of a weak QC. Then return early.
// -------------------------------------------------------------------------------------------------
if (!prev_header_ext) {
if (!prev_finality_ext) {
EOS_ASSERT( !qc_extension_present && new_qc_claim.block_num == block_num && new_qc_claim.is_strong_qc == false,
invalid_qc_claim,
"Block #${b}, which is the finality transition block, doesn't have the expected extensions",
Expand All @@ -3795,10 +3795,9 @@ struct controller_impl {
// at this point both current block and its parent have IF extensions, and we are past the
// IF transition block
// ----------------------------------------------------------------------------------------
assert(header_ext && prev_header_ext);
assert(header_ext && prev_finality_ext);

const auto& prev_f_ext = *prev_header_ext;
const auto prev_qc_claim = prev_f_ext.qc_claim;
const auto& prev_qc_claim = prev_finality_ext->qc_claim;

// validate QC claim against previous block QC info

Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ struct block_header_state {
const finalizer_policy& get_last_pending_finalizer_policy() const;
const proposer_policy& get_last_proposed_proposer_policy() const;

template<typename Ext> std::optional<Ext> header_extension() const {
template<typename Ext> const Ext* header_extension() const {
if (auto itr = header_exts.find(Ext::extension_id()); itr != header_exts.end()) {
return std::optional<Ext>{std::get<Ext>(itr->second)};
return &std::get<Ext>(itr->second);
}
return {};
return nullptr;
}
};

Expand Down

0 comments on commit fea71ac

Please sign in to comment.