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

IF: Unification: Create new block_header_state and block_state #1941

Closed
Tracked by #1508
linh2931 opened this issue Nov 30, 2023 · 1 comment · Fixed by #1975 or #2013
Closed
Tracked by #1508

IF: Unification: Create new block_header_state and block_state #1941

linh2931 opened this issue Nov 30, 2023 · 1 comment · Fixed by #1975 or #2013
Assignees

Comments

@linh2931
Copy link
Member

linh2931 commented Nov 30, 2023

Add new block_header_state and block_state. Use the block_state in a new fork database.

The old code in block_header_state.{hpp,cpp} and block_state.{hpp,cpp} should have been moved to block_header_state_legacy.{hpp,cpp} and block_state_legacy.{hpp,cpp}, respectively, in #1940. For this issue, put the new code into a new block_header_state.{hpp,cpp} and block_state.{hpp,cpp} as appropriate.

@greg7mdp
Copy link
Contributor

greg7mdp commented Nov 30, 2023

Here is what we came up with in the meeting:

struct building_block_input {
   block_id_type                   previous;
   block_timestamp_type            timestamp;
   account_name                    producer;
   vector<digest_type>             new_protocol_feature_activations;
};
      
// this struct can be extracted from a building block
struct assembled_block_input : public building_block_input {
   digest_type                     transaction_mroot;
   digest_type                     action_mroot;
   std::optional<proposer_policy>  new_proposer_policy;
   std::optional<finalizer_policy> new_finalizer_policy;
   std::optional<quorum_certificate> qc;                 // assert(qc.block_height <= num_from_id(previous));
};

struct block_header_state {
   block_header                        header;
   protocol_feature_activation_set_ptr activated_protocol_features;

   block_header_state_core             core;
   incremental_merkle_tree             proposal_mtree;
   incremental_merkle_tree             finality_mtree;

   finalizer_policy_ptr                finalizer_policy; // finalizer set + threshold + generation, supports `digest()`
   proposer_policy_ptr                 proposer_policy;  // producer authority schedule, supports `digest()`
   
   flat_map<uint32_t, proposer_policy_ptr> proposer_policies;
   flat_map<uint32_t, finalizer_policy_ptr> finalizer_policies;

   digest_type          compute_finalizer_digest() const;
   block_timestamp_type timestamp() const;
   account_name         producer() const;
   block_id_type        previous() const;
   uint32_t             block_num() const { return num_from_id(previous()) + 1; }
   
   block_header_state   next(const assembled_block_input& data) const;
   
   // block descending from this need the provided qc in the block extension
   bool                 is_needed(const quorum_certificate& qc) const {
      return !core.last_qc_block_height || qc.block_height > *core.last_qc_block_height;
   }
};

struct block_state  {
   block_header_state         bhs; // provides parent link
   block_id_type              id;
   signed_block_ptr           block;
   digest_type                finalizer_digest;
   pending_quorum_certificate pending_qc;
};

namespace detail {
   f1(const block_header_state_core& prev, uint32_t last_qc_block_height, bool is_last_qc_strong) -> block_header_state_core;
   f2(const block_header_state& prev, const block_header_state_core &new_core, const sha256& new_static_leaf,
      const std::optional<sha256>& new_dynamic_leaf) -> block_header_state;std::optional<sha256> new_dynamic_leaf)
}
   struct quorum_certificate {
      uint32_t block_height;
      valid_quorum_certificate qc;
   };

[greg] I think that's right

struct block_header_state_core {
   uint32_t                last_final_block_height = 0;     // last irreversible (final) block.
   std::optional<uint32_t> final_on_strong_qc_block_height; // will become final if this header achives a strong QC.
   std::optional<uint32_t> last_qc_block_height;            // 

   block_header_state_core next(uint32_t last_qc_block_height, bool is_last_qc_strong) const;
};

@arhag arhag added 👍 lgtm and removed triage labels Nov 30, 2023
@BenjaminGormanPMP BenjaminGormanPMP added this to the Leap v6.0.0-rc1 milestone Nov 30, 2023
@greg7mdp greg7mdp linked a pull request Dec 11, 2023 that will close this issue
heifner added a commit that referenced this issue Dec 15, 2023
heifner added a commit that referenced this issue Dec 15, 2023
@arhag arhag linked a pull request Dec 20, 2023 that will close this issue
heifner added a commit that referenced this issue Dec 21, 2023
heifner added a commit that referenced this issue Dec 21, 2023
heifner added a commit that referenced this issue Dec 21, 2023
heifner added a commit that referenced this issue Dec 21, 2023
heifner added a commit that referenced this issue Dec 21, 2023
This reverts commit 26c61be.
heifner added a commit that referenced this issue Dec 21, 2023
heifner added a commit that referenced this issue Dec 21, 2023
heifner added a commit that referenced this issue Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
5 participants