Skip to content

Commit

Permalink
GH-2348 Calculate IF Genesis Block finality digest correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Mar 28, 2024
1 parent aaa9284 commit 86cca8e
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,28 @@ block_state_ptr block_state::create_if_genesis_block(const block_state_legacy& b
result.activated_protocol_features = bsp.activated_protocol_features;
result.core = finality_core::create_core_for_genesis_block(bsp.block_num());

assert(result.block->contains_header_extension(instant_finality_extension::extension_id())); // required by transition mechanism
instant_finality_extension if_ext = result.block->extract_header_extension<instant_finality_extension>();
assert(if_ext.new_finalizer_policy); // required by transition mechanism
result.active_finalizer_policy = std::make_shared<finalizer_policy>(*if_ext.new_finalizer_policy);
result.active_proposer_policy = std::make_shared<proposer_policy>();
result.active_proposer_policy->active_time = bsp.timestamp();
result.active_proposer_policy->proposer_schedule = bsp.active_schedule;
// TODO: https://github.com/AntelopeIO/leap/issues/2057
// TODO: Do not aggregate votes on blocks created from block_state_legacy. This can be removed when #2057 complete.
result.pending_qc = pending_quorum_certificate{result.active_finalizer_policy->finalizers.size(), result.active_finalizer_policy->threshold, result.active_finalizer_policy->max_weak_sum_before_weak_final()};
result.validated = bsp.is_valid();
result.pub_keys_recovered = bsp._pub_keys_recovered;
result.cached_trxs = bsp._cached_trxs;

// Calculate Merkle tree root in Savanna way so that it is stored in Leaf Node when building block_state.
auto digests = *bsp.action_receipt_digests_savanna;
auto action_mroot_svnn = calculate_merkle(std::move(digests));
result.action_mroot = action_mroot_svnn;
// built leaf_node and validation_tree
valid_t::finality_leaf_node_t leaf_node {
.block_num = bsp.block_num(),
.finality_digest = digest_type{},
.finality_digest = result.compute_finality_digest(),
.action_mroot = action_mroot_svnn
};
incremental_merkle_tree validation_tree;
Expand All @@ -85,21 +100,6 @@ block_state_ptr block_state::create_if_genesis_block(const block_state_legacy& b
.validation_mroots = { validation_tree.get_root() }
};

assert(result.block->contains_header_extension(instant_finality_extension::extension_id())); // required by transition mechanism
instant_finality_extension if_ext = result.block->extract_header_extension<instant_finality_extension>();
assert(if_ext.new_finalizer_policy); // required by transition mechanism
result.active_finalizer_policy = std::make_shared<finalizer_policy>(*if_ext.new_finalizer_policy);
result.active_proposer_policy = std::make_shared<proposer_policy>();
result.active_proposer_policy->active_time = bsp.timestamp();
result.active_proposer_policy->proposer_schedule = bsp.active_schedule;
// TODO: https://github.com/AntelopeIO/leap/issues/2057
// TODO: Do not aggregate votes on blocks created from block_state_legacy. This can be removed when #2057 complete.
result.pending_qc = pending_quorum_certificate{result.active_finalizer_policy->finalizers.size(), result.active_finalizer_policy->threshold, result.active_finalizer_policy->max_weak_sum_before_weak_final()};
result.validated = bsp.is_valid();
result.pub_keys_recovered = bsp._pub_keys_recovered;
result.cached_trxs = bsp._cached_trxs;
result.action_mroot = action_mroot_svnn;

return result_ptr;
}

Expand Down

0 comments on commit 86cca8e

Please sign in to comment.