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

Commit

Permalink
Fix/wasm output format (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
guilherme-brandao authored Feb 7, 2024
1 parent d8dbea1 commit 8325728
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
13 changes: 8 additions & 5 deletions cmd/node/appchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (ap *AppChain) SendInferences(ctx context.Context, topicId uint64, results
ap.Logger.Info().Err(err).Msg("failed to send inferences to allora blockchain")
}

ap.Logger.Info().Str("txhash", txResp.TxHash).Msg("successfully sent inferences to allora blockchain")
ap.Logger.Info().Any("Tx Resp:", txResp).Msg("successfully sent inferences to allora blockchain")

return workersInferences
}
Expand All @@ -212,11 +212,14 @@ func (ap *AppChain) SendUpdatedWeights(ctx context.Context, topicId uint64, resu

for peer, value := range extractedWeights {
ap.Logger.Info().Str("peer", peer)
parsed, err := parseFloatToUint64Weights(strconv.FormatFloat(value, 'f', -1, 64))
parsed, err := parseFloatToUint64Weights(value)
if err != nil {
ap.Logger.Error().Err(err).Msg("Error parsing uint")
continue
}

fmt.Printf("\n Worker Node: %s Weight: %v \n", peer, cosmossdk_io_math.NewUint(parsed))

weight := &types.Weight{
TopicId: topicId,
Reputer: ap.ReputerAddress,
Expand All @@ -238,7 +241,7 @@ func (ap *AppChain) SendUpdatedWeights(ctx context.Context, topicId uint64, resu
ap.Logger.Info().Err(err).Msg("failed to send weights to allora blockchain")
}

ap.Logger.Info().Str("txhash", txResp.TxHash).Msg("successfully sent weights to allora blockchain")
ap.Logger.Info().Any("Tx Resp:", txResp).Msg("successfully sent weights to allora blockchain")
}

func parseFloatToUint64Weights(input string) (uint64, error) {
Expand Down Expand Up @@ -278,11 +281,11 @@ func extractNumber(stdout string) (string, error) {
return response.Value, nil
}

func extractWeights(stdout string) (map[string]float64, error) {
func extractWeights(stdout string) (map[string]string, error) {
fmt.Println("Extracting weights from stdout: ", stdout)

var weights WorkerWeights
err := json.Unmarshal([]byte(stdout), &weights.Weights)
err := json.Unmarshal([]byte(stdout), &weights)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/node/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ExecuteResult struct {

func sendResultsToChain(ctx echo.Context, a api.API, appChainClient AppChain, req ExecuteRequest, res ExecuteResponse) {

// Only in weight functions that we will have a "type" in the response
// Only in weight functions that we will have a "type" in the response
functionType := "inferences"
functionType, err := getResponseInfo(res.Results[0].Result.Stdout)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/node/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ type WeightsResponse struct {
}

type WorkerWeights struct {
Weights map[string]float64 `json:"-"` // Use a map to dynamically handle worker identifiers
Type string `json:"type"`
Weights map[string]string `json:"weights"`
}

type WeightsCalcDependencies struct {
Expand Down

0 comments on commit 8325728

Please sign in to comment.