Skip to content

Commit

Permalink
GH-2057 Rename result to next_header_state
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Mar 19, 2024
1 parent b8a772c commit f00fd32
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,63 +76,63 @@ 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

void finish_next(const block_header_state& prev,
block_header_state& result,
block_header_state& next_header_state,
vector<digest_type> new_protocol_feature_activations,
std::shared_ptr<proposer_policy> new_proposer_policy,
qc_claim_t qc_claim) {

// activated protocol features
// ---------------------------
if (!new_protocol_feature_activations.empty()) {
result.activated_protocol_features = std::make_shared<protocol_feature_activation_set>(
next_header_state.activated_protocol_features = std::make_shared<protocol_feature_activation_set>(
*prev.activated_protocol_features, std::move(new_protocol_feature_activations));
} else {
result.activated_protocol_features = prev.activated_protocol_features;
next_header_state.activated_protocol_features = prev.activated_protocol_features;
}

// proposer policy
// ---------------
result.active_proposer_policy = prev.active_proposer_policy;
next_header_state.active_proposer_policy = prev.active_proposer_policy;

if(!prev.proposer_policies.empty()) {
auto it = prev.proposer_policies.begin();
// +1 since this is called after the block is built, this will be the active schedule for the next block
if (it->first.slot <= result.header.timestamp.slot + 1) {
result.active_proposer_policy = it->second;
result.proposer_policies = { ++it, prev.proposer_policies.end() };
if (it->first.slot <= next_header_state.header.timestamp.slot + 1) {
next_header_state.active_proposer_policy = it->second;
next_header_state.proposer_policies = { ++it, prev.proposer_policies.end() };
} else {
result.proposer_policies = prev.proposer_policies;
next_header_state.proposer_policies = prev.proposer_policies;
}
}

if (new_proposer_policy) {
// called when assembling the block
result.proposer_policies[new_proposer_policy->active_time] = std::move(new_proposer_policy);
next_header_state.proposer_policies[new_proposer_policy->active_time] = std::move(new_proposer_policy);
}

// finalizer policy
// ----------------
result.active_finalizer_policy = prev.active_finalizer_policy;
next_header_state.active_finalizer_policy = prev.active_finalizer_policy;

// finality_core
// -------------
block_ref parent_block {
.block_id = prev.block_id,
.timestamp = prev.timestamp()
};
result.core = prev.core.next(parent_block, qc_claim);
next_header_state.core = prev.core.next(parent_block, qc_claim);

// Finally update block id from header
// -----------------------------------
result.block_id = result.header.calculate_id();
next_header_state.block_id = next_header_state.header.calculate_id();
}

block_header_state block_header_state::next(block_header_state_input& input) const {
block_header_state result;
block_header_state next_header_state;

// header
// ------
result.header = {
next_header_state.header = {
.timestamp = input.timestamp, // [greg todo] do we have to do the slot++ stuff from the legacy version?
.producer = input.producer,
.confirmed = 0,
Expand All @@ -149,22 +149,22 @@ block_header_state block_header_state::next(block_header_state_input& input) con
input.new_proposer_policy};

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

// add protocol_feature_activation extension
// -----------------------------------------
if (!input.new_protocol_feature_activations.empty()) {
uint16_t ext_id = protocol_feature_activation::extension_id();
protocol_feature_activation pfa_ext{.protocol_features = input.new_protocol_feature_activations};

emplace_extension(result.header.header_extensions, ext_id, fc::raw::pack(pfa_ext));
result.header_exts.emplace(ext_id, std::move(pfa_ext));
emplace_extension(next_header_state.header.header_extensions, ext_id, fc::raw::pack(pfa_ext));
next_header_state.header_exts.emplace(ext_id, std::move(pfa_ext));
}

finish_next(*this, result, std::move(input.new_protocol_feature_activations), std::move(input.new_proposer_policy), input.most_recent_ancestor_with_qc);
finish_next(*this, next_header_state, std::move(input.new_protocol_feature_activations), std::move(input.new_proposer_policy), input.most_recent_ancestor_with_qc);

return result;
return next_header_state;
}

/**
Expand All @@ -180,10 +180,10 @@ block_header_state block_header_state::next(const signed_block_header& h, valida
EOS_ASSERT( h.producer == producer, wrong_producer, "wrong producer specified" );
EOS_ASSERT( !h.new_producers, producer_schedule_exception, "Block header contains legacy producer schedule outdated by activation of WTMsig Block Signatures" );

block_header_state result;
result.header = static_cast<const block_header&>(h);
result.header_exts = h.validate_and_extract_header_extensions();
auto& exts = result.header_exts;
block_header_state next_header_state;
next_header_state.header = static_cast<const block_header&>(h);
next_header_state.header_exts = h.validate_and_extract_header_extensions();
auto& exts = next_header_state.header_exts;

// retrieve protocol_feature_activation from incoming block header extension
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -214,9 +214,9 @@ block_header_state block_header_state::next(const signed_block_header& h, valida
("n", no_finality_tree_associated)("e", h.action_mroot.empty())("f", next_core_metadata.final_on_strong_qc_block_num));
};

finish_next(*this, result, std::move(new_protocol_feature_activations), if_ext.new_proposer_policy, if_ext.qc_claim);
finish_next(*this, next_header_state, std::move(new_protocol_feature_activations), if_ext.new_proposer_policy, if_ext.qc_claim);

return result;
return next_header_state;
}

} // namespace eosio::chain
Expand Down

0 comments on commit f00fd32

Please sign in to comment.