Skip to content

refactor(x/sync): remove need for passing proof nodes to completeWorkItem #4064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

alarso16
Copy link
Contributor

@alarso16 alarso16 commented Jul 9, 2025

Why this should be merged

As a part of the refactor to allow Firewood to use x/sync, we should remove any proof logic from sync manager. This moves finding the next key to request to the proof commit implementation, as well as parsing the proof from bytes.

How this works

The completeWorkItem function does not need to know the largest handled key, but rather the next key that needs retrieved. This is handled through a hook, since even on some non-error returns, it shouldn't be called (see implementation). Instead of passing in the DB to the Sync Manager, it will take this ProofClient

How this was tested

Unit tests.

Need to be documented in RELEASES.md?

No.

@alarso16 alarso16 added merkledb go Pull requests that update Go code labels Jul 9, 2025
@alarso16 alarso16 force-pushed the alarso16/move-next-key branch 2 times, most recently from 6936bbb to 4a3dae0 Compare July 9, 2025 16:41
@alarso16 alarso16 marked this pull request as ready for review July 9, 2025 16:42
@Copilot Copilot AI review requested due to automatic review settings July 9, 2025 16:42
Copy link
Contributor

@Copilot Copilot AI left a comment

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 completeWorkItem function in the x/sync package to simplify work item completion by removing the need to pass proof nodes and calculating the next key to fetch within the proof response handlers instead.

  • Moves next key calculation logic from completeWorkItem to handleRangeProofResponse and handleChangeProofResponse
  • Simplifies completeWorkItem function signature by removing ctx and proofOfLargestKey parameters
  • Adds test coverage for the findNextKey function with identical keys edge case

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
x/sync/manager.go Refactors proof response handlers to calculate next key before calling completeWorkItem and simplifies the completeWorkItem function signature
x/sync/sync_test.go Adds new test case for findNextKey function when start and end keys are identical

@alarso16 alarso16 force-pushed the alarso16/move-next-key branch 9 times, most recently from ab1bd24 to c8e2fd9 Compare July 15, 2025 18:52
//
// Invariant: [lastReceivedKey] < [rangeEnd].
// If [rangeEnd] is Nothing it's considered > [lastReceivedKey].
func (c *xSyncClient) findNextKey(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Everything this function and below was completely unmodified.

"github.com/stretchr/testify/require"
)

func Test_Sync_FindNextKey_InSync(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests are unmodified besides initialization

Copy link
Contributor

Choose a reason for hiding this comment

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

These comments significantly reduce review time, ty for doing that!

Copy link
Contributor

Choose a reason for hiding this comment

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

I would avoid unnecessary moves if possible in this PR, it makes it difficult to review - it's okay (and common) in Go to just stuff things in one file.

x/sync/db.go Outdated
@@ -12,3 +19,18 @@ type DB interface {
merkledb.ChangeProofer
merkledb.RangeProofer
}

type ProofClient interface {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any ideas for a better name?

Copy link
Contributor

Choose a reason for hiding this comment

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

SyncClient?

Copy link
Contributor

@joshua-kim joshua-kim Jul 16, 2025

Choose a reason for hiding this comment

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

What do we define this interface for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The x/sync manager should be able to work with other database implementations besides MerkleDB (specifically, Firewood). This is the smallest reasonable interface to allow other databases to hook in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about DBSyncClient?

Copy link
Contributor

@rkuris rkuris left a comment

Choose a reason for hiding this comment

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

This looks fine to me, not sure why we are removing BranchFactor16. We support this in firewood as well, although it is not a runtime option, it's compile time. We could check and refuse to open if the feature isn't enabled in a future release. For now, I think we can just implement it without BranchFactor16 working.

x/sync/db.go Outdated
@@ -12,3 +19,18 @@ type DB interface {
merkledb.ChangeProofer
merkledb.RangeProofer
}

type ProofClient interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

SyncClient?

"github.com/stretchr/testify/require"
)

func Test_Sync_FindNextKey_InSync(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

These comments significantly reduce review time, ty for doing that!

x/sync/db.go Outdated
@@ -12,3 +19,18 @@ type DB interface {
merkledb.ChangeProofer
merkledb.RangeProofer
}

type ProofClient interface {
Copy link
Contributor

@joshua-kim joshua-kim Jul 16, 2025

Choose a reason for hiding this comment

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

What do we define this interface for?

BranchFactor merkledb.BranchFactor
}

type xSyncClient struct {
Copy link
Contributor

@joshua-kim joshua-kim Jul 16, 2025

Choose a reason for hiding this comment

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

This abstraction feels very difficult to reason about and there doesn't seem to be a clear abstraction boundary defined - what is this type intended to represent and what is it's responsibility? It's not really a client - it doesn't make any requests, but seems to define handlers for how to interpret responses + you can interact with the underlying database it's coupled to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't really a client, but I didn't know what to call it. The goal was to remove the dependence on database and proof implementation (specifically merkledb) from the sync manager. The x/sync manager in particular shouldn't depend on any specific database/proof implementation

@alarso16 alarso16 force-pushed the alarso16/move-next-key branch 2 times, most recently from 7c2a3af to 7b6273f Compare July 17, 2025 14:35
@alarso16 alarso16 force-pushed the alarso16/move-next-key branch from 7b6273f to 389b0bf Compare July 17, 2025 14:46
@alarso16 alarso16 force-pushed the alarso16/move-next-key branch from 5cb257f to 2fb7fbd Compare July 17, 2025 15:16
@alarso16 alarso16 force-pushed the alarso16/move-next-key branch 2 times, most recently from b603332 to 333553e Compare July 17, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code merkledb
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants