@@ -117,6 +117,9 @@ BOOST_FIXTURE_TEST_CASE(ephemeral_tests, RegTestingSetup)
117117 TestMemPoolEntryHelper entry;
118118 CTxMemPool::setEntries empty_ancestors;
119119
120+ TxValidationState child_state;
121+ Txid child_txid;
122+
120123 // Arbitrary non-0 feerate for these tests
121124 CFeeRate dustrelay (DUST_RELAY_TX_FEE);
122125
@@ -130,88 +133,143 @@ BOOST_FIXTURE_TEST_CASE(ephemeral_tests, RegTestingSetup)
130133 // We first start with nothing "in the mempool", using package checks
131134
132135 // Trivial single transaction with no dust
133- BOOST_CHECK (!CheckEphemeralSpends ({dust_spend}, dustrelay, pool));
136+ BOOST_CHECK (CheckEphemeralSpends ({dust_spend}, dustrelay, pool, child_state, child_txid));
137+ BOOST_CHECK (child_state.IsValid ());
138+ BOOST_CHECK_EQUAL (child_txid, Txid ());
134139
135140 // Now with dust, ok because the tx has no dusty parents
136- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1}, dustrelay, pool));
141+ BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1}, dustrelay, pool, child_state, child_txid));
142+ BOOST_CHECK (child_state.IsValid ());
143+ BOOST_CHECK_EQUAL (child_txid, Txid ());
137144
138145 // Dust checks pass
139- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, dust_spend}, CFeeRate (0 ), pool));
140- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, dust_spend}, dustrelay, pool));
146+ BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, dust_spend}, CFeeRate (0 ), pool, child_state, child_txid));
147+ BOOST_CHECK (child_state.IsValid ());
148+ BOOST_CHECK_EQUAL (child_txid, Txid ());
149+ BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, dust_spend}, dustrelay, pool, child_state, child_txid));
150+ BOOST_CHECK (child_state.IsValid ());
151+ BOOST_CHECK_EQUAL (child_txid, Txid ());
141152
142153 auto dust_non_spend = make_tx ({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX - 1 }}, /* version=*/ 2 );
143154
144155 // Child spending non-dust only from parent should be disallowed even if dust otherwise spent
145156 const auto dust_non_spend_txid{dust_non_spend->GetHash ()};
146- const Txid null_txid;
147- assert (dust_non_spend_txid != null_txid);
148- BOOST_CHECK_EQUAL (CheckEphemeralSpends ({grandparent_tx_1, dust_non_spend, dust_spend}, dustrelay, pool).value_or (null_txid), dust_non_spend_txid);
149- BOOST_CHECK_EQUAL (CheckEphemeralSpends ({grandparent_tx_1, dust_spend, dust_non_spend}, dustrelay, pool).value_or (null_txid), dust_non_spend_txid);
150- BOOST_CHECK_EQUAL (CheckEphemeralSpends ({grandparent_tx_1, dust_non_spend}, dustrelay, pool).value_or (null_txid), dust_non_spend_txid);
157+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, dust_non_spend, dust_spend}, dustrelay, pool, child_state, child_txid));
158+ BOOST_CHECK (!child_state.IsValid ());
159+ BOOST_CHECK_EQUAL (child_txid, dust_non_spend_txid);
160+ child_state = TxValidationState ();
161+ child_txid = Txid ();
162+
163+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, dust_spend, dust_non_spend}, dustrelay, pool, child_state, child_txid));
164+ BOOST_CHECK (!child_state.IsValid ());
165+ BOOST_CHECK_EQUAL (child_txid, dust_non_spend_txid);
166+ child_state = TxValidationState ();
167+ child_txid = Txid ();
168+
169+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, dust_non_spend}, dustrelay, pool, child_state, child_txid));
170+ BOOST_CHECK (!child_state.IsValid ());
171+ BOOST_CHECK_EQUAL (child_txid, dust_non_spend_txid);
172+ child_state = TxValidationState ();
173+ child_txid = Txid ();
151174
152175 auto grandparent_tx_2 = make_ephemeral_tx (random_outpoints (1 ), /* version=*/ 2 );
153176 const auto dust_txid_2 = grandparent_tx_2->GetHash ();
154177
155178 // Spend dust from one but not another is ok, as long as second grandparent has no child
156- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend}, dustrelay, pool));
179+ BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend}, dustrelay, pool, child_state, child_txid));
180+ BOOST_CHECK (child_state.IsValid ());
181+ BOOST_CHECK_EQUAL (child_txid, Txid ());
157182
158183 auto dust_non_spend_both_parents = make_tx ({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}, COutPoint{dust_txid_2, EPHEMERAL_DUST_INDEX - 1 }}, /* version=*/ 2 );
159184 // But if we spend from the parent, it must spend dust
160- BOOST_CHECK_EQUAL (CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_non_spend_both_parents}, dustrelay, pool).value_or (null_txid), dust_non_spend_both_parents->GetHash ());
185+ BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_non_spend_both_parents}, dustrelay, pool, child_state, child_txid));
186+ BOOST_CHECK (!child_state.IsValid ());
187+ BOOST_CHECK_EQUAL (child_txid, dust_non_spend_both_parents->GetHash ());
188+ child_state = TxValidationState ();
189+ child_txid = Txid ();
161190
162191 auto dust_spend_both_parents = make_tx ({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}, COutPoint{dust_txid_2, EPHEMERAL_DUST_INDEX}}, /* version=*/ 2 );
163- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend_both_parents}, dustrelay, pool));
192+ BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend_both_parents}, dustrelay, pool, child_state, child_txid));
193+ BOOST_CHECK (child_state.IsValid ());
194+ BOOST_CHECK_EQUAL (child_txid, Txid ());
164195
165196 // Spending other outputs is also correct, as long as the dusty one is spent
166197 const std::vector<COutPoint> all_outpoints{COutPoint (dust_txid, 0 ), COutPoint (dust_txid, 1 ), COutPoint (dust_txid, 2 ),
167198 COutPoint (dust_txid_2, 0 ), COutPoint (dust_txid_2, 1 ), COutPoint (dust_txid_2, 2 )};
168199 auto dust_spend_all_outpoints = make_tx (all_outpoints, /* version=*/ 2 );
169- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend_all_outpoints}, dustrelay, pool));
200+ BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, dust_spend_all_outpoints}, dustrelay, pool, child_state, child_txid));
201+ BOOST_CHECK (child_state.IsValid ());
202+ BOOST_CHECK_EQUAL (child_txid, Txid ());
170203
171204 // 2 grandparents with dust <- 1 dust-spending parent with dust <- child with no dust
172205 auto parent_with_dust = make_ephemeral_tx ({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}, COutPoint{dust_txid_2, EPHEMERAL_DUST_INDEX}}, /* version=*/ 2 );
173206 // Ok for parent to have dust
174- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust}, dustrelay, pool));
207+ BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust}, dustrelay, pool, child_state, child_txid));
208+ BOOST_CHECK (child_state.IsValid ());
209+ BOOST_CHECK_EQUAL (child_txid, Txid ());
175210 auto child_no_dust = make_tx ({COutPoint{parent_with_dust->GetHash (), EPHEMERAL_DUST_INDEX}}, /* version=*/ 2 );
176- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_no_dust}, dustrelay, pool));
211+ BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_no_dust}, dustrelay, pool, child_state, child_txid));
212+ BOOST_CHECK (child_state.IsValid ());
213+ BOOST_CHECK_EQUAL (child_txid, Txid ());
177214
178215 // 2 grandparents with dust <- 1 dust-spending parent with dust <- child with dust
179216 auto child_with_dust = make_ephemeral_tx ({COutPoint{parent_with_dust->GetHash (), EPHEMERAL_DUST_INDEX}}, /* version=*/ 2 );
180- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_with_dust}, dustrelay, pool));
217+ BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1, grandparent_tx_2, parent_with_dust, child_with_dust}, dustrelay, pool, child_state, child_txid));
218+ BOOST_CHECK (child_state.IsValid ());
219+ BOOST_CHECK_EQUAL (child_txid, Txid ());
181220
182221 // Tests with parents in mempool
183222
184223 // Nothing in mempool, this should pass for any transaction
185- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_1}, dustrelay, pool));
224+ BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_1}, dustrelay, pool, child_state, child_txid));
225+ BOOST_CHECK (child_state.IsValid ());
226+ BOOST_CHECK_EQUAL (child_txid, Txid ());
186227
187228 // Add first grandparent to mempool and fetch entry
188229 pool.addUnchecked (entry.FromTx (grandparent_tx_1));
189230
190231 // Ignores ancestors that aren't direct parents
191- BOOST_CHECK (!CheckEphemeralSpends ({child_no_dust}, dustrelay, pool));
232+ BOOST_CHECK (CheckEphemeralSpends ({child_no_dust}, dustrelay, pool, child_state, child_txid));
233+ BOOST_CHECK (child_state.IsValid ());
234+ BOOST_CHECK_EQUAL (child_txid, Txid ());
192235
193236 // Valid spend of dust with grandparent in mempool
194- BOOST_CHECK (!CheckEphemeralSpends ({parent_with_dust}, dustrelay, pool));
237+ BOOST_CHECK (CheckEphemeralSpends ({parent_with_dust}, dustrelay, pool, child_state, child_txid));
238+ BOOST_CHECK (child_state.IsValid ());
239+ BOOST_CHECK_EQUAL (child_txid, Txid ());
195240
196241 // Second grandparent in same package
197- BOOST_CHECK (!CheckEphemeralSpends ({parent_with_dust, grandparent_tx_2}, dustrelay, pool));
242+ BOOST_CHECK (CheckEphemeralSpends ({parent_with_dust, grandparent_tx_2}, dustrelay, pool, child_state, child_txid));
243+ BOOST_CHECK (child_state.IsValid ());
244+ BOOST_CHECK_EQUAL (child_txid, Txid ());
245+
198246 // Order in package doesn't matter
199- BOOST_CHECK (!CheckEphemeralSpends ({grandparent_tx_2, parent_with_dust}, dustrelay, pool));
247+ BOOST_CHECK (CheckEphemeralSpends ({grandparent_tx_2, parent_with_dust}, dustrelay, pool, child_state, child_txid));
248+ BOOST_CHECK (child_state.IsValid ());
249+ BOOST_CHECK_EQUAL (child_txid, Txid ());
200250
201251 // Add second grandparent to mempool
202252 pool.addUnchecked (entry.FromTx (grandparent_tx_2));
203253
204254 // Only spends single dust out of two direct parents
205- BOOST_CHECK_EQUAL (CheckEphemeralSpends ({dust_non_spend_both_parents}, dustrelay, pool).value_or (null_txid), dust_non_spend_both_parents->GetHash ());
255+ BOOST_CHECK (!CheckEphemeralSpends ({dust_non_spend_both_parents}, dustrelay, pool, child_state, child_txid));
256+ BOOST_CHECK (!child_state.IsValid ());
257+ BOOST_CHECK_EQUAL (child_txid, dust_non_spend_both_parents->GetHash ());
258+ child_state = TxValidationState ();
259+ child_txid = Txid ();
206260
207261 // Spends both parents' dust
208- BOOST_CHECK (!CheckEphemeralSpends ({parent_with_dust}, dustrelay, pool));
262+ BOOST_CHECK (CheckEphemeralSpends ({parent_with_dust}, dustrelay, pool, child_state, child_txid));
263+ BOOST_CHECK (child_state.IsValid ());
264+ BOOST_CHECK_EQUAL (child_txid, Txid ());
209265
210266 // Now add dusty parent to mempool
211267 pool.addUnchecked (entry.FromTx (parent_with_dust));
212268
213269 // Passes dust checks even with non-parent ancestors
214- BOOST_CHECK (!CheckEphemeralSpends ({child_no_dust}, dustrelay, pool));
270+ BOOST_CHECK (CheckEphemeralSpends ({child_no_dust}, dustrelay, pool, child_state, child_txid));
271+ BOOST_CHECK (child_state.IsValid ());
272+ BOOST_CHECK_EQUAL (child_txid, Txid ());
215273}
216274
217275BOOST_FIXTURE_TEST_CASE (version3_tests, RegTestingSetup)
0 commit comments