Skip to content

Commit

Permalink
Merge pull request #634 from evoskuil/master
Browse files Browse the repository at this point in the history
Style, add, parse and integrate node.threads setting.  @evoskuil evoskuil committed 1 minute ago
  • Loading branch information
evoskuil committed May 28, 2024
2 parents ea6aa44 + ab4dee5 commit 368702e
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 45 deletions.
2 changes: 1 addition & 1 deletion include/bitcoin/node/chasers/chaser_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class BCN_API chaser_check
network::result_handler&& handler) NOEXCEPT;

protected:
virtual size_t get_maximum_inventory() const NOEXCEPT;
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

Expand All @@ -73,6 +72,7 @@ class BCN_API chaser_check

map_ptr get_map() NOEXCEPT;
size_t get_unassociated() NOEXCEPT;
size_t get_inventory_size() const NOEXCEPT;

// These are thread safe.
const size_t maximum_concurrency_;
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node/chasers/chaser_validate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BCN_API chaser_validate
const uint32_t subsidy_interval_blocks_;

// These are protected by strand.
network::threadpool pool_;
network::threadpool threadpool_;
system::hash_digest neutrino_{};
};

Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/node/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class BCN_API settings
uint32_t maximum_concurrency;
uint16_t sample_period_seconds;
uint32_t currency_window_minutes;
uint32_t threads;

/// Helpers.
virtual size_t maximum_height_() const NOEXCEPT;
Expand Down
15 changes: 2 additions & 13 deletions src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ void chaser_check::put_hashes(const map_ptr& map,
this, map, std::move(handler)));
}

////LOGN("Hashes -" << map->size() << " (" << count_maps() << ") remain.");
void chaser_check::do_get_hashes(const map_handler& handler) NOEXCEPT
{
BC_ASSERT(stranded());
Expand All @@ -256,7 +255,6 @@ void chaser_check::do_get_hashes(const map_handler& handler) NOEXCEPT
handler(error::success, map);
}

////LOGN("Hashes +" << map->size() << " (" << count_maps() << ") remain.");
void chaser_check::do_put_hashes(const map_ptr& map,
const result_handler& handler) NOEXCEPT
{
Expand Down Expand Up @@ -302,7 +300,7 @@ size_t chaser_check::get_unassociated() NOEXCEPT
// Inventory size gets set only once.
if (is_zero(inventory_))
{
inventory_ = get_maximum_inventory();
inventory_ = get_inventory_size();
if (is_zero(inventory_)) return zero;
}

Expand Down Expand Up @@ -341,7 +339,7 @@ size_t chaser_check::get_unassociated() NOEXCEPT
return count;
}

size_t chaser_check::get_maximum_inventory() const NOEXCEPT
size_t chaser_check::get_inventory_size() const NOEXCEPT
{
// Either condition means blocks shouldn't be getting downloaded (yet).
const auto peers = config().network.outbound_connections;
Expand All @@ -356,15 +354,6 @@ size_t chaser_check::get_maximum_inventory() const NOEXCEPT
return system::ceilinged_divide(inventory, peers);
}

////size_t chaser_check::count_maps() const NOEXCEPT
////{
//// return std::accumulate(maps_.begin(), maps_.end(), zero,
//// [](size_t sum, const map_ptr& map) NOEXCEPT
//// {
//// return sum + map->size();
//// });
////}

BC_POP_WARNING()
BC_POP_WARNING()
BC_POP_WARNING()
Expand Down
6 changes: 2 additions & 4 deletions src/chasers/chaser_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ using namespace system::neutrino;
using namespace database;
using namespace std::placeholders;

constexpr auto threads = 64_size;

// Shared pointer is required to keep the race object alive in bind closure.
BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR)
BC_PUSH_WARNING(SMART_PTR_NOT_NEEDED)
Expand All @@ -47,7 +45,7 @@ chaser_validate::chaser_validate(full_node& node) NOEXCEPT
: chaser(node),
initial_subsidy_(node.config().bitcoin.initial_subsidy()),
subsidy_interval_blocks_(node.config().bitcoin.subsidy_interval_blocks),
pool_(threads, network::thread_priority::normal)
threadpool_(std::min(node.config().node.threads, 1_u32))
{
}

Expand Down Expand Up @@ -284,7 +282,7 @@ bool chaser_validate::enqueue_block(const header_link& link) NOEXCEPT

fire(events::block_buffered, context.height);
for (auto tx = txs.begin(); !closed() && tx != txs.end(); ++tx)
boost::asio::post(pool_.service(),
boost::asio::post(threadpool_.service(),
std::bind(&chaser_validate::validate_tx,
this, context, *tx, racer));

Expand Down
5 changes: 5 additions & 0 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,11 @@ options_metadata parser::load_settings() THROWS
)

/* [node] */
(
"node.threads",
value<uint32_t>(&configured.node.threads),
"The number of threads in the validation threadpool, defaults to 16."
)
(
"node.headers_first",
value<bool>(&configured.node.headers_first),
Expand Down
3 changes: 2 additions & 1 deletion src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ settings::settings() NOEXCEPT
maximum_height{ 0 },
maximum_concurrency{ 50'000 },
sample_period_seconds{ 10 },
currency_window_minutes{ 60 }
currency_window_minutes{ 60 },
threads{ 1 }
{
}

Expand Down
23 changes: 5 additions & 18 deletions test/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,12 @@ BOOST_AUTO_TEST_CASE(configuration__construct1__none_context__expected)
BOOST_REQUIRE(!instance.test);
BOOST_REQUIRE(!instance.write);

// Just a sample of settings.
BOOST_REQUIRE(instance.database.minimize);
BOOST_REQUIRE(instance.node.headers_first);
BOOST_REQUIRE_EQUAL(instance.network.threads, 1_u32);
BOOST_REQUIRE_EQUAL(instance.bitcoin.first_version, 1_u32);
BOOST_REQUIRE_EQUAL(instance.log.application, levels::application_defined);
BOOST_REQUIRE_EQUAL(instance.log.news, levels::news_defined);
BOOST_REQUIRE_EQUAL(instance.log.session, levels::session_defined);
BOOST_REQUIRE_EQUAL(instance.log.protocol, false /*levels::protocol_defined*/);
BOOST_REQUIRE_EQUAL(instance.log.proxy, false /*levels::proxy_defined*/);
BOOST_REQUIRE_EQUAL(instance.log.remote, levels::remote_defined);
BOOST_REQUIRE_EQUAL(instance.log.fault, levels::fault_defined);
BOOST_REQUIRE_EQUAL(instance.log.quitting, false /*levels::quitting_defined*/);
BOOST_REQUIRE_EQUAL(instance.log.objects, false /*levels::objects_defined*/);
BOOST_REQUIRE_EQUAL(instance.log.verbose, false /*levels::verbose_defined*/);

BOOST_REQUIRE_EQUAL(instance.log.maximum_size, 1'000'000_u32);
BOOST_REQUIRE_EQUAL(instance.log.log_file1(), "bn_end.log");
BOOST_REQUIRE_EQUAL(instance.log.log_file2(), "bn_begin.log");
BOOST_REQUIRE_EQUAL(instance.log.events_file(), "events.log");
BOOST_REQUIRE_EQUAL(instance.log.path, "");
#if defined(HAVE_MSC)
BOOST_REQUIRE_EQUAL(instance.log.symbols, "");
#endif
}

BOOST_AUTO_TEST_SUITE_END()
15 changes: 8 additions & 7 deletions test/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,31 @@ BOOST_AUTO_TEST_CASE(settings__log__default_context__expected)
BOOST_REQUIRE_EQUAL(log.log_file1(), "bn_end.log");
BOOST_REQUIRE_EQUAL(log.log_file2(), "bn_begin.log");
BOOST_REQUIRE_EQUAL(log.events_file(), "events.log");
#if defined(HAVE_MSC)
BOOST_REQUIRE_EQUAL(log.symbols, "");
#endif
}

// [node]

BOOST_AUTO_TEST_CASE(settings__node__default_context__expected)
{
using namespace network;

const node::settings node{};
BOOST_REQUIRE_EQUAL(node.headers_first, true);
BOOST_REQUIRE_EQUAL(node.allowed_deviation, 1.5);

BOOST_REQUIRE_EQUAL(node.snapshot_bytes, 107'374'182'400_u64);
BOOST_REQUIRE_EQUAL(node.snapshot_valid, 100'000_u32);

BOOST_REQUIRE_EQUAL(node.maximum_height, 0_u32);
BOOST_REQUIRE_EQUAL(node.maximum_height_(), max_size_t);

BOOST_REQUIRE_EQUAL(node.maximum_concurrency, 50000_u32);
BOOST_REQUIRE_EQUAL(node.maximum_concurrency_(), 50000_size);

BOOST_REQUIRE_EQUAL(node.sample_period_seconds, 10_u16);
BOOST_REQUIRE(node.sample_period() == network::steady_clock::duration(network::seconds(10)));

BOOST_REQUIRE(node.sample_period() == steady_clock::duration(seconds(10)));
BOOST_REQUIRE_EQUAL(node.currency_window_minutes, 60_u32);
BOOST_REQUIRE(node.currency_window() == network::steady_clock::duration(network::minutes(60)));
BOOST_REQUIRE(node.currency_window() == steady_clock::duration(minutes(60)));
BOOST_REQUIRE_EQUAL(node.threads, 1_u32);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 368702e

Please sign in to comment.