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