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: SHiP changes to support IBC services (adding finality_data log) #2321

Merged
merged 21 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9eb67cc
implement controller::get_chain_head_finality_data() for SHiP
linh2931 Mar 16, 2024
d08e321
update ABI definition and types for the new finality_data log
linh2931 Mar 16, 2024
900fa22
Support finality_data in state_history_plugin
linh2931 Mar 17, 2024
0bda766
add new finality_data tests to state_history_plugin test
linh2931 Mar 17, 2024
54797c0
update ship_streamer tests for finality_data
linh2931 Mar 17, 2024
31e4100
rename get_chain_head_finality_data() to head_finality_data()
linh2931 Mar 17, 2024
84c80f9
Merge remote-tracking branch 'origin/hotstuff_integration' into ship_…
linh2931 Mar 18, 2024
3db6e06
cache action_mroot when producing blocks
linh2931 Mar 18, 2024
55717d1
make head_finality_data() return std::optional<finality_data_t>
linh2931 Mar 18, 2024
a3a0a6f
small refactoring in state_history_plugin.cpp
linh2931 Mar 18, 2024
bbe8735
Introduce get_blocks_request_v1 to support fetch_finality_data parame…
linh2931 Mar 20, 2024
b1b9642
remove leftover debugging statements
linh2931 Mar 20, 2024
0c6d290
Add finality_data ABI definition so clients have a standard type defi…
linh2931 Mar 21, 2024
79142ab
simplify std::visitor uses; cache base_digest; and minor changes for …
linh2931 Mar 21, 2024
e421b74
use cached base_digest actually; minor review changes
linh2931 Mar 26, 2024
417615d
Merge branch 'hotstuff_integration' into ship_finality_info_support
linh2931 Mar 26, 2024
35a040d
minor changes responding to review comments
linh2931 Mar 26, 2024
f412147
make cached base_digest as an optional
linh2931 Mar 26, 2024
5c82eec
remove an unnecessary compute_base_digest()
linh2931 Mar 26, 2024
21de5c4
use apply_s for head_finality_data to simplify code
linh2931 Mar 26, 2024
f1a1893
Merge branch 'hotstuff_integration' into ship_finality_info_support
linh2931 Mar 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ block_state::block_state(const block_header_state& bhs,
const std::optional<valid_t>& valid,
const std::optional<quorum_certificate>& qc,
const signer_callback_type& signer,
const block_signing_authority& valid_block_signing_authority)
const block_signing_authority& valid_block_signing_authority,
const digest_type& action_mroot)
: block_header_state(bhs)
, block(std::make_shared<signed_block>(signed_block_header{bhs.header}))
, strong_digest(compute_finality_digest())
Expand All @@ -40,6 +41,7 @@ block_state::block_state(const block_header_state& bhs,
, valid(valid)
, 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)
{
block->transactions = std::move(trx_receipts);

Expand Down Expand Up @@ -90,6 +92,8 @@ block_state::block_state(const block_state_legacy& bsp, const digest_type& actio
validated = bsp.is_valid();
pub_keys_recovered = bsp._pub_keys_recovered;
cached_trxs = bsp._cached_trxs;
action_mroot = action_mroot_svnn;
base_digest = compute_base_digest();
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
}

block_state::block_state(snapshot_detail::snapshot_block_state_v7&& sbs)
Expand Down Expand Up @@ -297,6 +301,17 @@ 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() {
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
};
}

void inject_additional_signatures( signed_block& b, const std::vector<signature_type>& additional_signatures)
{
if (!additional_signatures.empty()) {
Expand Down
21 changes: 18 additions & 3 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ struct assembled_block {
deque<transaction_receipt> trx_receipts; // Comes from building_block::pending_trx_receipts
std::optional<valid_t> valid; // Comes from assemble_block
std::optional<quorum_certificate> qc; // QC to add as block extension to new block
digest_type action_mroot;

block_header_state& get_bhs() { return bhs; }
};
Expand Down Expand Up @@ -370,7 +371,7 @@ struct assembled_block {
[&](assembled_block_if& ab) {
auto bsp = std::make_shared<block_state>(ab.bhs, std::move(ab.trx_metas),
std::move(ab.trx_receipts), ab.valid, ab.qc, signer,
valid_block_signing_authority);
valid_block_signing_authority, ab.action_mroot);
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
return completed_block{block_handle{std::move(bsp)}, {}};
}},
v);
Expand Down Expand Up @@ -760,6 +761,7 @@ struct building_block {
// have one.
if (!validating_bsp->valid) {
validating_bsp->valid = bb.parent.new_valid(bhs, action_mroot);
validating_bsp->action_mroot = action_mroot; // caching for constructing finality_data. Only needed when block is commited.
}
} else {
// Create the valid structure for producing
Expand All @@ -772,7 +774,8 @@ struct building_block {
std::move(bb.pending_trx_metas),
std::move(bb.pending_trx_receipts),
valid,
qc_data.qc
qc_data.qc,
action_mroot // caching for constructing finality_data.
};

return assembled_block{.v = std::move(ab)};
Expand Down Expand Up @@ -4119,6 +4122,15 @@ 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(); }});
}
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved

uint32_t earliest_available_block_num() const {
return (blog.first_block_num() != 0) ? blog.first_block_num() : fork_db_root_block_num();
}
Expand Down Expand Up @@ -4642,6 +4654,10 @@ const signed_block_ptr& controller::head_block()const {
return my->chain_head.block();
}

std::optional<finality_data_t> controller::head_finality_data() const {
return my->head_finality_data();
}

uint32_t controller::fork_db_head_block_num()const {
return my->fork_db_head_block_num();
}
Expand Down Expand Up @@ -4697,7 +4713,6 @@ time_point controller::last_irreversible_block_time() const {
return my->fork_db_root_timestamp().to_time_point();
}


const dynamic_global_property_object& controller::get_dynamic_global_properties()const {
return my->db.get<dynamic_global_property_object>();
}
Expand Down
19 changes: 18 additions & 1 deletion libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ struct valid_t {
std::vector<digest_type> validation_mroots;
};

// This is mostly used by SHiP to stream finality_data
struct finality_data_t {
uint32_t major_version{light_header_protocol_version_major};
uint32_t minor_version{light_header_protocol_version_minor};
uint32_t active_finalizer_policy_generation{0};
digest_type action_mroot{};
digest_type base_digest{};
};

struct block_state : public block_header_state { // block_header_state provides parent link
// ------ data members -------------------------------------------------------------
signed_block_ptr block;
Expand All @@ -69,6 +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 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 All @@ -81,6 +92,7 @@ struct block_state : public block_header_state { // block_header_state provi
friend struct fc::reflector<block_state>;
friend struct controller_impl;
friend struct completed_block;
friend struct building_block;
public:
// ------ functions -----------------------------------------------------------------
const block_id_type& id() const { return block_header_state::id(); }
Expand All @@ -107,6 +119,9 @@ struct block_state : public block_header_state { // block_header_state provi
// Returns finality_mroot_claim of the current block
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();

// vote_status
vote_status aggregate_vote(const vote_message& vote); // aggregate vote into pending_qc
void verify_qc(const valid_quorum_certificate& qc) const; // verify given qc is valid with respect block_state
Expand All @@ -128,7 +143,8 @@ struct block_state : public block_header_state { // block_header_state provi
const std::optional<valid_t>& valid,
const std::optional<quorum_certificate>& qc,
const signer_callback_type& signer,
const block_signing_authority& valid_block_signing_authority);
const block_signing_authority& valid_block_signing_authority,
const digest_type& action_mroot);

block_state(const block_state_legacy& bsp, const digest_type& action_mroot_svnn);

Expand All @@ -149,4 +165,5 @@ using block_state_pair = std::pair<std::shared_ptr<block_state_legacy>, blo
// not exporting pending_qc or valid_qc
FC_REFLECT( eosio::chain::valid_t::finality_leaf_node_t, (major_version)(minor_version)(block_num)(finality_digest)(action_mroot) )
FC_REFLECT( eosio::chain::valid_t, (validation_tree)(validation_mroots))
FC_REFLECT( eosio::chain::finality_data_t, (major_version)(minor_version)(active_finalizer_policy_generation)(action_mroot)(base_digest))
FC_REFLECT_DERIVED( eosio::chain::block_state, (eosio::chain::block_header_state), (block)(strong_digest)(weak_digest)(pending_qc)(valid_qc)(valid)(validated) )
3 changes: 3 additions & 0 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ namespace eosio::chain {
const signed_block_ptr& head_block()const;
// returns nullptr after instant finality enabled
block_state_legacy_ptr head_block_state_legacy()const;
// returns finality_data associated with chain head for SHiP when in Savanna,
// std::nullopt in Legacy
std::optional<finality_data_t> head_finality_data() const;

uint32_t fork_db_head_block_num()const;
block_id_type fork_db_head_block_id()const;
Expand Down
27 changes: 25 additions & 2 deletions libraries/state_history/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ extern const char* const state_history_plugin_abi = R"({
{ "name": "fetch_deltas", "type": "bool" }
]
},
{
"name": "get_blocks_request_v1", "fields": [
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
{ "name": "start_block_num", "type": "uint32" },
{ "name": "end_block_num", "type": "uint32" },
{ "name": "max_messages_in_flight", "type": "uint32" },
{ "name": "have_positions", "type": "block_position[]" },
{ "name": "irreversible_only", "type": "bool" },
{ "name": "fetch_block", "type": "bool" },
{ "name": "fetch_traces", "type": "bool" },
{ "name": "fetch_deltas", "type": "bool" },
{ "name": "fetch_finality_data", "type": "bool" }
]
},
{
"name": "get_blocks_ack_request_v0", "fields": [
{ "name": "num_messages", "type": "uint32" }
Expand All @@ -46,7 +59,8 @@ extern const char* const state_history_plugin_abi = R"({
{ "name": "prev_block", "type": "block_position?" },
{ "name": "block", "type": "bytes?" },
{ "name": "traces", "type": "bytes?" },
{ "name": "deltas", "type": "bytes?" }
{ "name": "deltas", "type": "bytes?" },
{ "name": "finality_data", "type": "bytes?" }
]
},
{
Expand Down Expand Up @@ -546,13 +560,22 @@ extern const char* const state_history_plugin_abi = R"({
{ "type": "uint32", "name": "account_cpu_usage_average_window" },
{ "type": "uint32", "name": "account_net_usage_average_window" }
]
},
{
"name": "finality_data", "fields": [
{ "name": "major_version", "type": "uint32" },
{ "name": "minor_version", "type": "uint32" },
{ "name": "active_finalizer_policy_generation", "type": "uint32" },
{ "name": "action_mroot", "type": "checksum256" },
{ "name": "base_digest", "type": "checksum256" }
]
}
],
"types": [
{ "new_type_name": "transaction_id", "type": "checksum256" }
],
"variants": [
{ "name": "request", "types": ["get_status_request_v0", "get_blocks_request_v0", "get_blocks_ack_request_v0"] },
{ "name": "request", "types": ["get_status_request_v0", "get_blocks_request_v0", "get_blocks_request_v1", "get_blocks_ack_request_v0"] },
{ "name": "result", "types": ["get_status_result_v0", "get_blocks_result_v0"] },

{ "name": "action_receipt", "types": ["action_receipt_v0"] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ datastream<ST>& operator<<(datastream<ST>& ds, const eosio::state_history::get_b
history_pack_big_bytes(ds, obj.block);
history_pack_big_bytes(ds, obj.traces);
history_pack_big_bytes(ds, obj.deltas);
history_pack_big_bytes(ds, obj.finality_data);
return ds;
}

Expand Down
11 changes: 9 additions & 2 deletions libraries/state_history/include/eosio/state_history/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ struct get_blocks_request_v0 {
bool fetch_deltas = false;
};

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

struct get_blocks_ack_request_v0 {
uint32_t num_messages = 0;
};
Expand All @@ -119,9 +123,11 @@ struct get_blocks_result_base {
struct get_blocks_result_v0 : get_blocks_result_base {
std::optional<bytes> traces;
std::optional<bytes> deltas;
std::optional<bytes> finality_data;
};

using state_request = std::variant<get_status_request_v0, get_blocks_request_v0, get_blocks_ack_request_v0>;
using state_request = std::variant<get_status_request_v0, get_blocks_request_v0, get_blocks_request_v1, get_blocks_ack_request_v0>;
using get_blocks_request = std::variant<get_blocks_request_v0, get_blocks_request_v1>;
using state_result = std::variant<get_status_result_v0, get_blocks_result_v0>;

} // namespace state_history
Expand All @@ -133,7 +139,8 @@ FC_REFLECT(eosio::state_history::block_position, (block_num)(block_id));
FC_REFLECT_EMPTY(eosio::state_history::get_status_request_v0);
FC_REFLECT(eosio::state_history::get_status_result_v0, (head)(last_irreversible)(trace_begin_block)(trace_end_block)(chain_state_begin_block)(chain_state_end_block)(chain_id));
FC_REFLECT(eosio::state_history::get_blocks_request_v0, (start_block_num)(end_block_num)(max_messages_in_flight)(have_positions)(irreversible_only)(fetch_block)(fetch_traces)(fetch_deltas));
FC_REFLECT_DERIVED(eosio::state_history::get_blocks_request_v1, (eosio::state_history::get_blocks_request_v0), (fetch_finality_data));
FC_REFLECT(eosio::state_history::get_blocks_ack_request_v0, (num_messages));
FC_REFLECT(eosio::state_history::get_blocks_result_base, (head)(last_irreversible)(this_block)(prev_block)(block));
FC_REFLECT_DERIVED(eosio::state_history::get_blocks_result_v0, (eosio::state_history::get_blocks_result_base), (traces)(deltas));
FC_REFLECT_DERIVED(eosio::state_history::get_blocks_result_v0, (eosio::state_history::get_blocks_result_base), (traces)(deltas)(finality_data));
// clang-format on
Loading
Loading