forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_opening.py
2686 lines (2134 loc) · 109 KB
/
test_opening.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from fixtures import * # noqa: F401,F403
from fixtures import TEST_NETWORK
from pyln.client import RpcError, Millisatoshi
from utils import (
only_one, wait_for, sync_blockheight, first_channel_id, calc_lease_fee, check_coin_moves
)
from pyln.testing.utils import FUNDAMOUNT
from pathlib import Path
from pprint import pprint
import pytest
import re
import unittest
def find_next_feerate(node, peer):
chan = only_one(node.rpc.listpeerchannels(peer.info['id'])['channels'])
return chan['next_feerate']
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_queryrates(node_factory, bitcoind):
opts = {'dev-no-reconnect': None}
l1, l2 = node_factory.get_nodes(2, opts=opts)
amount = 10 ** 6
l1.fundwallet(amount * 10)
l2.fundwallet(amount * 10)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
with pytest.raises(RpcError, match=r'not advertising liquidity'):
l1.rpc.dev_queryrates(l2.info['id'], amount, amount * 10)
l2.rpc.call('funderupdate', {'policy': 'match',
'policy_mod': 100,
'per_channel_max_msat': '1btc',
'fuzz_percent': 0,
'lease_fee_base_msat': '2sat',
'funding_weight': 1000,
'lease_fee_basis': 140,
'channel_fee_max_base_msat': '3sat',
'channel_fee_max_proportional_thousandths': 101})
result = l1.rpc.dev_queryrates(l2.info['id'], amount, amount)
assert result['our_funding_msat'] == Millisatoshi(amount * 1000)
assert result['their_funding_msat'] == Millisatoshi(amount * 1000)
assert result['funding_weight'] == 1000
assert result['lease_fee_base_msat'] == Millisatoshi(2000)
assert result['lease_fee_basis'] == 140
assert result['channel_fee_max_base_msat'] == Millisatoshi(3000)
assert result['channel_fee_max_proportional_thousandths'] == 101
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v1') # Mixed v1 + v2, v2 manually turned on
def test_multifunding_v2_best_effort(node_factory, bitcoind):
'''
Check that best_effort flag works.
'''
disconnects = ["-WIRE_INIT",
"-WIRE_ACCEPT_CHANNEL",
"-WIRE_FUNDING_SIGNED"]
l1 = node_factory.get_node(options={'experimental-dual-fund': None},
allow_warning=True,
may_reconnect=True)
l2 = node_factory.get_node(options={'experimental-dual-fund': None},
allow_warning=True,
may_reconnect=True)
l3 = node_factory.get_node(disconnect=disconnects)
l4 = node_factory.get_node()
l1.fundwallet(2000000)
destinations = [{"id": '{}@localhost:{}'.format(l2.info['id'], l2.port),
"amount": 50000},
{"id": '{}@localhost:{}'.format(l3.info['id'], l3.port),
"amount": 50000},
{"id": '{}@localhost:{}'.format(l4.info['id'], l4.port),
"amount": 50000}]
for i, d in enumerate(disconnects):
failed_sign = d == "-WIRE_FUNDING_SIGNED"
# Should succeed due to best-effort flag.
min_channels = 1 if failed_sign else 2
l1.rpc.multifundchannel(destinations, minchannels=min_channels)
bitcoind.generate_block(6, wait_for_mempool=1)
# l3 should fail to have channels; l2 also fails on last attempt
node_list = [l1, l4] if failed_sign else [l1, l2, l4]
for node in node_list:
node.daemon.wait_for_log(r'to CHANNELD_NORMAL')
# There should be working channels to l2 and l4 for every run
# but the last
working_chans = [l4] if failed_sign else [l2, l4]
for ldest in working_chans:
inv = ldest.rpc.invoice(5000, 'i{}'.format(i), 'i{}'.format(i))['bolt11']
l1.rpc.pay(inv)
# Function to find the SCID of the channel that is
# currently open.
# Cannot use LightningNode.get_channel_scid since
# it assumes the *first* channel found is the one
# wanted, but in our case we close channels and
# open again, so multiple channels may remain
# listed.
def get_funded_channel_scid(n1, n2):
channels = n1.rpc.listpeerchannels(n2.info['id'])['channels']
assert channels and len(channels) != 0
for c in channels:
state = c['state']
if state in ('DUALOPEND_AWAITING_LOCKIN', 'CHANNELD_AWAITING_LOCKIN', 'CHANNELD_NORMAL'):
return c['short_channel_id']
assert False
# Now close channels to l2 and l4, for the next run.
if not failed_sign:
l1.rpc.close(get_funded_channel_scid(l1, l2))
l1.rpc.close(get_funded_channel_scid(l1, l4))
for node in node_list:
node.daemon.wait_for_log(r'to CLOSINGD_COMPLETE')
# With 2 down, it will fail to fund channel
l2.stop()
l3.stop()
with pytest.raises(RpcError, match=r'(Connection refused|Bad file descriptor)'):
l1.rpc.multifundchannel(destinations, minchannels=2)
# This works though.
l1.rpc.multifundchannel(destinations, minchannels=1)
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_v2_open_sigs_reconnect_2(node_factory, bitcoind):
""" We test reconnect where L2 drops after sending their tx-sigs """
disconnects_2 = ['+WIRE_TX_SIGNATURES']
l1, l2 = node_factory.get_nodes(2,
opts=[{'may_reconnect': True},
{'disconnect': disconnects_2,
'may_reconnect': True}])
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
# Fund the channel, should disconnect after getting l2's sigs
with pytest.raises(RpcError):
l1.rpc.fundchannel(l2.info['id'], chan_amount)
# peer reconnects, and we resend our sigs
l1.daemon.wait_for_log('Peer has reconnected, state DUALOPEND_OPEN_COMMITTED')
l1.daemon.wait_for_log('peer_out WIRE_TX_SIGNATURES')
l1.daemon.wait_for_log('Broadcasting funding tx')
l2.daemon.wait_for_log('Broadcasting funding tx')
txid = l2.rpc.listpeerchannels(l1.info['id'])['channels'][0]['funding_txid']
bitcoind.generate_block(6, wait_for_mempool=txid)
# Make sure we're ok.
l1.daemon.wait_for_log(r'to CHANNELD_NORMAL')
l2.daemon.wait_for_log(r'to CHANNELD_NORMAL')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_v2_open_sigs_reconnect_1(node_factory, bitcoind):
""" We test reconnect where L2 drops while sending tx-sigs.
Absolutely pure voodoo (the fundchannel command succeeds anyway after a
reconnect) """
disconnects_2 = ['-WIRE_TX_SIGNATURES']
l1, l2 = node_factory.get_nodes(2,
opts=[{'may_reconnect': True},
{'disconnect': disconnects_2,
'may_reconnect': True}])
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
# Fund the channel, should disconnect after sending l2 sigs
l1.rpc.fundchannel(l2.info['id'], chan_amount)
# peer reconnects, and we resend our sigs
l1.daemon.wait_for_logs(['peer_in WIRE_CHANNEL_REESTABLISH',
'peer_out WIRE_COMMITMENT_SIGNED',
# Incredible that this works imo
'Unable to send our sigs, our psbt isn\'t signed',
'No channel open attempt/command!'])
l2.daemon.wait_for_logs(['peer_in WIRE_CHANNEL_REESTABLISH',
'peer_out WIRE_COMMITMENT_SIGNED',
'peer_out WIRE_TX_SIGNATURES'])
l1.daemon.wait_for_log('Broadcasting funding tx')
l2.daemon.wait_for_log('Broadcasting funding tx')
txid = l2.rpc.listpeerchannels(l1.info['id'])['channels'][0]['funding_txid']
bitcoind.generate_block(6, wait_for_mempool=txid)
# Make sure we're ok.
l1.daemon.wait_for_log(r'to CHANNELD_NORMAL')
l2.daemon.wait_for_log(r'to CHANNELD_NORMAL')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_v2_open_sigs_out_of_order(node_factory, bitcoind):
""" Test what happens if the tx-sigs get sent "before" commitment signed """
disconnects = ['$WIRE_COMMITMENT_SIGNED']
l1, l2 = node_factory.get_nodes(2,
opts=[{},
{'disconnect': disconnects}])
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
# Fund the channel, should error because L2 doesn't see our commitment-signed
# so they think we've sent things out of order
with pytest.raises(RpcError, match='tx_signatures sent before commitment sigs'):
l1.rpc.fundchannel(l2.info['id'], chan_amount)
# L1 should remove the in-progress channel
wait_for(lambda: l1.rpc.listpeerchannels()['channels'] == [])
# L2 should fail it to chain
l2.daemon.wait_for_logs([r'to AWAITING_UNILATERAL',
# We can't broadcast this, we don't have sigs for funding
'sendrawtx exit 25'])
@pytest.mark.openchannel('v2')
def test_v2_fail_second(node_factory, bitcoind):
""" Open a channel succeeds; opening a second channel
failure should not drop the connection """
l1, l2 = node_factory.line_graph(2, wait_for_announce=True)
# Should have one channel between them.
only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])
amount = 2**24 - 1
l1.fundwallet(amount + 10000000)
# make sure we can generate PSBTs.
addr = l1.rpc.newaddr()['bech32']
bitcoind.rpc.sendtoaddress(addr, (amount + 1000000) / 10**8)
bitcoind.generate_block(1)
wait_for(lambda: len(l1.rpc.listfunds()["outputs"]) != 0)
# Some random (valid) psbt
psbt = l1.rpc.fundpsbt(amount, '253perkw', 250, reserve=0)['psbt']
start = l1.rpc.openchannel_init(l2.info['id'], amount, psbt)
# They will both see a pair of channels
assert len(l1.rpc.listpeerchannels(l2.info['id'])['channels']) == 2
assert len(l2.rpc.listpeerchannels(l1.info['id'])['channels']) == 2
# We can abort a channel
l1.rpc.openchannel_abort(start['channel_id'])
# We should have deleted the 'in-progress' channel info
only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])
only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])
# check that tx-abort was sent
l1.daemon.wait_for_log(r'peer_out WIRE_TX_ABORT')
l2.daemon.wait_for_log(r'peer_out WIRE_TX_ABORT')
# Should be able to reattempt without reconnecting
assert l1.rpc.getpeer(l2.info['id'])['connected']
start = l1.rpc.openchannel_init(l2.info['id'], amount, psbt)
assert len(l1.rpc.listpeerchannels(l2.info['id'])['channels']) == 2
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_v2_open_sigs_restart_while_dead(node_factory, bitcoind):
# Same thing as above, except the transaction mines
# while we're asleep
disconnects_1 = ['-WIRE_TX_SIGNATURES']
disconnects_2 = ['+WIRE_TX_SIGNATURES']
l1, l2 = node_factory.get_nodes(2,
opts=[{'disconnect': disconnects_1,
'may_reconnect': True,
'may_fail': True},
{'disconnect': disconnects_2,
'may_reconnect': True,
'may_fail': True}])
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
# Make a channel happen, with multiple disconnects!
with pytest.raises(RpcError):
l1.rpc.fundchannel(l2.info['id'], chan_amount)
l1.daemon.wait_for_log('Broadcasting funding tx')
l1.daemon.wait_for_log('sendrawtx exit 0')
l2.daemon.wait_for_log('Broadcasting funding tx')
l2.daemon.wait_for_log('sendrawtx exit 0')
l1.stop()
l2.stop()
bitcoind.generate_block(6)
l1.restart()
l2.restart()
# Make sure we're ok.
l2.daemon.wait_for_log(r'to CHANNELD_NORMAL')
l1.daemon.wait_for_log(r'to CHANNELD_NORMAL')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_v2_rbf_single(node_factory, bitcoind, chainparams):
l1, l2 = node_factory.get_nodes(2)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
res = l1.rpc.fundchannel(l2.info['id'], chan_amount)
chan_id = res['channel_id']
vins = bitcoind.rpc.decoderawtransaction(res['tx'])['vin']
assert(only_one(vins))
prev_utxos = ["{}:{}".format(vins[0]['txid'], vins[0]['vout'])]
# Check that we're waiting for lockin
l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN')
next_feerate = find_next_feerate(l1, l2)
# Check that feerate info is correct
info_1 = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])
assert info_1['initial_feerate'] == info_1['last_feerate']
rate = int(info_1['last_feerate'][:-5])
assert int(info_1['next_feerate'][:-5]) == rate * 25 // 24
# Initiate an RBF
startweight = 42 + 172 # base weight, funding output
initpsbt = l1.rpc.utxopsbt(chan_amount, next_feerate, startweight,
prev_utxos, reservedok=True,
excess_as_change=True)
# Do the bump
bump = l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
assert update['commitments_secured']
# Check that feerate info has incremented
info_2 = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])
assert info_1['initial_feerate'] == info_2['initial_feerate']
assert info_1['next_feerate'] == info_2['last_feerate']
rate = int(info_2['last_feerate'][:-5])
assert int(info_2['next_feerate'][:-5]) == rate * 25 // 24
# Sign our inputs, and continue
signed_psbt = l1.rpc.signpsbt(update['psbt'])['signed_psbt']
l1.rpc.openchannel_signed(chan_id, signed_psbt)
# Do it again, with a higher feerate
info_2 = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])
assert info_1['initial_feerate'] == info_2['initial_feerate']
assert info_1['next_feerate'] == info_2['last_feerate']
rate = int(info_2['last_feerate'][:-5])
assert int(info_2['next_feerate'][:-5]) == rate * 25 // 24
# We 4x the feerate to beat the min-relay fee
next_rate = '{}perkw'.format(rate * 25 // 24 * 4)
# Gotta unreserve the psbt and re-reserve with higher feerate
l1.rpc.unreserveinputs(initpsbt['psbt'])
initpsbt = l1.rpc.utxopsbt(chan_amount, next_rate, startweight,
prev_utxos, reservedok=True,
excess_as_change=True)
# Do the bump+sign
bump = l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'],
funding_feerate=next_rate)
update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
assert update['commitments_secured']
signed_psbt = l1.rpc.signpsbt(update['psbt'])['signed_psbt']
l1.rpc.openchannel_signed(chan_id, signed_psbt)
bitcoind.generate_block(1)
sync_blockheight(bitcoind, [l1])
l1.daemon.wait_for_log(' to CHANNELD_NORMAL')
# Check that feerate info is gone
info_1 = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])
assert 'initial_feerate' not in info_1
assert 'last_feerate' not in info_1
assert 'next_feerate' not in info_1
# Shut l2 down, force close the channel.
l2.stop()
resp = l1.rpc.close(l2.info['id'], unilateraltimeout=1)
assert resp['type'] == 'unilateral'
l1.daemon.wait_for_log(' to CHANNELD_SHUTTING_DOWN')
l1.daemon.wait_for_log('sendrawtx exit 0')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_v2_rbf_abort_retry(node_factory, bitcoind, chainparams):
l1, l2 = node_factory.get_nodes(2, opts={'allow_warning': True})
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendmany("",
{l1.rpc.newaddr()['bech32']: amount / 10**8 + 0.01,
l2.rpc.newaddr()['bech32']: amount / 10**8 + 0.01})
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
wait_for(lambda: len(l2.rpc.listfunds()['outputs']) > 0)
l1_utxos = ['{}:{}'.format(utxo['txid'], utxo['output']) for utxo in l1.rpc.listfunds()['outputs']]
# setup l2 to dual-fund!
l2.rpc.call('funderupdate', {'policy': 'match',
'policy_mod': 100,
'leases_only': False})
res = l1.rpc.fundchannel(l2.info['id'], chan_amount)
chan_id = res['channel_id']
vins = bitcoind.rpc.decoderawtransaction(res['tx'])['vin']
prev_utxos = ["{}:{}".format(vin['txid'], vin['vout']) for vin in vins if "{}:{}".format(vin['txid'], vin['vout']) in l1_utxos]
# Check that we're waiting for lockin
l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN')
# Check that feerate info is correct
info_1 = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])
next_rate = "{}perkw".format(info_1['next_feerate'][:-5])
# Initiate an RBF
startweight = 42 + 172 # base weight, funding output
initpsbt = l1.rpc.utxopsbt(chan_amount, next_rate, startweight,
prev_utxos, reservedok=True,
excess_as_change=True)
# Do the bump
bump = l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
# We abort the channel mid-way throught the RBF
l1.rpc.openchannel_abort(chan_id)
with pytest.raises(RpcError):
l1.rpc.openchannel_update(chan_id, bump['psbt'])
# - initiate a channel open eclair -> cln
# - wait for the transaction to be published
# - eclair initiates rbf, and cancels it by sending tx_abort before exchanging commit_sig
# - at that point everything looks good, cln echoes the tx_abort and stays connected
# - eclair initiates another RBF attempt and sends tx_init_rbf: for some unknown reason, cln answers with channel_reestablish (??) followed by an error saying "Bad reestablish message: WIRE_TX_INIT_RBF"
# attempt to initiate an RBF again
info_1 = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])
next_rate = "{}perkw".format(int(info_1['next_feerate'][:-5]) * 2)
# Gotta unreserve the psbt and re-reserve with higher feerate
l1.rpc.unreserveinputs(initpsbt['psbt'])
initpsbt = l1.rpc.utxopsbt(chan_amount, next_rate, startweight,
prev_utxos, reservedok=True,
excess_as_change=True)
# Do the bump+sign
bump = l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'],
funding_feerate=next_rate)
update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
signed_psbt = l1.rpc.signpsbt(update['psbt'])['signed_psbt']
l1.rpc.openchannel_signed(chan_id, signed_psbt)
bitcoind.generate_block(1)
sync_blockheight(bitcoind, [l1])
l1.daemon.wait_for_log(' to CHANNELD_NORMAL')
assert not l1.daemon.is_in_log('WIRE_CHANNEL_REESTABLISH')
assert not l2.daemon.is_in_log('WIRE_CHANNEL_REESTABLISH')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_v2_rbf_abort_channel_opens(node_factory, bitcoind, chainparams):
l1, l2 = node_factory.get_nodes(2, opts={'wumbo': None,
'allow_warning': True})
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendmany("",
{l1.rpc.newaddr()['bech32']: amount / 10**8 + 0.01,
l2.rpc.newaddr()['bech32']: amount / 10**8 + 0.01})
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
wait_for(lambda: len(l2.rpc.listfunds()['outputs']) > 0)
l1_utxos = ['{}:{}'.format(utxo['txid'], utxo['output']) for utxo in l1.rpc.listfunds()['outputs']]
# setup l2 to dual-fund!
l2.rpc.call('funderupdate', {'policy': 'match',
'policy_mod': 100,
'leases_only': False})
res = l1.rpc.fundchannel(l2.info['id'], chan_amount)
chan_id = res['channel_id']
vins = bitcoind.rpc.decoderawtransaction(res['tx'])['vin']
prev_utxos = ["{}:{}".format(vin['txid'], vin['vout']) for vin in vins if "{}:{}".format(vin['txid'], vin['vout']) in l1_utxos]
# Check that we're waiting for lockin
l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN')
# Check that feerate info is correct
info_1 = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])
next_rate = "{}perkw".format(info_1['next_feerate'][:-5])
# Initiate an RBF
startweight = 42 + 172 # base weight, funding output
initpsbt = l1.rpc.utxopsbt(chan_amount, next_rate, startweight,
prev_utxos, reservedok=True,
excess_as_change=True)
# Do the bump
bump = l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
# We abort the channel mid-way throught the RBF
l1.rpc.openchannel_abort(chan_id)
with pytest.raises(RpcError):
l1.rpc.openchannel_update(chan_id, bump['psbt'])
# When the original open tx is mined, we should still arrive at
# NORMAL channel ops
bitcoind.generate_block(1)
sync_blockheight(bitcoind, [l1])
l1.daemon.wait_for_log(' to CHANNELD_NORMAL')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_v2_rbf_liquidity_ad(node_factory, bitcoind, chainparams):
opts = {'funder-policy': 'match', 'funder-policy-mod': 100,
'lease-fee-base-sat': '100sat', 'lease-fee-basis': 100,
'may_reconnect': True}
l1, l2 = node_factory.get_nodes(2, opts=opts)
# what happens when we RBF?
feerate = 2000
amount = 500000
l1.fundwallet(20000000)
l2.fundwallet(20000000)
# l1 leases a channel from l2
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
rates = l1.rpc.dev_queryrates(l2.info['id'], amount, amount)
chan_id = l1.rpc.fundchannel(l2.info['id'], amount, request_amt=amount,
feerate='{}perkw'.format(feerate),
compact_lease=rates['compact_lease'])['channel_id']
vins = [x for x in l1.rpc.listfunds()['outputs'] if x['reserved']]
assert only_one(vins)
prev_utxos = ["{}:{}".format(vins[0]['txid'], vins[0]['output'])]
# Check that we're waiting for lockin
l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN')
est_fees = calc_lease_fee(amount, feerate, rates)
# This should be the accepter's amount
fundings = only_one(l1.rpc.listpeerchannels()['channels'])['funding']
assert Millisatoshi(amount * 1000) == fundings['remote_funds_msat']
assert Millisatoshi(est_fees + amount * 1000) == fundings['local_funds_msat']
assert Millisatoshi(est_fees) == fundings['fee_paid_msat']
assert 'fee_rcvd_msat' not in fundings
# rbf the lease with a higher amount
rate = int(find_next_feerate(l1, l2)[:-5])
# We 4x the feerate to beat the min-relay fee
next_feerate = '{}perkw'.format(rate * 4)
# Restart the node between open + rbf; works as expected
l1.restart()
# Initiate an RBF
startweight = 42 + 172 # base weight, funding output
initpsbt = l1.rpc.utxopsbt(amount, next_feerate, startweight,
prev_utxos, reservedok=True,
excess_as_change=True)['psbt']
# reconnect after restart
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
# do the bump
bump = l1.rpc.openchannel_bump(chan_id, amount, initpsbt,
funding_feerate=next_feerate)
update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
assert update['commitments_secured']
# Sign our inputs, and continue
signed_psbt = l1.rpc.signpsbt(update['psbt'])['signed_psbt']
l1.rpc.openchannel_signed(chan_id, signed_psbt)
# There's data in the datastore now (l2 only)
assert l1.rpc.listdatastore() == {'datastore': []}
only_one(l2.rpc.listdatastore("funder/{}".format(chan_id))['datastore'])
# what happens when the channel opens?
bitcoind.generate_block(6)
l1.daemon.wait_for_log('to CHANNELD_NORMAL')
# Datastore should be cleaned up!
assert l1.rpc.listdatastore() == {'datastore': []}
wait_for(lambda: l2.rpc.listdatastore() == {'datastore': []})
# This should be the accepter's amount
fundings = only_one(l1.rpc.listpeerchannels()['channels'])['funding']
# The is still there!
assert Millisatoshi(amount * 1000) == Millisatoshi(fundings['remote_funds_msat'])
wait_for(lambda: [c['active'] for c in l1.rpc.listchannels(l1.get_channel_scid(l2))['channels']] == [True, True])
# send some payments, mine a block or two
inv = l2.rpc.invoice(10**4, '1', 'no_1')
l1.rpc.pay(inv['bolt11'])
# l2 attempts to close a channel that it leased, should succeed
# (channel isnt leased)
l2.rpc.close(l1.get_channel_scid(l2))
l1.daemon.wait_for_log('State changed from CLOSINGD_SIGEXCHANGE to CLOSINGD_COMPLETE')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_v2_rbf_multi(node_factory, bitcoind, chainparams):
l1, l2 = node_factory.get_nodes(2,
opts={'may_reconnect': True,
'dev-no-reconnect': None,
'allow_warning': True})
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
res = l1.rpc.fundchannel(l2.info['id'], chan_amount)
chan_id = res['channel_id']
vins = bitcoind.rpc.decoderawtransaction(res['tx'])['vin']
assert(only_one(vins))
prev_utxos = ["{}:{}".format(vins[0]['txid'], vins[0]['vout'])]
# Check that we're waiting for lockin
l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN')
# Attempt to do abort, should fail since we've
# already gotten an inflight
with pytest.raises(RpcError):
l1.rpc.openchannel_abort(chan_id)
rate = int(find_next_feerate(l1, l2)[:-5])
# We 4x the feerate to beat the min-relay fee
next_feerate = '{}perkw'.format(rate * 4)
# Initiate an RBF
startweight = 42 + 172 # base weight, funding output
initpsbt = l1.rpc.utxopsbt(chan_amount, next_feerate, startweight,
prev_utxos, reservedok=True,
excess_as_change=True)
# Do the bump
bump = l1.rpc.openchannel_bump(chan_id, chan_amount,
initpsbt['psbt'],
funding_feerate=next_feerate)
# Abort this open attempt! We will re-try
aborted = l1.rpc.openchannel_abort(chan_id)
assert not aborted['channel_canceled']
# We no longer disconnect on aborts, because magic!
assert only_one(l1.rpc.listpeers()['peers'])['connected']
# Do the bump, again, same feerate
bump = l1.rpc.openchannel_bump(chan_id, chan_amount,
initpsbt['psbt'],
funding_feerate=next_feerate)
update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
assert update['commitments_secured']
# Sign our inputs, and continue
signed_psbt = l1.rpc.signpsbt(update['psbt'])['signed_psbt']
l1.rpc.openchannel_signed(chan_id, signed_psbt)
# We 2x the feerate to beat the min-relay fee
rate = int(find_next_feerate(l1, l2)[:-5])
next_feerate = '{}perkw'.format(rate * 2)
# Initiate another RBF, double the channel amount this time
startweight = 42 + 172 # base weight, funding output
initpsbt = l1.rpc.utxopsbt(chan_amount * 2, next_feerate, startweight,
prev_utxos, reservedok=True,
excess_as_change=True)
# Do the bump
bump = l1.rpc.openchannel_bump(chan_id, chan_amount * 2,
initpsbt['psbt'],
funding_feerate=next_feerate)
update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
assert update['commitments_secured']
# Sign our inputs, and continue
signed_psbt = l1.rpc.signpsbt(update['psbt'])['signed_psbt']
l1.rpc.openchannel_signed(chan_id, signed_psbt)
bitcoind.generate_block(1)
sync_blockheight(bitcoind, [l1])
l1.daemon.wait_for_log(' to CHANNELD_NORMAL')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_rbf_reconnect_init(node_factory, bitcoind, chainparams):
disconnects = ['-WIRE_TX_INIT_RBF',
'+WIRE_TX_INIT_RBF']
l1, l2 = node_factory.get_nodes(2,
opts=[{'disconnect': disconnects,
'may_reconnect': True},
{'may_reconnect': True}])
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
res = l1.rpc.fundchannel(l2.info['id'], chan_amount)
chan_id = res['channel_id']
vins = bitcoind.rpc.decoderawtransaction(res['tx'])['vin']
assert(only_one(vins))
prev_utxos = ["{}:{}".format(vins[0]['txid'], vins[0]['vout'])]
# Check that we're waiting for lockin
l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN')
next_feerate = find_next_feerate(l1, l2)
# Initiate an RBF
startweight = 42 + 172 # base weight, funding output
initpsbt = l1.rpc.utxopsbt(chan_amount, next_feerate, startweight,
prev_utxos, reservedok=True,
excess_as_change=True)
# Do the bump!?
for d in disconnects:
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
with pytest.raises(RpcError):
l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
assert l1.rpc.getpeer(l2.info['id']) is not None
# This should succeed
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_rbf_reconnect_ack(node_factory, bitcoind, chainparams):
disconnects = ['-WIRE_TX_ACK_RBF',
'+WIRE_TX_ACK_RBF']
l1, l2 = node_factory.get_nodes(2,
opts=[{'may_reconnect': True},
{'disconnect': disconnects,
'may_reconnect': True}])
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
res = l1.rpc.fundchannel(l2.info['id'], chan_amount)
chan_id = res['channel_id']
vins = bitcoind.rpc.decoderawtransaction(res['tx'])['vin']
assert(only_one(vins))
prev_utxos = ["{}:{}".format(vins[0]['txid'], vins[0]['vout'])]
# Check that we're waiting for lockin
l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN')
next_feerate = find_next_feerate(l1, l2)
# Initiate an RBF
startweight = 42 + 172 # base weight, funding output
initpsbt = l1.rpc.utxopsbt(chan_amount, next_feerate, startweight,
prev_utxos, reservedok=True,
excess_as_change=True)
# Do the bump!?
for d in disconnects:
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
with pytest.raises(RpcError):
l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
assert l1.rpc.getpeer(l2.info['id']) is not None
# This should succeed
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_rbf_reconnect_tx_construct(node_factory, bitcoind, chainparams):
disconnects = ['=WIRE_TX_ADD_INPUT', # Initial funding succeeds
'-WIRE_TX_ADD_INPUT',
'+WIRE_TX_ADD_INPUT',
'-WIRE_TX_ADD_OUTPUT',
'+WIRE_TX_ADD_OUTPUT',
'-WIRE_TX_COMPLETE',
'+WIRE_TX_COMPLETE',
'-WIRE_COMMITMENT_SIGNED',
'+WIRE_COMMITMENT_SIGNED']
l1, l2 = node_factory.get_nodes(2,
opts=[{'disconnect': disconnects,
'may_reconnect': True,
'dev-no-reconnect': None},
{'may_reconnect': True,
'dev-no-reconnect': None,
'broken_log': 'dualopend daemon died before signed PSBT returned'}])
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
res = l1.rpc.fundchannel(l2.info['id'], chan_amount)
chan_id = res['channel_id']
vins = bitcoind.rpc.decoderawtransaction(res['tx'])['vin']
assert(only_one(vins))
prev_utxos = ["{}:{}".format(vins[0]['txid'], vins[0]['vout'])]
# Check that we're waiting for lockin
l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN')
# rbf the lease with a higher amount
rate = int(find_next_feerate(l1, l2)[:-5])
# We 4x the feerate to beat the min-relay fee
next_feerate = '{}perkw'.format(rate * 4)
# Initiate an RBF
startweight = 42 + 172 # base weight, funding output
initpsbt = l1.rpc.utxopsbt(chan_amount, next_feerate, startweight,
prev_utxos, reservedok=True,
excess_as_change=True)
# Run through TX_ADD wires
for d in disconnects[1:-4]:
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
with pytest.raises(RpcError):
l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
wait_for(lambda: l1.rpc.getpeer(l2.info['id'])['connected'] is False)
# The first TX_COMPLETE breaks
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
bump = l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
with pytest.raises(RpcError):
update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
wait_for(lambda: l1.rpc.getpeer(l2.info['id'])['connected'] is False)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
# l1 should remember, l2 has forgotten
# l2 should send tx-abort, to reset
l2.daemon.wait_for_log(r'tx-abort: Sent next_funding_txid .* doesn\'t match ours .*')
l1.daemon.wait_for_log(r'Cleaned up incomplete inflight')
# abort doesn't cause a disconnect
assert l1.rpc.getpeer(l2.info['id'])['connected']
# The next TX_COMPLETE break (both remember) + they break on the
# COMMITMENT_SIGNED during the reconnect
bump = l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
with pytest.raises(RpcError):
update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
wait_for(lambda: l1.rpc.getpeer(l2.info['id'])['connected'] is False)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
l2.daemon.wait_for_logs([r'Got dualopend reestablish',
r'No commitment, not sending our sigs'])
l1.daemon.wait_for_logs([r'Got dualopend reestablish',
r'No commitment, not sending our sigs',
r'dev_disconnect: -WIRE_COMMITMENT_SIGNED',
'peer_disconnect_done'])
assert not l1.rpc.getpeer(l2.info['id'])['connected']
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
# COMMITMENT_SIGNED disconnects *during* the reconnect
# We can't bump because the last negotiation is in the wrong state
with pytest.raises(RpcError, match=r'Funding sigs for this channel not secured'):
l1.rpc.openchannel_bump(chan_id, chan_amount, initpsbt['psbt'])
# l2 reconnects, but doesn't have l1's commitment
l2.daemon.wait_for_logs([r'Got dualopend reestablish',
r'No commitment, not sending our sigs',
# This is a BROKEN log, it's expected!
r'dualopend daemon died before signed PSBT returned'])
# We don't have the commtiments yet, there's no scratch_txid
inflights = only_one(l1.rpc.listpeerchannels()['channels'])['inflight']
assert len(inflights) == 2
assert 'scratch_txid' not in inflights[1]
# After reconnecting, we have a scratch txid!
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
wait_for(lambda: 'scratch_txid' in only_one(l1.rpc.listpeerchannels()['channels'])['inflight'][1])
# We can call update again! It should short-circuit this time :)
update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
assert update['commitments_secured']
signed_psbt = l1.rpc.signpsbt(update['psbt'])['signed_psbt']
l1.rpc.openchannel_signed(chan_id, signed_psbt)
l2.daemon.wait_for_log('Broadcasting funding tx')
txid = l2.rpc.listpeerchannels(l1.info['id'])['channels'][0]['funding_txid']
bitcoind.generate_block(6, wait_for_mempool=txid)
# Make sure we're ok.
l1.daemon.wait_for_log(r'to CHANNELD_NORMAL')
l2.daemon.wait_for_log(r'to CHANNELD_NORMAL')
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
@pytest.mark.openchannel('v2')
def test_rbf_reconnect_tx_sigs(node_factory, bitcoind, chainparams):
disconnects = ['=WIRE_TX_SIGNATURES', # Initial funding succeeds
'-WIRE_TX_SIGNATURES', # When we send tx-sigs, RBF
'=WIRE_TX_SIGNATURES', # When we reconnect
'+WIRE_TX_SIGNATURES'] # When we RBF again
l2_disconnects = ['=WIRE_TX_SIGNATURES', # Initial funding succeeds
'-WIRE_TX_SIGNATURES', # Don't send L2 tx-sigs on RBF
'=WIRE_TX_SIGNATURES', # When we reconnect
'-WIRE_TX_SIGNATURES'] # Don't send when we RBF again
l1, l2 = node_factory.get_nodes(2,
opts=[{'disconnect': disconnects,
'may_reconnect': True},
{'disconnect': l2_disconnects,
'may_reconnect': True,
# "dualopend daemon died before signed PSBT returned"
# happens occassionally
'broken_log': 'dualopend daemon died before signed PSBT returned'}])
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
amount = 2**24
chan_amount = 100000
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
bitcoind.generate_block(1)
# Wait for it to arrive.
wait_for(lambda: len(l1.rpc.listfunds()['outputs']) > 0)
res = l1.rpc.fundchannel(l2.info['id'], chan_amount)