channeld: allow remote node to exceed their own HTLC count limits.

We try not to exceed either side, but the spec still allows them to
(we don't, but older nodes would have, as could other implementations).

Fixes: #3953
Changelog-Fixed: protocol: overzealous close when peer sent more HTLCs than they'd told us we could send.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-03-16 11:15:09 +10:30
parent a7af106321
commit 3fd22f86df

View File

@@ -489,7 +489,6 @@ static enum channel_add_err add_htlc(struct channel *channel,
enum side sender = htlc_state_owner(state), recipient = !sender; enum side sender = htlc_state_owner(state), recipient = !sender;
const struct htlc **committed, **adding, **removing; const struct htlc **committed, **adding, **removing;
const struct channel_view *view; const struct channel_view *view;
u32 min_concurrent_htlcs;
htlc = tal(tmpctx, struct htlc); htlc = tal(tmpctx, struct htlc);
@@ -573,16 +572,19 @@ static enum channel_add_err add_htlc(struct channel *channel,
* HTLCs to its local commitment transaction... * HTLCs to its local commitment transaction...
* - SHOULD fail the channel. * - SHOULD fail the channel.
*/ */
/* Also we should not add more htlc's than sender or recipient if (tal_count(committed) - tal_count(removing) + tal_count(adding)
* configured. This mitigates attacks in which a peer can force the > channel->config[recipient].max_accepted_htlcs) {
* opener of the channel to pay unnecessary onchain fees during a fee return CHANNEL_ERR_TOO_MANY_HTLCS;
}
/* Also *we* should not add more htlc's we configured. This
* mitigates attacks in which a peer can force the opener of
* the channel to pay unnecessary onchain fees during a fee
* spike with large commitment transactions. * spike with large commitment transactions.
*/ */
min_concurrent_htlcs = channel->config[recipient].max_accepted_htlcs; if (sender == LOCAL
if (min_concurrent_htlcs > channel->config[sender].max_accepted_htlcs) && tal_count(committed) - tal_count(removing) + tal_count(adding)
min_concurrent_htlcs = channel->config[sender].max_accepted_htlcs; > channel->config[LOCAL].max_accepted_htlcs) {
if (tal_count(committed) - tal_count(removing) + tal_count(adding)
> min_concurrent_htlcs) {
return CHANNEL_ERR_TOO_MANY_HTLCS; return CHANNEL_ERR_TOO_MANY_HTLCS;
} }