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 592876a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 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
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

// 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
10 changes: 3 additions & 7 deletions dot/network/warp_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ type WarpSyncProvider interface {
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 +50,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 592876a

Please sign in to comment.