+22
internal/mempool/mempool.go
+22
internal/mempool/mempool.go
···
199
199
// Remove taken operations
200
200
m.operations = m.operations[n:]
201
201
202
+
// Adjust lastSavedLen to account for removed operations
203
+
if m.lastSavedLen > 0 {
204
+
if m.lastSavedLen > n {
205
+
m.lastSavedLen -= n // Some saved ops remain
206
+
} else {
207
+
m.lastSavedLen = 0 // All saved ops were taken
208
+
}
209
+
}
210
+
211
+
// ✨ Mark dirty since state changed
212
+
m.dirty = true
213
+
202
214
return result, nil
203
215
}
204
216
···
294
306
// Validate before saving
295
307
if err := m.validateLocked(); err != nil {
296
308
return fmt.Errorf("mempool validation failed, refusing to save: %w", err)
309
+
}
310
+
311
+
// Bounds check to prevent panic
312
+
if m.lastSavedLen > len(m.operations) {
313
+
// This shouldn't happen, but if it does, log and reset
314
+
if m.verbose {
315
+
m.logger.Printf("Warning: lastSavedLen (%d) > operations (%d), resetting to 0",
316
+
m.lastSavedLen, len(m.operations))
317
+
}
318
+
m.lastSavedLen = 0
297
319
}
298
320
299
321
// Get only new operations since last save