refactor(pruner): unexport pruneUpto and oldestRetainedBlock#3781
refactor(pruner): unexport pruneUpto and oldestRetainedBlock#3781Ehsan-saradar wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the pruner package API surface by unexporting helpers that were only public to support the external pruner_test package, and relocates their direct tests into internal (package pruner) test files.
Changes:
- Unexports
PruneUpto→pruneUptoandOldestRetainedBlock→oldestRetainedBlock, updating in-package call sites. - Moves/adjusts tests to
package pruner, adding new internal test files for the unexported helpers. - Updates references in running event filter initialization and retention helpers to use the new unexported names.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pruner/running_event_filter.go | Updates running event filter initialization to use oldestRetainedBlock. |
| pruner/running_event_filter_test.go | Switches to package pruner and updates test wiring to use internal helpers. |
| pruner/retention.go | Uses oldestRetainedBlock internally and updates related doc references. |
| pruner/retention_test.go | Removes external test of the unexported helper and adjusts assertion text. |
| pruner/retention_internal_test.go | Adds internal tests for oldestRetainedBlock. |
| pruner/pruneupto_internal_test.go | Adds internal tests for pruneUpto lifecycle/resume/carve-out behavior. |
| pruner/pruner.go | Updates pruner implementation to call oldestRetainedBlock / pruneUpto. |
| pruner/pruner_test.go | Updates comments to reflect the unexported helper name. |
| pruner/accessors.go | Unexports PruneUpto to pruneUpto and updates internal references. |
| pruner/accessors_test.go | Keeps external coverage for PruneBlockDataUpto and updates comments accordingly. |
Comments suppressed due to low confidence (1)
pruner/pruner.go:404
- This method now calls a package-level helper with the same name (pruneUpto). Although correct, the name collision makes it easy to misread as recursion and can be error-prone during future refactors. Consider renaming either the receiver method or the package-level helper to make call sites unambiguous (e.g., pruneBlocksUpto / pruneUptoInternal).
func (p *Pruner) pruneUpto(ctx context.Context, oldestBlockToKeep uint64) error {
start := time.Now()
blocksPruned, oldestKept, err := pruneUpto(
ctx,
p.database,
oldestBlockToKeep,
p.targetBatchByteSize,
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // a [*BlockPrunedError]. Retention is probed via BlockCommitments — the | ||
| // source of truth for "block has not been pruned", since it has no | ||
| // carve-out (see [PruneUpto]). | ||
| // carve-out (see [pruneUpto]). |
There was a problem hiding this comment.
Good catch — fixed in 7f6cabc. Switched it to the exported [PruneBlockDataUpto], which documents the same carve-out and actually resolves on pkg.go.dev, so no internal name leaks into the public docs.
| // plain core accessors instead — the two checks diverge at oldestKept-1, | ||
| // where state is preserved by carve-out but block-level data is not. | ||
| // See [PruneUpto] for the carve-out semantics. Returns db.ErrKeyNotFound | ||
| // See [pruneUpto] for the carve-out semantics. Returns db.ErrKeyNotFound |
There was a problem hiding this comment.
Agreed, same fix applied here — now points at the exported [PruneBlockDataUpto] instead of the unexported helper.
| // state at that block is queryable. Use this for state access only; for | ||
| // block-level data use [RequireRetained] + the plain core accessors instead. | ||
| // See [PruneUpto] for the carve-out semantics. Returns db.ErrKeyNotFound | ||
| // See [pruneUpto] for the carve-out semantics. Returns db.ErrKeyNotFound |
There was a problem hiding this comment.
Done here too — linked to [PruneBlockDataUpto]. Thanks for flagging all three.
|
Also picked up the low-confidence note about the |
These functions were exported only so the external pruner_test package
could reach them; neither is part of the pruner package's cross-package
API. Unexport them to `pruneUpto` / `oldestRetainedBlock` and relocate
their direct tests into internal (package pruner) test files, following
the existing accessors_internal_test.go precedent:
- pruneUpto lifecycle tests -> pruneupto_internal_test.go
- oldestRetainedBlock tests -> retention_internal_test.go
- running_event_filter_test.go moves to package pruner since it uses
pruneUpto to set up pruned state before exercising the exported
InitializeRunningEventFilter
TestPruneBlockDataUpto stays in the external test package: it covers the
still-exported PruneBlockDataUpto.
FindOldestBlockAtOrAfter (also named in NethermindEth#3671) is intentionally left
exported: migration/historyprunner consumes it (and ErrNoBlockInWindow)
as production API, so it is not test-only.
Closes NethermindEth#3671
- Point exported docs (RequireRetained, HeaderBy*IfStateRetained, oldestRetainedBlock) at the exported [PruneBlockDataUpto] instead of the unexported [pruneUpto], so the GoDoc links resolve on pkg.go.dev and no internal name leaks into the public API docs. - Rename the Pruner.pruneUpto method to runPruneUpto so it no longer shares a name with the package-level pruneUpto helper it calls — removes the read-as-recursion ambiguity at the call site.
7f6cabc to
a6f143b
Compare
Closes #3671.
PruneUptoandOldestRetainedBlockwere exported only so the externalpruner_testpackage could reach them — neither is real cross-package API. Unexported both topruneUpto/oldestRetainedBlockand moved their direct tests into internal (package pruner) test files, following the existingaccessors_internal_test.gopattern.running_event_filter_test.gomoves topackage prunertoo, since it usespruneUptoto set up state before exercising the exportedInitializeRunningEventFilter.TestPruneBlockDataUptostays external — it covers the still-exportedPruneBlockDataUpto.Left
FindOldestBlockAtOrAfter(also named in the issue) exported on purpose:migration/historyprunnerconsumes it (andErrNoBlockInWindow) as production API, so it's not test-only.Lint and tests pass locally.