Skip to content

Commit

Permalink
Rename block_in protocol bypass functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Jun 6, 2024
1 parent e6a186d commit c6ad363
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
5 changes: 3 additions & 2 deletions include/bitcoin/node/protocols/protocol_block_in_31800.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class BCN_API protocol_block_in_31800
virtual void do_purge(channel_t) NOEXCEPT;
virtual void do_split(channel_t) NOEXCEPT;
virtual void do_report(count_t count) NOEXCEPT;
virtual void do_bypass(height_t height) NOEXCEPT;

/// Check incoming block message.
virtual bool handle_receive_block(const code& ec,
Expand All @@ -75,7 +74,6 @@ class BCN_API protocol_block_in_31800
private:
using type_id = network::messages::inventory::type_id;

bool is_under_bypass(size_t height) const NOEXCEPT;
code check(const system::chain::block& block,
const system::chain::context& ctx, bool bypass) const NOEXCEPT;

Expand All @@ -89,6 +87,9 @@ class BCN_API protocol_block_in_31800
void handle_get_hashes(const code& ec, const map_ptr& map,
size_t bypass) NOEXCEPT;

void set_bypass(height_t height) NOEXCEPT;
bool is_bypassed(size_t height) const NOEXCEPT;

// This is thread safe.
const network::messages::inventory::type_id block_type_;

Expand Down
14 changes: 5 additions & 9 deletions src/protocols/protocol_block_in_31800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,7 @@ void protocol_block_in_31800::send_get_data(const map_ptr& map,
return;
}

// Protocols cannot rely on the bypass message because they miss startup
// initialization, and they do not maintain work order. So this is updated
// wit each get_hashes response. If there is a regression then all channels
// are purged, so bypass only progresses forward in the protocol.
BC_ASSERT(bypass >= bypass_);
do_bypass(bypass);
set_bypass(bypass);

if (map->empty())
return;
Expand Down Expand Up @@ -316,7 +311,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,

// Transaction/witness commitments are required under checkpoint.
// This ensures that the block/header hash represents expected txs.
const auto bypass = is_under_bypass(ctx.height) && !malleable64;
const auto bypass = is_bypassed(ctx.height) && !malleable64;

// Performs full check if block is mally64 (mally32 caught either way).
if (const auto code = check(*block_ptr, ctx, bypass))
Expand Down Expand Up @@ -463,14 +458,15 @@ void protocol_block_in_31800::handle_get_hashes(const code& ec,
// bypass
// ----------------------------------------------------------------------------

void protocol_block_in_31800::do_bypass(height_t height) NOEXCEPT
void protocol_block_in_31800::set_bypass(height_t height) NOEXCEPT
{
BC_ASSERT(stranded());
bypass_ = height;
}

bool protocol_block_in_31800::is_under_bypass(size_t height) const NOEXCEPT
bool protocol_block_in_31800::is_bypassed(size_t height) const NOEXCEPT
{
BC_ASSERT(stranded());
return height <= bypass_;
}

Expand Down

0 comments on commit c6ad363

Please sign in to comment.