@@ -186,17 +186,18 @@ def verify_utxo_hash(self):
186
186
assert_equal (nodei_utxo_hash , node3_utxo_hash )
187
187
188
188
def generate_small_transactions (self , node , count , utxo_list ):
189
- FEE = 1000 # TODO: replace this with node relay fee based calculation
190
189
num_transactions = 0
191
190
random .shuffle (utxo_list )
192
191
while len (utxo_list ) >= 2 and num_transactions < count :
192
+ fee = 1000
193
193
tx = CTransaction ()
194
194
input_amount = 0
195
195
for _ in range (2 ):
196
196
utxo = utxo_list .pop ()
197
197
tx .vin .append (CTxIn (COutPoint (int (utxo ['txid' ], 16 ), utxo ['vout' ])))
198
198
input_amount += int (utxo ['amount' ] * COIN )
199
- output_amount = (input_amount - FEE ) // 3
199
+ output_amount = (input_amount - fee ) // 3
200
+ fee = input_amount - (3 * output_amount )
200
201
201
202
if output_amount <= 0 :
202
203
# Sanity check -- if we chose inputs that are too small, skip
@@ -205,6 +206,9 @@ def generate_small_transactions(self, node, count, utxo_list):
205
206
for _ in range (3 ):
206
207
tx .vout .append (CTxOut (output_amount , bytes .fromhex (utxo ['scriptPubKey' ])))
207
208
209
+ # ELEMENTS: add fee output
210
+ tx .vout .append (CTxOut (fee ))
211
+
208
212
# Sign and send the transaction to get into the mempool
209
213
tx_signed_hex = node .signrawtransactionwithwallet (tx .serialize ().hex ())['hex' ]
210
214
node .sendrawtransaction (tx_signed_hex )
@@ -234,10 +238,13 @@ def run_test(self):
234
238
# Main test loop:
235
239
# each time through the loop, generate a bunch of transactions,
236
240
# and then either mine a single new block on the tip, or some-sized reorg.
237
- for i in range (40 ):
238
- self .log .info (f"Iteration { i } , generating 2500 transactions { self .restart_counts } " )
241
+ # ELEMENTS: modified to only run until successfully testing a node crash on restart
242
+ # with a maximum of 10 iterations
243
+ i = 0
244
+ while self .crashed_on_restart < 1 :
245
+ self .log .info (f"Iteration { i } , generating 3000 transactions { self .restart_counts } " )
239
246
# Generate a bunch of small-ish transactions
240
- self .generate_small_transactions (self .nodes [3 ], 2500 , utxo_list )
247
+ self .generate_small_transactions (self .nodes [3 ], 3000 , utxo_list )
241
248
# Pick a random block between current tip, and starting tip
242
249
current_height = self .nodes [3 ].getblockcount ()
243
250
random_height = random .randint (starting_tip_height , current_height )
@@ -265,6 +272,11 @@ def run_test(self):
265
272
utxo_list = self .nodes [3 ].listunspent ()
266
273
self .log .debug (f"Node3 utxo count: { len (utxo_list )} " )
267
274
275
+ if i >= 11 :
276
+ raise AssertionError (f"12 iterations without node crash, this should not happen" )
277
+ else :
278
+ i += 1
279
+
268
280
# Check that the utxo hashes agree with node3
269
281
# Useful side effect: each utxo cache gets flushed here, so that we
270
282
# won't get crashes on shutdown at the end of the test.
0 commit comments