From 64c29575c6cf9e3803f1648573566636463bebe9 Mon Sep 17 00:00:00 2001 From: Diego C Date: Fri, 26 Apr 2024 20:31:43 +0200 Subject: [PATCH] Check different errors on topic name (#119) cover against bad names on topic names (reputer , worker have different schema names on b7s) --- cmd/node/appchain.go | 1 + cmd/node/execute.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/node/appchain.go b/cmd/node/appchain.go index f88cef3..2661db5 100644 --- a/cmd/node/appchain.go +++ b/cmd/node/appchain.go @@ -36,6 +36,7 @@ const NUM_REGISTRATION_RETRY_MIN_DELAY = 1 const NUM_REGISTRATION_RETRY_MAX_DELAY = 2 const NUM_STAKING_RETRY_MIN_DELAY = 1 const NUM_STAKING_RETRY_MAX_DELAY = 2 +const REPUTER_TOPIC_SUFFIX = "/reputer" func getAlloraClient(config AppChainConfig) (*cosmosclient.Client, error) { // create a allora client instance diff --git a/cmd/node/execute.go b/cmd/node/execute.go index 8a5aced..7d348ce 100644 --- a/cmd/node/execute.go +++ b/cmd/node/execute.go @@ -60,8 +60,20 @@ func sendResultsToChain(log zerolog.Logger, appChainClient *AppChain, res node.C } appChainClient.SendWorkerModeData(reqCtx, topicId, aggregate.Aggregate(res.Data)) } else { // for losses + // if topicId does not end in "/reputer + + if !strings.HasSuffix(res.Topic, REPUTER_TOPIC_SUFFIX) { + log.Error().Str("Topic", res.Topic).Str("worker mode", appChainClient.Config.WorkerMode).Msg("Invalid reputer topic format") + return + } // Get the topicId from the reputer topic string - topicId, err := strconv.ParseUint(res.Topic[:strings.Index(res.Topic, "/")], 10, 64) + index := strings.Index(res.Topic, "/") + if index == -1 { + // Handle the error: "/" not found in res.Topic + log.Error().Str("Topic", res.Topic).Msg("Invalid topic format") + return + } + topicId, err := strconv.ParseUint(res.Topic[:index], 10, 64) if err != nil { log.Error().Str("Topic", res.Topic).Str("worker mode", appChainClient.Config.WorkerMode).Err(err).Msg("Cannot parse reputer topic ID") return