lnwallet: update updateLog.modifiedHtlcs to use fn.Set

This commit is contained in:
Keagan McClelland 2024-05-24 15:07:32 -07:00
parent ab96de3f07
commit c3c4e79593
No known key found for this signature in database
GPG Key ID: FA7E65C951F12439

View File

@ -44,7 +44,7 @@ type updateLog struct {
// htlcs, hence update types `Fail|MalformedFail|Settle`. A modified // htlcs, hence update types `Fail|MalformedFail|Settle`. A modified
// HTLC is one that's present in the log, and has as a pending fail or // HTLC is one that's present in the log, and has as a pending fail or
// settle that's attempting to consume it. // settle that's attempting to consume it.
modifiedHtlcs map[uint64]struct{} modifiedHtlcs fn.Set[uint64]
} }
// newUpdateLog creates a new updateLog instance. // newUpdateLog creates a new updateLog instance.
@ -55,7 +55,7 @@ func newUpdateLog(logIndex, htlcCounter uint64) *updateLog {
htlcIndex: make(map[uint64]*fn.Node[*PaymentDescriptor]), htlcIndex: make(map[uint64]*fn.Node[*PaymentDescriptor]),
logIndex: logIndex, logIndex: logIndex,
htlcCounter: htlcCounter, htlcCounter: htlcCounter,
modifiedHtlcs: make(map[uint64]struct{}), modifiedHtlcs: fn.NewSet[uint64](),
} }
} }
@ -122,21 +122,20 @@ func (u *updateLog) removeHtlc(i uint64) {
u.Remove(entry) u.Remove(entry)
delete(u.htlcIndex, i) delete(u.htlcIndex, i)
delete(u.modifiedHtlcs, i) u.modifiedHtlcs.Remove(i)
} }
// htlcHasModification returns true if the HTLC identified by the passed index // htlcHasModification returns true if the HTLC identified by the passed index
// has a pending modification within the log. // has a pending modification within the log.
func (u *updateLog) htlcHasModification(i uint64) bool { func (u *updateLog) htlcHasModification(i uint64) bool {
_, o := u.modifiedHtlcs[i] return u.modifiedHtlcs.Contains(i)
return o
} }
// markHtlcModified marks an HTLC as modified based on its HTLC index. After a // markHtlcModified marks an HTLC as modified based on its HTLC index. After a
// call to this method, htlcHasModification will return true until the HTLC is // call to this method, htlcHasModification will return true until the HTLC is
// removed. // removed.
func (u *updateLog) markHtlcModified(i uint64) { func (u *updateLog) markHtlcModified(i uint64) {
u.modifiedHtlcs[i] = struct{}{} u.modifiedHtlcs.Add(i)
} }
// compactLogs performs garbage collection within the log removing HTLCs which // compactLogs performs garbage collection within the log removing HTLCs which