Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ship_finality_info_support' into G…
Browse files Browse the repository at this point in the history
…H-2334-bls-serialization
  • Loading branch information
heifner committed Mar 27, 2024
2 parents 0fd2540 + 21de5c4 commit 3a65b3f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
10 changes: 5 additions & 5 deletions libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ block_state::block_state(const block_header_state& prev, signed_block_ptr b, con
, strong_digest(compute_finality_digest())
, weak_digest(create_weak_digest(strong_digest))
, pending_qc(prev.active_finalizer_policy->finalizers.size(), prev.active_finalizer_policy->threshold, prev.active_finalizer_policy->max_weak_sum_before_weak_final())
, base_digest(compute_base_digest())
{
// ASSUMPTION FROM controller_impl::apply_block = all untrusted blocks will have their signatures pre-validated here
if( !skip_validate_signee ) {
Expand All @@ -43,7 +42,6 @@ block_state::block_state(const block_header_state& bhs,
, pub_keys_recovered(true) // called by produce_block so signature recovery of trxs must have been done
, cached_trxs(std::move(trx_metas))
, action_mroot(action_mroot)
, base_digest(compute_base_digest())
{
block->transactions = std::move(trx_receipts);

Expand Down Expand Up @@ -95,7 +93,6 @@ block_state::block_state(const block_state_legacy& bsp, const digest_type& actio
pub_keys_recovered = bsp._pub_keys_recovered;
cached_trxs = bsp._cached_trxs;
action_mroot = action_mroot_svnn;
base_digest = compute_base_digest();
}

block_state::block_state(snapshot_detail::snapshot_block_state_v7&& sbs)
Expand Down Expand Up @@ -306,11 +303,14 @@ digest_type block_state::get_finality_mroot_claim(const qc_claim_t& qc_claim) co
return get_validation_mroot(next_core_metadata.final_on_strong_qc_block_num);
}

finality_data_t block_state::get_finality_data() const {
finality_data_t block_state::get_finality_data() {
if (!base_digest) {
base_digest = compute_base_digest(); // cache it
}
return {
// other fields take the default values set by finality_data_t definition
.action_mroot = action_mroot,
.base_digest = base_digest
.base_digest = *base_digest
};
}

Expand Down
7 changes: 1 addition & 6 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4123,12 +4123,7 @@ struct controller_impl {
}

std::optional<finality_data_t> head_finality_data() const {
// We cannot use apply_s here as it returns an empty `finality_data_t` in
// Legacy, which causes SHiP to generate a null `finality_data` log
// (we want no `finality_data` is generated at all).
return apply<std::optional<finality_data_t>>(chain_head,
overloaded{ [](const block_state_legacy_ptr& head) { return std::nullopt; },
[](const block_state_ptr& head) { return head->get_finality_data(); }});
return apply_s<std::optional<finality_data_t>>(chain_head, [](const block_state_ptr& head) { return head->get_finality_data(); });
}

uint32_t earliest_available_block_num() const {
Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ struct block_state : public block_header_state { // block_header_state provi
// ------ data members caching information available elsewhere ----------------------
bool pub_keys_recovered = false;
deque<transaction_metadata_ptr> cached_trxs;
digest_type action_mroot; // For base_digest sent to SHiP
digest_type base_digest; // For base_digest sent to SHiP
digest_type action_mroot; // For finality_data sent to SHiP
std::optional<digest_type> base_digest; // For finality_data sent to SHiP

// ------ private methods -----------------------------------------------------------
bool is_valid() const { return validated; }
Expand Down Expand Up @@ -120,7 +120,7 @@ struct block_state : public block_header_state { // block_header_state provi
digest_type get_finality_mroot_claim(const qc_claim_t& qc_claim) const;

// Returns finality_data of the current block
finality_data_t get_finality_data() const;
finality_data_t get_finality_data();

// vote_status
vote_status aggregate_vote(const vote_message& vote); // aggregate vote into pending_qc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct get_blocks_request_v0 {
};

struct get_blocks_request_v1 : get_blocks_request_v0 {
bool fetch_finality_data = false;;
bool fetch_finality_data = false;
};

struct get_blocks_ack_request_v0 {
Expand Down
6 changes: 3 additions & 3 deletions plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
// thread-safe
std::optional<chain::block_id_type> get_block_id(uint32_t block_num) {
if( trace_log ) {
if ( auto id = trace_log->get_block_id( block_num ); id )
if ( auto id = trace_log->get_block_id( block_num ) )
return id;
}
if( chain_state_log ) {
if( auto id = chain_state_log->get_block_id( block_num ); id )
if( auto id = chain_state_log->get_block_id( block_num ) )
return id;
}
if( finality_data_log ) {
if( auto id = finality_data_log->get_block_id( block_num ); id )
if( auto id = finality_data_log->get_block_id( block_num ) )
return id;
}
try {
Expand Down

0 comments on commit 3a65b3f

Please sign in to comment.