Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class BCN_API protocol_header_in_31800
system::hashes&& start_hashes) const NOEXCEPT;

// These are protected by strand.
bool translating_{};
bool archiving_{};
size_t top_{};
size_t index_{};
Expand Down
6 changes: 4 additions & 2 deletions src/protocols/protocol_header_in_31800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,10 @@ void protocol_header_in_31800::complete() NOEXCEPT
BC_ASSERT(stranded());

// There are no header announcements at 31800, so translate from inv.
if (!subscribed && is_current_chain(true))
// A bip130 peer also reverts to inv (e.g. above eight blocks announced).
if (!translating_ && is_current_chain(true))
{
translating_ = true;
subscribed = true;
SUBSCRIBE_CHANNEL(inventory, handle_receive_inventory, _1, _2);
LOGP("Subscribed to block announcements at [" << opposite() << "].");
Expand All @@ -423,7 +425,7 @@ bool protocol_header_in_31800::handle_receive_inventory(const code& ec,
{
if (!query.is_block(item.hash))
{
// This is inefficient but simple and limited to protocol 31800.
// This is inefficient but simple.
// Since subscribed is set, the response headers will be cached.
SEND(create_get_headers(), handle_send, _1);
return true;
Expand Down
43 changes: 43 additions & 0 deletions test/functional/p2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,49 @@ BC_FIXTURE_TEST_CASE(functional_p2p__inventory_31800__unknown_block__get_headers
BC_REQUIRE(proven->start_hashes.front() == genesis.hash());
}

// inv (in, 70012)
// ----------------------------------------------------------------------------

// A bip130 peer also announces by inv (e.g. above eight blocks announced).
BC_FIXTURE_TEST_CASE(functional_p2p__inventory_70012__unknown_block__get_headers, p2p_compact_setup_fixture)
{
BC_REQUIRE(handshake(network_node, level::bip130));
receive(get_headers::command);
send(headers{}, level::bip130);
receive(send_headers::command);

send(inventory{ { { inventory_item::type_id::block, header1()->hash() } } }, level::bip130);
send(ping{ 42 }, level::bip130);

BC_REQUIRE(received(get_headers::command, pong::command));
}

BC_FIXTURE_TEST_CASE(functional_p2p__inventory_70012__completed_twice__requested_once, p2p_compact_setup_fixture)
{
BC_REQUIRE(handshake(network_node, level::bip130));
receive(get_headers::command);
send(headers{}, level::bip130);
send(headers{}, level::bip130);

send(inventory{ { { inventory_item::type_id::block, header1()->hash() } } }, level::bip130);
send(ping{ 42 }, level::bip130);

BC_REQUIRE(received(get_headers::command, pong::command));
BC_REQUIRE(!received(get_headers::command, pong::command));
}

BC_AUTO_TEST_CASE(functional_p2p__inventory_70012__not_current__not_requested)
{
BC_REQUIRE(handshake(network_node, level::bip130));
receive(get_headers::command);
send(headers{}, level::bip130);

send(inventory{ { { inventory_item::type_id::block, header1()->hash() } } }, level::bip130);
send(ping{ 42 }, level::bip130);

BC_REQUIRE(!received(get_headers::command, pong::command));
}

// sendheaders (in, 70012)
// ----------------------------------------------------------------------------

Expand Down
Loading