htlcswitch/circuit_map: trim using NextLocalHtlcIndex
This commit is contained in:
parent
cae1d468e7
commit
ed4f77871a
@ -343,8 +343,9 @@ func (cm *circuitMap) decodeCircuit(v []byte) (*PaymentCircuit, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// trimAllOpenCircuits reads the set of active channels from disk and trims
|
// trimAllOpenCircuits reads the set of active channels from disk and trims
|
||||||
// keystones for any non-pending channels. This method is intended to be called
|
// keystones for any non-pending channels using the next unallocated htlc index.
|
||||||
// on startup. Each link will also trim it's own circuits upon startup.
|
// This method is intended to be called on startup. Each link will also trim
|
||||||
|
// it's own circuits upon startup.
|
||||||
//
|
//
|
||||||
// NOTE: This operation will be applied to the persistent state of all active
|
// NOTE: This operation will be applied to the persistent state of all active
|
||||||
// channels. Therefore, it must be called before any links are created to avoid
|
// channels. Therefore, it must be called before any links are created to avoid
|
||||||
@ -356,9 +357,31 @@ func (cm *circuitMap) trimAllOpenCircuits() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, activeChannel := range activeChannels {
|
for _, activeChannel := range activeChannels {
|
||||||
|
if activeChannel.IsPending {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, skip any channels that have not been assigned their
|
||||||
|
// final channel identifier, otherwise we would try to trim
|
||||||
|
// htlcs belonging to the all-zero, sourceHop ID.
|
||||||
chanID := activeChannel.ShortChanID
|
chanID := activeChannel.ShortChanID
|
||||||
start := activeChannel.LocalCommitment.LocalHtlcIndex
|
if chanID == sourceHop {
|
||||||
if err := cm.TrimOpenCircuits(chanID, start); err != nil {
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next, retrieve the next unallocated htlc index, which bounds
|
||||||
|
// the cutoff of confirmed htlc indexes.
|
||||||
|
start, err := activeChannel.NextLocalHtlcIndex()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, remove all pending circuits above at or above the
|
||||||
|
// next unallocated local htlc indexes. This has the effect of
|
||||||
|
// reverting any circuits that have either not been locked in,
|
||||||
|
// or had not been included in a pending commitment.
|
||||||
|
err = cm.TrimOpenCircuits(chanID, start)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user