Skip to content

Commit

Permalink
Making use of block_checker
Browse files Browse the repository at this point in the history
# Conflicts:
#	nano/secure/ledger_view_unconfirmed.cpp
  • Loading branch information
clemahieu committed Mar 18, 2024
1 parent 79be90f commit 60e3df9
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 137 deletions.
1 change: 0 additions & 1 deletion nano/core_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ add_executable(
bootstrap_ascending.cpp
bootstrap_server.cpp
cli.cpp
confirmation_height.cpp
confirmation_solicitor.cpp
conflicts.cpp
difficulty.cpp
Expand Down
8 changes: 6 additions & 2 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ TEST (bulk_pull, end_not_owned)
nano::test::system system (1);
nano::keypair key2;
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, 100));
auto block = system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, 100);
ASSERT_NE (nullptr, block);
system.nodes[0]->ledger.confirm (system.nodes[0]->store.tx_begin_write (), block->hash ());
nano::block_hash latest (system.nodes[0]->latest (nano::dev::genesis_key.pub));
nano::block_builder builder;
auto open = builder
Expand Down Expand Up @@ -125,6 +127,7 @@ TEST (bulk_pull, ascending_one_hash)
.build ();
node.work_generate_blocking (*block1);
ASSERT_EQ (nano::block_status::progress, node.process (block1));
node.ledger.confirm (node.store.tx_begin_write (), block1->hash ());
auto socket = std::make_shared<nano::transport::socket> (node, nano::transport::socket::endpoint_type_t::server);
auto connection = std::make_shared<nano::transport::tcp_server> (socket, system.nodes[0]);
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
Expand Down Expand Up @@ -157,6 +160,7 @@ TEST (bulk_pull, ascending_two_account)
.build ();
node.work_generate_blocking (*block1);
ASSERT_EQ (nano::block_status::progress, node.process (block1));
node.ledger.confirm (node.store.tx_begin_write (), block1->hash ());
auto socket = std::make_shared<nano::transport::socket> (node, nano::transport::socket::endpoint_type_t::server);
auto connection = std::make_shared<nano::transport::tcp_server> (socket, system.nodes[0]);
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
Expand Down Expand Up @@ -260,7 +264,7 @@ TEST (bulk_pull, count_limit)
.work (*system.work.generate (send1->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, node0->process (receive1));

node0->ledger.confirm (node0->store.tx_begin_write (), receive1->hash ());
auto connection (std::make_shared<nano::transport::tcp_server> (std::make_shared<nano::transport::socket> (*node0, nano::transport::socket::endpoint_type_t::server), node0));
auto req = std::make_unique<nano::bulk_pull> (nano::dev::network_params.network);
req->start = receive1->hash ();
Expand Down
6 changes: 5 additions & 1 deletion nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ TEST (ledger, process_modifies_sideband)
.work (*pool.generate (nano::dev::genesis->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (store.tx_begin_write (), send1));
ASSERT_EQ (send1->sideband ().timestamp, ledger.unconfirmed (store.tx_begin_read ()).get (send1->hash ())->sideband ().timestamp);
auto retrieved = ledger.unconfirmed (store.tx_begin_read ()).get (send1->hash ());
ASSERT_NE (nullptr, retrieved);
ASSERT_TRUE (retrieved->has_sideband ());
ASSERT_TRUE (send1->has_sideband ());
ASSERT_EQ (send1->sideband ().timestamp, retrieved->sideband ().timestamp);
}

// Create a send block and publish it.
Expand Down
14 changes: 12 additions & 2 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ TEST (node, send_single)
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
system.wallet (1)->insert_adhoc (key2.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
ASSERT_EQ (std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (nano::dev::genesis_key.pub));
ASSERT_TIMELY_EQ (5s, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (nano::dev::genesis_key.pub));
ASSERT_TRUE (system.nodes[0]->balance (key2.pub).is_zero ());
ASSERT_TIMELY (10s, !system.nodes[0]->balance (key2.pub).is_zero ());
}
Expand All @@ -157,7 +157,7 @@ TEST (node, send_single_observing_peer)
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
system.wallet (1)->insert_adhoc (key2.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
ASSERT_EQ (std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (nano::dev::genesis_key.pub));
ASSERT_TIMELY_EQ (5s, std::numeric_limits<nano::uint128_t>::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (nano::dev::genesis_key.pub));
ASSERT_TRUE (system.nodes[0]->balance (key2.pub).is_zero ());
ASSERT_TIMELY (10s, std::all_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr<nano::node> const & node_a) { return !node_a->balance (key2.pub).is_zero (); }));
}
Expand Down Expand Up @@ -192,6 +192,16 @@ TEST (node, send_out_of_order)
node1.process_active (send3);
node1.process_active (send2);
node1.process_active (send1);
ASSERT_TIMELY (5s, std::all_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr<nano::node> const & node_a) {
auto blocks = { send1, send2, send3 };
return std::all_of (blocks.begin (), blocks.end (), [&] (std::shared_ptr<nano::block> block) {
//return node_a->ledger.unconfirmed (block->hash ());
return false;
});
}));
node1.ledger.confirm (node1.store.tx_begin_write (), send3->hash ());
auto & node2 = *system.nodes[1];
node2.ledger.confirm (node2.store.tx_begin_write (), send3->hash ());
ASSERT_TIMELY (10s, std::all_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr<nano::node> const & node_a) { return node_a->balance (nano::dev::genesis_key.pub) == nano::dev::constants.genesis_amount - node1.config.receive_minimum.number () * 3; }));
}

Expand Down
4 changes: 2 additions & 2 deletions nano/node/confirmation_height_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ void nano::confirmation_height_processor::unpause ()
}

void nano::confirmation_height_processor::add (std::shared_ptr<nano::block> const & block_a)
{
{/*
{
nano::lock_guard<nano::mutex> lk (mutex);
awaiting_processing.get<tag_sequence> ().emplace_back (block_a);
}
condition.notify_one ();
condition.notify_one ();*/
}

void nano::confirmation_height_processor::set_next_hash ()
Expand Down
28 changes: 3 additions & 25 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,32 +1264,10 @@ void nano::node::process_confirmed_data (store::transaction const & transaction_
}
}

void nano::node::process_confirmed (nano::election_status const & status_a, uint64_t iteration_a)
void nano::node::process_confirmed (nano::election_status const & status_a)
{
auto hash (status_a.winner->hash ());
decltype (iteration_a) const num_iters = (config.block_processor_batch_max_time / network_params.node.process_confirmed_interval) * 4;
if (auto block_l = ledger.unconfirmed (ledger.store.tx_begin_read ()).get (hash))
{
logger.trace (nano::log::type::node, nano::log::detail::process_confirmed, nano::log::arg{ "block", block_l });

confirmation_height_processor.add (block_l);
}
else if (iteration_a < num_iters)
{
iteration_a++;
std::weak_ptr<nano::node> node_w (shared ());
workers.add_timed_task (std::chrono::steady_clock::now () + network_params.node.process_confirmed_interval, [node_w, status_a, iteration_a] () {
if (auto node_l = node_w.lock ())
{
node_l->process_confirmed (status_a, iteration_a);
}
});
}
else
{
// Do some cleanup due to this block never being processed by confirmation height processor
active.remove_election_winner_details (hash);
}
logger.trace (nano::log::type::node, nano::log::detail::process_confirmed, nano::log::arg{ "block", status_a.winner });
ledger.confirm (store.tx_begin_write (), status_a.winner->hash ());
}

std::shared_ptr<nano::node> nano::node::shared ()
Expand Down
3 changes: 2 additions & 1 deletion nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <nano/node/wallet.hpp>
#include <nano/node/websocket.hpp>
#include <nano/node/write_database_queue.hpp>
#include <nano/secure/unconfirmed_set.hpp>
#include <nano/secure/utility.hpp>

#include <boost/program_options.hpp>
Expand Down Expand Up @@ -84,7 +85,7 @@ class node final : public std::enable_shared_from_this<nano::node>
int store_version ();
void receive_confirmed (store::transaction const & block_transaction_a, nano::block_hash const & hash_a, nano::account const & destination_a);
void process_confirmed_data (store::transaction const &, std::shared_ptr<nano::block> const &, nano::block_hash const &, nano::account &, nano::uint128_t &, bool &, bool &, nano::account &);
void process_confirmed (nano::election_status const &, uint64_t = 0);
void process_confirmed (nano::election_status const &);
void process_active (std::shared_ptr<nano::block> const &);
std::optional<nano::block_status> process_local (std::shared_ptr<nano::block> const &);
void process_local_async (std::shared_ptr<nano::block> const &);
Expand Down
Loading

0 comments on commit 60e3df9

Please sign in to comment.