Skip to content

Commit

Permalink
Merge 942c030 into cdded06
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed May 10, 2024
2 parents cdded06 + 942c030 commit 2b7d00e
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 39 deletions.
33 changes: 32 additions & 1 deletion console/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,37 @@ void executor::read_test() const

#if defined(UNDEFINED)

void executor::read_test() const
{
logger("Wire size computation.");
const auto start = fine_clock::now();
constexpr auto last = 500'000_size;

size_t size{};
for (auto height = zero; !cancel_ && height <= last; ++height)
{
const auto link = query_.to_candidate(height);
if (link.is_terminal())
{
logger(format("Max candidate height is (%1%).") % sub1(height));
return;
}

const auto bytes = query_.get_block_size(link);
if (is_zero(bytes))
{
logger(format("Block (%1%) is not associated.") % height);
return;
}

size += bytes;
}

const auto span = duration_cast<milliseconds>(fine_clock::now() - start);
logger(format("Wire size (%1%) at (%2%) in (%3%) ms.") %
size % last % span.count());
}

void executor::read_test() const
{
constexpr auto start_tx = 15'000_u32;
Expand Down Expand Up @@ -1398,7 +1429,7 @@ void executor::read_test() const
logger("HIT <enter> TO START");
std::string line{};
std::getline(input_, line);
const auto start = (fine_clock::now();
const auto start = fine_clock::now();

for (size_t height = 492'224; (height <= 492'224) && !cancel_; ++height)
{
Expand Down
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 @@ -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
3 changes: 3 additions & 0 deletions include/bitcoin/node/full_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ class BCN_API full_node
/// The specified timestamp is current.
virtual bool is_current(uint32_t timestamp) const NOEXCEPT;

/// Maximum optimal block inventory sizing based on chain and config.
virtual size_t maximum_inventory() const NOEXCEPT;

protected:
/// Session attachments.
/// -----------------------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions include/bitcoin/node/settings.hpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
9 changes: 9 additions & 0 deletions src/full_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ bool full_node::is_current(uint32_t timestamp) const NOEXCEPT
return time >= current;
}

size_t full_node::maximum_inventory() const NOEXCEPT
{
const auto peers = config().network.outbound_connections;
return is_zero(peers) ? messages::max_inventory :
std::min(ceilinged_divide(query_.get_unassociated_count(), peers),
messages::max_inventory);

}

// Session attachments.
// ----------------------------------------------------------------------------

Expand Down
30 changes: 15 additions & 15 deletions src/parser.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 2b7d00e

Please sign in to comment.