Skip to content

Commit

Permalink
GH-353 Renamed instant_finality_extension to finality_extension
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Jul 12, 2024
1 parent 273e5e4 commit 0a0cb71
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 103 deletions.
10 changes: 5 additions & 5 deletions libraries/chain/abi_serializer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <eosio/chain/abi_serializer.hpp>
#include <eosio/chain/asset.hpp>
#include <eosio/chain/exceptions.hpp>
#include <eosio/chain/finality/instant_finality_extension.hpp>
#include <eosio/chain/finality/finality_extension.hpp>
#include <fc/io/raw.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <fc/io/varint.hpp>
Expand Down Expand Up @@ -634,11 +634,11 @@ namespace eosio { namespace chain {
_variant_to_binary(type, var, ds, ctx);
}

void impl::abi_to_variant::add_block_header_instant_finality_extension( mutable_variant_object& mvo, const header_extension_multimap& header_exts ) {
if (header_exts.count(instant_finality_extension::extension_id())) {
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<instant_finality_extension>(header_exts.lower_bound(instant_finality_extension::extension_id())->second);
mvo("instant_finality_extension", if_extension);
std::get<finality_extension>(header_exts.lower_bound(finality_extension::extension_id())->second);
mvo("finality_extension", if_extension);
}
}

Expand Down
18 changes: 9 additions & 9 deletions libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <eosio/chain/block_header_state.hpp>
#include <eosio/chain/block_header_state_utils.hpp>
#include <eosio/chain/finality/instant_finality_extension.hpp>
#include <eosio/chain/finality/finality_extension.hpp>
#include <eosio/chain/finality/proposer_policy.hpp>
#include <eosio/chain/exceptions.hpp>
#include <limits>
Expand Down Expand Up @@ -174,7 +174,7 @@ void evaluate_finalizer_policies_for_promotion(const block_header_state& prev,

// -------------------------------------------------------------------------------------------------
// `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
// header extensions (either new protocol_features or finality_extension) applicable to this
// next block .
//
// These extensions either result from the execution of the previous block (in case this node
Expand All @@ -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,
instant_finality_extension if_ext,
finality_extension if_ext,
bool log) { // only log on assembled blocks, to avoid double logging
// activated protocol features
// ---------------------------
Expand Down Expand Up @@ -296,11 +296,11 @@ 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);
}
instant_finality_extension new_if_ext { input.most_recent_ancestor_with_qc,
finality_extension new_if_ext { input.most_recent_ancestor_with_qc,
std::move(new_finalizer_policy_diff),
std::move(new_proposer_policy_diff) };

uint16_t if_ext_id = instant_finality_extension::extension_id();
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);

Expand Down Expand Up @@ -351,12 +351,12 @@ block_header_state block_header_state::next(const signed_block_header& h, valida
validator( timestamp(), activated_protocol_features->protocol_features, new_protocol_feature_activations );
}

// retrieve instant_finality_extension data from block header extension
// retrieve finality_extension data from block header extension
// --------------------------------------------------------------------
EOS_ASSERT(exts.count(instant_finality_extension::extension_id()) > 0, invalid_block_header_extension,
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(instant_finality_extension::extension_id());
const auto& if_ext = std::get<instant_finality_extension>(if_entry->second);
auto if_entry = exts.lower_bound(finality_extension::extension_id());
const auto& if_ext = std::get<finality_extension>(if_entry->second);

if (h.is_proper_svnn_block()) {
// if there is no Finality Tree Root associated with the block,
Expand Down
12 changes: 6 additions & 6 deletions libraries/chain/block_header_state_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ namespace eosio::chain {
result.producer_to_last_implied_irb[proauth.producer_name] = dpos_proposed_irreversible_blocknum;
}

if (header_exts.count(instant_finality_extension::extension_id())) { // transition to savanna has started
if (header_exts.count(finality_extension::extension_id())) { // transition to savanna has started
const auto& if_extension =
std::get<instant_finality_extension>(header_exts.lower_bound(instant_finality_extension::extension_id())->second);
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;
}
Expand Down Expand Up @@ -222,11 +222,11 @@ namespace eosio::chain {
.is_strong_qc = false };
finalizer_policy no_policy;
auto new_fin_policy_diff = no_policy.create_diff(*new_finalizer_policy);
emplace_extension(h.header_extensions, instant_finality_extension::extension_id(),
fc::raw::pack(instant_finality_extension{ initial_if_claim, std::move(new_fin_policy_diff), {} }));
emplace_extension(h.header_extensions, finality_extension::extension_id(),
fc::raw::pack(finality_extension{ initial_if_claim, std::move(new_fin_policy_diff), {} }));
} else if (qc_claim) {
emplace_extension(h.header_extensions, instant_finality_extension::extension_id(),
fc::raw::pack(instant_finality_extension{ *qc_claim, {}, {} }));
emplace_extension(h.header_extensions, finality_extension::extension_id(),
fc::raw::pack(finality_extension{ *qc_claim, {}, {} }));
}

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

assert(bsp.block->contains_header_extension(instant_finality_extension::extension_id())); // required by transition mechanism
instant_finality_extension if_ext = bsp.block->extract_header_extension<instant_finality_extension>();
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)));

Expand Down Expand Up @@ -299,10 +299,10 @@ void block_state::verify_qc(const valid_quorum_certificate& qc) const {
}

qc_claim_t block_state::extract_qc_claim() const {
auto itr = header_exts.lower_bound(instant_finality_extension::extension_id());
auto itr = header_exts.lower_bound(finality_extension::extension_id());
if (itr == header_exts.end())
return {};
const auto& if_ext = std::get<instant_finality_extension>(itr->second);
const auto& if_ext = std::get<finality_extension>(itr->second);
return if_ext.qc_claim;
}

Expand Down
42 changes: 21 additions & 21 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ struct controller_impl {
}

void transition_to_savanna() {
assert(chain_head.header().contains_header_extension(instant_finality_extension::extension_id()));
assert(chain_head.header().contains_header_extension(finality_extension::extension_id()));
// copy head branch from legacy forkdb legacy to savanna forkdb
if (check_shutdown())
return;
Expand Down Expand Up @@ -1463,7 +1463,7 @@ struct controller_impl {
root_id = (*bitr)->id();

if constexpr (std::is_same_v<block_state_legacy_ptr, std::decay_t<decltype(*bitr)>>) {
if ((*bitr)->header.contains_header_extension(instant_finality_extension::extension_id())) {
if ((*bitr)->header.contains_header_extension(finality_extension::extension_id())) {
savanna_transition_required = true;
// Do not advance irreversible past IF Genesis Block
break;
Expand Down Expand Up @@ -1591,7 +1591,7 @@ struct controller_impl {
});
block_handle_accessor::apply_l<void>(chain_head, [&](const auto& head) { // chain_head is updated via replay_push_block
assert(!next->is_proper_svnn_block());
if (next->contains_header_extension(instant_finality_extension::extension_id())) {
if (next->contains_header_extension(finality_extension::extension_id())) {
assert(legacy_branch.empty() || head->block->previous == legacy_branch.back()->block->calculate_id());
legacy_branch.push_back(head);
// note if is_proper_svnn_block is not reached then transistion will happen live
Expand Down Expand Up @@ -1799,7 +1799,7 @@ struct controller_impl {

init(startup_t::snapshot);
block_handle_accessor::apply_l<void>(chain_head, [&](auto& head) {
if (block_states.second && head->header.contains_header_extension(instant_finality_extension::extension_id())) {
if (block_states.second && head->header.contains_header_extension(finality_extension::extension_id())) {
// snapshot generated in transition to savanna
if (fork_db.version_in_use() == fork_database::in_use_t::legacy) {
fork_db.switch_from_legacy(block_states.second);
Expand Down Expand Up @@ -2055,7 +2055,7 @@ struct controller_impl {
{
return block_handle_accessor::apply<block_state_pair>(chain_head, overloaded{
[&](const block_state_legacy_ptr& head) -> block_state_pair {
if (head->header.contains_header_extension(instant_finality_extension::extension_id())) {
if (head->header.contains_header_extension(finality_extension::extension_id())) {
// During transition to Savanna, we need to build Transition Savanna block
// from Savanna Genesis block
return { head, get_transition_savanna_block(head) };
Expand Down Expand Up @@ -3275,7 +3275,7 @@ struct controller_impl {
if (auto* dm_logger = get_deep_mind_logger(false)) {
block_handle_accessor::apply<void>(chain_head,
[&](const block_state_legacy_ptr& head) {
if (head->block->contains_header_extension(instant_finality_extension::extension_id())) {
if (head->block->contains_header_extension(finality_extension::extension_id())) {
auto bsp = get_transition_savanna_block(head);
assert(bsp);
assert(bsp->active_finalizer_policy);
Expand Down Expand Up @@ -3426,15 +3426,15 @@ 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(instant_finality_extension::extension_id())) {
if (bheader_exts.count(finality_extension::extension_id())) {
const auto& if_extension =
std::get<instant_finality_extension>(bheader_exts.lower_bound(instant_finality_extension::extension_id())->second);
std::get<finality_extension>(bheader_exts.lower_bound(finality_extension::extension_id())->second);
elog("b if: ${i}", ("i", if_extension));
}
flat_multimap<uint16_t, block_header_extension> abheader_exts = ab.validate_and_extract_header_extensions();
if (abheader_exts.count(instant_finality_extension::extension_id())) {
if (abheader_exts.count(finality_extension::extension_id())) {
const auto& if_extension =
std::get<instant_finality_extension>(abheader_exts.lower_bound(instant_finality_extension::extension_id())->second);
std::get<finality_extension>(abheader_exts.lower_bound(finality_extension::extension_id())->second);
elog("ab if: ${i}", ("i", if_extension));
}
}
Expand All @@ -3445,8 +3445,8 @@ 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(instant_finality_extension::extension_id()); if_entry != hexts.end()) {
auto& if_ext = std::get<instant_finality_extension>(if_entry->second);
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);

// get the matching qc extension if present
auto exts = b->validate_and_extract_extensions();
Expand Down Expand Up @@ -3711,14 +3711,14 @@ struct controller_impl {
});
}

// Verify QC claim made by instant_finality_extension in header extension
// Verify QC claim made by finality_extension in header extension
// and quorum_certificate_extension in block extension are valid.
// Called from net-threads. It is thread safe as signed_block is never modified
// after creation.
// -----------------------------------------------------------------------------
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 = instant_finality_extension::extension_id();
auto if_ext_id = finality_extension::extension_id();

// extract current block extension and previous header extension
auto block_exts = b->validate_and_extract_extensions();
Expand All @@ -3745,7 +3745,7 @@ struct controller_impl {
}

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

// If there is a header extension, but the previous block does not have a header extension,
Expand All @@ -3765,7 +3765,7 @@ struct controller_impl {
// ----------------------------------------------------------------------------------------
assert(header_ext && prev_header_ext);

const auto& prev_if_ext = std::get<instant_finality_extension>(*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;

// validate QC claim against previous block QC info
Expand Down Expand Up @@ -3832,7 +3832,7 @@ struct controller_impl {
block_handle create_block_state_i( ForkDB& forkdb, const block_id_type& id, const signed_block_ptr& b, const BS& prev ) {
constexpr bool savanna_mode = std::is_same_v<typename std::decay_t<BS>, block_state>;
if constexpr (savanna_mode) {
// Verify claim made by instant_finality_extension in block header extension and
// Verify claim made by finality_extension in block header extension and
// quorum_certificate_extension in block extension are valid.
// This is the only place the evaluation is done.
verify_qc_claim(id, b, prev);
Expand Down Expand Up @@ -4517,14 +4517,14 @@ struct controller_impl {
// (where root() is updated), like in SHiP case where it is called
// as a result receiving accepted_block signal.
// Search both root and legacy_branch for the first block having
// instant_finality_extension -- the Savanna Genesis Block.
// finality_extension -- the Savanna Genesis Block.
// Then start from the Savanna Genesis Block to create corresponding
// Savanna blocks.
if (legacy_root->header.contains_header_extension(instant_finality_extension::extension_id())) {
if (legacy_root->header.contains_header_extension(finality_extension::extension_id())) {
prev = block_state::create_if_genesis_block(*legacy_root);
} else {
for (; bitr != legacy_branch.rend(); ++bitr) {
if ((*bitr)->header.contains_header_extension(instant_finality_extension::extension_id())) {
if ((*bitr)->header.contains_header_extension(finality_extension::extension_id())) {
prev = block_state::create_if_genesis_block(*(*bitr));
++bitr;
break;
Expand Down Expand Up @@ -4561,7 +4561,7 @@ struct controller_impl {
[&](const block_state_legacy_ptr& head) -> std::optional<finality_data_t> {
// When in Legacy, if it is during transition to Savana, we need to
// build finality_data for the corresponding Savanna block
if (head->header.contains_header_extension(instant_finality_extension::extension_id())) {
if (head->header.contains_header_extension(finality_extension::extension_id())) {
// during transition
return get_transition_block_finality_data(head);
} else {
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/eosio/chain/abi_serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ namespace impl {
out(name, std::move(mvo));
}

static void add_block_header_instant_finality_extension( mutable_variant_object& mvo, const header_extension_multimap& header_exts );
static void add_block_header_finality_extension( mutable_variant_object& mvo, const header_extension_multimap& header_exts );

/**
* overload of to_variant_object for signed_block
Expand Down Expand Up @@ -679,7 +679,7 @@ namespace impl {
std::get<producer_schedule_change_extension>(header_exts.lower_bound(producer_schedule_change_extension::extension_id())->second);
mvo("new_producer_schedule", new_producer_schedule);
}
add_block_header_instant_finality_extension(mvo, header_exts);
add_block_header_finality_extension(mvo, header_exts);

mvo("producer_signature", block.producer_signature);
add(mvo, "transactions", block.transactions, resolver, ctx);
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/eosio/chain/block_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <eosio/chain/block_timestamp.hpp>
#include <eosio/chain/producer_schedule.hpp>
#include <eosio/chain/protocol_feature_activation.hpp>
#include <eosio/chain/finality/instant_finality_extension.hpp>
#include <eosio/chain/finality/finality_extension.hpp>

#include <optional>
#include <type_traits>
Expand All @@ -20,7 +20,7 @@ namespace eosio::chain {
using block_header_extension_types = detail::block_header_extension_types<
protocol_feature_activation,
producer_schedule_change_extension,
instant_finality_extension
finality_extension
>;

using block_header_extension = block_header_extension_types::block_header_extension_t;
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 @@ -4,7 +4,7 @@
#include <eosio/chain/protocol_feature_manager.hpp>
#include <eosio/chain/finality/quorum_certificate.hpp>
#include <eosio/chain/finality/finalizer_policy.hpp>
#include <eosio/chain/finality/instant_finality_extension.hpp>
#include <eosio/chain/finality/finality_extension.hpp>
#include <eosio/chain/chain_snapshot.hpp>
#include <future>

Expand Down
Loading

0 comments on commit 0a0cb71

Please sign in to comment.