Skip to content

Commit

Permalink
make cached base_digest as an optional
Browse files Browse the repository at this point in the history
  • Loading branch information
linh2931 committed Mar 26, 2024
1 parent 35a040d commit f412147
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 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 @@ -303,11 +301,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
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

0 comments on commit f412147

Please sign in to comment.