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

Function test_fee_limits

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

Source from the content-addressed store, hash-verified

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