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

feat(dot/network): Add warp sync request handler #4186

Open
wants to merge 14 commits into
base: development
Choose a base branch
from

Conversation

dimartiro
Copy link
Contributor

@dimartiro dimartiro commented Sep 18, 2024

Changes

Adds warp sync request handler.

  • Register warp sync handler at /sync/warp
  • Added request message encoding / decoding
  • Add handler to respond to warp sync requests
  • tests

This implementation is slightly different from the one proposed in #4052, but I think it's more straightforward and less complex, which will help us achieve a quick warp sync implementation. We can discuss or revisit this later.

Tests

go test ./dot/network

Issues

closing: #4052

@dimartiro dimartiro self-assigned this Sep 18, 2024
@dimartiro dimartiro linked an issue Sep 18, 2024 that may be closed by this pull request
3 tasks
@dimartiro dimartiro changed the base branch from eclesio/sync-strategy to development September 18, 2024 19:23
dot/network/service.go Outdated Show resolved Hide resolved
dot/network/warp_sync.go Outdated Show resolved Hide resolved
dot/network/warp_sync.go Outdated Show resolved Hide resolved
dot/network/warp_sync.go Show resolved Hide resolved
Copy link
Member

@EclesioMeloJunior EclesioMeloJunior left a comment

Choose a reason for hiding this comment

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

LGTM

dot/network/service.go Outdated Show resolved Hide resolved
@@ -66,6 +66,7 @@ type Config struct {
// Service interfaces
BlockState BlockState
Syncer Syncer
warpSyncProvider WarpSyncProvider
Copy link
Contributor

Choose a reason for hiding this comment

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

This will probably need to be public right?

}

// Decode decodes the message into a WarpProofRequest
func (wsr *WarpProofRequest) Decode(in []byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (wsr *WarpProofRequest) Decode(in []byte) error {
func (wpr *WarpProofRequest) Decode(in []byte) error {

same for below receivers

// Encode encodes the warp sync request
func (wsr *WarpProofRequest) Encode() ([]byte, error) {
buffer := bytes.NewBuffer(nil)
encoder := scale.NewEncoder(buffer)
Copy link
Contributor

Choose a reason for hiding this comment

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

For both encoding and decoding here, do we need to create the encoder/decoder object? Can we not just call scale.Marshal and scale.Unmarshal?

stream.Conn().RemotePeer(),
resp,
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a log or something for the !ok case?


// Test encoding
reqEnc, err := testWarpReqMessage.Encode()
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any tests in substrate with hardcoded bytes that we could use here? We have run into a problem before in serialization tests where we can encode and decode to an expected type, but the actual byte representation is incorrect.

However giving how simple this is, probably is not the end of the world. I just wanted to make a note of this

Copy link
Contributor

@jimjbrettj jimjbrettj left a comment

Choose a reason for hiding this comment

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

Small questions/comments, but overall great work and LGTM!

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.

Implement warp sync request handler
3 participants