diff --git a/node/consensus/ceremony/broadcast_messaging.go b/node/consensus/ceremony/broadcast_messaging.go index 1d8c872..59e6e58 100644 --- a/node/consensus/ceremony/broadcast_messaging.go +++ b/node/consensus/ceremony/broadcast_messaging.go @@ -51,7 +51,7 @@ func (e *CeremonyDataClockConsensusEngine) handleMessage( msg, ) if err != nil { - e.logger.Error( + e.logger.Debug( "could not process message for engine", zap.Error(err), zap.String("engine_name", name), diff --git a/node/consensus/ceremony/consensus_frames.go b/node/consensus/ceremony/consensus_frames.go index f298ab2..8d00bc1 100644 --- a/node/consensus/ceremony/consensus_frames.go +++ b/node/consensus/ceremony/consensus_frames.go @@ -696,7 +696,10 @@ func (e *CeremonyDataClockConsensusEngine) commitLongestPath() ( e.logger.Info( "committing candidate", zap.Uint64("frame_number", s.FrameNumber), - zap.Binary("prover", s.GetPublicKeySignatureEd448().PublicKey.KeyValue), + zap.Binary( + "prover", + s.GetPublicKeySignatureEd448().PublicKey.KeyValue, + ), ) addr, err := s.GetAddress() diff --git a/node/consensus/ceremony/peer_messaging.go b/node/consensus/ceremony/peer_messaging.go index 707a6b0..5d53458 100644 --- a/node/consensus/ceremony/peer_messaging.go +++ b/node/consensus/ceremony/peer_messaging.go @@ -98,7 +98,7 @@ func (e *CeremonyDataClockConsensusEngine) handleClockFramesResponse( } if !bytes.Equal(peerID, e.syncingTarget) { - e.logger.Warn( + e.logger.Debug( "received clock frames response from unexpected target", zap.Binary("peer_id", peerID), zap.Binary("expected_peer_id", e.syncingTarget), diff --git a/node/p2p/blossomsub.go b/node/p2p/blossomsub.go index d547027..66486d3 100644 --- a/node/p2p/blossomsub.go +++ b/node/p2p/blossomsub.go @@ -76,7 +76,11 @@ func NewBlossomSub( logger.Info("established peer id", zap.String("peer_id", h.ID().String())) - go discoverPeers(p2pConfig, ctx, logger, h) + kademliaDHT := initDHT(ctx, p2pConfig, logger, h) + routingDiscovery := routing.NewRoutingDiscovery(kademliaDHT) + util.Advertise(ctx, routingDiscovery, string(BITMASK_ALL)) + + go discoverPeers(p2pConfig, ctx, logger, h, routingDiscovery) // TODO: turn into an option flag for console logging, this is too noisy for // default logging behavior @@ -319,43 +323,50 @@ func discoverPeers( ctx context.Context, logger *zap.Logger, h host.Host, + routingDiscovery *routing.RoutingDiscovery, ) { logger.Info("initiating peer discovery") - kademliaDHT := initDHT(ctx, p2pConfig, logger, h) - routingDiscovery := routing.NewRoutingDiscovery(kademliaDHT) - util.Advertise(ctx, routingDiscovery, string(BITMASK_ALL)) - - peerCount := 0 - for peerCount < p2pConfig.MinPeers { - peerChan, err := routingDiscovery.FindPeers(ctx, string(BITMASK_ALL)) - if err != nil { - panic(err) - } - - for peer := range peerChan { - if peer.ID == h.ID() { - continue + discover := func(peerCount int) { + for peerCount < p2pConfig.MinPeers { + peerChan, err := routingDiscovery.FindPeers(ctx, string(BITMASK_ALL)) + if err != nil { + logger.Error("could not find peers", zap.Error(err)) } - logger.Info("found peer", zap.String("peer_id", peer.ID.Pretty())) - err := h.Connect(ctx, peer) - if err != nil { - logger.Warn( - "error while connecting to blossomsub peer", - zap.String("peer_id", peer.ID.Pretty()), - zap.Error(err), - ) - } else { - logger.Info( - "connected to peer", - zap.String("peer_id", peer.ID.Pretty()), - ) - peerCount++ + for peer := range peerChan { + if peer.ID == h.ID() { + continue + } + + logger.Info("found peer", zap.String("peer_id", peer.ID.Pretty())) + err := h.Connect(ctx, peer) + if err != nil { + logger.Warn( + "error while connecting to blossomsub peer", + zap.String("peer_id", peer.ID.Pretty()), + zap.Error(err), + ) + } else { + logger.Info( + "connected to peer", + zap.String("peer_id", peer.ID.Pretty()), + ) + peerCount++ + } } } } + discover(0) + + go func() { + for { + time.Sleep(30 * time.Second) + discover(len(h.Network().Peers())) + } + }() + logger.Info("completed initial peer discovery") }