Skip to content

Commit 573b2ca

Browse files
committed
feat(cmd/network): Add nodes info to network show { <id> | entities }
1 parent 91a9530 commit 573b2ca

5 files changed

Lines changed: 98 additions & 11 deletions

File tree

cmd/network/show.go

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import (
1010

1111
"github.com/spf13/cobra"
1212

13+
"github.com/oasisprotocol/oasis-core/go/beacon/api"
1314
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
15+
"github.com/oasisprotocol/oasis-core/go/common/entity"
1416
consensusPretty "github.com/oasisprotocol/oasis-core/go/common/prettyprint"
17+
"github.com/oasisprotocol/oasis-core/go/common/quantity"
1518
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
1619
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
1720
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
@@ -40,6 +43,81 @@ const (
4043
selParameters
4144
)
4245

46+
func printEntityNodes(ctx context.Context, stakingConn staking.Backend, registryConn registry.Backend, beaconConn api.Backend, entity *entity.Entity, height int64) error {
47+
epoch, err := beaconConn.GetEpoch(ctx, height)
48+
if err != nil {
49+
return err
50+
}
51+
52+
fmt.Printf("=== ENTITY ===\n")
53+
54+
entityAddr := staking.NewAddress(entity.ID)
55+
fmt.Printf("Entity Address: %s\n", entityAddr.String())
56+
57+
fmt.Printf("Entity ID: %s\n", entity.ID.String())
58+
59+
account, err := stakingConn.Account(
60+
ctx,
61+
&staking.OwnerQuery{Height: height, Owner: entityAddr},
62+
)
63+
if err != nil {
64+
return err
65+
}
66+
67+
balance := &account.Escrow.Active.Balance
68+
69+
d := quantity.NewFromUint64(uint64(1_000))
70+
commission := account.Escrow.CommissionSchedule.CurrentRate(epoch)
71+
err = commission.Quo(d)
72+
cobra.CheckErr(err)
73+
74+
q := quantity.NewFromUint64(uint64(1_000_000_000))
75+
err = balance.Quo(q)
76+
cobra.CheckErr(err)
77+
78+
fmt.Printf("Stake: %s ROSE\n", balance.String())
79+
fmt.Printf("Commission: %s%%\n", commission.String())
80+
81+
fmt.Println()
82+
fmt.Printf("=== NODES ===\n")
83+
for i, node := range entity.Nodes {
84+
fmt.Printf("Node ID: %s\n", node.String())
85+
idQuery2 := &registry.IDQuery{
86+
Height: height,
87+
ID: node,
88+
}
89+
90+
nodeStatus, err := registryConn.GetNodeStatus(ctx, idQuery2)
91+
if err != nil {
92+
fmt.Println(" Node is not active")
93+
continue
94+
}
95+
96+
if node, err2 := registryConn.GetNode(ctx, idQuery2); err2 == nil {
97+
fmt.Printf(" Node Roles: %s\n", node.Roles.String())
98+
fmt.Printf(" Software Version: %s\n", node.SoftwareVersion)
99+
if len(node.Runtimes) > 0 {
100+
fmt.Printf(" Runtimes:\n")
101+
}
102+
for _, runtime := range node.Runtimes {
103+
fmt.Printf(" Runtime ID: %s\n", runtime.ID)
104+
fmt.Printf(" Runtime Version: %s\n", runtime.Version)
105+
}
106+
fmt.Printf(" Node Status:\n")
107+
fmt.Printf(" Expiration Processed: %t\n", nodeStatus.ExpirationProcessed)
108+
fmt.Printf(" Freeze End Time: %d\n", nodeStatus.FreezeEndTime)
109+
fmt.Printf(" Election Eligible After: %d\n", nodeStatus.ElectionEligibleAfter)
110+
} else {
111+
return fmt.Errorf("could not get a node: %s", err2)
112+
}
113+
114+
if i < len(entity.Nodes)-1 {
115+
fmt.Println()
116+
}
117+
}
118+
return nil
119+
}
120+
43121
var showCmd = &cobra.Command{
44122
Use: "show { <id> | committees | entities | gas-costs | native-token | nodes | parameters | paratimes | validators }",
45123
Short: "Show network properties",
@@ -63,6 +141,7 @@ var showCmd = &cobra.Command{
63141
roothashConn := conn.Consensus().RootHash()
64142
schedulerConn := conn.Consensus().Scheduler()
65143
stakingConn := conn.Consensus().Staking()
144+
beaconConn := conn.Consensus().Beacon()
66145

67146
// Figure out the height to use if "latest".
68147
height, err := common.GetActualHeight(
@@ -92,7 +171,7 @@ var showCmd = &cobra.Command{
92171
}
93172

94173
if entity, err := registryConn.GetEntity(ctx, idQuery); err == nil {
95-
err = prettyPrint(entity)
174+
err = printEntityNodes(ctx, stakingConn, registryConn, beaconConn, entity, height)
96175
cobra.CheckErr(err)
97176
return
98177
}
@@ -125,7 +204,7 @@ var showCmd = &cobra.Command{
125204
cobra.CheckErr(err) // If this doesn't work the other large queries won't either.
126205
for _, entity := range entities {
127206
if staking.NewAddress(entity.ID).Equal(addr) {
128-
err = prettyPrint(entity)
207+
err = printEntityNodes(ctx, stakingConn, registryConn, beaconConn, entity, height)
129208
cobra.CheckErr(err)
130209
return
131210
}

docs/network.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ The provided ID can be one of the following:
410410
- If the entity ID is provided, Oasis CLI shows information on the entity and
411411
its corresponding nodes in the network registry. For example:
412412

413-
![code shell](../examples/network-show/id-entity.in)
413+
![code shell](../examples/network-show/id-entity.in.static)
414414

415-
![code json](../examples/network-show/id-entity.out)
415+
![code json](../examples/network-show/id-entity.out.static)
416416

417417
- If the node ID is provided, Oasis CLI shows detailed information of the node
418418
such as the Oasis Core software version, the node's role, supported
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis network show xQN6ffLSdc51EfEQ2BzltK1iWYAw6Y1CkBAbFzlhhEQ=

examples/network-show/id-entity.out

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== ENTITY ===
2+
Entity Address: oasis1qzp84num6xgspdst65yv7yqegln6ndcxmuuq8s9w
3+
Entity ID: xQN6ffLSdc51EfEQ2BzltK1iWYAw6Y1CkBAbFzlhhEQ=
4+
Stake: 11598463 ROSE
5+
Commission: 20%
6+
7+
=== NODES ===
8+
Node ID: Kb6opWKGbJHL0LK2Lto+m5ROIAXLhIr1lxQz0/kAOUM=
9+
Node Roles: validator
10+
Software Version: 24.1
11+
Node Status:
12+
Expiration Processed: false
13+
Freeze End Time: 0
14+
Election Eligible After: 38659

0 commit comments

Comments
 (0)