Skip to content
Merged
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
19 changes: 7 additions & 12 deletions pkg/sync/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,18 @@ func (syncService *SyncService[H]) initStore(ctx context.Context, initial H) (bo
// but does not start the Subscriber. Returns peer IDs for later use.
func (syncService *SyncService[H]) setupP2PInfrastructure(ctx context.Context) ([]peer.ID, error) {
ps := syncService.p2p.PubSub()
var err error

_, _, chainID, err := syncService.p2p.Info()
if err != nil {
return nil, fmt.Errorf("error while fetching the network: %w", err)
}
Comment on lines +257 to +259
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The error message "error while fetching the network" is a bit vague. A more specific message, such as "error while fetching p2p info", would be more descriptive of what syncService.p2p.Info() does and would aid in debugging, as the function primarily retrieves information from the p2p client rather than performing a network fetch.

Suggested change
if err != nil {
return nil, fmt.Errorf("error while fetching the network: %w", err)
}
if err != nil {
return nil, fmt.Errorf("error while fetching p2p info: %w", err)
}

networkID := syncService.getNetworkID(chainID)

// Create subscriber but DON'T start it yet
syncService.sub, err = goheaderp2p.NewSubscriber[H](
ps,
pubsub.DefaultMsgIdFn,
goheaderp2p.WithSubscriberNetworkID(syncService.getChainID()),
goheaderp2p.WithSubscriberNetworkID(networkID),
goheaderp2p.WithSubscriberMetrics(),
)
if err != nil {
Expand All @@ -269,12 +274,6 @@ func (syncService *SyncService[H]) setupP2PInfrastructure(ctx context.Context) (
return nil, fmt.Errorf("error while starting store: %w", err)
}

_, _, network, err := syncService.p2p.Info()
if err != nil {
return nil, fmt.Errorf("error while fetching the network: %w", err)
}
networkID := syncService.getNetworkID(network)

if syncService.p2pServer, err = newP2PServer(syncService.p2p.Host(), syncService.store, networkID); err != nil {
return nil, fmt.Errorf("error while creating p2p server: %w", err)
}
Expand Down Expand Up @@ -446,10 +445,6 @@ func (syncService *SyncService[H]) getNetworkID(network string) string {
return network + "-" + string(syncService.syncType)
}

func (syncService *SyncService[H]) getChainID() string {
return syncService.genesis.ChainID + "-" + string(syncService.syncType)
}

func (syncService *SyncService[H]) getPeerIDs() []peer.ID {
peerIDs := syncService.p2p.PeerIDs()
if !syncService.conf.Node.Aggregator {
Expand Down
Loading