From 2757edac702a7dfccd9c42d62a80afb903c268e1 Mon Sep 17 00:00:00 2001 From: zees-dev Date: Sun, 23 Jun 2024 15:56:38 +1200 Subject: [PATCH] worker result integrate metadata aggregation --- models/execute/response.go | 1 + node/aggregate/aggregate.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/models/execute/response.go b/models/execute/response.go index 080a7bad..d87c960b 100644 --- a/models/execute/response.go +++ b/models/execute/response.go @@ -16,6 +16,7 @@ type Result struct { RequestID string `json:"request_id"` Usage Usage `json:"usage,omitempty"` Signature []byte `json:"signature,omitempty"` + Metadata interface{} `json:"metadata,omitempty"` } // Cluster represents the set of peers that executed the request. diff --git a/node/aggregate/aggregate.go b/node/aggregate/aggregate.go index 0de8925c..e1bdc592 100644 --- a/node/aggregate/aggregate.go +++ b/node/aggregate/aggregate.go @@ -19,12 +19,15 @@ type Result struct { Frequency float64 `json:"frequency,omitempty"` // Signature of this result Signature []byte `json:"signature,omitempty"` + // Metadata is used to store additional information about the result. + Metadata interface{} `json:"metadata,omitempty"` } type resultStats struct { seen uint peers []peer.ID signature []byte + metadata interface{} } func Aggregate(results execute.ResultMap) Results { @@ -46,12 +49,14 @@ func Aggregate(results execute.ResultMap) Results { seen: 0, peers: make([]peer.ID, 0), signature: res.Signature, + metadata: res.Metadata, } } stat.seen++ stat.peers = append(stat.peers, executingPeer) stat.signature = res.Signature + stat.metadata = res.Metadata stats[output] = stat } @@ -65,6 +70,7 @@ func Aggregate(results execute.ResultMap) Results { Peers: stat.peers, Frequency: 100 * float64(stat.seen) / float64(total), Signature: stat.signature, + Metadata: stat.metadata, } aggregated = append(aggregated, aggr)