Skip to content

Commit

Permalink
Simplify handler
Browse files Browse the repository at this point in the history
  • Loading branch information
dimartiro committed Sep 18, 2024
1 parent a7e03f7 commit 0e840fc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dot/network/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type Config struct {
// Service interfaces
BlockState BlockState
Syncer Syncer
warpSyncHandler WarpSyncRequestHandler
warpSyncProvider WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/sync)

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/core)

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / zombienet-tests

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/rpc/subscription)

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / linting

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / linting

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / linting

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / linting

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/lib/babe)

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/rpc/modules)

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/rpc)

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/lib/grandpa)

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot)

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/network)

undefined: WarpSyncProvider

Check failure on line 69 in dot/network/config.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: WarpSyncProvider
TransactionHandler TransactionHandler

// Used to specify the address broadcasted to other peers, and avoids using pubip.Get
Expand Down
4 changes: 2 additions & 2 deletions dot/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type Service struct {
blockState BlockState
syncer Syncer
transactionHandler TransactionHandler
warpSyncHandler WarpSyncRequestHandler
warpSyncProvider WarpSyncProvider

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/sync)

undefined: WarpSyncProvider

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/core)

undefined: WarpSyncProvider

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / zombienet-tests

undefined: WarpSyncProvider

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/rpc/subscription)

undefined: WarpSyncProvider

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / linting

undefined: WarpSyncProvider) (typecheck)

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / linting

undefined: WarpSyncProvider) (typecheck)

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / linting

undefined: WarpSyncProvider) (typecheck)

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/lib/babe)

undefined: WarpSyncProvider

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/rpc/modules)

undefined: WarpSyncProvider

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/rpc)

undefined: WarpSyncProvider

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/lib/grandpa)

undefined: WarpSyncProvider

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot)

undefined: WarpSyncProvider

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / integration-tests (github.com/ChainSafe/gossamer/dot/network)

undefined: WarpSyncProvider

Check failure on line 133 in dot/network/service.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: WarpSyncProvider

// Configuration options
noBootstrap bool
Expand Down Expand Up @@ -217,7 +217,7 @@ func NewService(cfg *Config) (*Service, error) {
noBootstrap: cfg.NoBootstrap,
noMDNS: cfg.NoMDNS,
syncer: cfg.Syncer,
warpSyncHandler: cfg.warpSyncHandler,
warpSyncProvider: cfg.warpSyncProvider,
notificationsProtocols: make(map[MessageType]*notificationsProtocol),
lightRequest: make(map[peer.ID]struct{}),
telemetryInterval: cfg.telemetryInterval,
Expand Down
17 changes: 3 additions & 14 deletions dot/network/warp_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@ package network

import (
"github.com/ChainSafe/gossamer/dot/network/messages"
"github.com/ChainSafe/gossamer/lib/common"
libp2pnetwork "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
)

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)
}

type WarpSyncRequestHandler struct {
backend WarpSyncProvider
}

func (w *WarpSyncRequestHandler) handleRequest(req messages.WarpProofRequest) ([]byte, error) {
func (s *Service) handleWarpSyncRequest(req messages.WarpProofRequest) ([]byte, error) {
// use the backend to generate the warp proof
proof, err := w.backend.generate(req.Begin)
proof, err := s.warpSyncProvider.generate(req.Begin)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -54,7 +43,7 @@ func (s *Service) handleWarpSyncMessage(stream libp2pnetwork.Stream, msg message
}()

if req, ok := msg.(*messages.WarpProofRequest); ok {
resp, err := s.warpSyncHandler.handleRequest(*req)
resp, err := s.handleWarpSyncRequest(*req)
if err != nil {
logger.Debugf("cannot create response for request: %s", err)
return nil
Expand Down

0 comments on commit 0e840fc

Please sign in to comment.