Skip to content

refactor(pruner): unexport pruneUpto and oldestRetainedBlock#3781

Open
Ehsan-saradar wants to merge 2 commits into
NethermindEth:mainfrom
Ehsan-saradar:fix/3671-unexport-prune-funcs
Open

refactor(pruner): unexport pruneUpto and oldestRetainedBlock#3781
Ehsan-saradar wants to merge 2 commits into
NethermindEth:mainfrom
Ehsan-saradar:fix/3671-unexport-prune-funcs

Conversation

@Ehsan-saradar

Copy link
Copy Markdown
Contributor

Closes #3671.

PruneUpto and OldestRetainedBlock were exported only so the external pruner_test package could reach them — neither is real cross-package API. Unexported both to pruneUpto / oldestRetainedBlock and moved their direct tests into internal (package pruner) test files, following the existing accessors_internal_test.go pattern. running_event_filter_test.go moves to package pruner too, since it uses pruneUpto to set up state before exercising the exported InitializeRunningEventFilter.

TestPruneBlockDataUpto stays external — it covers the still-exported PruneBlockDataUpto.

Left FindOldestBlockAtOrAfter (also named in the issue) exported on purpose: migration/historyprunner consumes it (and ErrNoBlockInWindow) as production API, so it's not test-only.

Lint and tests pass locally.

Copilot AI review requested due to automatic review settings July 2, 2026 07:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PruneUptopruneUpto and OldestRetainedBlockoldestRetainedBlock, 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.

Comment thread pruner/retention.go Outdated
// 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]).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pruner/retention.go Outdated
// 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, same fix applied here — now points at the exported [PruneBlockDataUpto] instead of the unexported helper.

Comment thread pruner/retention.go Outdated
// 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here too — linked to [PruneBlockDataUpto]. Thanks for flagging all three.

@Ehsan-saradar

Copy link
Copy Markdown
Contributor Author

Also picked up the low-confidence note about the pruneUpto name clash: renamed the Pruner.pruneUpto method to runPruneUpto so it no longer shares a name with the package-level pruneUpto helper it delegates to. The call site reads as a plain call now instead of looking like recursion. Both changes are in 7f6cabc.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

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.
@Ehsan-saradar Ehsan-saradar force-pushed the fix/3671-unexport-prune-funcs branch from 7f6cabc to a6f143b Compare July 6, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexport some of prune pkg functions

2 participants