htlcswitch: only pipeline settle if add is locked-in
The counter-party shouldn't be doing this anyways as they would be giving away a preimage for free. Them doing this would bork their own channel due to open circuits not getting trimmed on startup. Removing this faulty behavior also makes it easier to reason about the circuit logic.
This commit is contained in:
2 files changed
+198
-3
No files matched your search
@@ -1676,6 +1676,28 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
||||
case *lnwire.UpdateFulfillHTLC:
|
||||
pre := msg.PaymentPreimage
|
||||
idx := msg.ID
|
||||
|
||||
// Before we pipeline the settle, we'll check the set of active
|
||||
// htlc's to see if the related UpdateAddHTLC has been fully
|
||||
// locked-in.
|
||||
var lockedin bool
|
||||
htlcs := l.channel.ActiveHtlcs()
|
||||
for _, add := range htlcs {
|
||||
// The HTLC will be outgoing and match idx.
|
||||
if !add.Incoming && add.HtlcIndex == idx {
|
||||
lockedin = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !lockedin {
|
||||
l.fail(
|
||||
LinkFailureError{code: ErrInvalidUpdate},
|
||||
"unable to handle upstream settle",
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if err := l.channel.ReceiveHTLCSettle(pre, idx); err != nil {
|
||||
l.fail(
|
||||
LinkFailureError{
|
||||
|
||||
Reference in new issue
Block a user