Skip to content
Merged
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
7 changes: 6 additions & 1 deletion src/c2pool/merged/coin_broadcaster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ class CoinBroadcaster
}

/// Broadcast raw block bytes to ALL connected peers (parent chain).
void submit_block_raw(const std::vector<unsigned char>& block_bytes)
/// Relay a raw block to every connected peer. Returns the number of peers
/// the block was successfully sent to (0 => NOT broadcast). Embedded aux
/// backends rely on this count to honour the never-silent-drop invariant
/// (#162): a found block that reached 0 peers must surface as a failure.
size_t submit_block_raw(const std::vector<unsigned char>& block_bytes)
{
std::lock_guard<std::mutex> lock(m_mutex);
int sent = 0, failed = 0;
Expand All @@ -275,6 +279,7 @@ class CoinBroadcaster
<< sent << "/" << (sent + failed) << " peers ("
<< block_bytes.size() << " bytes)";
}
return static_cast<size_t>(sent);
}

/// Send inv announcement to ALL connected peers (merged chain relay).
Expand Down
16 changes: 16 additions & 0 deletions test/test_coin_broadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,22 @@ TEST(CoinBroadcaster, ConstructionDefaults)
EXPECT_EQ(bc.connected_count(), 0);
}

// PE never-silent-drop (#162): with no peers connected, submit_block_raw must
// report 0 relays so embedded aux backends surface a found block as a failure
// rather than claiming a phantom broadcast.
TEST(CoinBroadcaster, SubmitBlockRawNoPeersReturnsZero)
{
boost::asio::io_context ioc;
std::vector<std::byte> prefix = {std::byte{0xfd}, std::byte{0xd2},
std::byte{0xc8}, std::byte{0xf1}};
CoinBroadcaster bc(ioc, "LTC", prefix, NetService("192.168.1.1", 19335));

ASSERT_EQ(bc.connected_count(), 0);
std::vector<unsigned char> dummy_block(80, 0x00);
EXPECT_EQ(bc.submit_block_raw(dummy_block), 0u)
<< "no peers => 0 relays => caller must NOT claim broadcast success";
}

TEST(CoinBroadcaster, ConstructionWithConfig)
{
boost::asio::io_context ioc;
Expand Down
Loading