diff --git a/test/e2e/app/app.go b/test/e2e/app/app.go index 0a0194c98..e7ba110e9 100644 --- a/test/e2e/app/app.go +++ b/test/e2e/app/app.go @@ -184,6 +184,10 @@ func (app *Application) Commit() abci.ResponseCommit { panic(err) } app.logger.Info("Created state sync snapshot", "height", snapshot.Height) + err = app.snapshots.Prune(maxSnapshotCount) + if err != nil { + app.logger.Error("Failed to prune snapshots", "err", err) + } } retainHeight := int64(0) if app.cfg.RetainBlocks > 0 { diff --git a/test/e2e/app/snapshots.go b/test/e2e/app/snapshots.go index 4ef20375f..6a9c0e0dc 100644 --- a/test/e2e/app/snapshots.go +++ b/test/e2e/app/snapshots.go @@ -16,6 +16,9 @@ import ( const ( snapshotChunkSize = 1e6 + + // Keep only the most recent 10 snapshots. Older snapshots are pruned + maxSnapshotCount = 10 ) // SnapshotStore stores state sync snapshots. Snapshots are stored simply as @@ -105,6 +108,27 @@ func (s *SnapshotStore) Create(state *State) (abci.Snapshot, error) { return snapshot, nil } +// Prune removes old snapshots ensuring only the most recent n snapshots remain +func (s *SnapshotStore) Prune(n int) error { + s.Lock() + defer s.Unlock() + // snapshots are appended to the metadata struct, hence pruning removes from + // the front of the array + i := 0 + for ; i < len(s.metadata)-n; i++ { + h := s.metadata[i].Height + if err := os.Remove(filepath.Join(s.dir, fmt.Sprintf("%v.json", h))); err != nil { + return err + } + } + + // update metadata by removing the deleted snapshots + pruned := make([]abci.Snapshot, len(s.metadata[i:])) + copy(pruned, s.metadata[i:]) + s.metadata = pruned + return nil +} + // List lists available snapshots. func (s *SnapshotStore) List() ([]*abci.Snapshot, error) { s.RLock() diff --git a/test/e2e/generator/generate.go b/test/e2e/generator/generate.go index deffb533a..e5ffcdace 100644 --- a/test/e2e/generator/generate.go +++ b/test/e2e/generator/generate.go @@ -54,7 +54,7 @@ var ( e2e.StateSyncRPC: 45, } nodePersistIntervals = uniformChoice{0, 1, 5} - nodeSnapshotIntervals = uniformChoice{0, 3} + nodeSnapshotIntervals = uniformChoice{0, 5} nodeRetainBlocks = uniformChoice{0, 2 * int(e2e.EvidenceAgeHeight), 4 * int(e2e.EvidenceAgeHeight)} nodePerturbations = probSetChoice{ "disconnect": 0.1,