Skip to content

Commit 04448ce

Browse files
committed
[txorphanage] add GetTx so that orphan vin can be read
1 parent e810842 commit 04448ce

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

src/test/fuzz/txorphan.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,8 @@ FUZZ_TARGET(txorphan, .init = initialize_orphanage)
157157
ptx_potential_parent = tx;
158158
}
159159

160+
const bool have_tx{orphanage.HaveTx(tx->GetWitnessHash())};
161+
const bool get_tx_nonnull{orphanage.GetTx(tx->GetWitnessHash()) != nullptr};
162+
Assert(have_tx == get_tx_nonnull);
160163
}
161164
}

src/test/orphanage_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ BOOST_AUTO_TEST_CASE(same_txid_diff_witness)
250250
// EraseTx fails as transaction by this wtxid doesn't exist.
251251
BOOST_CHECK_EQUAL(orphanage.EraseTx(mutated_wtxid), 0);
252252
BOOST_CHECK(orphanage.HaveTx(normal_wtxid));
253+
BOOST_CHECK(orphanage.GetTx(normal_wtxid) == child_normal);
253254
BOOST_CHECK(!orphanage.HaveTx(mutated_wtxid));
255+
BOOST_CHECK(orphanage.GetTx(mutated_wtxid) == nullptr);
254256

255257
// Must succeed. Both transactions should be present in orphanage.
256258
BOOST_CHECK(orphanage.AddTx(child_mutated, peer));

src/txorphanage.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ bool TxOrphanage::HaveTx(const Wtxid& wtxid) const
179179
return m_orphans.count(wtxid);
180180
}
181181

182+
CTransactionRef TxOrphanage::GetTx(const Wtxid& wtxid) const
183+
{
184+
auto it = m_orphans.find(wtxid);
185+
return it != m_orphans.end() ? it->second.tx : nullptr;
186+
}
187+
182188
bool TxOrphanage::HaveTxFromPeer(const Wtxid& wtxid, NodeId peer) const
183189
{
184190
auto it = m_orphans.find(wtxid);

src/txorphanage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class TxOrphanage {
3333
/** Add an additional announcer to an orphan if it exists. Otherwise, do nothing. */
3434
bool AddAnnouncer(const Wtxid& wtxid, NodeId peer);
3535

36+
CTransactionRef GetTx(const Wtxid& wtxid) const;
37+
3638
/** Check if we already have an orphan transaction (by wtxid only) */
3739
bool HaveTx(const Wtxid& wtxid) const;
3840

0 commit comments

Comments
 (0)