Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Check different errors on topic name (#119)
Browse files Browse the repository at this point in the history
cover against bad names on topic names (reputer , worker have different
schema names on b7s)
  • Loading branch information
xmariachi authored Apr 26, 2024
1 parent f6dc074 commit 64c2957
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/node/appchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion cmd/node/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 64c2957

Please sign in to comment.