23
23
24
24
25
25
def small_txpuzzle_randfee (
26
- wallet , from_node , conflist , unconflist , amount , min_fee , fee_increment
26
+ wallet , from_node , conflist , unconflist , amount , min_fee , fee_increment , batch_reqs
27
27
):
28
28
"""Create and send a transaction with a random fee using MiniWallet.
29
29
@@ -57,8 +57,11 @@ def small_txpuzzle_randfee(
57
57
tx .vout [0 ].nValue = int ((total_in - amount - fee ) * COIN )
58
58
tx .vout .append (deepcopy (tx .vout [0 ]))
59
59
tx .vout [1 ].nValue = int (amount * COIN )
60
+ tx .rehash ()
61
+ txid = tx .hash
62
+ tx_hex = tx .serialize ().hex ()
60
63
61
- txid = from_node .sendrawtransaction (hexstring = tx . serialize (). hex () , maxfeerate = 0 )
64
+ batch_reqs . append ( from_node .sendrawtransaction . get_request (hexstring = tx_hex , maxfeerate = 0 ) )
62
65
unconflist .append ({"txid" : txid , "vout" : 0 , "value" : total_in - amount - fee })
63
66
unconflist .append ({"txid" : txid , "vout" : 1 , "value" : amount })
64
67
@@ -115,13 +118,12 @@ def check_estimates(node, fees_seen):
115
118
check_smart_estimates (node , fees_seen )
116
119
117
120
118
- def send_tx (wallet , node , utxo , feerate ):
119
- """Broadcast a 1in-1out transaction with a specific input and feerate (sat/vb)."""
120
- return wallet .send_self_transfer (
121
- from_node = node ,
121
+ def make_tx (wallet , utxo , feerate ):
122
+ """Create a 1in-1out transaction with a specific input and feerate (sat/vb)."""
123
+ return wallet .create_self_transfer (
122
124
utxo_to_spend = utxo ,
123
125
fee_rate = Decimal (feerate * 1000 ) / COIN ,
124
- )[ 'txid' ]
126
+ )
125
127
126
128
127
129
class EstimateFeeTest (BitcoinTestFramework ):
@@ -156,6 +158,7 @@ def transact_and_mine(self, numblocks, mining_node):
156
158
# resorting to tx's that depend on the mempool when those run out
157
159
for _ in range (numblocks ):
158
160
random .shuffle (self .confutxo )
161
+ batch_sendtx_reqs = []
159
162
for _ in range (random .randrange (100 - 50 , 100 + 50 )):
160
163
from_index = random .randint (1 , 2 )
161
164
(tx_bytes , fee ) = small_txpuzzle_randfee (
@@ -166,9 +169,12 @@ def transact_and_mine(self, numblocks, mining_node):
166
169
Decimal ("0.005" ),
167
170
min_fee ,
168
171
min_fee ,
172
+ batch_sendtx_reqs ,
169
173
)
170
174
tx_kbytes = tx_bytes / 1000.0
171
175
self .fees_per_kb .append (float (fee ) / tx_kbytes )
176
+ for node in self .nodes :
177
+ node .batch (batch_sendtx_reqs )
172
178
self .sync_mempools (wait = 0.1 )
173
179
mined = mining_node .getblock (self .generate (mining_node , 1 )[0 ], True )["tx" ]
174
180
# update which txouts are confirmed
@@ -245,14 +251,20 @@ def sanity_check_rbf_estimates(self, utxos):
245
251
assert_greater_than_or_equal (len (utxos ), 250 )
246
252
for _ in range (5 ):
247
253
# Broadcast 45 low fee transactions that will need to be RBF'd
254
+ txs = []
248
255
for _ in range (45 ):
249
256
u = utxos .pop (0 )
250
- txid = send_tx (self .wallet , node , u , low_feerate )
257
+ tx = make_tx (self .wallet , u , low_feerate )
251
258
utxos_to_respend .append (u )
252
- txids_to_replace .append (txid )
259
+ txids_to_replace .append (tx ["txid" ])
260
+ txs .append (tx )
253
261
# Broadcast 5 low fee transaction which don't need to
254
262
for _ in range (5 ):
255
- send_tx (self .wallet , node , utxos .pop (0 ), low_feerate )
263
+ tx = make_tx (self .wallet , utxos .pop (0 ), low_feerate )
264
+ txs .append (tx )
265
+ batch_send_tx = [node .sendrawtransaction .get_request (tx ["hex" ]) for tx in txs ]
266
+ for n in self .nodes :
267
+ n .batch (batch_send_tx )
256
268
# Mine the transactions on another node
257
269
self .sync_mempools (wait = 0.1 , nodes = [node , miner ])
258
270
for txid in txids_to_replace :
@@ -261,7 +273,12 @@ def sanity_check_rbf_estimates(self, utxos):
261
273
# RBF the low-fee transactions
262
274
while len (utxos_to_respend ) > 0 :
263
275
u = utxos_to_respend .pop (0 )
264
- send_tx (self .wallet , node , u , high_feerate )
276
+ tx = make_tx (self .wallet , u , high_feerate )
277
+ node .sendrawtransaction (tx ["hex" ])
278
+ txs .append (tx )
279
+ dec_txs = [res ["result" ] for res in node .batch ([node .decoderawtransaction .get_request (tx ["hex" ]) for tx in txs ])]
280
+ self .wallet .scan_txs (dec_txs )
281
+
265
282
266
283
# Mine the last replacement txs
267
284
self .sync_mempools (wait = 0.1 , nodes = [node , miner ])
0 commit comments