From d17cbbb29e635676f83c962e5a364b7c447b2975 Mon Sep 17 00:00:00 2001
From: mpetrun5 <matija.petrunic@gmail.com>
Date: Wed, 10 Apr 2024 15:10:54 +0200
Subject: [PATCH 1/5] feat: add message ID field to more easily track message
 accross networks

---
 relayer/message/message.go   | 4 +++-
 relayer/proposal/proposal.go | 4 +++-
 relayer/relayer.go           | 5 +++--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/relayer/message/message.go b/relayer/message/message.go
index 4d0ffd9f..1859c247 100644
--- a/relayer/message/message.go
+++ b/relayer/message/message.go
@@ -5,14 +5,16 @@ type Message struct {
 	Source      uint8       // Source where message was initiated
 	Destination uint8       // Destination chain of message
 	Data        interface{} // Data associated with the message
+	ID          string      // ID is used to track and identify message across networks
 	Type        MessageType // Message type
 }
 
-func NewMessage(source, destination uint8, data interface{}, msgType MessageType) *Message {
+func NewMessage(source, destination uint8, data interface{}, id string, msgType MessageType) *Message {
 	return &Message{
 		Source:      source,
 		Destination: destination,
 		Data:        data,
 		Type:        msgType,
+		ID:          id,
 	}
 }
diff --git a/relayer/proposal/proposal.go b/relayer/proposal/proposal.go
index 456d5ea8..fc82d9a0 100644
--- a/relayer/proposal/proposal.go
+++ b/relayer/proposal/proposal.go
@@ -6,13 +6,15 @@ type Proposal struct {
 	Destination uint8
 	Data        interface{}
 	Type        ProposalType
+	MessageID   string // MessageID identifies the message that created the proposal
 }
 
-func NewProposal(source uint8, destination uint8, data interface{}, propType ProposalType) *Proposal {
+func NewProposal(source uint8, destination uint8, data interface{}, messageID string, propType ProposalType) *Proposal {
 	return &Proposal{
 		Source:      source,
 		Destination: destination,
 		Data:        data,
 		Type:        propType,
+		MessageID:   messageID,
 	}
 }
diff --git a/relayer/relayer.go b/relayer/relayer.go
index 6f6a10f6..948250c1 100644
--- a/relayer/relayer.go
+++ b/relayer/relayer.go
@@ -61,11 +61,12 @@ func (r *Relayer) route(msgs []*message.Message) {
 		return
 	}
 
+	log := log.With().Uint8("domainID", destChain.DomainID()).Str("messageID", msgs[0].ID).Logger()
 	props := make([]*proposal.Proposal, 0)
 	for _, m := range msgs {
 		prop, err := destChain.ReceiveMessage(m)
 		if err != nil {
-			log.Err(err).Uint8("domainID", destChain.DomainID()).Msgf("Failed receiving message %+v", m)
+			log.Err(err).Msgf("Failed receiving message %+v", m)
 			continue
 		}
 		if prop != nil {
@@ -78,7 +79,7 @@ func (r *Relayer) route(msgs []*message.Message) {
 
 	err := destChain.Write(props)
 	if err != nil {
-		log.Err(err).Uint8("domainID", destChain.DomainID()).Msgf("Failed writing message")
+		log.Err(err).Msgf("Failed writing message")
 		return
 	}
 }

From 4d91e15876b084d7ccc091974b1fdce2f99c5961 Mon Sep 17 00:00:00 2001
From: mpetrun5 <matija.petrunic@gmail.com>
Date: Wed, 10 Apr 2024 15:12:31 +0200
Subject: [PATCH 2/5] Update codeowners

---
 .github/CODEOWNERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index a0a5ea96..2aed5bc8 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -1,4 +1,4 @@
 # CODEOWNERS: https://help.github.com/articles/about-codeowners/
 
 # Primary repo maintainers
-*       @P1sar @waymobetta @mpetrun5 @tcar121293 @MakMuftic @nmlinaric @vezenovm
+*     @mpetrun5 @tcar121293 @MakMuftic @nmlinaric 

From 5986311a78d9c8a90127c7636f55efab8c25d8e8 Mon Sep 17 00:00:00 2001
From: mpetrun5 <matija.petrunic@gmail.com>
Date: Wed, 10 Apr 2024 15:19:32 +0200
Subject: [PATCH 3/5] Fix tests

---
 relayer/relayer_test.go | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/relayer/relayer_test.go b/relayer/relayer_test.go
index ec8ab3ea..aab60835 100644
--- a/relayer/relayer_test.go
+++ b/relayer/relayer_test.go
@@ -70,6 +70,7 @@ func (s *RouteTestSuite) TestReceiveMessageFails() {
 
 func (s *RouteTestSuite) TestAvoidWriteWithoutProposals() {
 	s.mockRelayedChain.EXPECT().ReceiveMessage(gomock.Any()).Return(nil, nil)
+	s.mockRelayedChain.EXPECT().DomainID().Return(uint8(1))
 	chains := make(map[uint8]RelayedChain)
 	chains[1] = s.mockRelayedChain
 	relayer := NewRelayer(
@@ -105,6 +106,7 @@ func (s *RouteTestSuite) TestWritesToChain() {
 	props[0] = prop
 	s.mockRelayedChain.EXPECT().ReceiveMessage(gomock.Any()).Return(prop, nil)
 	s.mockRelayedChain.EXPECT().Write(props).Return(nil)
+	s.mockRelayedChain.EXPECT().DomainID().Return(uint8(1)).Times(1)
 	chains := make(map[uint8]RelayedChain)
 	chains[1] = s.mockRelayedChain
 	relayer := NewRelayer(

From 3dffe94ea64378679e748fe9989111c7dcfb6e44 Mon Sep 17 00:00:00 2001
From: mpetrun5 <matija.petrunic@gmail.com>
Date: Thu, 11 Apr 2024 13:28:50 +0200
Subject: [PATCH 4/5] Add additional messageID logs

---
 chains/evm/chain.go       | 2 +-
 chains/substrate/chain.go | 2 +-
 relayer/relayer.go        | 7 +++++++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/chains/evm/chain.go b/chains/evm/chain.go
index 3ff9e143..a09ea060 100644
--- a/chains/evm/chain.go
+++ b/chains/evm/chain.go
@@ -62,7 +62,7 @@ func (c *EVMChain) ReceiveMessage(m *message.Message) (*proposal.Proposal, error
 func (c *EVMChain) Write(props []*proposal.Proposal) error {
 	err := c.executor.Execute(props)
 	if err != nil {
-		c.logger.Err(err).Msgf("error writing proposals %+v on network %d", props, c.DomainID())
+		c.logger.Err(err).Str("messageID", props[0].MessageID).Msgf("error writing proposals %+v on network %d", props, c.DomainID())
 		return err
 	}
 
diff --git a/chains/substrate/chain.go b/chains/substrate/chain.go
index 09c80c67..9c72f922 100644
--- a/chains/substrate/chain.go
+++ b/chains/substrate/chain.go
@@ -57,7 +57,7 @@ func (c *SubstrateChain) ReceiveMessage(m *message.Message) (*proposal.Proposal,
 func (c *SubstrateChain) Write(props []*proposal.Proposal) error {
 	err := c.executor.Execute(props)
 	if err != nil {
-		c.logger.Err(err).Msgf("error writing proposals %+v on network %d", props, c.DomainID())
+		c.logger.Err(err).Str("messageID", props[0].MessageID).Msgf("error writing proposals %+v on network %d", props, c.DomainID())
 		return err
 	}
 
diff --git a/relayer/relayer.go b/relayer/relayer.go
index 948250c1..e925b118 100644
--- a/relayer/relayer.go
+++ b/relayer/relayer.go
@@ -64,11 +64,16 @@ func (r *Relayer) route(msgs []*message.Message) {
 	log := log.With().Uint8("domainID", destChain.DomainID()).Str("messageID", msgs[0].ID).Logger()
 	props := make([]*proposal.Proposal, 0)
 	for _, m := range msgs {
+		log.Debug().Msgf("Sending message to chain: %d", destChain.DomainID())
+
 		prop, err := destChain.ReceiveMessage(m)
 		if err != nil {
 			log.Err(err).Msgf("Failed receiving message %+v", m)
 			continue
 		}
+
+		log.Debug().Msgf("Received message on chain: %d", destChain.DomainID())
+
 		if prop != nil {
 			props = append(props, prop)
 		}
@@ -77,6 +82,8 @@ func (r *Relayer) route(msgs []*message.Message) {
 		return
 	}
 
+	log.Debug().Msgf("Writing message on chain: %d", destChain.DomainID())
+
 	err := destChain.Write(props)
 	if err != nil {
 		log.Err(err).Msgf("Failed writing message")

From c88573fad3a60569fd7ad6947a33e01124f72a61 Mon Sep 17 00:00:00 2001
From: mpetrun5 <matija.petrunic@gmail.com>
Date: Thu, 11 Apr 2024 13:38:51 +0200
Subject: [PATCH 5/5] Fix tests

---
 relayer/relayer.go | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/relayer/relayer.go b/relayer/relayer.go
index e925b118..634a7c5d 100644
--- a/relayer/relayer.go
+++ b/relayer/relayer.go
@@ -64,7 +64,7 @@ func (r *Relayer) route(msgs []*message.Message) {
 	log := log.With().Uint8("domainID", destChain.DomainID()).Str("messageID", msgs[0].ID).Logger()
 	props := make([]*proposal.Proposal, 0)
 	for _, m := range msgs {
-		log.Debug().Msgf("Sending message to chain: %d", destChain.DomainID())
+		log.Debug().Msgf("Sending message")
 
 		prop, err := destChain.ReceiveMessage(m)
 		if err != nil {
@@ -72,7 +72,7 @@ func (r *Relayer) route(msgs []*message.Message) {
 			continue
 		}
 
-		log.Debug().Msgf("Received message on chain: %d", destChain.DomainID())
+		log.Debug().Msgf("Received message")
 
 		if prop != nil {
 			props = append(props, prop)
@@ -82,8 +82,7 @@ func (r *Relayer) route(msgs []*message.Message) {
 		return
 	}
 
-	log.Debug().Msgf("Writing message on chain: %d", destChain.DomainID())
-
+	log.Debug().Msgf("Writing message")
 	err := destChain.Write(props)
 	if err != nil {
 		log.Err(err).Msgf("Failed writing message")