From 3eefb74bfb4e4b34b89dcbc33e059cbf3ff566d0 Mon Sep 17 00:00:00 2001 From: Paul Noel Date: Mon, 1 May 2023 18:57:23 +0000 Subject: [PATCH] node/pkg/watcher: watcher audit change --- node/pkg/watchers/sui/watcher.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/node/pkg/watchers/sui/watcher.go b/node/pkg/watchers/sui/watcher.go index c3c253009..6b0f6d528 100644 --- a/node/pkg/watchers/sui/watcher.go +++ b/node/pkg/watchers/sui/watcher.go @@ -87,6 +87,15 @@ type ( } `json:"params"` } + SuiTxnQueryError struct { + Jsonrpc string `json:"jsonrpc"` + Error struct { + Code int `json:"code"` + Message *string `json:"message"` + } `json:"error"` + ID int `json:"id"` + } + SuiTxnQuery struct { Jsonrpc string `json:"jsonrpc"` Result []SuiResult `json:"result"` @@ -419,7 +428,6 @@ func (e *Watcher) Run(ctx context.Context) error { tx58 := base58.Encode(r.TxHash) buf := fmt.Sprintf(`{"jsonrpc":"2.0", "id": 1, "method": "sui_getEvents", "params": ["%s"]}`, tx58) - logger.Error(buf) resp, err := http.Post(e.suiRPC, "application/json", strings.NewReader(buf)) if err != nil { @@ -439,8 +447,19 @@ func (e *Watcher) Run(ctx context.Context) error { logger.Debug("receive", zap.String("body", string(body))) - if strings.Contains(string(body), "error") { - logger.Error("Failed to get events for re-observation request", zap.String("Result", string(body))) + // Do we have an error? + var err_res SuiTxnQueryError + err = json.Unmarshal(body, &err_res) + if err != nil { + logger.Error("Failed to unmarshal event error message", zap.String("Result", string(body))) + p2p.DefaultRegistry.AddErrorCount(vaa.ChainIDSui, 1) + return err + } + + if err_res.Error.Message != nil { + logger.Error("Failed to get events for re-observation request, detected error", zap.String("Result", string(body))) + p2p.DefaultRegistry.AddErrorCount(vaa.ChainIDSui, 1) + // Don't need to kill the watcher on this error. So, just continue. continue } var res SuiTxnQuery