Skip to content

Commit b7d3bc4

Browse files
committed
sweepbatcher: auto-increment sweep.ID in StoreMock
1 parent 09d28b5 commit b7d3bc4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

sweepbatcher/store_mock.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type StoreMock struct {
1515
batches map[int32]dbBatch
1616
sweeps map[wire.OutPoint]dbSweep
1717
mu sync.Mutex
18+
sweepID int32
1819
}
1920

2021
// NewStoreMock instantiates a new mock store.
@@ -122,7 +123,18 @@ func (s *StoreMock) UpsertSweep(ctx context.Context, sweep *dbSweep) error {
122123
s.mu.Lock()
123124
defer s.mu.Unlock()
124125

125-
s.sweeps[sweep.Outpoint] = *sweep
126+
sweepCopy := *sweep
127+
128+
if old, exists := s.sweeps[sweep.Outpoint]; exists {
129+
// Preserve existing sweep ID.
130+
sweepCopy.ID = old.ID
131+
} else {
132+
// Assign fresh sweep ID.
133+
sweepCopy.ID = s.sweepID
134+
s.sweepID++
135+
}
136+
137+
s.sweeps[sweep.Outpoint] = sweepCopy
126138

127139
return nil
128140
}

0 commit comments

Comments
 (0)