|
| 1 | +// SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | +// DGB tx-relay dead-probe regression (#905, port of the btc #880 fix). |
| 3 | +// |
| 4 | +// send_shares() collects the new-tx hashes each share references so it can |
| 5 | +// remember_tx-forward them to a peer. The pre-fix probe guarded on a TOP-LEVEL |
| 6 | +// m_new_transaction_hashes that NO dgb share type declares (the field is nested |
| 7 | +// in m_tx_info), so the collection was ALWAYS empty and DGB never relayed a tx |
| 8 | +// byte to a peer for ANY share version. This pins append_share_tx_refs, the |
| 9 | +// SSOT send_shares() now uses: |
| 10 | +// - v17/v33 (carry m_tx_info) -> the referenced hashes ARE collected |
| 11 | +// - v34/v35/v36 (no m_tx_info) -> compiled out, vacuously empty |
| 12 | +// |
| 13 | +// FAILS-BEFORE: revert append_share_tx_refs to probe obj->m_new_transaction_hashes |
| 14 | +// and the v17/v33 expectations below collapse to 0 -- the historical dead path. |
| 15 | + |
| 16 | +#include <gtest/gtest.h> |
| 17 | + |
| 18 | +#include <vector> |
| 19 | + |
| 20 | +#include <core/uint256.hpp> |
| 21 | +#include <impl/dgb/share.hpp> |
| 22 | +#include <impl/dgb/coin/share_tx_relay_refs.hpp> |
| 23 | + |
| 24 | +namespace { |
| 25 | + |
| 26 | +uint256 mk(const char* hex) { uint256 h; h.SetHex(hex); return h; } |
| 27 | + |
| 28 | +const char* H1 = "1111111111111111111111111111111111111111111111111111111111111111"; |
| 29 | +const char* H2 = "2222222222222222222222222222222222222222222222222222222222222222"; |
| 30 | + |
| 31 | +// v17: m_tx_info present -> referenced hashes collected in order. |
| 32 | +TEST(DGB_tx_relay_refs, V17CollectsNestedNewTxHashes) |
| 33 | +{ |
| 34 | + dgb::Share s; |
| 35 | + s.m_tx_info.m_new_transaction_hashes = {mk(H1), mk(H2)}; |
| 36 | + |
| 37 | + std::vector<uint256> refs; |
| 38 | + dgb::append_share_tx_refs(&s, refs); |
| 39 | + |
| 40 | + ASSERT_EQ(refs.size(), 2u); // dead-probe regression makes this 0 |
| 41 | + EXPECT_EQ(refs[0], mk(H1)); |
| 42 | + EXPECT_EQ(refs[1], mk(H2)); |
| 43 | +} |
| 44 | + |
| 45 | +// v33: same nested carrier -> collected. |
| 46 | +TEST(DGB_tx_relay_refs, V33CollectsNestedNewTxHashes) |
| 47 | +{ |
| 48 | + dgb::NewShare s; |
| 49 | + s.m_tx_info.m_new_transaction_hashes = {mk(H1)}; |
| 50 | + |
| 51 | + std::vector<uint256> refs; |
| 52 | + dgb::append_share_tx_refs(&s, refs); |
| 53 | + |
| 54 | + ASSERT_EQ(refs.size(), 1u); // dead-probe regression makes this 0 |
| 55 | + EXPECT_EQ(refs[0], mk(H1)); |
| 56 | +} |
| 57 | + |
| 58 | +// v34/v35: no m_tx_info member -> probe compiled out, vacuously empty. |
| 59 | +TEST(DGB_tx_relay_refs, SegwitVariantsCarryNoRefsByConstruction) |
| 60 | +{ |
| 61 | + dgb::SegwitMiningShare v34; |
| 62 | + dgb::PaddingBugfixShare v35; |
| 63 | + |
| 64 | + std::vector<uint256> refs; |
| 65 | + dgb::append_share_tx_refs(&v34, refs); |
| 66 | + dgb::append_share_tx_refs(&v35, refs); |
| 67 | + |
| 68 | + EXPECT_TRUE(refs.empty()); |
| 69 | +} |
| 70 | + |
| 71 | +// v36 merged-mining: no m_tx_info member -> vacuously empty. |
| 72 | +TEST(DGB_tx_relay_refs, MergedMiningShareCarriesNoRefs) |
| 73 | +{ |
| 74 | + dgb::MergedMiningShare v36; |
| 75 | + |
| 76 | + std::vector<uint256> refs; |
| 77 | + dgb::append_share_tx_refs(&v36, refs); |
| 78 | + |
| 79 | + EXPECT_TRUE(refs.empty()); |
| 80 | +} |
| 81 | + |
| 82 | +} // namespace |
0 commit comments