Skip to content

Commit

Permalink
improve logging in RelayMsgs::Send
Browse files Browse the repository at this point in the history
Signed-off-by: Masanori Yoshida <[email protected]>
  • Loading branch information
siburu committed Jul 19, 2024
1 parent 291e808 commit 3d40e23
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions core/relayMsgs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package core

import (
"encoding/json"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"
)
Expand Down Expand Up @@ -69,10 +71,19 @@ func (r *RelayMsgs) Send(src, dst Chain) {
txSize += uint64(len(bz))

if r.IsMaxTx(msgLen, txSize) {
logger := logger.With()
if jsonMsgs, err := msgsToJSON(msgs); err != nil {
logger.Error("failed to marshal msgs to JSON", err)
} else {
logger = logger.With("msgs", jsonMsgs)
}

// Submit the transactions to src chain and update its status
msgIDs, err := src.SendMsgs(msgs)
if err != nil {
logger.Error("failed to send msgs", err, "msgs", msgs)
logger.Error("failed to send msgs", err)
} else {
logger.Info("successfully sent msgs", "side", "src")
}
r.Succeeded = r.Succeeded && (err == nil)
if err == nil {
Expand All @@ -90,9 +101,18 @@ func (r *RelayMsgs) Send(src, dst Chain) {

// submit leftover msgs
if len(msgs) > 0 {
logger := logger.With()
if jsonMsgs, err := msgsToJSON(msgs); err != nil {
logger.Error("failed to marshal msgs to JSON", err)
} else {
logger = logger.With("msgs", jsonMsgs)
}

msgIDs, err := src.SendMsgs(msgs)
if err != nil {
logger.Error("failed to send msgs", err, "msgs", msgs)
logger.Error("failed to send msgs", err)
} else {
logger.Info("successfully sent msgs", "side", "src")
}
r.Succeeded = r.Succeeded && (err == nil)
if err == nil {
Expand All @@ -118,10 +138,19 @@ func (r *RelayMsgs) Send(src, dst Chain) {
txSize += uint64(len(bz))

if r.IsMaxTx(msgLen, txSize) {
logger := logger.With()
if jsonMsgs, err := msgsToJSON(msgs); err != nil {
logger.Error("failed to marshal msgs to JSON", err)
} else {
logger = logger.With("msgs", jsonMsgs)
}

// Submit the transaction to dst chain and update its status
msgIDs, err := dst.SendMsgs(msgs)
if err != nil {
logger.Error("failed to send msgs", err, "msgs", msgs)
logger.Error("failed to send msgs", err)
} else {
logger.Info("successfully sent msgs", "side", "dst")
}
r.Succeeded = r.Succeeded && (err == nil)
if err == nil {
Expand All @@ -139,9 +168,18 @@ func (r *RelayMsgs) Send(src, dst Chain) {

// submit leftover msgs
if len(msgs) > 0 {
logger := logger.With()
if jsonMsgs, err := msgsToJSON(msgs); err != nil {
logger.Error("failed to marshal msgs to JSON", err)
} else {
logger = logger.With("msgs", jsonMsgs)
}

msgIDs, err := dst.SendMsgs(msgs)
if err != nil {
logger.Error("failed to send msgs", err, "msgs", msgs)
logger.Error("failed to send msgs", err)
} else {
logger.Info("successfully sent msgs", "side", "dst")
}
r.Succeeded = r.Succeeded && (err == nil)
if err == nil {
Expand All @@ -154,6 +192,18 @@ func (r *RelayMsgs) Send(src, dst Chain) {
r.DstMsgIDs = dstMsgIDs
}

func msgsToJSON(msgs []sdk.Msg) ([]string, error) {
var jsons []string
for _, msg := range msgs {
if bz, err := json.Marshal(msg); err != nil {
return nil, err
} else {
jsons = append(jsons, string(bz))
}
}
return jsons, nil
}

// Merge merges the argument into the receiver
func (r *RelayMsgs) Merge(other *RelayMsgs) {
r.Src = append(r.Src, other.Src...)
Expand Down

0 comments on commit 3d40e23

Please sign in to comment.