Skip to content

Commit 21d2cc6

Browse files
rustyrussellniftynei
authored andcommitted
lightningd: apply feerate changes correctly.
Feerate changes are asymmetric, as they can only be sent by the funder. For FUNDER, the remote feerate is set when upon send of commitment_signed, and the local feerate is set on receipt of revoke_and_ack. For non-funder, the local feerate is set on receipt of commitment_signed, and the remote feerate set on send of revoke_and_ack. In our code, these two happen together. channeld gets this right, but lightningd ignored the funder/fundee distinction, and as a result, receipt of a commitment_signed by the funder altered fees in the database. If there was a reconnection event or restart, then these (incorrect) values would be used, causing us to complain about a 'Bad commit_sig signature' and close the channel. Signed-off-by: Rusty Russell <[email protected]>
1 parent 61e1d64 commit 21d2cc6

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Note: You should always set `allow-deprecated-apis=false` to test for changes.
5959

6060
### Fixed
6161

62+
- Fixed bogus "Bad commit_sig signature" which caused channel closures when reconnecting after updating fees under simultaneous bidirectional traffic.
6263
- Relative `--lightning_dir` is now working again.
6364
- Build: MacOS now builds again (missing pwritev).
6465

lightningd/peer_htlcs.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,10 @@ void peer_sending_commitsig(struct channel *channel, const u8 *msg)
13431343
channel->next_htlc_id += num_local_added;
13441344
}
13451345

1346-
/* Update their feerate. */
1347-
channel->channel_info.feerate_per_kw[REMOTE] = feerate;
1346+
/* Update remote feerate if we are funder. */
1347+
if (channel->funder == LOCAL)
1348+
channel->channel_info.feerate_per_kw[REMOTE] = feerate;
1349+
13481350
if (feerate > channel->max_possible_feerate)
13491351
channel->max_possible_feerate = feerate;
13501352
if (feerate < channel->min_possible_feerate)
@@ -1546,12 +1548,13 @@ void peer_got_commitsig(struct channel *channel, const u8 *msg)
15461548
}
15471549
}
15481550

1549-
/* Update both feerates: if we're funder, REMOTE should already be
1550-
* that feerate, if we're not, we're about to ACK anyway. */
1551-
channel->channel_info.feerate_per_kw[LOCAL]
1552-
= channel->channel_info.feerate_per_kw[REMOTE]
1553-
= feerate;
1554-
1551+
/* Update both feerates if we're not funder (for funder, receiving
1552+
* commitment_signed doesn't alter fees). */
1553+
if (channel->funder == REMOTE) {
1554+
channel->channel_info.feerate_per_kw[LOCAL]
1555+
= channel->channel_info.feerate_per_kw[REMOTE]
1556+
= feerate;
1557+
}
15551558
if (feerate > channel->max_possible_feerate)
15561559
channel->max_possible_feerate = feerate;
15571560
if (feerate < channel->min_possible_feerate)
@@ -1658,9 +1661,10 @@ void peer_got_revoke(struct channel *channel, const u8 *msg)
16581661
return;
16591662
}
16601663

1661-
/* Update feerate: if we are funder, their revoke_and_ack has set
1664+
/* Update feerate if we are funder, their revoke_and_ack has set
16621665
* this for local feerate. */
1663-
channel->channel_info.feerate_per_kw[LOCAL] = feerate;
1666+
if (channel->funder == LOCAL)
1667+
channel->channel_info.feerate_per_kw[LOCAL] = feerate;
16641668

16651669
/* FIXME: Check per_commitment_secret -> per_commit_point */
16661670
update_per_commit_point(channel, &next_per_commitment_point);

tests/test_connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,6 @@ def test_feerate_spam(node_factory, chainparams):
21482148
l1.daemon.wait_for_log('peer_out WIRE_UPDATE_FEE', timeout=5)
21492149

21502150

2151-
@pytest.mark.xfail(strict=True)
21522151
@unittest.skipIf(not DEVELOPER, "need dev-feerate")
21532152
def test_feerate_stress(node_factory, executor):
21542153
# Third node makes HTLC traffic less predictable.

0 commit comments

Comments
 (0)