Skip to content

Commit

Permalink
Merge branch 'hotstuff_integration' of github.com:AntelopeIO/leap int…
Browse files Browse the repository at this point in the history
…o gh_2285
  • Loading branch information
greg7mdp committed Mar 15, 2024
2 parents af8d8e6 + 8a548e3 commit 846703a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 25 deletions.
28 changes: 19 additions & 9 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,14 @@ struct controller_impl {
});
}

block_state_pair get_block_state_to_snapshot() const
{
return apply<block_state_pair>(
chain_head,
overloaded{[](const block_state_legacy_ptr& head) { return block_state_pair{ head, {} }; },
[](const block_state_ptr& head) { return block_state_pair{ {}, head }; }});
}

void add_to_snapshot( const snapshot_writer_ptr& snapshot ) {
// clear in case the previous call to clear did not finish in time of deadline
clear_expired_input_transactions( fc::time_point::maximum() );
Expand All @@ -1802,10 +1810,10 @@ struct controller_impl {
});

apply<void>(chain_head, [&](const auto& head) {
snapshot_detail::snapshot_block_state_variant_v7 block_state_variant(*head);
snapshot_detail::snapshot_block_state_data_v7 block_state_data(get_block_state_to_snapshot());

snapshot->write_section("eosio::chain::block_state", [&]( auto& section ) {
section.add_row(block_state_variant, db);
section.add_row(block_state_data, db);
});
});

Expand Down Expand Up @@ -1857,19 +1865,21 @@ struct controller_impl {

auto read_block_state_section = [&](auto& forkdb) { /// load and upgrade the block header state
using namespace snapshot_detail;
using v7 = snapshot_block_state_variant_v7;
using v7 = snapshot_block_state_data_v7;

if (header.version >= v7::minimum_version) {
// loading a snapshot saved by Leap 6.0 and above.
// -----------------------------------------------
if (std::clamp(header.version, v7::minimum_version, v7::maximum_version) == header.version ) {
snapshot->read_section("eosio::chain::block_state", [this]( auto &section ){
v7 block_state_variant;
section.read_row(block_state_variant, db);
std::visit(overloaded{
[&](snapshot_block_state_legacy_v7&& sbs) { chain_head = block_handle{std::make_shared<block_state_legacy>(std::move(sbs))}; },
[&](snapshot_block_state_v7&& sbs) { chain_head = block_handle{std::make_shared<block_state>(std::move(sbs))}; }},
std::move(block_state_variant.v));
v7 block_state_data;
section.read_row(block_state_data, db);
assert(block_state_data.bs_l || block_state_data.bs);
// todo: during the transition phase, both may be set. Restore appropriately!
if (block_state_data.bs_l)
chain_head = block_handle{std::make_shared<block_state_legacy>(std::move(*block_state_data.bs_l))};
else
chain_head = block_handle{std::make_shared<block_state>(std::move(*block_state_data.bs))};
});
} else {
EOS_THROW(snapshot_exception, "Unsupported block_state version");
Expand Down
3 changes: 2 additions & 1 deletion libraries/chain/fork_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ namespace eosio::chain {
}

template <class BSP>
void fork_database_impl<BSP>::add_impl(const bsp_t& n, mark_valid_t mark_valid, ignore_duplicate_t ignore_duplicate, bool validate, validator_t& validator) {
void fork_database_impl<BSP>::add_impl(const bsp_t& n, mark_valid_t mark_valid, ignore_duplicate_t ignore_duplicate,
bool validate, validator_t& validator) {
EOS_ASSERT( root, fork_database_exception, "root not yet set" );
EOS_ASSERT( n, fork_database_exception, "attempt to add null block state" );

Expand Down
5 changes: 2 additions & 3 deletions libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ struct block_state : public block_header_state { // block_header_state provi
void verify_signee(const std::vector<signature_type>& additional_signatures, const block_signing_authority& valid_block_signing_authority) const;
};

using block_state_ptr = std::shared_ptr<block_state>;

using block_state_ptr = std::shared_ptr<block_state>;
using block_state_variant_t = std::variant<std::shared_ptr<block_state_legacy>, block_state_ptr>;
using block_state_pair = std::pair<std::shared_ptr<block_state_legacy>, block_state_ptr>;


} // namespace eosio::chain

// not exporting pending_qc or valid_qc
Expand Down
26 changes: 14 additions & 12 deletions libraries/chain/include/eosio/chain/snapshot_detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,22 @@ namespace eosio::chain::snapshot_detail {
{}
};

struct snapshot_block_state_variant_v7 {
struct snapshot_block_state_data_v7 {
static constexpr uint32_t minimum_version = 7;
static constexpr uint32_t maximum_version = 7;

std::variant<snapshot_block_state_legacy_v7, snapshot_block_state_v7> v;
std::optional<snapshot_block_state_legacy_v7> bs_l;
std::optional<snapshot_block_state_v7> bs;

snapshot_block_state_variant_v7() = default;
snapshot_block_state_data_v7() = default;

explicit snapshot_block_state_variant_v7(const block_state& bs)
: v(snapshot_block_state_v7(bs))
{}

explicit snapshot_block_state_variant_v7(const block_state_legacy& bs)
: v(snapshot_block_state_legacy_v7(bs))
{}
explicit snapshot_block_state_data_v7(const block_state_pair& p)
{
if (p.first)
bs_l = snapshot_block_state_legacy_v7(*p.first);
if (p.second)
bs = snapshot_block_state_v7(*p.second);
}
};

}
Expand Down Expand Up @@ -214,6 +215,7 @@ FC_REFLECT( eosio::chain::snapshot_detail::snapshot_block_state_v7,
(valid)
)

FC_REFLECT( eosio::chain::snapshot_detail::snapshot_block_state_variant_v7,
(v)
FC_REFLECT( eosio::chain::snapshot_detail::snapshot_block_state_data_v7,
(bs_l)
(bs)
)
Binary file modified unittests/snapshots/snap_v7.bin.gz
Binary file not shown.
Binary file modified unittests/snapshots/snap_v7.bin.json.gz
Binary file not shown.
Binary file modified unittests/snapshots/snap_v7.json.gz
Binary file not shown.

0 comments on commit 846703a

Please sign in to comment.