diff --git a/protocol/messenger.go b/protocol/messenger.go index 29b49a734..e759df962 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -178,6 +178,9 @@ type Messenger struct { // used to track dispatched messages dispatchMessageTestCallback func(common.RawMessage) + // used to track unhandled messages + unhandledMessagesTracker func(*v1protocol.StatusMessage, error) + peersyncing *peersyncing.PeerSyncing peersyncingOffers map[string]uint64 peersyncingRequests map[string]uint64 @@ -3836,6 +3839,9 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte if err != nil { allMessagesProcessed = false logger.Warn("failed to process protobuf", zap.Error(err)) + if m.unhandledMessagesTracker != nil { + m.unhandledMessagesTracker(msg, err) + } continue } logger.Debug("Handled parsed message") diff --git a/protocol/messenger_builder_test.go b/protocol/messenger_builder_test.go index 570628ee2..4a476d655 100644 --- a/protocol/messenger_builder_test.go +++ b/protocol/messenger_builder_test.go @@ -12,7 +12,9 @@ import ( "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/multiaccounts" + "github.com/status-im/status-go/protocol/protobuf" "github.com/status-im/status-go/protocol/tt" + v1protocol "github.com/status-im/status-go/protocol/v1" "github.com/status-im/status-go/t/helpers" "github.com/status-im/status-go/walletdatabase" ) @@ -21,6 +23,8 @@ type testMessengerConfig struct { name string privateKey *ecdsa.PrivateKey logger *zap.Logger + + unhandledMessagesTracker *unhandledMessagesTracker } func (tmc *testMessengerConfig) complete() error { @@ -90,6 +94,10 @@ func newTestMessenger(waku types.Waku, config testMessengerConfig, extraOptions return nil, err } + if config.unhandledMessagesTracker != nil { + m.unhandledMessagesTracker = config.unhandledMessagesTracker.addMessage + } + err = m.Init() if err != nil { return nil, err @@ -97,3 +105,26 @@ func newTestMessenger(waku types.Waku, config testMessengerConfig, extraOptions return m, nil } + +type unhandedMessage struct { + *v1protocol.StatusMessage + err error +} + +type unhandledMessagesTracker struct { + messages map[protobuf.ApplicationMetadataMessage_Type][]*unhandedMessage +} + +func (u *unhandledMessagesTracker) addMessage(msg *v1protocol.StatusMessage, err error) { + msgType := msg.ApplicationLayer.Type + + if _, exists := u.messages[msgType]; !exists { + u.messages[msgType] = []*unhandedMessage{} + } + + newMessage := &unhandedMessage{ + StatusMessage: msg, + err: err, + } + u.messages[msgType] = append(u.messages[msgType], newMessage) +}