Handle double-HTLC-claims without failing the backwards channel
authorMatt Corallo <git@bluematt.me>
Tue, 29 Jun 2021 21:05:45 +0000 (21:05 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 28 Jul 2021 00:34:53 +0000 (00:34 +0000)
commit7e78fa660cec8a73286c94c1073ee588140e7a01
treeebd489edbb621e136852fec1abca7b7a22594cc7
parentfecac81874c41724a855c9e696c312353609df23
Handle double-HTLC-claims without failing the backwards channel

When receiving an update_fulfill_htlc message, we immediately
forward the claim backwards along the payment path before waiting
for a full commitment_signed dance. This is great, but can cause
duplicative claims if a node sends an update_fulfill_htlc message,
disconnects, reconnects, and then has to re-send its
update_fulfill_htlc message again.

While there was code to handle this, it treated it as a channel
error on the inbound channel, which is incorrect - this is an
expected, albeit incredibly rare, condition. Instead, we handle
these double-claims correctly, simply ignoring them.

With debug_assertions enabled, we also check that the previous
close of the same HTLC was a fulfill, and that we are not moving
from a HTLC failure to an HTLC claim after its too late.

A test is also added, which hits all three failure cases in
`Channel::get_update_fulfill_htlc`.

Found by the chanmon_consistency fuzzer.
lightning/src/ln/chanmon_update_fail_tests.rs
lightning/src/ln/channel.rs