@@ -31,70 +31,78 @@ def add_options(self, parser):
31
31
help = "Rate per second at which transactions are generated. (default 5 tx/s)" ,
32
32
)
33
33
34
- def run_test (self ):
35
- self .log .info ("Starting Double TX Relay Scenario" )
36
- self .block_queue = []
37
- self .mutex = Lock ()
38
- self .sent_txs = 0 # protected by mutex
39
- self .time_of_last_log = datetime .now () # protected by mutex
40
- self .failed_txs = 0 # protected by mutex
41
- self .node_details = {}
42
- self .miniwallet = MiniWallet (self .nodes [0 ])
34
+ def generate_spendable_coins (self ):
43
35
num_blocks = COINBASE_MATURITY + 100
44
36
self .log .info (f"Generating { num_blocks } blocks..." )
45
37
self .generate (self .miniwallet , num_blocks )
46
38
self .log .info ("Rescanning utxos" )
47
39
self .miniwallet .rescan_utxos ()
48
40
49
- split_num = 1000
41
+ def split_utxos ( self , num_outputs = 1000 ) -> list :
50
42
confirmed_utxos = self .miniwallet .get_utxos (confirmed_only = True )
51
- print (f"Starting with { len (confirmed_utxos )} confirmed utxos, now splitting each into 1000..." )
43
+ self .log .info (f"Got { len (confirmed_utxos )} confirmed utxos" )
44
+ self .log .info (f"Splitting each utxo into { num_outputs } utxos..." )
52
45
for i , utxo in enumerate (confirmed_utxos ):
53
- tx = self .miniwallet .send_self_transfer_multi (from_node = self .nodes [0 ], utxos_to_spend = [utxo ], num_outputs = split_num )
46
+ tx = self .miniwallet .send_self_transfer_multi (from_node = self .nodes [0 ], utxos_to_spend = [utxo ], num_outputs = num_outputs )
54
47
self .log .info (f"Sent tx { i } of { len (confirmed_utxos )} : { tx ['txid' ]} " )
55
- self .generate (self .miniwallet , 6 )
48
+ self .generate (self .miniwallet , 3 )
56
49
self .miniwallet .rescan_utxos ()
57
-
50
+ self . log . info ( "Split complete" )
58
51
confirmed_utxos = self .miniwallet .get_utxos (confirmed_only = True )
59
- self .log .info (f"Now got { len (confirmed_utxos )} utxos" )
52
+ self .log .info (f"Got { len (confirmed_utxos )} confirmed utxos" )
53
+ return confirmed_utxos
60
54
61
- self .log .info (
62
- f"Starting process to send transactions at a rate of { self .options .txproductionrate } tx/s"
63
- )
55
+ def produce_transactions (self , confirmed_utxos : list ):
56
+ self .log .info (f"Starting process to send anyone-can-spend transactions. Aiming for a rate of { self .options .txproductionrate } tx/s" )
64
57
tx_count = 0
65
- start_time = time .time ()
66
- interval = 1 / self .options .txproductionrate
58
+ target_interval = 1 / self .options .txproductionrate
67
59
time_to_next_tx = 0
60
+
61
+ start_time = time .time ()
62
+ interval_start_time = time .time ()
63
+ interval_end_time = time .time ()
68
64
next_log_time = start_time + 10
69
65
70
66
while True :
71
67
for node in self .nodes :
72
- time .sleep (time_to_next_tx )
73
68
69
+ time .sleep (time_to_next_tx )
74
70
tx_start_time = time .time ()
75
- if len (confirmed_utxos ) == 0 :
71
+
72
+ if not confirmed_utxos :
76
73
self .generate (self .miniwallet , 1 )
77
74
self .miniwallet .rescan_utxos ()
78
75
confirmed_utxos = self .miniwallet .get_utxos (confirmed_only = True )
76
+
79
77
utxo = confirmed_utxos .pop ()
80
78
try :
81
79
self .miniwallet .send_self_transfer (from_node = node , utxo_to_spend = utxo )
82
80
tx_count += 1
83
81
except JSONRPCException as e :
84
82
self .log .warning (f"tx failed: { e } , continuing" )
85
83
86
- # Adjust next sleep
84
+ # Adjust sleep before next send
87
85
tx_end_time = time .time ()
88
86
tx_duration = tx_end_time - tx_start_time
89
- time_to_next_tx = max (0 , interval - tx_duration )
87
+ time_to_next_tx = max (0 , target_interval - tx_duration )
90
88
91
89
current_time = time .time ()
92
- elapsed_time = current_time - start_time
93
90
94
91
if current_time >= next_log_time :
95
- tps = tx_count / elapsed_time
92
+ interval_end_time = time .time ()
93
+ tps = tx_count / (interval_end_time - interval_start_time )
96
94
self .log .info (f"Transactions per second (TPS): { tps } " )
97
95
next_log_time += 10
96
+ interval_start_time = time .time ()
97
+ tx_count = 0
98
+
99
+
100
+ def run_test (self ):
101
+ self .log .info ("Starting Double TX Relay Scenario" )
102
+ self .miniwallet = MiniWallet (self .nodes [0 ])
103
+ self .generate_spendable_coins ()
104
+ confirmed_utxos = self .split_utxos (num_outputs = 1000 )
105
+ self .produce_transactions (confirmed_utxos )
98
106
99
107
100
108
if __name__ == "__main__" :
0 commit comments