Skip to content

Commit

Permalink
chore_: remove sent message cache when query success
Browse files Browse the repository at this point in the history
  • Loading branch information
kaichaosun committed May 24, 2024
1 parent 1d2a81a commit 79399ce
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions wakuv2/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,12 +1033,6 @@ func (w *Waku) checkIfMessagesStored() {
// message is sent 5 seconds ago, check if it's stored
if uint32(w.timesource.Now().Unix()) > sendTime+5 {
queryMsgIds = append(queryMsgIds, msgID)
delete(subMsgs, msgID)
if len(subMsgs) == 0 {
delete(w.sendMsgIDs, pubsubTopic)
} else {
w.sendMsgIDs[pubsubTopic] = subMsgs
}
}
}
w.logger.Debug("Store query for message hashes", zap.Any("queryMsgIds", queryMsgIds), zap.String("pubsubTopic", pubsubTopic))
Expand Down Expand Up @@ -1148,6 +1142,14 @@ func (w *Waku) messageHashBasedQuery(ctx context.Context, hashes []gethcommon.Ha
} else {
missedHashes = append(missedHashes, hash)
}

subMsgs := w.sendMsgIDs[pubsubTopic]
delete(subMsgs, hash)
if len(subMsgs) == 0 {
delete(w.sendMsgIDs, pubsubTopic)
} else {
w.sendMsgIDs[pubsubTopic] = subMsgs
}
}

w.logger.Debug("Ack message hashes", zap.Any("ackHashes", ackHashes))
Expand Down Expand Up @@ -1559,7 +1561,10 @@ func (w *Waku) processReceivedMessage(e *common.ReceivedMessage) {

if e.MsgType == common.SendMessageType && !(*e.Envelope.Message().Ephemeral) {
w.sendMsgIDsMu.Lock()
subMsgs := w.sendMsgIDs[e.PubsubTopic]
subMsgs, ok := w.sendMsgIDs[e.PubsubTopic]
if !ok {
subMsgs = make(map[gethcommon.Hash]uint32)
}
subMsgs[e.Hash()] = e.Sent
w.sendMsgIDs[e.PubsubTopic] = subMsgs
w.sendMsgIDsMu.Unlock()
Expand Down

0 comments on commit 79399ce

Please sign in to comment.