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: Create new efficient incremental Merkle tree #2361

Merged
merged 30 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
54e88ed
Fix misspelled function name, and incorrect name `clz_power_2`
greg7mdp Mar 25, 2024
cce8e5c
File reorg to separate `legacy` and `optimized` merkle implementation
greg7mdp Mar 25, 2024
c775d7a
Make `merkle` names consistent and deprecate `canonical`
greg7mdp Mar 25, 2024
f7364c5
Move `merkle` types into their correct headers.
greg7mdp Mar 25, 2024
7bab066
Merge branch 'hotstuff_integration' of github.com:AntelopeIO/leap int…
greg7mdp Mar 27, 2024
fd02885
Initial new merkle tree implementation.
greg7mdp Mar 28, 2024
afd97ca
Add stack depth check.
greg7mdp Mar 28, 2024
bcb2545
Add alternative to `std::popcount` for cdt which does not support C++…
greg7mdp Mar 29, 2024
a09fd7d
Remove destructive version of `calculate_merkle`.
greg7mdp Mar 29, 2024
8ea41a4
Add alternative to `std::bit_floor` for cdt which does not support C+…
greg7mdp Mar 29, 2024
d2f1c92
Add perf tests, fix warning.
greg7mdp Mar 29, 2024
12e6a53
Add multithreading to , add test, remove stack size debug code
greg7mdp Mar 29, 2024
da5d431
Merge branch 'hotstuff_integration' of github.com:AntelopeIO/leap int…
greg7mdp Mar 29, 2024
209090e
Simplify `canonical` template param from `incremental_merkle_tree_leg…
greg7mdp Mar 29, 2024
8ed91d9
Update comments.
greg7mdp Mar 29, 2024
fb6f69e
Merge branch 'hotstuff_integration' of github.com:AntelopeIO/leap int…
greg7mdp Mar 29, 2024
264dffe
Merge branch 'hotstuff_integration' of github.com:AntelopeIO/leap int…
greg7mdp Mar 29, 2024
0663a3d
Add `num_digests_appended()` method, not used but pretty cool doc on …
greg7mdp Mar 29, 2024
08c5186
Reduce number of boost test assertions.
greg7mdp Mar 29, 2024
ac2f980
Small cleanup of the test.
greg7mdp Mar 30, 2024
b5f522f
Cleanup messages from performance test.
greg7mdp Mar 30, 2024
198e512
Finish removing references to `canonical`.
greg7mdp Mar 30, 2024
89e3d8d
Address PR comments, templatize `calculate_merkle`.
greg7mdp Mar 30, 2024
b86a162
Remove `post_async_task` for the `calculate_merkle` of action/transac…
greg7mdp Mar 30, 2024
f2a3c27
Update `calculate_merkle_pow2` to use 2 threads for sizes from 256 to…
greg7mdp Mar 30, 2024
808d586
Update comment.
greg7mdp Mar 30, 2024
95f06f2
Fix gcc-11 compiler warnings.
greg7mdp Mar 30, 2024
064717e
Fix compilation error with gcc10.
greg7mdp Mar 30, 2024
54e5d70
Fix typo.
greg7mdp Mar 30, 2024
82178a7
Add class comment for `incremental_merkle_tree`.
greg7mdp Mar 30, 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
1 change: 0 additions & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ target_include_directories(eosio_rapidjson INTERFACE ../rapidjson/include)

## SORT .cpp by most likely to change / break compile
add_library( eosio_chain
merkle.cpp
name.cpp
transaction.cpp
block.cpp
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ block_state_ptr block_state::create_if_genesis_block(const block_state_legacy& b
result.valid_qc = {}; // best qc received from the network inside block extension, empty until first savanna proper IF block

// Calculate Merkle tree root in Savanna way so that it is stored in Leaf Node when building block_state.
auto digests = *bsp.action_receipt_digests_savanna;
auto action_mroot_svnn = calculate_merkle(std::move(digests));
const auto& digests = *bsp.action_receipt_digests_savanna;
auto action_mroot_svnn = calculate_merkle(digests);

// build leaf_node and validation_tree
valid_t::finality_leaf_node_t leaf_node {
Expand Down
31 changes: 15 additions & 16 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,13 @@ struct building_block {
auto [transaction_mroot, action_mroot] = std::visit(
overloaded{[&](digests_t& trx_receipts) { // calculate the two merkle roots in separate threads
auto trx_merkle_fut =
post_async_task(ioc, [&]() { return legacy_merkle(std::move(trx_receipts)); });
post_async_task(ioc, [&]() { return calculate_merkle_legacy(std::move(trx_receipts)); });
auto action_merkle_fut =
post_async_task(ioc, [&]() { return legacy_merkle(std::move(*action_receipts.digests_l)); });
post_async_task(ioc, [&]() { return calculate_merkle_legacy(std::move(*action_receipts.digests_l)); });
return std::make_pair(trx_merkle_fut.get(), action_merkle_fut.get());
},
[&](const checksum256_type& trx_checksum) {
return std::make_pair(trx_checksum, legacy_merkle(std::move(*action_receipts.digests_l)));
return std::make_pair(trx_checksum, calculate_merkle_legacy(std::move(*action_receipts.digests_l)));
}},
trx_mroot_or_receipt_digests());

Expand All @@ -706,15 +706,14 @@ struct building_block {
[&](building_block_if& bb) -> assembled_block {
// compute the action_mroot and transaction_mroot
auto [transaction_mroot, action_mroot] = std::visit(
overloaded{[&](digests_t& trx_receipts) { // calculate the two merkle roots in separate threads
auto trx_merkle_fut =
post_async_task(ioc, [&]() { return calculate_merkle(std::move(trx_receipts)); });
auto action_merkle_fut =
post_async_task(ioc, [&]() { return calculate_merkle(std::move(*action_receipts.digests_s)); });
return std::make_pair(trx_merkle_fut.get(), action_merkle_fut.get());
overloaded{[&](digests_t& trx_receipts) {
// calculate_merkle takes 3.2ms for 50,000 digests (legacy version took 11.1ms)
return std::make_pair(calculate_merkle(trx_receipts),
calculate_merkle(*action_receipts.digests_s));
},
[&](const checksum256_type& trx_checksum) {
return std::make_pair(trx_checksum, calculate_merkle(std::move(*action_receipts.digests_s)));
return std::make_pair(trx_checksum,
calculate_merkle(*action_receipts.digests_s));
}},
trx_mroot_or_receipt_digests());

Expand Down Expand Up @@ -1308,8 +1307,8 @@ struct controller_impl {
// IRREVERSIBLE applies (validates) blocks when irreversible, new_valid will be done after apply in log_irreversible
assert(read_mode == db_read_mode::IRREVERSIBLE || legacy->action_receipt_digests_savanna);
if (legacy->action_receipt_digests_savanna) {
auto digests = *legacy->action_receipt_digests_savanna;
auto action_mroot = calculate_merkle(std::move(digests));
const auto& digests = *legacy->action_receipt_digests_savanna;
auto action_mroot = calculate_merkle(digests);
// Create the valid structure for producing
new_bsp->valid = prev->new_valid(*new_bsp, action_mroot, new_bsp->strong_digest);
}
Expand Down Expand Up @@ -1522,8 +1521,8 @@ struct controller_impl {
validator_t{}, skip_validate_signee);
// legacy_branch is from head, all should be validated
assert(bspl->action_receipt_digests_savanna);
auto digests = *bspl->action_receipt_digests_savanna;
auto action_mroot = calculate_merkle(std::move(digests));
const auto& digests = *bspl->action_receipt_digests_savanna;
auto action_mroot = calculate_merkle(digests);
// Create the valid structure for producing
new_bsp->valid = prev->new_valid(*new_bsp, action_mroot, new_bsp->strong_digest);
prev = new_bsp;
Expand Down Expand Up @@ -4066,9 +4065,9 @@ struct controller_impl {
// @param if_active true if instant finality is active
static checksum256_type calc_merkle( deque<digest_type>&& digests, bool if_active ) {
if (if_active) {
return calculate_merkle( std::move(digests) );
return calculate_merkle( digests );
} else {
return legacy_merkle( std::move(digests) );
return calculate_merkle_legacy( std::move(digests) );
}
}

Expand Down
1 change: 0 additions & 1 deletion libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <eosio/chain/block_header.hpp>
#include <eosio/chain/finality_core.hpp>
#include <eosio/chain/incremental_merkle.hpp>
#include <eosio/chain/protocol_feature_manager.hpp>
#include <eosio/chain/hotstuff/hotstuff.hpp>
#include <eosio/chain/hotstuff/finalizer_policy.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <eosio/chain/block_header.hpp>
#include <eosio/chain/incremental_merkle.hpp>
#include <eosio/chain/incremental_merkle_legacy.hpp>
#include <eosio/chain/protocol_feature_manager.hpp>
#include <eosio/chain/chain_snapshot.hpp>
#include <future>
Expand Down Expand Up @@ -34,7 +34,7 @@ namespace detail {
uint32_t dpos_proposed_irreversible_blocknum = 0;
uint32_t dpos_irreversible_blocknum = 0;
producer_authority_schedule active_schedule;
incremental_legacy_merkle_tree blockroot_merkle;
incremental_merkle_tree_legacy blockroot_merkle;
flat_map<account_name,uint32_t> producer_to_last_produced;
flat_map<account_name,uint32_t> producer_to_last_implied_irb;
block_signing_authority valid_block_signing_authority;
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <eosio/chain/block.hpp>
#include <eosio/chain/transaction_metadata.hpp>
#include <eosio/chain/action_receipt.hpp>
#include <eosio/chain/incremental_merkle.hpp>

namespace eosio::chain {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <eosio/chain/kv_config.hpp>
#include <eosio/chain/wasm_config.hpp>
#include <eosio/chain/producer_schedule.hpp>
#include <eosio/chain/incremental_merkle.hpp>
#include <eosio/chain/snapshot.hpp>
#include <chainbase/chainbase.hpp>
#include "multi_index_includes.hpp"
Expand Down
Loading
Loading