Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat_: hash based query for outgoing messages. #5217

Merged
merged 19 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/messenger_raw_message_resend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (s *MessengerRawMessageResendTest) TestMessageSent() {
rawMessage, err := s.bobMessenger.RawMessageByID(ids[0])
s.Require().NoError(err)
s.Require().NotNil(rawMessage)
if rawMessage.Sent {
if rawMessage.SendCount > 0 {
return nil
}
return errors.New("raw message should be sent finally")
Expand All @@ -232,7 +232,7 @@ func (s *MessengerRawMessageResendTest) TestMessageResend() {
rawMessage, err := s.bobMessenger.RawMessageByID(ids[0])
s.Require().NoError(err)
s.Require().NotNil(rawMessage)
if !rawMessage.Sent {
if rawMessage.SendCount < 2 {
return errors.New("message ApplicationMetadataMessage_COMMUNITY_REQUEST_TO_JOIN was not resent yet")
}
return nil
Expand Down
6 changes: 6 additions & 0 deletions eth-node/bridge/geth/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,9 @@ func GetWakuFilterFrom(f types.Filter) *wakucommon.Filter {
func (w *wakuFilterWrapper) ID() string {
return w.id
}

func (w *GethWakuWrapper) ConfirmMessageDelivered(hashes []common.Hash) {
}

func (w *GethWakuWrapper) SetStorePeerID(peerID peer.ID) {
}
8 changes: 8 additions & 0 deletions eth-node/bridge/geth/wakuv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,11 @@ func GetWakuV2FilterFrom(f types.Filter) *wakucommon.Filter {
func (w *wakuV2FilterWrapper) ID() string {
return w.id
}

func (w *gethWakuV2Wrapper) ConfirmMessageDelivered(hashes []common.Hash) {
w.waku.ConfirmMessageDelivered(hashes)
}

func (w *gethWakuV2Wrapper) SetStorePeerID(peerID peer.ID) {
w.waku.SetStorePeerID(peerID)
}
6 changes: 6 additions & 0 deletions eth-node/types/waku.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,10 @@ type Waku interface {

// ClearEnvelopesCache clears waku envelopes cache
ClearEnvelopesCache()

// ConfirmMessageDelivered updates a message has been delivered in waku
ConfirmMessageDelivered(hash []common.Hash)

// SetStorePeerID updates the peer id of store node
SetStorePeerID(peerID peer.ID)
}
5 changes: 5 additions & 0 deletions protocol/messenger_mailserver_cycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ func (m *Messenger) connectToMailserver(ms mailservers.Mailserver) error {
m.logger.Info("mailserver available", zap.String("address", m.mailserverCycle.activeMailserver.UniqueID()))
m.EmitMailserverAvailable()
signal.SendMailserverAvailable(m.mailserverCycle.activeMailserver.Address, m.mailserverCycle.activeMailserver.ID)
peerID, err := m.mailserverCycle.activeMailserver.PeerID()
if err != nil {
m.logger.Error("could not decode the peer id of mailserver", zap.Error(err))
}
m.transport.SetStorePeerID(peerID)

// Query mailserver
if m.config.codeControlFlags.AutoRequestHistoricMessages {
Expand Down
2 changes: 1 addition & 1 deletion protocol/messenger_messages_tracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (s *MessengerMessagesTrackingSuite) testMessageMarkedAsSent(textSize int) {
// Message should be marked as sent eventually
err = tt.RetryWithBackOff(func() error {
rawMessage, err = s.bob.persistence.RawMessageByID(inputMessage.ID)
if err != nil || !rawMessage.Sent {
if err != nil || rawMessage.SendCount < 1 {
osmaczko marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("message not marked as sent")
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion protocol/messenger_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (m *Messenger) AddStorePeer(address string) (peer.ID, error) {
}

func (m *Messenger) AddRelayPeer(address string) (peer.ID, error) {
return m.transport.AddStorePeer(address)
return m.transport.AddRelayPeer(address)
}

func (m *Messenger) DialPeer(address string) error {
Expand Down
2 changes: 2 additions & 0 deletions protocol/messenger_peersyncing.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func (m *Messenger) markDeliveredMessages(acks [][]byte) {
m.logger.Debug("Can't set message status as delivered", zap.Error(err))
}

m.transport.ConfirmMessageDelivered(messageID)

//send signal to client that message status updated
if m.config.messengerSignalsHandler != nil {
message, err := m.persistence.MessageByID(messageID)
Expand Down
6 changes: 3 additions & 3 deletions protocol/transport/envelopes_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (m *EnvelopesMonitor) Add(messageIDs [][]byte, envelopeHashes []types.Hash,
defer m.mu.Unlock()

for _, messageID := range messageIDs {
m.messageEnvelopeHashes[string(messageID)] = envelopeHashes
m.messageEnvelopeHashes[types.HexBytes(messageID).String()] = envelopeHashes
}

for i, envelopeHash := range envelopeHashes {
Expand Down Expand Up @@ -399,7 +399,7 @@ func (m *EnvelopesMonitor) processMessageIDs(messageIDs [][]byte) {
sentMessageIDs := make([][]byte, 0, len(messageIDs))

for _, messageID := range messageIDs {
hashes, ok := m.messageEnvelopeHashes[string(messageID)]
hashes, ok := m.messageEnvelopeHashes[types.HexBytes(messageID).String()]
if !ok {
continue
}
Expand Down Expand Up @@ -432,6 +432,6 @@ func (m *EnvelopesMonitor) clearMessageState(envelopeID types.Hash) {
}
delete(m.envelopes, envelopeID)
for _, messageID := range envelope.messageIDs {
delete(m.messageEnvelopeHashes, string(messageID))
delete(m.messageEnvelopeHashes, types.HexBytes(messageID).String())
}
}
19 changes: 19 additions & 0 deletions protocol/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,22 @@ func (t *Transport) RemovePubsubTopicKey(topic string) error {
}
return nil
}

func (t *Transport) ConfirmMessageDelivered(messageID string) {
if t.envelopesMonitor == nil {
return
}
hashes, ok := t.envelopesMonitor.messageEnvelopeHashes[messageID]
if !ok {
return
}
commHashes := make([]common.Hash, len(hashes))
for i, h := range hashes {
commHashes[i] = common.BytesToHash(h[:])
}
t.waku.ConfirmMessageDelivered(commHashes)
}

func (t *Transport) SetStorePeerID(peerID peer.ID) {
t.waku.SetStorePeerID(peerID)
}
3 changes: 2 additions & 1 deletion wakuv2/common/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type MessageType int
const (
RelayedMessageType MessageType = iota
StoreMessageType
SendMessageType
)

// MessageParams specifies the exact way a message should be wrapped
Expand All @@ -46,7 +47,7 @@ type ReceivedMessage struct {
Padding []byte
Signature []byte

Sent uint32 // Time when the message was posted into the network
Sent uint32 // Time when the message was posted into the network in seconds
Src *ecdsa.PublicKey // Message recipient (identity used to decode the message)
Dst *ecdsa.PublicKey // Message recipient (identity used to decode the message)

Expand Down
Loading