From 0df61844406de1795b888c36a7b4b5d847a0d479 Mon Sep 17 00:00:00 2001 From: echennells Date: Sat, 14 Nov 2026 19:33:25 +0000 Subject: [PATCH] Translate block inventory announcements from sendheaders peers. --- .../protocols/protocol_header_in_31800.hpp | 1 + src/protocols/protocol_header_in_31800.cpp | 6 ++- test/functional/p2p.cpp | 43 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/include/bitcoin/node/protocols/protocol_header_in_31800.hpp b/include/bitcoin/node/protocols/protocol_header_in_31800.hpp index 6b6280aad..a1f0f498d 100644 --- a/include/bitcoin/node/protocols/protocol_header_in_31800.hpp +++ b/include/bitcoin/node/protocols/protocol_header_in_31800.hpp @@ -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_{}; diff --git a/src/protocols/protocol_header_in_31800.cpp b/src/protocols/protocol_header_in_31800.cpp index cd7e3c2c7..e6b73b71d 100644 --- a/src/protocols/protocol_header_in_31800.cpp +++ b/src/protocols/protocol_header_in_31800.cpp @@ -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() << "]."); @@ -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; diff --git a/test/functional/p2p.cpp b/test/functional/p2p.cpp index 3a838fb66..b129db97b 100644 --- a/test/functional/p2p.cpp +++ b/test/functional/p2p.cpp @@ -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) // ----------------------------------------------------------------------------