diff --git a/pruner/checkpoint.go b/pruner/checkpoint.go index 591333cb3f..6811d42fbf 100644 --- a/pruner/checkpoint.go +++ b/pruner/checkpoint.go @@ -32,6 +32,14 @@ type checkpoint struct { FailedHeaders map[uint64]struct{} `json:"failed"` } +func newCheckpoint(prunerKind string) *checkpoint { + return &checkpoint{ + PrunerKind: prunerKind, + LastPrunedHeight: 1, + FailedHeaders: map[uint64]struct{}{}, + } +} + // DetectPreviousRun ensures that a node that has been run with "full" pruning // mode previously cannot revert back to an "archival" one. This check should // only be performed when a node is either a Full or Bridge node. @@ -52,7 +60,8 @@ func DetectPreviousRun(ctx context.Context, ds datastore.Datastore, expectedKind return ErrDisallowRevertToArchival } // allow conversion from archival to full by overriding previous checkpoint - cp.PrunerKind = expectedKind + log.Infow("overriding checkpoint to enable full pruning mode...") + cp = newCheckpoint(expectedKind) return storeCheckpoint(ctx, wrappedDs, cp) } return nil @@ -92,11 +101,7 @@ func (s *Service) loadCheckpoint(ctx context.Context) error { cp, err := getCheckpoint(ctx, s.ds) if err != nil { if errors.Is(err, errCheckpointNotFound) { - s.checkpoint = &checkpoint{ - PrunerKind: s.pruner.Kind(), - LastPrunedHeight: 1, - FailedHeaders: map[uint64]struct{}{}, - } + s.checkpoint = newCheckpoint(s.pruner.Kind()) return storeCheckpoint(ctx, s.ds, s.checkpoint) } return err diff --git a/pruner/checkpoint_test.go b/pruner/checkpoint_test.go index 6eaf92a1ce..ea65fb48e1 100644 --- a/pruner/checkpoint_test.go +++ b/pruner/checkpoint_test.go @@ -83,6 +83,7 @@ func TestCheckpointOverride(t *testing.T) { assert.NoError(t, err) cp, err := getCheckpoint(ctx, namespaceWrapped) - t.Log(err) - t.Log(cp) + require.NoError(t, err) + assert.Equal(t, "full", cp.PrunerKind) + assert.Equal(t, uint64(1), cp.LastPrunedHeight) }