Inspired by refactorings in #30000 as the coverage appeared a bit sparse.
Added some minimal border value testing, timeouts, and tightened existing assertions.
Inspired by refactorings in #30000 as the coverage appeared a bit sparse.
Added some minimal border value testing, timeouts, and tightened existing assertions.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
For detailed information about the code coverage, see the test coverage report.
See the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
175 {
176- size_t sizeBefore = orphanage.CountOrphans();
177 orphanage.EraseForPeer(i);
178- BOOST_CHECK(orphanage.CountOrphans() < sizeBefore);
179+ BOOST_CHECK(orphanage.CountOrphans() == expected_num_orphans - 2);
180+ expected_num_orphans -= 2;
nit: just update the value beforehand?
0 expected_num_orphans -= 2;
1 BOOST_CHECK(orphanage.CountOrphans() == expected_num_orphans);
203+ tx.vin[0].prevout.n = 0;
204+ tx.vin[0].prevout.hash = Txid::FromUint256(InsecureRand256());
205+ tx.vin[0].scriptSig << OP_1;
206+ tx.vout.resize(1);
207+ tx.vout[0].nValue = 1*CENT;
208+ tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
MakeTransactionSpending()
?
213+
214+ // Jump ORPHAN_TX_EXPIRE_TIME minutes, orphan should be timed out on limiting
215+ SetMockTime(GetTime() + 20 * 60);
216+ BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 1);
217+ orphanage.LimitOrphans(1, rng);
218+ BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 0);
current_time
parameter to the TxOrphanage
methods to make it easier to test and fuzz the expiration (also should have a test for the sorting for GetChildrenFromSamePeer
results)
210+ // One second shy of expiration
211+ SetMockTime(now - 1 + 20 * 60);
212+ orphanage.LimitOrphans(1, rng);
213+ BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 1);
214+
215+ // Jump ORPHAN_TX_EXPIRE_TIME minutes, orphan should be timed out on limiting
206+ orphanage.AddTx(timeout_tx, 0);
207+ orphanage.LimitOrphans(1, rng);
208+ BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 1);
209+
210+ // One second shy of expiration
211+ SetMockTime(now - 1 + 20 * 60);
181+
182+ // Non-existent peer; nothing should be deleted
183+ orphanage.EraseForPeer(/*peer=*/-1);
184+ BOOST_CHECK_EQUAL(orphanage.CountOrphans(), expected_num_orphans);
185+
186+ // Test EraseOrphansFor: Each of first three peers announced
EraseOrphansFor
doesn’t exist
182+ // Non-existent peer; nothing should be deleted
183+ orphanage.EraseForPeer(/*peer=*/-1);
184+ BOOST_CHECK_EQUAL(orphanage.CountOrphans(), expected_num_orphans);
185+
186+ // Each of first three peers announced
187+ // two transactions each.
201+ BOOST_CHECK_EQUAL(orphanage.CountOrphans(), expected_num_orphans);
202+ orphanage.LimitOrphans(/*max_orphans=*/expected_num_orphans - 1, rng);
203+ BOOST_CHECK_EQUAL(orphanage.CountOrphans(), expected_num_orphans - 1);
204 orphanage.LimitOrphans(40, rng);
205- BOOST_CHECK(orphanage.CountOrphans() <= 40);
206+ BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 40);
expected_num_orphans
like expected_num_orphans -3
in the LimitOrphans
call would make it more explicit (but not necessarily in the BOOST_CHECK
), otherwise it made me wonder whether the current count is more than 40 or not.
209+ BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 10);
210 orphanage.LimitOrphans(0, rng);
211- BOOST_CHECK(orphanage.CountOrphans() == 0);
212+ BOOST_CHECK_EQUAL(orphanage.CountOrphans(), 0);
213+
214+ // Add one more orphan, check timeout logic
Can you please share how exactly is this being done check timeout logic
here?
I see from the AddTx
code that if the tx size is more than the standard weight, then it will not be added in the orphanage. Is the timeout logic here that the size of this tx is less than the standard weight and therefore it’s inserted?
LimitOrphans
13@@ -14,6 +14,11 @@
14 #include <map>
15 #include <set>
16
17+/** Expiration time for orphan transactions */
18+static constexpr auto ORPHAN_TX_EXPIRE_TIME{20min};
19+/** Minimum time between orphan transactions expire time checks */
20+static constexpr auto ORPHAN_TX_EXPIRE_INTERVAL{5min};
21+
reACK 172c1ad
Thanks for very quickly addressing my comments @instagibbs, appreciate it!