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

Commit

Permalink
Update b7s topic id (#133)
Browse files Browse the repository at this point in the history
Update our b7s topic Id format as `allora-topic-{num}` so identify our
subgroups of workers/reputers
  • Loading branch information
RedBird96 authored Jun 26, 2024
1 parent ed08de4 commit 9630a7d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
50 changes: 26 additions & 24 deletions cmd/node/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/rs/zerolog"
)

const B7S_TOPIC_FORMAT_PREFIX = "allora-topic-"

// ExecuteRequest describes the payload for the REST API request for function execution.
type ExecuteRequest struct {
execute.Request
Expand Down Expand Up @@ -51,32 +53,21 @@ func sendResultsToChain(log zerolog.Logger, appChainClient *AppChain, res node.C
log.Debug().Str("Topic", res.Topic).Str("worker mode", appChainClient.Config.WorkerMode).Msg("Found topic ID")

reqCtx := context.Background()
numTopicId := "0"
// remove prffix and suffix from "allora-topic-{xxx}-reputer/worker"
if strings.Contains(res.Topic, "reputer") {
numTopicId = res.Topic[len(B7S_TOPIC_FORMAT_PREFIX) : len(res.Topic)-len(WorkerModeReputer)-1]
} else {
numTopicId = res.Topic[len(B7S_TOPIC_FORMAT_PREFIX) : len(res.Topic)-len(WorkerModeWorker)-1]
}
topicId, err := strconv.ParseUint(numTopicId, 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
}
if appChainClient.Config.WorkerMode == WorkerModeWorker { // for inference or forecast
topicId, err := strconv.ParseUint(res.Topic, 10, 64)
if err != nil {
log.Error().Str("Topic", res.Topic).Str("worker mode", appChainClient.Config.WorkerMode).Err(err).Msg("Cannot parse worker topic ID")
return
}
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
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
}
appChainClient.SendReputerModeData(reqCtx, topicId, aggregate.Aggregate(res.Data))
}
}
Expand All @@ -101,7 +92,7 @@ func createExecutor(a api.API) func(ctx echo.Context) error {
})

// Get the execution result.
code, id, results, cluster, err := a.Node.ExecuteFunction(ctx.Request().Context(), execute.Request(req.Request), req.Topic)
code, id, results, cluster, err := a.Node.ExecuteFunction(ctx.Request().Context(), execute.Request(req.Request), buildb7sTopic(req.Topic))
if err != nil {
a.Log.Warn().Str("function", req.FunctionID).Err(err).Msg("node failed to execute function")
}
Expand All @@ -123,3 +114,14 @@ func createExecutor(a api.API) func(ctx echo.Context) error {
return ctx.JSON(http.StatusOK, res)
}
}

func buildb7sTopic(alloraTopic string) string {
res := ""
if strings.Contains(alloraTopic, "reputer") {
topicNum := alloraTopic[0 : len(alloraTopic)-8]
res = B7S_TOPIC_FORMAT_PREFIX + topicNum + "-" + WorkerModeReputer
} else {
res = B7S_TOPIC_FORMAT_PREFIX + alloraTopic + "-" + WorkerModeWorker
}
return res
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.2
require (
cosmossdk.io/math v1.3.0
github.com/allora-network/allora-chain v0.2.7
github.com/allora-network/b7s v0.0.2-0.20240624040826-bb318df1a6f7
github.com/allora-network/b7s v0.0.2-0.20240626021501-5a913378a8d8
github.com/cockroachdb/pebble v1.1.0
github.com/cosmos/cosmos-sdk v0.50.5
github.com/ignite/cli/v28 v28.3.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/allora-network/allora-chain v0.2.7 h1:wnxFV0JReueWagN/au4dG60a2I3gziM4OLOtrgUF5xY=
github.com/allora-network/allora-chain v0.2.7/go.mod h1:nYJd641Y0iieiL+t+P5VOWnYdiAq2kiazdbL1Bi4jrw=
github.com/allora-network/b7s v0.0.2-0.20240621170738-ab0de3bc5d87 h1:nAdc0StAeq27X8UUx7x+cWnW6TkoX0sLm1hQHxaE7Xw=
github.com/allora-network/b7s v0.0.2-0.20240621170738-ab0de3bc5d87/go.mod h1:rJJrdC5Y83LEDFxo/iJp3JJpi8I6TJncOTigMWk8ieE=
github.com/allora-network/b7s v0.0.2-0.20240624040826-bb318df1a6f7 h1:8Bo8i4uSjDwPir+CAxJyqiSRs/u6z0isK5txmf2Eq4Y=
github.com/allora-network/b7s v0.0.2-0.20240624040826-bb318df1a6f7/go.mod h1:rJJrdC5Y83LEDFxo/iJp3JJpi8I6TJncOTigMWk8ieE=
github.com/allora-network/b7s v0.0.2-0.20240626021501-5a913378a8d8 h1:w0MOdikeH7bmSoqJCgc9j9bRp7+sIRK7Rvf0P00S12g=
github.com/allora-network/b7s v0.0.2-0.20240626021501-5a913378a8d8/go.mod h1:rJJrdC5Y83LEDFxo/iJp3JJpi8I6TJncOTigMWk8ieE=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
Expand Down

0 comments on commit 9630a7d

Please sign in to comment.