Skip to content

Commit 0ebcbe6

Browse files
committed
autogenerate-rpc-examples.py: more block generation and synchronization.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent b0f4abd commit 0ebcbe6

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

tests/autogenerate-rpc-examples.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def setup_test_nodes(node_factory, bitcoind, regenerate_blockchain):
161161
for node in fund_nodes:
162162
node.fundwallet(FUND_WALLET_AMOUNT_SAT)
163163
# Connect nodes and fund channels
164+
sync_blockheight(bitcoind, [l1, l2, l3, l4, l5, l6])
164165
update_example(node=l2, method='getinfo', params={})
165166
update_example(node=l1, method='connect', params={'id': l2.info['id'], 'host': 'localhost', 'port': l2.daemon.port})
166167
update_example(node=l2, method='connect', params={'id': l3.info['id'], 'host': 'localhost', 'port': l3.daemon.port})
@@ -247,7 +248,7 @@ def generate_transactions_examples(l1, l2, l3, l4, l5, c25, bitcoind):
247248
update_example(node=l2, method='close', params={'id': l3.info['id'], 'unilateraltimeout': 1})
248249
address_l41 = l4.rpc.newaddr()
249250
update_example(node=l3, method='close', params={'id': l4.info['id'], 'destination': address_l41['bech32']})
250-
bitcoind.generate_block(1)
251+
bitcoind.generate_block(1, wait_for_mempool=2)
251252
sync_blockheight(bitcoind, [l1, l2, l3, l4])
252253

253254
# Channel 2 to 3 is closed, l1->l3 payment will fail where `failed` forward will be saved on l2
@@ -263,6 +264,12 @@ def generate_transactions_examples(l1, l2, l3, l4, l5, c25, bitcoind):
263264
update_example(node=l2, method='setchannel', params={'id': c23_2, 'ignorefeelimits': True})
264265
update_example(node=l2, method='setchannel', params={'id': c25, 'feebase': 4000, 'feeppm': 300, 'enforcedelay': 0})
265266

267+
# Those involved in the channel close will instaclose, so listchannels will differ.
268+
# Make sure everyone sees those new channels though.
269+
for n in [l1, l2, l3, l4]:
270+
wait_for(lambda: len(n.rpc.listchannels(c23_2)['channels']) == 2)
271+
wait_for(lambda: len(n.rpc.listchannels(c34_2)['channels']) == 2)
272+
266273
# Some more invoices for signing and preapproving
267274
inv_l12 = l1.rpc.invoice(1000, 'label inv_l12', 'description inv_l12')
268275
inv_l24 = l2.rpc.invoice(123000, 'label inv_l24', 'description inv_l24', 3600)
@@ -621,6 +628,7 @@ def generate_utils_examples(l1, l2, l3, l4, l5, l6, c23_2, c34_2, inv_l11, inv_l
621628
utxos = [f"{funds_l2['outputs'][2]['txid']}:{funds_l2['outputs'][2]['output']}"]
622629
withdraw_l22 = update_example(node=l2, method='withdraw', params={'destination': address_l22['p2tr'], 'satoshi': 'all', 'feerate': '20000perkb', 'minconf': 0, 'utxos': utxos})
623630
bitcoind.generate_block(4, wait_for_mempool=[withdraw_l22['txid']])
631+
sync_blockheight(bitcoind, [l2])
624632
update_example(node=l2, method='multiwithdraw', params={'outputs': [{l1.rpc.newaddr()['bech32']: '2222000msat'}, {l1.rpc.newaddr()['bech32']: '3333000msat'}]})
625633
update_example(node=l2, method='multiwithdraw', params={'outputs': [{l1.rpc.newaddr('p2tr')['p2tr']: 1000}, {l1.rpc.newaddr()['bech32']: 1000}, {l2.rpc.newaddr()['bech32']: 1000}, {l3.rpc.newaddr()['bech32']: 1000}, {l3.rpc.newaddr()['bech32']: 1000}, {l4.rpc.newaddr('p2tr')['p2tr']: 1000}, {l1.rpc.newaddr()['bech32']: 1000}]})
626634
l2.rpc.connect(l4.info['id'], 'localhost', l4.port)
@@ -668,6 +676,9 @@ def generate_utils_examples(l1, l2, l3, l4, l5, l6, c23_2, c34_2, inv_l11, inv_l
668676
l1.rpc.reserveinputs(fullpsbt)
669677
signed_psbt = l1.rpc.signpsbt(fullpsbt)['signed_psbt']
670678
update_example(node=l1, method='sendpsbt', params={'psbt': signed_psbt})
679+
# Includes two multiwithdraw calls above
680+
bitcoind.generate_block(1, wait_for_mempool=3)
681+
sync_blockheight(bitcoind, [l1, l2, l3, l4])
671682

672683
# SQL
673684
update_example(node=l1, method='sql', params={'query': 'SELECT id FROM peers'}, description=['A simple peers selection query:'])
@@ -721,7 +732,7 @@ def generate_splice_examples(node_factory, bitcoind, regenerate_blockchain):
721732
signpsbt_res1 = l7.rpc.signpsbt(spupdate2_res1['psbt'])
722733
update_example(node=l7, method='splice_signed', params={'channel_id': chan_id_78, 'psbt': signpsbt_res1['signed_psbt']})
723734

724-
bitcoind.generate_block(1)
735+
bitcoind.generate_block(1, wait_for_mempool=1)
725736
sync_blockheight(bitcoind, [l7])
726737
l7.daemon.wait_for_log(' to CHANNELD_NORMAL')
727738
time.sleep(1)
@@ -736,6 +747,8 @@ def generate_splice_examples(node_factory, bitcoind, regenerate_blockchain):
736747
spupdate2_res2 = update_example(node=l7, method='splice_update', params=[chan_id_78, spupdate1_res2['psbt']])
737748
assert(spupdate2_res2['commitments_secured'] is True)
738749
update_example(node=l7, method='splice_signed', params={'channel_id': chan_id_78, 'psbt': spupdate2_res2['psbt']})
750+
bitcoind.generate_block(1, wait_for_mempool=1)
751+
sync_blockheight(bitcoind, [l7, l8])
739752
update_example(node=l7, method='stop', params={})
740753

741754
logger.info('Splice Done!')
@@ -766,7 +779,6 @@ def generate_channels_examples(node_factory, bitcoind, l1, l3, l4, l5, regenerat
766779

767780
amount = 2 ** 24
768781
l9.fundwallet(amount + 10000000)
769-
bitcoind.generate_block(1)
770782
wait_for(lambda: len(l9.rpc.listfunds()["outputs"]) != 0)
771783
l9.rpc.connect(l10.info['id'], 'localhost', l10.port)
772784

@@ -784,8 +796,8 @@ def generate_channels_examples(node_factory, bitcoind, l1, l3, l4, l5, regenerat
784796
update_example(node=l9, method='txsend', params=[tx_prep_2['txid']])
785797
l9.rpc.close(l10.info['id'])
786798

787-
bitcoind.generate_block(1)
788-
sync_blockheight(bitcoind, [l9])
799+
bitcoind.generate_block(1, wait_for_mempool=1)
800+
sync_blockheight(bitcoind, [l9, l10])
789801

790802
amount = 1000000
791803
fund_start_res3 = l9.rpc.fundchannel_start(l10.info['id'], amount)
@@ -851,10 +863,11 @@ def generate_channels_examples(node_factory, bitcoind, l1, l3, l4, l5, regenerat
851863
openchannelbump_res3 = update_example(node=l11, method='openchannel_bump', params=[chan_id, FUND_CHANNEL_AMOUNT_SAT * 2, initpsbt_2['psbt'], next_feerate])
852864
openchannelupdate_res2 = update_example(node=l11, method='openchannel_update', params=[chan_id, openchannelbump_res3['psbt']])
853865
signed_psbt_2 = update_example(node=l11, method='signpsbt', params=[openchannelupdate_res2['psbt']])
854-
update_example(node=l11, method='openchannel_signed', params=[chan_id, signed_psbt_2['signed_psbt']])
866+
psbt2_txid = update_example(node=l11, method='openchannel_signed', params=[chan_id, signed_psbt_2['signed_psbt']])['txid']
855867

856-
bitcoind.generate_block(1)
857-
sync_blockheight(bitcoind, [l11])
868+
bitcoind.generate_block(1, wait_for_mempool=psbt2_txid)
869+
sync_blockheight(bitcoind, [l11, l12])
870+
# FIXME: l11 doesn't remove initial transaction when it RBFs
858871
l11.daemon.wait_for_log(' to CHANNELD_NORMAL')
859872

860873
# Fundpsbt, channelopen init, abort, unreserve
@@ -869,8 +882,6 @@ def generate_channels_examples(node_factory, bitcoind, l1, l3, l4, l5, regenerat
869882
update_example(node=l11, method='unreserveinputs', params=[psbt_init_res2['psbt']])
870883

871884
# Reserveinputs
872-
bitcoind.generate_block(1)
873-
sync_blockheight(bitcoind, [l11])
874885
outputs = l11.rpc.listfunds()['outputs']
875886
psbt_1 = bitcoind.rpc.createpsbt([{'txid': outputs[0]['txid'], 'vout': outputs[0]['output']}], [])
876887
update_example(node=l11, method='reserveinputs', params={'psbt': psbt_1})
@@ -893,6 +904,7 @@ def generate_channels_examples(node_factory, bitcoind, l1, l3, l4, l5, regenerat
893904
l4.rpc.close(c41res['channel_id'])
894905
l3.rpc.disconnect(l5.info['id'], True)
895906
l4.rpc.disconnect(l1.info['id'], True)
907+
wait_for(lambda: len(bitcoind.rpc.getrawmempool()) == 4)
896908

897909
# Multifundchannel 2
898910
l1.fundwallet(10**8)
@@ -924,6 +936,7 @@ def generate_channels_examples(node_factory, bitcoind, l1, l3, l4, l5, regenerat
924936
])
925937
for channel in multifund_res1['channel_ids']:
926938
l1.rpc.close(channel['channel_id'])
939+
wait_for(lambda: len(bitcoind.rpc.getrawmempool()) == 4)
927940
l1.fundwallet(10**8)
928941

929942
destinations_2 = [
@@ -947,7 +960,7 @@ def generate_channels_examples(node_factory, bitcoind, l1, l3, l4, l5, regenerat
947960
l1.rpc.disconnect(l3.info['id'], True)
948961
l1.rpc.disconnect(l4.info['id'], True)
949962
l1.rpc.disconnect(l5.info['id'], True)
950-
bitcoind.generate_block(1)
963+
bitcoind.generate_block(1, wait_for_mempool=2)
951964
sync_blockheight(bitcoind, [l1, l3, l4, l5])
952965
logger.info('Channels Done!')
953966
except Exception as e:

0 commit comments

Comments
 (0)