mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-11-10 18:25:17 +00:00
QOL: improve peer connectivity
This commit is contained in:
parent
d74b267f1e
commit
f0a90f6913
@ -51,7 +51,7 @@ func (e *CeremonyDataClockConsensusEngine) handleMessage(
|
|||||||
msg,
|
msg,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.logger.Error(
|
e.logger.Debug(
|
||||||
"could not process message for engine",
|
"could not process message for engine",
|
||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
zap.String("engine_name", name),
|
zap.String("engine_name", name),
|
||||||
|
@ -696,7 +696,10 @@ func (e *CeremonyDataClockConsensusEngine) commitLongestPath() (
|
|||||||
e.logger.Info(
|
e.logger.Info(
|
||||||
"committing candidate",
|
"committing candidate",
|
||||||
zap.Uint64("frame_number", s.FrameNumber),
|
zap.Uint64("frame_number", s.FrameNumber),
|
||||||
zap.Binary("prover", s.GetPublicKeySignatureEd448().PublicKey.KeyValue),
|
zap.Binary(
|
||||||
|
"prover",
|
||||||
|
s.GetPublicKeySignatureEd448().PublicKey.KeyValue,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
addr, err := s.GetAddress()
|
addr, err := s.GetAddress()
|
||||||
|
@ -98,7 +98,7 @@ func (e *CeremonyDataClockConsensusEngine) handleClockFramesResponse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(peerID, e.syncingTarget) {
|
if !bytes.Equal(peerID, e.syncingTarget) {
|
||||||
e.logger.Warn(
|
e.logger.Debug(
|
||||||
"received clock frames response from unexpected target",
|
"received clock frames response from unexpected target",
|
||||||
zap.Binary("peer_id", peerID),
|
zap.Binary("peer_id", peerID),
|
||||||
zap.Binary("expected_peer_id", e.syncingTarget),
|
zap.Binary("expected_peer_id", e.syncingTarget),
|
||||||
|
@ -76,7 +76,11 @@ func NewBlossomSub(
|
|||||||
|
|
||||||
logger.Info("established peer id", zap.String("peer_id", h.ID().String()))
|
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
|
// TODO: turn into an option flag for console logging, this is too noisy for
|
||||||
// default logging behavior
|
// default logging behavior
|
||||||
@ -319,43 +323,50 @@ func discoverPeers(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
logger *zap.Logger,
|
logger *zap.Logger,
|
||||||
h host.Host,
|
h host.Host,
|
||||||
|
routingDiscovery *routing.RoutingDiscovery,
|
||||||
) {
|
) {
|
||||||
logger.Info("initiating peer discovery")
|
logger.Info("initiating peer discovery")
|
||||||
|
|
||||||
kademliaDHT := initDHT(ctx, p2pConfig, logger, h)
|
discover := func(peerCount int) {
|
||||||
routingDiscovery := routing.NewRoutingDiscovery(kademliaDHT)
|
for peerCount < p2pConfig.MinPeers {
|
||||||
util.Advertise(ctx, routingDiscovery, string(BITMASK_ALL))
|
peerChan, err := routingDiscovery.FindPeers(ctx, string(BITMASK_ALL))
|
||||||
|
if err != nil {
|
||||||
peerCount := 0
|
logger.Error("could not find peers", zap.Error(err))
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("found peer", zap.String("peer_id", peer.ID.Pretty()))
|
for peer := range peerChan {
|
||||||
err := h.Connect(ctx, peer)
|
if peer.ID == h.ID() {
|
||||||
if err != nil {
|
continue
|
||||||
logger.Warn(
|
}
|
||||||
"error while connecting to blossomsub peer",
|
|
||||||
zap.String("peer_id", peer.ID.Pretty()),
|
logger.Info("found peer", zap.String("peer_id", peer.ID.Pretty()))
|
||||||
zap.Error(err),
|
err := h.Connect(ctx, peer)
|
||||||
)
|
if err != nil {
|
||||||
} else {
|
logger.Warn(
|
||||||
logger.Info(
|
"error while connecting to blossomsub peer",
|
||||||
"connected to peer",
|
zap.String("peer_id", peer.ID.Pretty()),
|
||||||
zap.String("peer_id", peer.ID.Pretty()),
|
zap.Error(err),
|
||||||
)
|
)
|
||||||
peerCount++
|
} 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")
|
logger.Info("completed initial peer discovery")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user