MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_fee_limits

Function test_fee_limits

tests/test_connection.py:2485–2569  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

2483
2484
2485def test_fee_limits(node_factory, bitcoind):
2486 l1, l2, l3, l4 = node_factory.get_nodes(4, opts=[{'dev-max-fee-multiplier': 5, 'may_reconnect': True,
2487 'allow_warning': True},
2488 {'dev-max-fee-multiplier': 5, 'may_reconnect': True,
2489 'allow_warning': True},
2490 {'ignore-fee-limits': True, 'may_reconnect': True},
2491 {}])
2492
2493 node_factory.join_nodes([l1, l2], fundchannel=True)
2494
2495 # Kick off fee adjustment using HTLC.
2496 l1.pay(l2, 1000)
2497 assert 'ignore_fee_limits' not in only_one(l2.rpc.listpeerchannels()['channels'])
2498 assert 'ignore_fee_limits' not in only_one(l1.rpc.listpeerchannels()['channels'])
2499
2500 # L1 asks for stupid low fee (will actually hit the floor of 253)
2501 l1.stop()
2502 l1.set_feerates((15, 15, 15, 15), False)
2503 # We need to increase l2's floor, so it rejects l1.
2504 l2.set_feerates((15000, 11000, 7500, 3750, 2000))
2505 l1.start()
2506
2507 if 'anchors/even' in only_one(l1.rpc.listpeerchannels()['channels'])['channel_type']['names']:
2508 fee = 1255
2509 else:
2510 fee = 258
2511 l1.daemon.wait_for_log(f'Received WARNING .*: update_fee {fee} outside range 2000-75000')
2512 # They hang up on *us*
2513 l1.daemon.wait_for_log('Peer transient failure in CHANNELD_NORMAL: channeld: Owning subdaemon channeld died')
2514
2515 # Disconnects, but does not error. Make sure it's noted in their status though.
2516 # FIXME: does not happen for l1!
2517 # assert 'update_fee 253 outside range 1875-75000' in only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['status'][0]
2518 assert f'update_fee {fee} outside range 2000-75000' in only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['status'][0]
2519
2520 assert only_one(l2.rpc.listpeerchannels()['channels'])['feerate']['perkw'] != fee
2521 # Make l2 accept those fees, and it should recover.
2522 assert only_one(l2.rpc.setchannel(l1.get_channel_scid(l2), ignorefeelimits=True)['channels'])['ignore_fee_limits'] is True
2523 assert only_one(l2.rpc.listpeerchannels()['channels'])['ignore_fee_limits'] is True
2524
2525 # Now we stay happy (and connected!)
2526 wait_for(lambda: only_one(l2.rpc.listpeerchannels()['channels'])['feerate']['perkw'] == fee)
2527 assert only_one(l2.rpc.listpeerchannels()['channels'])['peer_connected'] is True
2528
2529 # This will fail to mutual close, since l2 won't ignore insane *close* fees!
2530 assert l1.rpc.close(l2.info['id'], unilateraltimeout=5)['type'] == 'unilateral'
2531
2532 # Make sure the resolution of this one doesn't interfere with the next!
2533 # Note: may succeed, may fail with insufficient fee, depending on how
2534 # bitcoind feels!
2535 l1.daemon.wait_for_log('sendrawtx exit')
2536 bitcoind.generate_block(1)
2537 sync_blockheight(bitcoind, [l1, l2])
2538
2539 # Trying to open a channel with too low a fee-rate is denied
2540 l1.rpc.connect(l4.info['id'], 'localhost', l4.port)
2541 with pytest.raises(RpcError, match='They sent (ERROR|WARNING) .* feerate_per_kw .* below minimum'):
2542 l1.fundchannel(l4, 10**6)

Callers

nothing calls this directly

Calls 15

only_oneFunction · 0.90
wait_forFunction · 0.90
sync_blockheightFunction · 0.90
get_nodesMethod · 0.80
join_nodesMethod · 0.80
listpeerchannelsMethod · 0.80
set_feeratesMethod · 0.80
wait_for_logMethod · 0.80
setchannelMethod · 0.80
get_channel_scidMethod · 0.80
generate_blockMethod · 0.80
payMethod · 0.45

Tested by

no test coverage detected