Skip to content

Commit

Permalink
GH-2045 Add constructor for transition from block_state_legacy to blo…
Browse files Browse the repository at this point in the history
…ck_state. Add missing set of transactions in block.
  • Loading branch information
heifner committed Jan 14, 2024
1 parent a482982 commit 4e631ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
25 changes: 24 additions & 1 deletion libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <eosio/chain/block_state.hpp>
#include <eosio/chain/block_header_state_utils.hpp>
#include <eosio/chain/block_state_legacy.hpp>
#include <eosio/chain/exceptions.hpp>

namespace eosio::chain {
Expand All @@ -16,7 +17,29 @@ block_state::block_state(const block_header_state& bhs, deque<transaction_metada
, block(std::make_shared<signed_block>(signed_block_header{bhs.header})) // [greg todo] do we need signatures?
, pub_keys_recovered(true) // probably not needed
, cached_trxs(std::move(trx_metas))
{}
{
block->transactions = std::move(trx_receipts);
}

// Used for transition from dbpos to instant-finality
block_state::block_state(const block_state_legacy& bsp) {
block_header_state::id = bsp.id();
header = bsp.header;
activated_protocol_features = bsp.activated_protocol_features;
std::optional<block_header_extension> ext = bsp.block->extract_header_extension(instant_finality_extension::extension_id());
assert(ext); // required by current transistion mechanism
const auto& if_extension = std::get<instant_finality_extension>(*ext);
assert(if_extension.new_finalizer_policy); // required by current transistion mechanism
active_finalizer_policy = std::make_shared<finalizer_policy>(*if_extension.new_finalizer_policy);
active_proposer_policy = std::make_shared<proposer_policy>();
active_proposer_policy->active_time = bsp.timestamp();
active_proposer_policy->proposer_schedule = bsp.active_schedule;
header_exts = bsp.header_exts; // not needed, but copy over just in case
block = bsp.block;
validated = bsp.is_valid();
pub_keys_recovered = bsp._pub_keys_recovered;
cached_trxs = bsp._cached_trxs;
}

deque<transaction_metadata_ptr> block_state::extract_trxs_metas() {
pub_keys_recovered = false;
Expand Down
6 changes: 5 additions & 1 deletion libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

namespace eosio::chain {

struct block_state_legacy;

struct block_state : public block_header_state { // block_header_state provides parent link
// ------ data members -------------------------------------------------------------
signed_block_ptr block;
bool validated; // We have executed the block's trxs and verified that action merkle root (block id) matches.
bool validated = false; // We have executed the block's trxs and verified that action merkle root (block id) matches.
digest_type strong_digest; // finalizer_digest (strong, cached so we can quickly validate votes)
digest_type weak_digest; // finalizer_digest (weak, cached so we can quickly validate votes)
pending_quorum_certificate pending_qc; // where we accumulate votes we receive
Expand Down Expand Up @@ -47,6 +49,8 @@ struct block_state : public block_header_state { // block_header_state provi

block_state(const block_header_state& bhs, deque<transaction_metadata_ptr>&& trx_metas,
deque<transaction_receipt>&& trx_receipts);

explicit block_state(const block_state_legacy& bsp);
};

using block_state_ptr = std::shared_ptr<block_state>;
Expand Down

0 comments on commit 4e631ae

Please sign in to comment.