From 3d40e236b49d52ff1fd460494b050525c0043efa Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Fri, 19 Jul 2024 10:24:15 +0900 Subject: [PATCH] improve logging in RelayMsgs::Send Signed-off-by: Masanori Yoshida --- core/relayMsgs.go | 58 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/core/relayMsgs.go b/core/relayMsgs.go index 9081267f..d51a66b7 100644 --- a/core/relayMsgs.go +++ b/core/relayMsgs.go @@ -1,6 +1,8 @@ package core import ( + "encoding/json" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/gogoproto/proto" ) @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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...)