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: add message ID field to more easily track message accross networks #26

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion relayer/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
4 changes: 3 additions & 1 deletion relayer/proposal/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
5 changes: 3 additions & 2 deletions relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
2 changes: 2 additions & 0 deletions relayer/relayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Loading