From f41214726e8c7d9161b0c8438f2bcb0ba6a4f18d Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Tue, 26 Mar 2024 13:28:38 -0400 Subject: [PATCH] make cached base_digest as an optional --- libraries/chain/block_state.cpp | 9 +++++---- libraries/chain/include/eosio/chain/block_state.hpp | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index e519ac6533..fdf585189c 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -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 ) { @@ -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); @@ -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 }; } diff --git a/libraries/chain/include/eosio/chain/block_state.hpp b/libraries/chain/include/eosio/chain/block_state.hpp index 5aed16b5a7..76d19e1c0a 100644 --- a/libraries/chain/include/eosio/chain/block_state.hpp +++ b/libraries/chain/include/eosio/chain/block_state.hpp @@ -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 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 base_digest; // For finality_data sent to SHiP // ------ private methods ----------------------------------------------------------- bool is_valid() const { return validated; } @@ -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