htlcswitch/link: trim fix

This commit is contained in:
Conner Fromknecht 2018-04-27 02:50:53 -07:00
parent ed4f77871a
commit 42a9a78180
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF

View File

@ -729,19 +729,31 @@ 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() if err != nil {
err := l.cfg.Circuits.TrimOpenCircuits(l.ShortChanID(), localHtlcIndex) l.errorf("unable to retrieve next local htlc index: %v",
if err != nil { err)
l.errorf("unable to trim circuits above local htlc index %d: %v", l.fail(ErrInternalLinkFailure.Error())
localHtlcIndex, err) return
l.fail(ErrInternalLinkFailure.Error()) }
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?