-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for metadata in execution results (#157)
- Loading branch information
Showing
21 changed files
with
190 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package metadata | ||
|
||
import ( | ||
"github.com/blocklessnetwork/b7s/models/execute" | ||
) | ||
|
||
type Provider interface { | ||
Metadata(execute.Request, execute.RuntimeOutput) (any, error) | ||
} | ||
|
||
type noopProvider struct{} | ||
|
||
func (p noopProvider) Metadata(execute.Request, execute.RuntimeOutput) (any, error) { | ||
return nil, nil | ||
} | ||
|
||
func NewNoopProvider() Provider { | ||
return noopProvider{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package aggregate | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/libp2p/go-libp2p/core/peer" | ||
|
||
"github.com/blocklessnetwork/b7s/models/execute" | ||
) | ||
|
||
type Results []Result | ||
|
||
// Result represents the execution result along with its aggregation stats. | ||
type Result struct { | ||
Result execute.RuntimeOutput `json:"result,omitempty"` | ||
// Peers that got this result. | ||
Peers []peer.ID `json:"peers,omitempty"` | ||
// Peers metadata | ||
Metadata NodeMetadata `json:"metadata,omitempty"` | ||
// How frequent was this result, in percentages. | ||
Frequency float64 `json:"frequency,omitempty"` | ||
} | ||
|
||
type NodeMetadata map[peer.ID]any | ||
|
||
func (m NodeMetadata) MarshalJSON() ([]byte, error) { | ||
|
||
em := make(map[string]any, len(m)) | ||
for p, v := range m { | ||
em[p.String()] = v | ||
} | ||
|
||
return json.Marshal(em) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.