QOL: improve peer connectivity

This commit is contained in:
Cassandra Heart 2023-09-30 02:02:15 -05:00
parent d74b267f1e
commit f0a90f6913
No known key found for this signature in database
GPG Key ID: 6352152859385958
4 changed files with 46 additions and 32 deletions

View File

@ -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),

View File

@ -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()

View File

@ -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),

View File

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