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): Initialize warp sync provider #4214

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions dot/network/mock_warp_sync_provider_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dot/network/warp_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
type WarpSyncProvider interface {
// Generate proof starting at given block hash. The proof is accumulated until maximum proof
// size is reached.
generate(start common.Hash) (encodedProof []byte, err error)
Generate(start common.Hash) (encodedProof []byte, err error)
}

func (s *Service) handleWarpSyncRequest(req messages.WarpProofRequest) ([]byte, error) {
dimartiro marked this conversation as resolved.
Show resolved Hide resolved
// use the backend to generate the warp proof
proof, err := s.warpSyncProvider.generate(req.Begin)
proof, err := s.warpSyncProvider.Generate(req.Begin)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions dot/network/warp_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestHandleWarpSyncRequestOk(t *testing.T) {

ctrl := gomock.NewController(t)
warpSyncProvider := NewMockWarpSyncProvider(ctrl)
warpSyncProvider.EXPECT().generate(common.EmptyHash).Return(expectedProof, nil).Times(1)
warpSyncProvider.EXPECT().Generate(common.EmptyHash).Return(expectedProof, nil).Times(1)

// Initiate service using the warp sync provider mock
srvc := createServiceWithWarpSyncHelper(t, warpSyncProvider)
Expand All @@ -94,7 +94,7 @@ func TestHandleWarpSyncRequestError(t *testing.T) {
ctrl := gomock.NewController(t)

warpSyncProvider := NewMockWarpSyncProvider(ctrl)
warpSyncProvider.EXPECT().generate(common.EmptyHash).Return(nil, expectedError).Times(1)
warpSyncProvider.EXPECT().Generate(common.EmptyHash).Return(nil, expectedError).Times(1)

// Initiate service using the warp sync provider mock
srvc := createServiceWithWarpSyncHelper(t, warpSyncProvider)
Expand Down
7 changes: 7 additions & 0 deletions dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ChainSafe/gossamer/dot/sync"
"github.com/ChainSafe/gossamer/dot/system"
"github.com/ChainSafe/gossamer/dot/types"
consensus_grandpa "github.com/ChainSafe/gossamer/internal/client/consensus/grandpa"
"github.com/ChainSafe/gossamer/internal/database"
"github.com/ChainSafe/gossamer/internal/log"
"github.com/ChainSafe/gossamer/internal/metrics"
Expand Down Expand Up @@ -348,6 +349,11 @@ func (nodeBuilder) createNetworkService(config *cfg.Config, stateSrvc *state.Ser
if err != nil {
return nil, fmt.Errorf("failed to parse network log level: %w", err)
}

warpSyncProvider := consensus_grandpa.NewWarpSyncProofProvider(
stateSrvc.Block, stateSrvc.Grandpa,
)

// network service configuation
networkConfig := network.Config{
LogLvl: networkLogLevel,
Expand All @@ -370,6 +376,7 @@ func (nodeBuilder) createNetworkService(config *cfg.Config, stateSrvc *state.Ser
Metrics: metrics.NewIntervalConfig(config.PrometheusExternal),
NodeKey: config.Network.NodeKey,
ListenAddress: config.Network.ListenAddress,
WarpSyncProvider: warpSyncProvider,
}

networkSrvc, err := network.NewService(&networkConfig)
Expand Down
7 changes: 7 additions & 0 deletions internal/client/consensus/grandpa/warp_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ type WarpSyncProofProvider struct {
grandpaState GrandpaState
}

func NewWarpSyncProofProvider(blockState BlockState, grandpaState GrandpaState) *WarpSyncProofProvider {
return &WarpSyncProofProvider{
blockState: blockState,
grandpaState: grandpaState,
}
}

// Generate build a warp sync encoded proof starting from the given block hash
func (np *WarpSyncProofProvider) Generate(start common.Hash) ([]byte, error) {
// Get and traverse all GRANDPA authorities changes from the given block hash
Expand Down
Loading