Skip to content

Commit d305d7f

Browse files
committed
chore_: more logs
1 parent 34e04eb commit d305d7f

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

wakuv2/waku.go

+36-27
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ type Waku struct {
131131
sendMsgIDs map[string]map[gethcommon.Hash]uint32
132132
sendMsgIDsMu sync.RWMutex
133133

134+
storePeerID peer.ID
135+
134136
topicHealthStatusChan chan peermanager.TopicHealthStatus
135137
connStatusSubscriptions map[string]*types.ConnStatusSubscription
136138
connStatusMu sync.Mutex
@@ -993,6 +995,9 @@ func (w *Waku) checkIfMessagesStored() {
993995
for pubsubTopic, subMsgs := range w.sendMsgIDs {
994996
var queryMsgIds []gethcommon.Hash
995997
for msgID, sendTime := range subMsgs {
998+
if len(queryMsgIds) >= 20 {
999+
break
1000+
}
9961001
// message is sent 5 seconds ago, check if it's stored
9971002
if uint32(w.timesource.Now().Unix()) > sendTime+5 {
9981003
queryMsgIds = append(queryMsgIds, msgID)
@@ -1061,35 +1066,43 @@ func (w *Waku) Send(pubsubTopic string, msg *pb.WakuMessage) ([]byte, error) {
10611066

10621067
// ctx, peer, r.PubsubTopic, contentTopics, uint64(r.From), uint64(r.To), options, processEnvelopes
10631068
func (w *Waku) messageHashBasedQuery(ctx context.Context, hashes []gethcommon.Hash, pubsubTopic string) {
1064-
selectedPeers, err := w.node.PeerManager().SelectPeers(
1065-
peermanager.PeerSelectionCriteria{
1066-
SelectionType: peermanager.Automatic,
1067-
Proto: store.StoreQueryID_v300,
1068-
PubsubTopics: []string{pubsubTopic},
1069-
Ctx: ctx,
1070-
},
1071-
)
1072-
if err != nil {
1073-
w.logger.Warn("could not select peers", zap.Error(err))
1074-
return
1069+
selectedPeer := w.storePeerID
1070+
if selectedPeer == "" {
1071+
selectedPeers, err := w.node.PeerManager().SelectPeers(
1072+
peermanager.PeerSelectionCriteria{
1073+
SelectionType: peermanager.Automatic,
1074+
Proto: store.StoreQueryID_v300,
1075+
PubsubTopics: []string{pubsubTopic},
1076+
Ctx: ctx,
1077+
},
1078+
)
1079+
if err != nil {
1080+
w.logger.Error("could not select peers", zap.Error(err))
1081+
return
1082+
}
1083+
selectedPeer = selectedPeers[0]
10751084
}
10761085

10771086
var opts []store.RequestOption
10781087
requestID := protocol.GenerateRequestID()
10791088
opts = append(opts, store.WithRequestID(requestID))
1080-
opts = append(opts, store.WithPeer(selectedPeers[0]))
1089+
opts = append(opts, store.WithPeer(selectedPeer))
10811090

10821091
messageHashes := make([]pb.MessageHash, len(hashes))
10831092
for i, hash := range hashes {
10841093
messageHashes[i] = pb.ToMessageHash(hash.Bytes())
10851094
}
10861095

1096+
w.logger.Debug("store.queryByHash request", zap.String("requestID", hexutil.Encode(requestID)), zap.String("peerID", selectedPeer.String()), zap.Any("messageHashes", messageHashes))
1097+
10871098
result, err := w.node.Store().QueryByHash(ctx, messageHashes, opts...)
10881099
if err != nil {
1089-
w.logger.Warn("store.queryByHash failed", zap.String("requestID", hexutil.Encode(requestID)), zap.Error(err))
1100+
w.logger.Error("store.queryByHash failed", zap.String("requestID", hexutil.Encode(requestID)), zap.String("peerID", selectedPeer.String()), zap.Error(err))
10901101
return
10911102
}
10921103

1104+
w.logger.Debug("store.queryByHash result", zap.String("requestID", hexutil.Encode(requestID)), zap.Int("messages", len(result.Messages())))
1105+
10931106
var ackHashes []gethcommon.Hash
10941107
var missedHashes []gethcommon.Hash
10951108
for _, hash := range hashes {
@@ -1100,10 +1113,19 @@ func (w *Waku) messageHashBasedQuery(ctx context.Context, hashes []gethcommon.Ha
11001113
break
11011114
}
11021115
}
1116+
11031117
if found {
11041118
ackHashes = append(ackHashes, hash)
1119+
w.SendEnvelopeEvent(common.EnvelopeEvent{
1120+
Hash: hash,
1121+
Event: common.EventEnvelopeSent,
1122+
})
11051123
} else {
11061124
missedHashes = append(missedHashes, hash)
1125+
w.SendEnvelopeEvent(common.EnvelopeEvent{
1126+
Hash: hash,
1127+
Event: common.EventEnvelopeExpired,
1128+
})
11071129
}
11081130

11091131
subMsgs := w.sendMsgIDs[pubsubTopic]
@@ -1117,20 +1139,6 @@ func (w *Waku) messageHashBasedQuery(ctx context.Context, hashes []gethcommon.Ha
11171139

11181140
w.logger.Debug("Ack message hashes", zap.Any("ackHashes", ackHashes))
11191141
w.logger.Debug("Missed message hashes", zap.Any("missedHashes", missedHashes))
1120-
1121-
for _, hash := range ackHashes {
1122-
w.SendEnvelopeEvent(common.EnvelopeEvent{
1123-
Hash: hash,
1124-
Event: common.EventEnvelopeSent,
1125-
})
1126-
}
1127-
1128-
for _, hash := range missedHashes {
1129-
w.SendEnvelopeEvent(common.EnvelopeEvent{
1130-
Hash: hash,
1131-
Event: common.EventEnvelopeExpired,
1132-
})
1133-
}
11341142
}
11351143

11361144
func (w *Waku) query(ctx context.Context, peerID peer.ID, pubsubTopic string, topics []common.TopicType, from uint64, to uint64, requestID []byte, opts []legacy_store.HistoryRequestOption) (*legacy_store.Result, error) {
@@ -1165,6 +1173,7 @@ func (w *Waku) query(ctx context.Context, peerID peer.ID, pubsubTopic string, to
11651173
}
11661174

11671175
func (w *Waku) Query(ctx context.Context, peerID peer.ID, pubsubTopic string, topics []common.TopicType, from uint64, to uint64, opts []legacy_store.HistoryRequestOption, processEnvelopes bool) (cursor *storepb.Index, envelopesCount int, err error) {
1176+
w.storePeerID = peerID
11681177
requestID := protocol.GenerateRequestID()
11691178
pubsubTopic = w.getPubsubTopic(pubsubTopic)
11701179

0 commit comments

Comments
 (0)