From 8325728a1f500c6eab36ac20224d25ecd6d30f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Brand=C3=A3o?= <37072140+guilherme-brandao@users.noreply.github.com> Date: Wed, 7 Feb 2024 19:51:29 +0000 Subject: [PATCH] Fix/wasm output format (#47) ORA-604 https://linear.app/upshot/issue/ORA-604/head-breaks-sending-weights-to-allora-blockchain --- cmd/node/appchain.go | 13 ++++++++----- cmd/node/execute.go | 2 +- cmd/node/types.go | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/node/appchain.go b/cmd/node/appchain.go index 289020c..4aba70b 100644 --- a/cmd/node/appchain.go +++ b/cmd/node/appchain.go @@ -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 } @@ -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, @@ -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) { @@ -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 } diff --git a/cmd/node/execute.go b/cmd/node/execute.go index aca7a13..73dfa09 100644 --- a/cmd/node/execute.go +++ b/cmd/node/execute.go @@ -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 { diff --git a/cmd/node/types.go b/cmd/node/types.go index 94017df..8a90cb8 100644 --- a/cmd/node/types.go +++ b/cmd/node/types.go @@ -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 {