@@ -117,6 +117,9 @@ BOOST_FIXTURE_TEST_CASE(ephemeral_tests, RegTestingSetup)
117
117
TestMemPoolEntryHelper entry;
118
118
CTxMemPool::setEntries empty_ancestors;
119
119
120
+ TxValidationState child_state;
121
+ Txid child_txid;
122
+
120
123
// Arbitrary non-0 feerate for these tests
121
124
CFeeRate dustrelay (DUST_RELAY_TX_FEE);
122
125
@@ -130,88 +133,143 @@ BOOST_FIXTURE_TEST_CASE(ephemeral_tests, RegTestingSetup)
130
133
// We first start with nothing "in the mempool", using package checks
131
134
132
135
// 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 ());
134
139
135
140
// 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 ());
137
144
138
145
// 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 ());
141
152
142
153
auto dust_non_spend = make_tx ({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX - 1 }}, /* version=*/ 2 );
143
154
144
155
// Child spending non-dust only from parent should be disallowed even if dust otherwise spent
145
156
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 ();
151
174
152
175
auto grandparent_tx_2 = make_ephemeral_tx (random_outpoints (1 ), /* version=*/ 2 );
153
176
const auto dust_txid_2 = grandparent_tx_2->GetHash ();
154
177
155
178
// 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 ());
157
182
158
183
auto dust_non_spend_both_parents = make_tx ({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}, COutPoint{dust_txid_2, EPHEMERAL_DUST_INDEX - 1 }}, /* version=*/ 2 );
159
184
// 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 ();
161
190
162
191
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 ());
164
195
165
196
// Spending other outputs is also correct, as long as the dusty one is spent
166
197
const std::vector<COutPoint> all_outpoints{COutPoint (dust_txid, 0 ), COutPoint (dust_txid, 1 ), COutPoint (dust_txid, 2 ),
167
198
COutPoint (dust_txid_2, 0 ), COutPoint (dust_txid_2, 1 ), COutPoint (dust_txid_2, 2 )};
168
199
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 ());
170
203
171
204
// 2 grandparents with dust <- 1 dust-spending parent with dust <- child with no dust
172
205
auto parent_with_dust = make_ephemeral_tx ({COutPoint{dust_txid, EPHEMERAL_DUST_INDEX}, COutPoint{dust_txid_2, EPHEMERAL_DUST_INDEX}}, /* version=*/ 2 );
173
206
// 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 ());
175
210
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 ());
177
214
178
215
// 2 grandparents with dust <- 1 dust-spending parent with dust <- child with dust
179
216
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 ());
181
220
182
221
// Tests with parents in mempool
183
222
184
223
// 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 ());
186
227
187
228
// Add first grandparent to mempool and fetch entry
188
229
pool.addUnchecked (entry.FromTx (grandparent_tx_1));
189
230
190
231
// 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 ());
192
235
193
236
// 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 ());
195
240
196
241
// 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
+
198
246
// 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 ());
200
250
201
251
// Add second grandparent to mempool
202
252
pool.addUnchecked (entry.FromTx (grandparent_tx_2));
203
253
204
254
// 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 ();
206
260
207
261
// 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 ());
209
265
210
266
// Now add dusty parent to mempool
211
267
pool.addUnchecked (entry.FromTx (parent_with_dust));
212
268
213
269
// 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 ());
215
273
}
216
274
217
275
BOOST_FIXTURE_TEST_CASE (version3_tests, RegTestingSetup)
0 commit comments