Skip to content

Commit

Permalink
GH-353 rename some variables
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Jul 15, 2024
1 parent 0a0cb71 commit dae8e99
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 90 deletions.
5 changes: 2 additions & 3 deletions libraries/chain/abi_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,8 @@ namespace eosio { namespace chain {

void impl::abi_to_variant::add_block_header_finality_extension( mutable_variant_object& mvo, const header_extension_multimap& header_exts ) {
if (header_exts.count(finality_extension::extension_id())) {
const auto& if_extension =
std::get<finality_extension>(header_exts.lower_bound(finality_extension::extension_id())->second);
mvo("finality_extension", if_extension);
const auto& f_ext = std::get<finality_extension>(header_exts.lower_bound(finality_extension::extension_id())->second);
mvo("finality_extension", f_ext);
}
}

Expand Down
34 changes: 17 additions & 17 deletions libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void evaluate_finalizer_policies_for_promotion(const block_header_state& prev,
void finish_next(const block_header_state& prev,
block_header_state& next_header_state,
vector<digest_type> new_protocol_feature_activations,
finality_extension if_ext,
finality_extension f_ext,
bool log) { // only log on assembled blocks, to avoid double logging
// activated protocol features
// ---------------------------
Expand All @@ -210,8 +210,8 @@ void finish_next(const block_header_state& prev,
}

std::optional<proposer_policy> new_proposer_policy;
if (if_ext.new_proposer_policy_diff) {
new_proposer_policy = prev.get_last_proposed_proposer_policy().apply_diff(*if_ext.new_proposer_policy_diff);
if (f_ext.new_proposer_policy_diff) {
new_proposer_policy = prev.get_last_proposed_proposer_policy().apply_diff(*f_ext.new_proposer_policy_diff);
}
if (new_proposer_policy) {
// called when assembling the block
Expand All @@ -226,7 +226,7 @@ void finish_next(const block_header_state& prev,
.timestamp = prev.timestamp(),
.finalizer_policy_generation = prev.active_finalizer_policy->generation
};
next_header_state.core = prev.core.next(parent_block, if_ext.qc_claim);
next_header_state.core = prev.core.next(parent_block, f_ext.qc_claim);

// finalizer policy
// ----------------
Expand All @@ -236,8 +236,8 @@ void finish_next(const block_header_state& prev,

next_header_state.last_pending_finalizer_policy_digest = fc::sha256::hash(next_header_state.get_last_pending_finalizer_policy());

if (if_ext.new_finalizer_policy_diff) {
finalizer_policy new_finalizer_policy = prev.get_last_proposed_finalizer_policy().apply_diff(*if_ext.new_finalizer_policy_diff);
if (f_ext.new_finalizer_policy_diff) {
finalizer_policy new_finalizer_policy = prev.get_last_proposed_finalizer_policy().apply_diff(*f_ext.new_finalizer_policy_diff);

// a new `finalizer_policy` was proposed in the previous block, and is present in the previous
// block's header extensions.
Expand Down Expand Up @@ -296,13 +296,13 @@ block_header_state block_header_state::next(block_header_state_input& input) con
if (input.new_proposer_policy) {
new_proposer_policy_diff = get_last_proposed_proposer_policy().create_diff(*input.new_proposer_policy);
}
finality_extension new_if_ext { input.most_recent_ancestor_with_qc,
std::move(new_finalizer_policy_diff),
std::move(new_proposer_policy_diff) };
finality_extension new_f_ext { input.most_recent_ancestor_with_qc,
std::move(new_finalizer_policy_diff),
std::move(new_proposer_policy_diff) };

uint16_t if_ext_id = 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, new_if_ext);
uint16_t f_ext_id = finality_extension::extension_id();
emplace_extension(next_header_state.header.header_extensions, f_ext_id, fc::raw::pack(new_f_ext));
next_header_state.header_exts.emplace(f_ext_id, new_f_ext);

// add protocol_feature_activation extension
// -----------------------------------------
Expand All @@ -314,7 +314,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(new_if_ext), true);
finish_next(*this, next_header_state, std::move(input.new_protocol_feature_activations), std::move(new_f_ext), true);

return next_header_state;
}
Expand Down Expand Up @@ -355,13 +355,13 @@ block_header_state block_header_state::next(const signed_block_header& h, valida
// --------------------------------------------------------------------
EOS_ASSERT(exts.count(finality_extension::extension_id()) > 0, invalid_block_header_extension,
"Instant Finality Extension is expected to be present in all block headers after switch to IF");
auto if_entry = exts.lower_bound(finality_extension::extension_id());
const auto& if_ext = std::get<finality_extension>(if_entry->second);
auto f_entry = exts.lower_bound(finality_extension::extension_id());
const auto& f_ext = std::get<finality_extension>(f_entry->second);

if (h.is_proper_svnn_block()) {
// if there is no Finality Tree Root associated with the block,
// then this needs to validate that h.action_mroot is the empty digest
auto next_core_metadata = core.next_metadata(if_ext.qc_claim);
auto next_core_metadata = core.next_metadata(f_ext.qc_claim);
bool no_finality_tree_associated = core.is_genesis_block_num(next_core_metadata.final_on_strong_qc_block_num);

EOS_ASSERT(no_finality_tree_associated == h.action_mroot.empty(), block_validate_exception,
Expand All @@ -371,7 +371,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, false);
finish_next(*this, next_header_state, std::move(new_protocol_feature_activations), f_ext, false);

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

if (header_exts.count(finality_extension::extension_id())) { // transition to savanna has started
const auto& if_extension =
std::get<finality_extension>(header_exts.lower_bound(finality_extension::extension_id())->second);
const auto& f_ext = std::get<finality_extension>(header_exts.lower_bound(finality_extension::extension_id())->second);
// copy over qc_claim from IF Genesis Block
result.qc_claim = if_extension.qc_claim;
result.qc_claim = f_ext.qc_claim;
}

return result;
Expand Down
10 changes: 5 additions & 5 deletions libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ block_state_ptr block_state::create_if_genesis_block(const block_state_legacy& b
result.activated_protocol_features = bsp.activated_protocol_features;

assert(bsp.block->contains_header_extension(finality_extension::extension_id())); // required by transition mechanism
finality_extension if_ext = bsp.block->extract_header_extension<finality_extension>();
assert(if_ext.new_finalizer_policy_diff); // required by transition mechanism
result.active_finalizer_policy = std::make_shared<finalizer_policy>(finalizer_policy{}.apply_diff(std::move(*if_ext.new_finalizer_policy_diff)));
finality_extension f_ext = bsp.block->extract_header_extension<finality_extension>();
assert(f_ext.new_finalizer_policy_diff); // required by transition mechanism
result.active_finalizer_policy = std::make_shared<finalizer_policy>(finalizer_policy{}.apply_diff(std::move(*f_ext.new_finalizer_policy_diff)));

block_ref genesis_block_ref {
.block_id = bsp.id(),
Expand Down Expand Up @@ -302,8 +302,8 @@ qc_claim_t block_state::extract_qc_claim() const {
auto itr = header_exts.lower_bound(finality_extension::extension_id());
if (itr == header_exts.end())
return {};
const auto& if_ext = std::get<finality_extension>(itr->second);
return if_ext.qc_claim;
const auto& f_ext = std::get<finality_extension>(itr->second);
return f_ext.qc_claim;
}

valid_t block_state::new_valid(const block_header_state& next_bhs, const digest_type& action_mroot, const digest_type& strong_digest) const {
Expand Down
32 changes: 15 additions & 17 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3427,15 +3427,13 @@ struct controller_impl {
if (b.header_extensions != ab.header_extensions) {
flat_multimap<uint16_t, block_header_extension> bheader_exts = b.validate_and_extract_header_extensions();
if (bheader_exts.count(finality_extension::extension_id())) {
const auto& if_extension =
std::get<finality_extension>(bheader_exts.lower_bound(finality_extension::extension_id())->second);
elog("b if: ${i}", ("i", if_extension));
const auto& f_ext = std::get<finality_extension>(bheader_exts.lower_bound(finality_extension::extension_id())->second);
elog("b if: ${i}", ("i", f_ext));
}
flat_multimap<uint16_t, block_header_extension> abheader_exts = ab.validate_and_extract_header_extensions();
if (abheader_exts.count(finality_extension::extension_id())) {
const auto& if_extension =
std::get<finality_extension>(abheader_exts.lower_bound(finality_extension::extension_id())->second);
elog("ab if: ${i}", ("i", if_extension));
const auto& f_ext = std::get<finality_extension>(abheader_exts.lower_bound(finality_extension::extension_id())->second);
elog("ab if: ${i}", ("i", f_ext));
}
}

Expand All @@ -3445,16 +3443,16 @@ struct controller_impl {
static std::optional<qc_data_t> extract_qc_data(const signed_block_ptr& b) {
std::optional<qc_data_t> qc_data;
auto hexts = b->validate_and_extract_header_extensions();
if (auto if_entry = hexts.lower_bound(finality_extension::extension_id()); if_entry != hexts.end()) {
auto& if_ext = std::get<finality_extension>(if_entry->second);
if (auto f_entry = hexts.lower_bound(finality_extension::extension_id()); f_entry != hexts.end()) {
auto& f_ext = std::get<finality_extension>(f_entry->second);

// get the matching qc extension if present
auto exts = b->validate_and_extract_extensions();
if (auto entry = exts.lower_bound(quorum_certificate_extension::extension_id()); entry != exts.end()) {
auto& qc_ext = std::get<quorum_certificate_extension>(entry->second);
return qc_data_t{ std::move(qc_ext.qc), if_ext.qc_claim };
return qc_data_t{ std::move(qc_ext.qc), f_ext.qc_claim };
}
return qc_data_t{ {}, if_ext.qc_claim };
return qc_data_t{ {}, f_ext.qc_claim };
}
return {};
}
Expand Down Expand Up @@ -3718,12 +3716,12 @@ struct controller_impl {
// -----------------------------------------------------------------------------
void verify_qc_claim( const block_id_type& id, const signed_block_ptr& b, const block_header_state& prev ) {
auto qc_ext_id = quorum_certificate_extension::extension_id();
auto if_ext_id = finality_extension::extension_id();
auto f_ext_id = finality_extension::extension_id();

// extract current block extension and previous header extension
auto block_exts = b->validate_and_extract_extensions();
std::optional<block_header_extension> prev_header_ext = prev.header.extract_header_extension(if_ext_id);
std::optional<block_header_extension> header_ext = b->extract_header_extension(if_ext_id);
std::optional<block_header_extension> prev_header_ext = prev.header.extract_header_extension(f_ext_id);
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;
uint32_t block_num = b->block_num();
Expand All @@ -3745,8 +3743,8 @@ struct controller_impl {
}

assert(header_ext);
const auto& if_ext = std::get<finality_extension>(*header_ext);
const auto new_qc_claim = if_ext.qc_claim;
const auto& f_ext = std::get<finality_extension>(*header_ext);
const auto new_qc_claim = f_ext.qc_claim;

// If there is a header extension, but the previous block does not have a header extension,
// ensure the block does not have a QC and the QC claim of the current block has a block_num
Expand All @@ -3765,8 +3763,8 @@ struct controller_impl {
// ----------------------------------------------------------------------------------------
assert(header_ext && prev_header_ext);

const auto& prev_if_ext = std::get<finality_extension>(*prev_header_ext);
const auto prev_qc_claim = prev_if_ext.qc_claim;
const auto& prev_f_ext = std::get<finality_extension>(*prev_header_ext);
const auto prev_qc_claim = prev_f_ext.qc_claim;

// validate QC claim against previous block QC info

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct block_header_state {
std::optional<std::pair<block_num_type, finalizer_policy_ptr>> pending_finalizer_policy;

// generation increases by one each time a new finalizer_policy is proposed in a block
// It matches the finalizer policy generation most recently included in this block's `if_extension` or its ancestors
// It matches the finalizer policy generation most recently included in this block's `finality_extension` or its ancestors
uint32_t finalizer_policy_generation{1};

// digest of the finalizer policy (which includes the generation number in it) with the greatest generation number
Expand Down
32 changes: 16 additions & 16 deletions unittests/block_header_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ BOOST_AUTO_TEST_CASE(finality_extension_with_empty_values_test)
std::optional<block_header_extension> ext = header.extract_header_extension(finality_extension::extension_id());
BOOST_REQUIRE( !!ext );

const auto& if_extension = std::get<finality_extension>(*ext);
BOOST_REQUIRE_EQUAL( if_extension.qc_claim.block_num, last_qc_block_num );
BOOST_REQUIRE_EQUAL( if_extension.qc_claim.is_strong_qc, is_last_strong_qc );
BOOST_REQUIRE( !if_extension.new_finalizer_policy_diff );
BOOST_REQUIRE( !if_extension.new_proposer_policy_diff );
const auto& f_ext = std::get<finality_extension>(*ext);
BOOST_REQUIRE_EQUAL( f_ext.qc_claim.block_num, last_qc_block_num );
BOOST_REQUIRE_EQUAL( f_ext.qc_claim.is_strong_qc, is_last_strong_qc );
BOOST_REQUIRE( !f_ext.new_finalizer_policy_diff );
BOOST_REQUIRE( !f_ext.new_proposer_policy_diff );
}

// test for finality_extension uniqueness
Expand Down Expand Up @@ -86,20 +86,20 @@ BOOST_AUTO_TEST_CASE(finality_extension_with_values_test)
std::optional<block_header_extension> ext = header.extract_header_extension(finality_extension::extension_id());
BOOST_REQUIRE( !!ext );

const auto& if_extension = std::get<finality_extension>(*ext);
const auto& f_ext = std::get<finality_extension>(*ext);

BOOST_REQUIRE_EQUAL( if_extension.qc_claim.block_num, last_qc_block_num );
BOOST_REQUIRE_EQUAL( if_extension.qc_claim.is_strong_qc, is_strong_qc );
BOOST_REQUIRE_EQUAL( f_ext.qc_claim.block_num, last_qc_block_num );
BOOST_REQUIRE_EQUAL( f_ext.qc_claim.is_strong_qc, is_strong_qc );

BOOST_REQUIRE( !!if_extension.new_finalizer_policy_diff );
BOOST_REQUIRE_EQUAL(if_extension.new_finalizer_policy_diff->generation, 1u);
BOOST_REQUIRE_EQUAL(if_extension.new_finalizer_policy_diff->threshold, 100u);
BOOST_REQUIRE_EQUAL(if_extension.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.description, "test description");
BOOST_REQUIRE_EQUAL(if_extension.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.weight, 50u);
BOOST_REQUIRE_EQUAL(if_extension.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.public_key.to_string(), "PUB_BLS_qVbh4IjYZpRGo8U_0spBUM-u-r_G0fMo4MzLZRsKWmm5uyeQTp74YFaMN9IDWPoVVT5rj_Tw1gvps6K9_OZ6sabkJJzug3uGfjA6qiaLbLh5Fnafwv-nVgzzzBlU2kwRrcHc8Q");
BOOST_REQUIRE( !!f_ext.new_finalizer_policy_diff );
BOOST_REQUIRE_EQUAL(f_ext.new_finalizer_policy_diff->generation, 1u);
BOOST_REQUIRE_EQUAL(f_ext.new_finalizer_policy_diff->threshold, 100u);
BOOST_REQUIRE_EQUAL(f_ext.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.description, "test description");
BOOST_REQUIRE_EQUAL(f_ext.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.weight, 50u);
BOOST_REQUIRE_EQUAL(f_ext.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.public_key.to_string(), "PUB_BLS_qVbh4IjYZpRGo8U_0spBUM-u-r_G0fMo4MzLZRsKWmm5uyeQTp74YFaMN9IDWPoVVT5rj_Tw1gvps6K9_OZ6sabkJJzug3uGfjA6qiaLbLh5Fnafwv-nVgzzzBlU2kwRrcHc8Q");

BOOST_REQUIRE( !!if_extension.new_proposer_policy_diff );
fc::time_point t = (fc::time_point)(if_extension.new_proposer_policy_diff->active_time);
BOOST_REQUIRE( !!f_ext.new_proposer_policy_diff );
fc::time_point t = (fc::time_point)(f_ext.new_proposer_policy_diff->active_time);
BOOST_REQUIRE_EQUAL(t.time_since_epoch().to_seconds(), 946684900ll);
}

Expand Down
18 changes: 9 additions & 9 deletions unittests/finality_proof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,38 @@ namespace finality_proof {
static qc_data_t extract_qc_data(const signed_block_ptr& b) {
assert(b);
auto hexts = b->validate_and_extract_header_extensions();
if (auto if_entry = hexts.lower_bound(finality_extension::extension_id()); if_entry != hexts.end()) {
auto& if_ext = std::get<finality_extension>(if_entry->second);
if (auto f_entry = hexts.lower_bound(finality_extension::extension_id()); f_entry != hexts.end()) {
auto& f_ext = std::get<finality_extension>(f_entry->second);

// get the matching qc extension if present
auto exts = b->validate_and_extract_extensions();
if (auto entry = exts.lower_bound(quorum_certificate_extension::extension_id()); entry != exts.end()) {
auto& qc_ext = std::get<quorum_certificate_extension>(entry->second);
return qc_data_t{ std::move(qc_ext.qc), if_ext.qc_claim };
return qc_data_t{ std::move(qc_ext.qc), f_ext.qc_claim };
}
return qc_data_t{ {}, if_ext.qc_claim };
return qc_data_t{ {}, f_ext.qc_claim };
}
return {};
}

static bool has_finalizer_policy_diffs(const signed_block_ptr& block){

// extract new finalizer policy
finality_extension if_ext = block->extract_header_extension<finality_extension>();
finality_extension f_ext = block->extract_header_extension<finality_extension>();

return if_ext.new_finalizer_policy_diff.has_value();
return f_ext.new_finalizer_policy_diff.has_value();

}

static finalizer_policy update_finalizer_policy(const signed_block_ptr block, const finalizer_policy& current_policy){

// extract new finalizer policy
finality_extension if_ext = block->extract_header_extension<finality_extension>();
finality_extension f_ext = block->extract_header_extension<finality_extension>();

assert(if_ext.new_finalizer_policy_diff.has_value());
assert(f_ext.new_finalizer_policy_diff.has_value());

finalizer_policy active_finalizer_policy =
current_policy.apply_diff(if_ext.new_finalizer_policy_diff.value());
current_policy.apply_diff(f_ext.new_finalizer_policy_diff.value());

return active_finalizer_policy;

Expand Down
Loading

0 comments on commit dae8e99

Please sign in to comment.