Skip to content

Commit f719343

Browse files
niftyneirustyrussell
authored andcommitted
tests: check that we don't re-up the leased funds when we RBF
Check that the peer won't put funds into a RBF'd channel lease. FIXME: allow leases to pass through to RBFs Changelog-None.
1 parent a9de23f commit f719343

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

tests/test_opening.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,85 @@ def test_v2_rbf_single(node_factory, bitcoind, chainparams):
334334
l1.daemon.wait_for_log('sendrawtx exit 0')
335335

336336

337+
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
338+
@pytest.mark.openchannel('v2')
339+
def test_v2_rbf_liquidity_ad(node_factory, bitcoind, chainparams):
340+
341+
opts = {'funder-policy': 'match', 'funder-policy-mod': 100,
342+
'lease-fee-base-msat': '100sat', 'lease-fee-basis': 100,
343+
'may_reconnect': True}
344+
l1, l2 = node_factory.get_nodes(2, opts=opts)
345+
346+
# what happens when we RBF?
347+
feerate = 2000
348+
amount = 500000
349+
l1.fundwallet(20000000)
350+
l2.fundwallet(20000000)
351+
352+
# l1 leases a channel from l2
353+
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
354+
rates = l1.rpc.dev_queryrates(l2.info['id'], amount, amount)
355+
l1.daemon.wait_for_log('disconnect')
356+
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
357+
chan_id = l1.rpc.fundchannel(l2.info['id'], amount, request_amt=amount,
358+
feerate='{}perkw'.format(feerate),
359+
compact_lease=rates['compact_lease'])['channel_id']
360+
361+
vins = [x for x in l1.rpc.listfunds()['outputs'] if x['reserved']]
362+
assert only_one(vins)
363+
prev_utxos = ["{}:{}".format(vins[0]['txid'], vins[0]['output'])]
364+
365+
# Check that we're waiting for lockin
366+
l1.daemon.wait_for_log(' to DUALOPEND_AWAITING_LOCKIN')
367+
368+
est_fees = calc_lease_fee(amount, feerate, rates)
369+
370+
# This should be the accepter's amount
371+
fundings = only_one(only_one(l1.rpc.listpeers()['peers'])['channels'])['funding']
372+
assert Millisatoshi(est_fees + amount * 1000) == Millisatoshi(fundings['remote_msat'])
373+
374+
# rbf the lease with a higher amount
375+
rate = int(find_next_feerate(l1, l2)[:-5])
376+
# We 4x the feerate to beat the min-relay fee
377+
next_feerate = '{}perkw'.format(rate * 4)
378+
379+
# Initiate an RBF
380+
startweight = 42 + 172 # base weight, funding output
381+
initpsbt = l1.rpc.utxopsbt(amount, next_feerate, startweight,
382+
prev_utxos, reservedok=True,
383+
min_witness_weight=110,
384+
excess_as_change=True)['psbt']
385+
386+
# do the bump
387+
bump = l1.rpc.openchannel_bump(chan_id, amount, initpsbt,
388+
funding_feerate=next_feerate)
389+
update = l1.rpc.openchannel_update(chan_id, bump['psbt'])
390+
assert update['commitments_secured']
391+
# Sign our inputs, and continue
392+
signed_psbt = l1.rpc.signpsbt(update['psbt'])['signed_psbt']
393+
l1.rpc.openchannel_signed(chan_id, signed_psbt)
394+
395+
# what happens when the channel opens?
396+
bitcoind.generate_block(6)
397+
l1.daemon.wait_for_log('to CHANNELD_NORMAL')
398+
399+
# This should be the accepter's amount
400+
fundings = only_one(only_one(l1.rpc.listpeers()['peers'])['channels'])['funding']
401+
# FIXME: The lease goes away :(
402+
assert Millisatoshi(0) == Millisatoshi(fundings['remote_msat'])
403+
404+
wait_for(lambda: [c['active'] for c in l1.rpc.listchannels(l1.get_channel_scid(l2))['channels']] == [True, True])
405+
406+
# send some payments, mine a block or two
407+
inv = l2.rpc.invoice(10**4, '1', 'no_1')
408+
l1.rpc.pay(inv['bolt11'])
409+
410+
# l2 attempts to close a channel that it leased, should succeed
411+
# (channel isnt leased)
412+
l2.rpc.close(l1.get_channel_scid(l2))
413+
l1.daemon.wait_for_log('State changed from CLOSINGD_SIGEXCHANGE to CLOSINGD_COMPLETE')
414+
415+
337416
@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need')
338417
@pytest.mark.openchannel('v2')
339418
def test_v2_rbf_multi(node_factory, bitcoind, chainparams):

0 commit comments

Comments
 (0)