Skip to content
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

Migrate x/sync to p2p #3106

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

Migrate x/sync to p2p #3106

wants to merge 20 commits into from

Conversation

joshua-kim
Copy link
Contributor

Why this should be merged

Eliminates our last usage of the blocking clients

How this works

Replaces usage of blocking client with p2p async clients

How this was tested

Added unit tests

x/sync/client.go Outdated Show resolved Hide resolved
@joshua-kim joshua-kim changed the base branch from p2p-test to master June 14, 2024 07:25
x/sync/metrics.go Outdated Show resolved Hide resolved
func (m *Manager) doWork(ctx context.Context, work *workItem) {
// Backoff for failed requests accounting for time this job has already
// spent waiting in the unprocessed queue
backoff := calculateBackoff(work.attempt)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not optimal since this worker goroutine is going to be waiting until this timeout passes and ideally we would prioritize requests that are always executable, but felt like something more complex would make the diff hard to review since the scope of this PR is just trying to get rid of the blocking networking calls

return client.GetRangeProof(ctx, request)
}

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

@joshua-kim joshua-kim Jun 21, 2024

Choose a reason for hiding this comment

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

All client-side error handling cases were moved into Test_Sync_Result_Correct_Root and server-side cases were moved into network_server_test

@joshua-kim joshua-kim self-assigned this Jun 21, 2024
@joshua-kim joshua-kim added the cleanup Code quality improvement label Jun 21, 2024
@joshua-kim joshua-kim marked this pull request as ready for review June 21, 2024 17:00
return client.AppRequest(ctx, set.Of(nodeID), requestBytes, onResponse)
}

func (m *Manager) retryWork(work *workItem) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another idea is to have a separate failed requests data structure. Feel like this will introduce more complexity into this PR though so for now we are just retrying by putting stuff in the work heap w/ it's own priority.

Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
network/p2p/p2ptest/client.go Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems a bit unusual to test our testing code... But since the tests are already written 🤷

Comment on lines -85 to -86
// tracking of peers & bandwidth usage
peers *p2p.PeerTracker
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to configure the p2p client to perform a similar type of peer sampling? It's a critical performance improvement to select peers based on historical bandwidth.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah we'll need to merge in some form of #3007

x/sync/client.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

The actual code in this file feels a bit weird. Can we move these helpers and definitions into manager.go (where they are actually used)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. Originally did this to minimize the diff but agree this looks weird now.

// spent waiting in the unprocessed queue
backoff := calculateBackoff(work.attempt)
if waitTime := backoff - time.Since(work.queueTime); waitTime > 0 {
<-time.After(waitTime)
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels a bit odd to me that we have access to a context but that we don't check it while we're waiting here.

x/sync/manager.go Outdated Show resolved Hide resolved
db: db,
log: log,
func maybeBytesToMaybe(mb *pb.MaybeBytes) maybe.Maybe[[]byte] {
if mb != nil && !mb.IsNothing {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think mb.IsNothing could just be removed right? Because mb == nil already implies Nothing. Should we remove this field from the type? Or is this needed for some other language?

To clarify - the mb.IsNothing check is needed if it's on the type... But I think we could get rid of it entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is showing up as a diff because of some code that got moved around it but this is previously existing code

Copy link
Contributor

Choose a reason for hiding this comment

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

A future improvement then haha

Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement
Projects
Status: In Progress 🏗
Development

Successfully merging this pull request may close these issues.

None yet

3 participants