Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how block_states are constructed for transition to contain correct validation tree data #32

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ block_state::block_state(const block_header_state& prev, signed_block_ptr b, con
}
}

block_state::block_state(const block_header_state& prev, signed_block_ptr b, const protocol_feature_set& pfs,
const validator_t& validator, bool skip_validate_signee,
const digest_type& action_mroot_savanna)
: block_state(prev, b, pfs, validator, skip_validate_signee)
{
action_mroot = action_mroot_savanna;
}
heifner marked this conversation as resolved.
Show resolved Hide resolved

block_state::block_state(const block_header_state& bhs,
deque<transaction_metadata_ptr>&& trx_metas,
deque<transaction_receipt>&& trx_receipts,
Expand Down Expand Up @@ -250,6 +258,8 @@ void block_state::verify_qc(const valid_quorum_certificate& qc) const {
valid_t block_state::new_valid(const block_header_state& next_bhs, const digest_type& action_mroot, const digest_type& strong_digest) const {
assert(valid);
assert(next_bhs.core.last_final_block_num() >= core.last_final_block_num());
assert(action_mroot != digest_type() );
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
assert(strong_digest != digest_type() );

// Copy parent's validation_tree and validation_mroots.
auto start = next_bhs.core.last_final_block_num() - core.last_final_block_num();
Expand Down
17 changes: 8 additions & 9 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1348,12 +1348,14 @@ struct controller_impl {
block_state_ptr prev = forkdb.root();
assert(prev);
for (auto bitr = legacy_branch.rbegin(); bitr != legacy_branch.rend(); ++bitr) {
assert((*bitr)->action_mroot_savanna.has_value());
const bool skip_validate_signee = true; // validated already
auto new_bsp = std::make_shared<block_state>(
*prev,
(*bitr)->block,
protocol_features.get_protocol_feature_set(),
validator_t{}, skip_validate_signee);
validator_t{}, skip_validate_signee,
*((*bitr)->action_mroot_savanna));
transition_add_to_savanna_fork_db(forkdb, *bitr, new_bsp, prev);
prev = new_bsp;
}
Expand Down Expand Up @@ -1529,11 +1531,13 @@ struct controller_impl {
prev = block_state::create_if_genesis_block(*legacy_branch[0]);
} else {
const auto& bspl = legacy_branch[i];
assert(bspl->action_mroot_savanna.has_value());
auto new_bsp = std::make_shared<block_state>(
*prev,
bspl->block,
protocol_features.get_protocol_feature_set(),
validator_t{}, skip_validate_signee);
validator_t{}, skip_validate_signee,
*(bspl->action_mroot_savanna));
// legacy_branch is from head, all should be validated
assert(bspl->action_mroot_savanna);
// Create the valid structure for producing
Expand Down Expand Up @@ -4439,17 +4443,12 @@ struct controller_impl {
const bool skip_validate_signee = true; // validated already

for (; bitr != legacy_branch.rend(); ++bitr) {
assert((*bitr)->action_mroot_savanna.has_value());
auto new_bsp = std::make_shared<block_state>(
*prev,
(*bitr)->block,
protocol_features.get_protocol_feature_set(),
validator_t{}, skip_validate_signee);

// We only need action_mroot of the last block for finality_data
if ((bitr + 1) == legacy_branch.rend()) {
assert((*bitr)->action_mroot_savanna);
new_bsp->action_mroot = *((*bitr)->action_mroot_savanna);
}
validator_t{}, skip_validate_signee, *((*bitr)->action_mroot_savanna));

prev = new_bsp;
}
Expand Down
9 changes: 9 additions & 0 deletions libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ struct block_state : public block_header_state { // block_header_state provi
const block_signing_authority& valid_block_signing_authority,
const digest_type& action_mroot);

// This is used during transition to Savanna to construct a Savanna block state from
// a Legacy block state, specifically for building action_mroot from action_mroot_savanna.
block_state(const block_header_state& prev,
signed_block_ptr b,
const protocol_feature_set& pfs,
const validator_t& validator,
bool skip_validate_signee,
const digest_type& action_mroot_savanna);

static std::shared_ptr<block_state> create_if_genesis_block(const block_state_legacy& bsp);

explicit block_state(snapshot_detail::snapshot_block_state_v7&& sbs);
Expand Down
Loading