diff --git a/pkg/sync/sync_service.go b/pkg/sync/sync_service.go index 6a17a42a85..9b018460ed 100644 --- a/pkg/sync/sync_service.go +++ b/pkg/sync/sync_service.go @@ -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) + } + 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 { @@ -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) } @@ -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 {