Skip to content

Commit

Permalink
feat(cmd/network/show): Add cmd for fetching compute committees
Browse files Browse the repository at this point in the history
  • Loading branch information
amela committed May 14, 2024
1 parent 750f8d6 commit 876507b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
59 changes: 58 additions & 1 deletion cmd/network/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import (
consensusPretty "github.com/oasisprotocol/oasis-core/go/common/prettyprint"
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
roothash "github.com/oasisprotocol/oasis-core/go/roothash/api"
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
"github.com/oasisprotocol/oasis-core/go/staking/api/token"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"

"github.com/oasisprotocol/cli/cmd/common"
cliConfig "github.com/oasisprotocol/cli/config"
"github.com/oasisprotocol/cli/table"
)

type propertySelector int
Expand All @@ -33,10 +35,11 @@ const (
selValidators
selNativeToken
selGasCosts
selCommittees
)

var showCmd = &cobra.Command{
Use: "show { <id> | entities | nodes | paratimes | validators | native-token | gas-costs }",
Use: "show { <id> | entities | nodes | paratimes | validators | native-token | gas-costs | committees }",
Short: "Show network properties",
Long: "Show network property stored in the registry, scheduler, genesis document or chain. Query by ID, hash or a specified kind.",
Args: cobra.ExactArgs(1),
Expand All @@ -55,6 +58,7 @@ var showCmd = &cobra.Command{

consensusConn := conn.Consensus()
registryConn := consensusConn.Registry()
roothashConn := consensusConn.RootHash()

// Figure out the height to use if "latest".
height, err := common.GetActualHeight(
Expand Down Expand Up @@ -195,6 +199,57 @@ var showCmd = &cobra.Command{
fmt.Println()
}
return
case selCommittees:
runtimes, err := registryConn.GetRuntimes(ctx, &registry.GetRuntimesQuery{
Height: height,
IncludeSuspended: false,
})
cobra.CheckErr(err)

for _, runtime := range runtimes {
if runtime.Kind != registry.KindCompute {
continue
}
table := table.New()
table.SetHeader([]string{"Entity ID", "Node ID", "Role"})

runtimeID := runtime.ID
paratimeName := getParatimeName(cfg, runtimeID.String())

fmt.Println("=== COMMITTEE ===")
fmt.Printf("Paratime: %s(%s)\n", paratimeName, runtimeID)
fmt.Printf("Height: %d\n", height)
fmt.Println()

state, _ := roothashConn.GetRuntimeState(ctx, &roothash.RuntimeRequest{
Height: height,
RuntimeID: runtimeID,
})
cobra.CheckErr(err)

var output [][]string
for _, member := range state.Committee.Members {
nodeQuery := &registry.IDQuery{
Height: height,
ID: member.PublicKey,
}

node, err := consensusConn.Registry().GetNode(ctx, nodeQuery)
cobra.CheckErr(err)

output = append(output, []string{
node.EntityID.String(),
member.PublicKey.String(),
member.Role.String(),
})
}

table.AppendBulk(output)
table.Render()
fmt.Println()
}
return

default:
// Should never happen.
}
Expand Down Expand Up @@ -242,6 +297,8 @@ func selectorFromString(s string) propertySelector {
return selNativeToken
case "gas-costs":
return selGasCosts
case "committees":
return selCommittees
}
return selInvalid
}
Expand Down
8 changes: 8 additions & 0 deletions docs/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ Above, we can see that the [maximum amount of gas](./account.md#gas-limit) our
transaction can spend must be set to at least 1000 **gas units**, otherwise it
will be rejected by the network.

#### `committees` {#committees}

Shows runtime committees.

![code shell](../examples/network-show/committees.in.static)

![code](../examples/network-show/committees.out.static)

#### `<id>` {#show-id}

The provided ID can be one of the following:
Expand Down

0 comments on commit 876507b

Please sign in to comment.