@@ -186,17 +186,18 @@ def verify_utxo_hash(self):
186186 assert_equal (nodei_utxo_hash , node3_utxo_hash )
187187
188188 def generate_small_transactions (self , node , count , utxo_list ):
189- FEE = 1000 # TODO: replace this with node relay fee based calculation
190189 num_transactions = 0
191190 random .shuffle (utxo_list )
192191 while len (utxo_list ) >= 2 and num_transactions < count :
192+ fee = 1000
193193 tx = CTransaction ()
194194 input_amount = 0
195195 for _ in range (2 ):
196196 utxo = utxo_list .pop ()
197197 tx .vin .append (CTxIn (COutPoint (int (utxo ['txid' ], 16 ), utxo ['vout' ])))
198198 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 )
200201
201202 if output_amount <= 0 :
202203 # Sanity check -- if we chose inputs that are too small, skip
@@ -205,6 +206,9 @@ def generate_small_transactions(self, node, count, utxo_list):
205206 for _ in range (3 ):
206207 tx .vout .append (CTxOut (output_amount , bytes .fromhex (utxo ['scriptPubKey' ])))
207208
209+ # ELEMENTS: add fee output
210+ tx .vout .append (CTxOut (fee ))
211+
208212 # Sign and send the transaction to get into the mempool
209213 tx_signed_hex = node .signrawtransactionwithwallet (tx .serialize ().hex ())['hex' ]
210214 node .sendrawtransaction (tx_signed_hex )
@@ -234,10 +238,13 @@ def run_test(self):
234238 # Main test loop:
235239 # each time through the loop, generate a bunch of transactions,
236240 # 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 } " )
239246 # 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 )
241248 # Pick a random block between current tip, and starting tip
242249 current_height = self .nodes [3 ].getblockcount ()
243250 random_height = random .randint (starting_tip_height , current_height )
@@ -265,6 +272,11 @@ def run_test(self):
265272 utxo_list = self .nodes [3 ].listunspent ()
266273 self .log .debug (f"Node3 utxo count: { len (utxo_list )} " )
267274
275+ if i >= 11 :
276+ raise AssertionError (f"12 iterations without node crash, this should not happen" )
277+ else :
278+ i += 1
279+
268280 # Check that the utxo hashes agree with node3
269281 # Useful side effect: each utxo cache gets flushed here, so that we
270282 # won't get crashes on shutdown at the end of the test.
0 commit comments