Skip to content

Commit

Permalink
Remove blcoks_in from session inbound, add perf to outbound.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed May 10, 2024
1 parent 1c51cf8 commit 12debc7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
4 changes: 2 additions & 2 deletions include/bitcoin/node/protocols/protocol_block_in_31800.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class BCN_API protocol_block_in_31800
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
template <typename SessionPtr>
protocol_block_in_31800(const SessionPtr& session,
const channel_ptr& channel, bool performance) NOEXCEPT
: protocol_performer(session, channel, performance),
const channel_ptr& channel) NOEXCEPT
: protocol_performer(session, channel),
block_type_(session->config().network.witness_node() ?
type_id::witness_block : type_id::block),
map_(chaser_check::empty_map())
Expand Down
13 changes: 6 additions & 7 deletions include/bitcoin/node/protocols/protocol_performer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ class BCN_API protocol_performer

protected:
template <typename SessionPtr>
protocol_performer(const SessionPtr& session, const channel_ptr& channel,
bool enable) NOEXCEPT
protocol_performer(const SessionPtr& session,
const channel_ptr& channel) NOEXCEPT
: node::protocol(session, channel),
network::tracker<protocol_performer>(session->log),
use_deviation_(session->config().node.allowed_deviation > 0.0),
drop_stall_(enable &&
to_bool(session->config().node.sample_period_seconds)),
deviation_(session->config().node.allowed_deviation > 0.0),
enabled_(to_bool(session->config().node.sample_period_seconds)),
performance_timer_(std::make_shared<network::deadline>(session->log,
channel->strand(), session->config().node.sample_period()))
{
Expand All @@ -61,8 +60,8 @@ class BCN_API protocol_performer
void send_performance(uint64_t rate) NOEXCEPT;

// These are thread safe.
const bool use_deviation_;
const bool drop_stall_;
const bool deviation_;
const bool enabled_;

// These are protected by strand.
uint64_t bytes_{ zero };
Expand Down
37 changes: 20 additions & 17 deletions include/bitcoin/node/sessions/attach.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,41 +57,44 @@ class attach
void attach_protocols(
const network::channel::ptr& channel) NOEXCEPT override
{
constexpr auto bip130 = network::messages::level::bip130;
constexpr auto headers = network::messages::level::headers_protocol;
constexpr auto in = is_same_type<Session, network::session_inbound>;

const auto headers_first = config().node.headers_first;
const auto version = channel->negotiated_version();
const auto self = session::shared_from_sibling<attach<Session>,
network::session>();

// Only session_outbound channels compete on performance.
auto performance = false;
if constexpr (is_same_type<Session, network::session_outbound>)
{
performance = true;
}

// Attach appropriate alert, reject, ping, and/or address protocols.
Session::attach_protocols(channel);

// Very hard to find < 31800 peer to connect with.
if (headers_first && version >= network::messages::level::bip130)
if (headers_first && version >= bip130)
{
// Headers-first synchronization (parallel block download).
channel->attach<protocol_header_in_70012>(self)->start();
channel->attach<protocol_header_out_70012>(self)->start();
channel->attach<protocol_block_in_31800>(self, performance)->start();
if constexpr (!in)
{
channel->attach<protocol_block_in_31800>(self)->start();
}
}
else if (headers_first &&
version >= network::messages::level::headers_protocol)
else if (headers_first && version >= headers)
{
// Headers-first synchronization (parallel block download).
channel->attach<protocol_header_in_31800>(self)->start();
channel->attach<protocol_header_out_31800>(self)->start();
channel->attach<protocol_block_in_31800>(self, performance)->start();
if constexpr (!in)
{
channel->attach<protocol_block_in_31800>(self)->start();
}
}
else
{
// Blocks-first synchronization (no header protocol).
channel->attach<protocol_block_in>(self)->start();
// Very hard to find < 31800 peer to connect with.
// Blocks-first synchronization (no headers protocol).
if constexpr (!in)
{
channel->attach<protocol_block_in>(self)->start();
}
}

channel->attach<protocol_block_out>(self)->start();
Expand Down
6 changes: 3 additions & 3 deletions src/protocols/protocol_performer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void protocol_performer::start_performance() NOEXCEPT
if (stopped())
return;

if (drop_stall_)
if (enabled_)
{
bytes_ = zero;
start_ = steady_clock::now();
Expand Down Expand Up @@ -90,11 +90,11 @@ void protocol_performer::send_performance(uint64_t rate) NOEXCEPT
{
BC_ASSERT(stranded());

if (drop_stall_)
if (enabled_)
{
// Must come first as this takes priority as per configuration.
// Shared performance manager detects slow and stalled channels.
if (use_deviation_)
if (deviation_)
{
performance_timer_->stop();
node::protocol::performance(identifier(), rate,
Expand Down

0 comments on commit 12debc7

Please sign in to comment.