Skip to content

Commit

Permalink
channeld: defer first update_fee until we have an HTLC to send.
Browse files Browse the repository at this point in the history
Sending update_fee immediately after channel establishment seems to
upset LND, so work around it by deferring it.  The reason we increase
the fee after establishment is because now we might need to close the
channel in a hurry due to htlcs, but until there are htlcs that's
unnecessary.

Fixes: #3596
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Apr 8, 2020
1 parent 11c21f9 commit 7e6af8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -2749,7 +2749,12 @@ static void handle_feerates(struct peer *peer, const u8 *inmsg)
*/
if (peer->channel->funder == LOCAL) {
peer->desired_feerate = feerate;
start_commit_timer(peer);
/* Don't do this for the first feerate, wait until something else
* happens. LND seems to get upset in some cases otherwise:
* see https://github.com/ElementsProject/lightning/issues/3596 */
if (peer->next_index[LOCAL] != 1
|| peer->next_index[REMOTE] != 1)
start_commit_timer(peer);
} else {
/* BOLT #2:
*
Expand Down
8 changes: 6 additions & 2 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,6 @@ def test_update_fee(node_factory, bitcoind):

# Make l1 send out feechange.
l1.set_feerates((14000, 11000, 7500, 3750))
l2.daemon.wait_for_log('peer updated fee to 14000')

# Now make sure an HTLC works.
# (First wait for route propagation.)
Expand All @@ -1376,6 +1375,8 @@ def test_update_fee(node_factory, bitcoind):

# Make payments.
l1.pay(l2, 200000000)
# First payment causes fee update.
l2.daemon.wait_for_log('peer updated fee to 14000')
l2.pay(l1, 100000000)

# Now shutdown cleanly.
Expand Down Expand Up @@ -1755,13 +1756,16 @@ def test_no_fee_estimate(node_factory, bitcoind, executor):
@unittest.skipIf(not DEVELOPER, "needs --dev-disconnect")
def test_funder_feerate_reconnect(node_factory, bitcoind):
# l1 updates fees, then reconnect so l2 retransmits commitment_signed.
disconnects = ['-WIRE_COMMITMENT_SIGNED']
disconnects = ['-WIRE_COMMITMENT_SIGNED*3']
l1 = node_factory.get_node(may_reconnect=True,
feerates=(7500, 7500, 7500, 7500))
l2 = node_factory.get_node(disconnect=disconnects, may_reconnect=True)
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
l1.fund_channel(l2, 10**6)

# Need a payment otherwise it won't update fee.
l1.pay(l2, 10**9 // 2)

# create fee update, causing disconnect.
l1.set_feerates((15000, 11000, 7500, 3750))
l2.daemon.wait_for_log(r'dev_disconnect: \-WIRE_COMMITMENT_SIGNED')
Expand Down

0 comments on commit 7e6af8b

Please sign in to comment.