htlcswitch/link: trim fix

This commit is contained in:
Conner Fromknecht committed 2018-05-02 01:12:18 -07:00
1 parent ed4f77871a
commit 42a9a78180
1 file changed
+22 -10
+22 -10
View File
@@ -729,21 +729,33 @@ func (l *channelLink) htlcManager() {
// Before handling any messages, revert any circuits that were marked // Before handling any messages, revert any circuits that were marked
// open in the switch's circuit map, but did not make it into a // open in the switch's circuit map, but did not make it into a
// commitment txn. We use the next local htlc index as the cut off // commitment txn. We use the next local htlc index as the cut off
// point, since all indexes below that are committed. // point, since all indexes below that are committed. This action is
// // only performed if the link's final short channel ID has been
// NOTE: This is automatically done by the switch when it starts up, // assigned, otherwise we would try to trim the htlcs belonging to the
// but is necessary to prevent inconsistencies in the case that the // all-zero, sourceHop ID.
// link flaps. This is a result of a link's life-cycle being shorter if l.ShortChanID() != sourceHop {
// than that of the switch. localHtlcIndex, err := l.channel.NextLocalHtlcIndex()
localHtlcIndex := l.channel.LocalHtlcIndex()
err := l.cfg.Circuits.TrimOpenCircuits(l.ShortChanID(), localHtlcIndex)
if err != nil { if err != nil {
l.errorf("unable to trim circuits above local htlc index %d: %v", l.errorf("unable to retrieve next local htlc index: %v",
localHtlcIndex, err) err)
l.fail(ErrInternalLinkFailure.Error()) l.fail(ErrInternalLinkFailure.Error())
return return
} }
// NOTE: This is automatically done by the switch when it starts
// up, but is necessary to prevent inconsistencies in the case
// that the link flaps. This is a result of a link's life-cycle
// being shorter than that of the switch.
chanID := l.ShortChanID()
err = l.cfg.Circuits.TrimOpenCircuits(chanID, localHtlcIndex)
if err != nil {
l.errorf("unable to trim circuits above local htlc "+
"index %d: %v", localHtlcIndex, err)
l.fail(ErrInternalLinkFailure.Error())
return
}
}
// TODO(roasbeef): need to call wipe chan whenever D/C? // TODO(roasbeef): need to call wipe chan whenever D/C?
// If this isn't the first time that this channel link has been // If this isn't the first time that this channel link has been