Skip to content

Commit

Permalink
fix(pruner): override checkpoint fully when switching from archival t…
Browse files Browse the repository at this point in the history
…o full
  • Loading branch information
renaynay committed Jan 6, 2025
1 parent 5f5ee45 commit 2b062ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 11 additions & 6 deletions pruner/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pruner/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 2b062ba

Please sign in to comment.