Skip to content

chore: minor deduplication#3139

Merged
tac0turtle merged 4 commits intomainfrom
marko/simplify2
Mar 9, 2026
Merged

chore: minor deduplication#3139
tac0turtle merged 4 commits intomainfrom
marko/simplify2

Conversation

@tac0turtle
Copy link
Contributor

@tac0turtle tac0turtle commented Mar 7, 2026

Overview

this pr attempts a simple deduplication of some functions

Summary by CodeRabbit

  • Refactor

    • Consolidated metadata read/write handling and improved metadata read error logging for more consistent behavior; no end-user functional changes.
  • Tests

    • Standardized test setup to use a single in-memory store helper across suites.
  • Chores

    • CI build updated to include an additional application and expanded build context.
    • Linter configuration updated to exclude an additional rule.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2026

📝 Walkthrough

Walkthrough

Introduces helpers to read/write 8-byte little-endian uint64 metadata, refactors DA/header/data/genesis height reads/writes to use them, switches tests from memStore(t) to testMemStore(t), and adds ev-node-grpc to CI with an updated gRPC Dockerfile and a lint exclude.

Changes

Cohort / File(s) Summary
Metadata helpers & usages
block/internal/cache/manager.go, block/internal/submitting/submitter.go
Added getMetadataUint64(ctx, st, key) and putUint64Metadata(ctx, st, key, val); replaced manual 8-byte little-endian encoding/decoding for DA-included, header/data, and genesis heights with these helpers; added error logging on read failures.
Test store initialization
block/internal/cache/manager_test.go, block/internal/cache/pending_data_test.go, block/internal/cache/pending_headers_test.go
Replaced memStore(t) with testMemStore(t) in tests and removed the old memStore helper; test behavior unchanged.
Store errors API
pkg/store/types.go
Added public ErrNotFound and helper IsNotFound(err error) bool to unify not-found error checks.
CI workflow
.github/workflows/ci.yml
Added ev-node-grpc to the docker build apps list so apps/grpc/Dockerfile is included in CI builds.
gRPC Dockerfile
apps/grpc/Dockerfile
COPY updated to include core/go.sum alongside core/go.mod into the ./core/ build context.
Lint config
.golangci.yml
Added G118 to the gosec excludes list.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Submitter as Submitter\n(block/internal/submitting)
participant Manager as Manager\n(block/internal/cache)
participant Store as Store\n(pkg/store)
Submitter->>Store: putUint64Metadata(key, val)\n(encode little-endian & SetMetadata)
Store-->>Submitter: OK / error
Note over Submitter,Store: Submitter updates in-memory DA heights after write
Manager->>Store: getMetadataUint64(key)\n(GetMetadata & validate 8 bytes)
Store-->>Manager: value/absent/error
Manager-->>Manager: decide seed or early return\n(based on ok & non-zero)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested reviewers

  • tuxcanfly
  • tzdybal
  • Manav-Aggarwal

Poem

🐇 I hopped through little-endian lanes,

Stored my numbers, soft as grains.
Tests snug in a cleaner nest,
CI builds the gRPC guest —
A carrot-sized change, and all is blessed! 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides only a minimal overview ('simple deduplication of some functions') and lacks details about rationale, context, and technical justification that the template requires. Expand the description to include context about why deduplication was needed, what specific functions were deduplicated, potential impacts, and any related issues or PR numbers.
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore: minor deduplication' accurately reflects the PR's main objective of deduplicating shared utility functions (getMetadataUint64, putUint64Metadata, and store error helpers) across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch marko/simplify2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2026

The latest Buf updates on your PR. Results from workflow CI / buf-check (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped✅ passed✅ passedMar 8, 2026, 9:59 AM

@claude
Copy link
Contributor

claude bot commented Mar 7, 2026

Claude finished @tac0turtle's task in 1m 33s —— View job


Code Review: chore: minor deduplication

  • Gather context and understand the PR
  • Review changed files
  • Provide comprehensive feedback

Summary

This is a clean, focused deduplication PR. The main changes are:

  1. getMetadataUint64 — new helper in cache package for reading 8-byte LE uint64 from metadata
  2. putUint64Metadata — new helper in submitter package for writing 8-byte LE uint64 to metadata
  3. Test store consolidationmemStore(t)testMemStore(t) across the cache package tests
  4. CI/Dockerfile — adds ev-node-grpc to the build matrix and copies core/go.sum in the gRPC Dockerfile

CodeRabbit Comments Already Addressed ✅

Both CodeRabbit review comments appear to have already been addressed in the final version of this PR:

  • getMetadataUint64 (manager.go:396–409) properly returns (uint64, bool, error), distinguishing not-found (isNotFound(err)false, nil) from backend errors and malformed-length values. The original concern about collapsing all failures to false is resolved.
  • processDAInclusionLoop (submitter.go:352–364) correctly persists with putUint64Metadata before advancing s.daIncludedHeight and deleting the per-height cache. A break on failure prevents state divergence.

Issues Found

1. initializeDAIncludedHeight is inconsistent with the new helpers (submitter.go:410–414)

func (s *Submitter) initializeDAIncludedHeight(ctx context.Context) error {
    if height, err := s.store.GetMetadata(ctx, store.DAIncludedHeightKey); err == nil && len(height) == 8 {
        s.SetDAIncludedHeight(binary.LittleEndian.Uint64(height))
    }
    return nil
}

This function silently swallows both backend errors and malformed-length values, never returning an error and always returning nil. Since putUint64Metadata was just introduced in the same file, a symmetric getMetadataUint64 helper (or reuse of the cache package's helper via a shared utility) would make this consistent and correctly surface store failures at startup.

Fix this →

2. TestPendingData_InitFromMetadata doesn't use the new testMemStore helper (pending_data_test.go:184–186)

ds, err := store.NewTestInMemoryKVStore()
require.NoError(t, err)
store := store.New(ds)

All other tests in this PR were migrated to testMemStore(t), but this test was missed. It's a minor inconsistency, but worth fixing for uniformity.

Fix this →


Minor Observations (Non-Blocking)

  • Duplication between packages: putUint64Metadata lives in submitting and getMetadataUint64 lives in cache. If this pattern is needed in more places, consider lifting both to pkg/store as exported helpers (e.g., store.GetUint64Metadata / store.PutUint64Metadata). This PR isn't the right time to do that, but worth tracking.
  • binary import still in submitter.go: initializeDAIncludedHeight is the only remaining manual binary usage in submitter.go. Fixing issue ABCI interface #1 above would allow removing "encoding/binary" from the imports in that file.

Verdict

The core logic changes are correct and well-structured. The two CodeRabbit findings are already addressed. The only actionable items are the initializeDAIncludedHeight inconsistency (should return errors rather than silently succeeding) and one missed testMemStore migration. Everything else looks good.

@tac0turtle tac0turtle marked this pull request as ready for review March 7, 2026 15:52
@tac0turtle tac0turtle requested a review from julienrbrt March 7, 2026 15:52
@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 48.57143% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.05%. Comparing base (a96974b) to head (8bec38a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
block/internal/cache/manager.go 47.61% 5 Missing and 6 partials ⚠️
block/internal/submitting/submitter.go 53.84% 2 Missing and 4 partials ⚠️
pkg/store/types.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3139      +/-   ##
==========================================
- Coverage   61.12%   61.05%   -0.08%     
==========================================
  Files         113      114       +1     
  Lines       11676    11687      +11     
==========================================
- Hits         7137     7135       -2     
- Misses       3737     3746       +9     
- Partials      802      806       +4     
Flag Coverage Δ
combined 61.05% <48.57%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@block/internal/cache/manager.go`:
- Around line 390-405: getMetadataUint64 currently collapses backend errors and
malformed values into a missing result; change its signature to return (uint64,
bool, error) so it returns the raw error when st.GetMetadata fails or when
len(b) != 8 (e.g., return an fmt.Errorf describing the malformed length), and
only use ok==false for the explicit not-found case; then update
initDAHeightFromStore to call value, ok, err := getMetadataUint64(ctx, m.store,
store.DAIncludedHeightKey), handle/log err distinctly (e.g.,
m.logger.Error/return) and only treat the not-found (ok==false) path as a
harmless skip, preserving transient read failures for diagnostics.

In `@block/internal/submitting/submitter.go`:
- Around line 357-359: The DA included height is advanced and the per-height
cache is deleted even when putUint64Metadata(s.ctx, s.store,
store.DAIncludedHeightKey, nextHeight) fails; modify the flow so you only update
s.daIncludedHeight and remove the per-height cache after putUint64Metadata
returns nil. Concretely, check the error from putUint64Metadata and on non-nil
return/propagate the error (or retry) without mutating s.daIncludedHeight or
performing the per-height cache deletion; only after a successful
putUint64Metadata call set s.daIncludedHeight = nextHeight and then delete the
per-height cache. Ensure you log the failure as you do now via
s.logger.Error().Err(err)... but avoid dropping in-memory state when persistence
fails.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c63884b7-8812-49b2-aa3e-9a1c928062f8

📥 Commits

Reviewing files that changed from the base of the PR and between a96974b and 2025893.

📒 Files selected for processing (5)
  • block/internal/cache/manager.go
  • block/internal/cache/manager_test.go
  • block/internal/cache/pending_data_test.go
  • block/internal/cache/pending_headers_test.go
  • block/internal/submitting/submitter.go

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

nice!

tac0turtle and others added 3 commits March 7, 2026 23:03
…g state

Address PR review feedback:
- getMetadataUint64 returns (uint64, bool, error) to distinguish missing
  keys from backend failures
- processDAInclusionLoop persists DAIncludedHeightKey before advancing
  in-memory state to prevent cache deletion on persist failure
- Expose store.ErrNotFound and store.IsNotFound for clean sentinel checks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
block/internal/submitting/submitter.go (1)

410-414: Consider aligning initializeDAIncludedHeight with the new error handling pattern.

This method uses the old pattern (direct GetMetadata call without explicit not-found checking via store.IsNotFound). While it works because err == nil short-circuits the condition, it's inconsistent with the new getMetadataUint64 pattern in manager.go.

For consistency, consider using the same approach or extracting a shared helper. However, this is a minor inconsistency and not a functional issue.

♻️ Optional: Align with new pattern
 // initializeDAIncludedHeight loads the DA included height from store
 func (s *Submitter) initializeDAIncludedHeight(ctx context.Context) error {
-	if height, err := s.store.GetMetadata(ctx, store.DAIncludedHeightKey); err == nil && len(height) == 8 {
-		s.SetDAIncludedHeight(binary.LittleEndian.Uint64(height))
+	height, err := s.store.GetMetadata(ctx, store.DAIncludedHeightKey)
+	if err != nil {
+		if !store.IsNotFound(err) {
+			return fmt.Errorf("failed to load DA included height: %w", err)
+		}
+		return nil // key absent, start from 0
+	}
+	if len(height) == 8 {
+		s.SetDAIncludedHeight(binary.LittleEndian.Uint64(height))
 	}
 	return nil
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@block/internal/submitting/submitter.go` around lines 410 - 414,
initializeDAIncludedHeight currently calls s.store.GetMetadata directly and
checks err==nil, which is inconsistent with the new error-handling pattern used
by getMetadataUint64 in manager.go; update initializeDAIncludedHeight to reuse
the same helper or explicit store.IsNotFound checks: call the shared
getMetadataUint64 (or replicate its logic) to fetch store.DAIncludedHeightKey,
handle a not-found via store.IsNotFound silently, log/return other errors, and
only call s.SetDAIncludedHeight when a valid 8-byte value is returned.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@block/internal/submitting/submitter.go`:
- Around line 410-414: initializeDAIncludedHeight currently calls
s.store.GetMetadata directly and checks err==nil, which is inconsistent with the
new error-handling pattern used by getMetadataUint64 in manager.go; update
initializeDAIncludedHeight to reuse the same helper or explicit store.IsNotFound
checks: call the shared getMetadataUint64 (or replicate its logic) to fetch
store.DAIncludedHeightKey, handle a not-found via store.IsNotFound silently,
log/return other errors, and only call s.SetDAIncludedHeight when a valid 8-byte
value is returned.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d54e3667-a359-417a-8e6e-14855b50fa0b

📥 Commits

Reviewing files that changed from the base of the PR and between 2b3dcdb and 8bec38a.

📒 Files selected for processing (3)
  • block/internal/cache/manager.go
  • block/internal/submitting/submitter.go
  • pkg/store/types.go

@tac0turtle tac0turtle merged commit 3b3d5e7 into main Mar 9, 2026
51 of 52 checks passed
@tac0turtle tac0turtle deleted the marko/simplify2 branch March 9, 2026 06:43
alpe added a commit that referenced this pull request Mar 9, 2026
* main:
  chore: minor deduplication (#3139)
  refactor(store,cache)!: optimize cache restore as O(1) (#3134)
  ci: remove spamoor results from benchmark results per PR (#3138)
  build(deps): Bump rollup from 4.22.4 to 4.59.0 in /docs in the npm_and_yarn group across 1 directory (#3136)
  fix(block): fix blocktime timer usage (#3137)
  build(deps): bump core v1.0.0 (#3135)
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.

2 participants