Skip to content

Commit

Permalink
Add snapshot_interval and remove maximum_inventory setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed May 10, 2024
1 parent 5c228b2 commit 942c030
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 38 deletions.
2 changes: 1 addition & 1 deletion include/bitcoin/node/chasers/chaser_check.hpp
Expand Up @@ -74,7 +74,7 @@ class BCN_API chaser_check
size_t get_unassociated() NOEXCEPT;

// These are thread safe.
const size_t maximum_advance_;
const size_t maximum_concurrency_;
const size_t maximum_height_;
const size_t connections_;
const size_t inventory_;
Expand Down
9 changes: 5 additions & 4 deletions include/bitcoin/node/settings.hpp
Expand Up @@ -63,15 +63,16 @@ class BCN_API settings
/// Properties.
bool headers_first;
float allowed_deviation;
uint16_t maximum_inventory;
uint32_t maximum_height;
uint32_t maximum_concurrency;
uint32_t snapshot_interval;
uint16_t sample_period_seconds;
uint32_t currency_window_minutes;
uint32_t maximum_advance;
uint32_t maximum_height;

/// Helpers.
virtual size_t maximum_advance_() const NOEXCEPT;
virtual size_t maximum_height_() const NOEXCEPT;
virtual size_t maximum_concurrency_() const NOEXCEPT;
virtual size_t snapshot_interval_() const NOEXCEPT;
virtual network::steady_clock::duration sample_period() const NOEXCEPT;
virtual network::wall_clock::duration currency_window() const NOEXCEPT;
};
Expand Down
9 changes: 4 additions & 5 deletions src/chasers/chaser_check.cpp
Expand Up @@ -43,11 +43,10 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

chaser_check::chaser_check(full_node& node) NOEXCEPT
: chaser(node),
maximum_advance_(node.config().node.maximum_advance_()),
maximum_concurrency_(node.config().node.maximum_concurrency_()),
maximum_height_(node.config().node.maximum_height_()),
connections_(node.config().network.outbound_connections),
inventory_(system::lesser(node.config().node.maximum_inventory,
messages::max_inventory))
inventory_(node.maximum_inventory())
{
}

Expand Down Expand Up @@ -288,7 +287,7 @@ size_t chaser_check::get_unassociated() NOEXCEPT
// not last requested, since all between are already downloaded.
const auto& query = archive();
const auto requested = requested_;
const auto stop = std::min(ceilinged_add(validated_, maximum_advance_),
const auto stop = std::min(ceilinged_add(validated_, maximum_concurrency_),
maximum_height_);

while (true)
Expand All @@ -306,7 +305,7 @@ size_t chaser_check::get_unassociated() NOEXCEPT
}

LOGN("Advance by ("
<< maximum_advance_ << ") above ("
<< maximum_concurrency_ << ") above ("
<< requested << ") from ("
<< validated_ << ") stop ("
<< stop << ") found ("
Expand Down
30 changes: 15 additions & 15 deletions src/parser.cpp
Expand Up @@ -884,29 +884,29 @@ options_metadata parser::load_settings() THROWS
"Allowable underperformance standard deviation, defaults to 1.5 (0 disables)."
)
(
"node.sample_period_seconds",
value<uint16_t>(&configured.node.sample_period_seconds),
"Sampling period for drop of stalled channels, defaults to 10 (0 disables)."
"node.maximum_height",
value<uint32_t>(&configured.node.maximum_height),
"Maximum block height to populate, defaults to 0 (unlimited)."
)
(
"node.currency_window_minutes",
value<uint32_t>(&configured.node.currency_window_minutes),
"Time from present that blocks are considered current, defaults to 60 (0 disables)."
"node.maximum_concurrency",
value<uint32_t>(&configured.node.maximum_concurrency),
"Maximum number of blocks to download concurrently, defaults to '50000' (0 disables)."
)
(
"node.maximum_inventory",
value<uint16_t>(&configured.node.maximum_inventory),
"Maximum size of block inventory requests, defaults to 8000."
"node.snapshot_interval",
value<uint32_t>(&configured.node.snapshot_interval),
"Block interval for automatic store snapshots, defaults to '100000' (0 disables)."
)
(
"node.maximum_advance",
value<uint32_t>(&configured.node.maximum_advance),
"Maximum number of blocks to download prior to validation, defaults to 0 (unlimited)."
"node.sample_period_seconds",
value<uint16_t>(&configured.node.sample_period_seconds),
"Sampling period for drop of stalled channels, defaults to 10 (0 disables)."
)
(
"node.maximum_height",
value<uint32_t>(&configured.node.maximum_height),
"The maximum block height to populate, defaults to 0 (unlimited)."
"node.currency_window_minutes",
value<uint32_t>(&configured.node.currency_window_minutes),
"Time from present that blocks are considered current, defaults to 60 (0 disables)."
)
// #######################
////(
Expand Down
22 changes: 14 additions & 8 deletions src/settings.cpp
Expand Up @@ -66,27 +66,33 @@ namespace node {
settings::settings() NOEXCEPT
: headers_first{ true },
allowed_deviation{ 1.5 },
maximum_inventory{ 8000 },
maximum_height{ 0 },
maximum_concurrency{ 50'000 },
snapshot_interval{ 100'000 },
sample_period_seconds{ 10 },
currency_window_minutes{ 60 },
maximum_advance{ 0 },
maximum_height{ 0 }
currency_window_minutes{ 60 }
{
}

settings::settings(chain::selection) NOEXCEPT
: settings()
{
// TODO: testnet, etc. maximum_concurrency, snapshot_interval.
}

size_t settings::maximum_advance_() const NOEXCEPT
size_t settings::maximum_height_() const NOEXCEPT
{
return is_zero(maximum_advance) ? max_size_t : maximum_advance;
return is_zero(maximum_height) ? max_size_t : maximum_height;
}

size_t settings::maximum_height_() const NOEXCEPT
size_t settings::maximum_concurrency_() const NOEXCEPT
{
return is_zero(maximum_height) ? max_size_t : maximum_height;
return is_zero(maximum_concurrency) ? max_size_t : maximum_concurrency;
}

size_t settings::snapshot_interval_() const NOEXCEPT
{
return is_zero(snapshot_interval) ? max_size_t : snapshot_interval;
}

network::steady_clock::duration settings::sample_period() const NOEXCEPT
Expand Down
16 changes: 11 additions & 5 deletions test/settings.cpp
Expand Up @@ -40,14 +40,20 @@ BOOST_AUTO_TEST_CASE(settings__node__default_context__expected)
const node::settings node{};
BOOST_REQUIRE_EQUAL(node.headers_first, true);
BOOST_REQUIRE_EQUAL(node.allowed_deviation, 1.5);
BOOST_REQUIRE_EQUAL(node.maximum_inventory, 8000);
BOOST_REQUIRE_EQUAL(node.sample_period_seconds, 10_u16);
BOOST_REQUIRE_EQUAL(node.currency_window_minutes, 60_u32);
BOOST_REQUIRE_EQUAL(node.maximum_advance, 0_u32);
BOOST_REQUIRE_EQUAL(node.maximum_advance_(), max_size_t);

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.snapshot_interval, 100'000_u32);
BOOST_REQUIRE_EQUAL(node.snapshot_interval_(), 100'000_size);

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

BOOST_REQUIRE_EQUAL(node.currency_window_minutes, 60_u32);
BOOST_REQUIRE(node.currency_window() == network::steady_clock::duration(network::minutes(60)));
}

Expand Down

0 comments on commit 942c030

Please sign in to comment.