Skip to content

Commit a87400a

Browse files
committed
Add --minimal flag
1 parent 9c39b65 commit a87400a

File tree

1 file changed

+40
-0
lines changed
  • shared/services/state/cli

1 file changed

+40
-0
lines changed

shared/services/state/cli/cli.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,42 @@ var prettyFlag = flag.Bool("p", false, "Pretty print the output")
2828
var inputFlag = flag.Bool("i", false, "Parse a network state from stdin instead of retrieving it from the network")
2929
var criticalDutiesSlotsFlag = flag.Bool("critical-duties-slots", false, "If passed, output a list of critical duties slots for the given state as if it were the final state in a 6300 epoch interval. This is outputted instead of the state json.")
3030
var criticalDutiesEpochCountFlag = flag.Uint64("critical-duties-epoch-count", 6300, "The number of epochs to consider when calculating critical duties")
31+
var minimalFlag = flag.Bool("minimal", false, "Truncate every list/map to at most one entry (useful for producing a small inspection file)")
32+
33+
// truncateNetworkState reduces every slice and map field to at most one element.
34+
func truncateNetworkState(ns *state.NetworkState) {
35+
if len(ns.NodeDetails) > 1 {
36+
ns.NodeDetails = ns.NodeDetails[:1]
37+
}
38+
if len(ns.MinipoolDetails) > 1 {
39+
ns.MinipoolDetails = ns.MinipoolDetails[:1]
40+
}
41+
if len(ns.MegapoolValidatorGlobalIndex) > 1 {
42+
ns.MegapoolValidatorGlobalIndex = ns.MegapoolValidatorGlobalIndex[:1]
43+
}
44+
if len(ns.OracleDaoMemberDetails) > 1 {
45+
ns.OracleDaoMemberDetails = ns.OracleDaoMemberDetails[:1]
46+
}
47+
if len(ns.ProtocolDaoProposalDetails) > 1 {
48+
ns.ProtocolDaoProposalDetails = ns.ProtocolDaoProposalDetails[:1]
49+
}
50+
if len(ns.MinipoolValidatorDetails) > 1 {
51+
for k := range ns.MinipoolValidatorDetails {
52+
delete(ns.MinipoolValidatorDetails, k)
53+
if len(ns.MinipoolValidatorDetails) == 1 {
54+
break
55+
}
56+
}
57+
}
58+
if len(ns.MegapoolValidatorDetails) > 1 {
59+
for k := range ns.MegapoolValidatorDetails {
60+
delete(ns.MegapoolValidatorDetails, k)
61+
if len(ns.MegapoolValidatorDetails) == 1 {
62+
break
63+
}
64+
}
65+
}
66+
}
3167

3268
func main() {
3369
flag.Parse()
@@ -85,6 +121,10 @@ func main() {
85121
os.Exit(1)
86122
}
87123

124+
if *minimalFlag {
125+
truncateNetworkState(networkState)
126+
}
127+
88128
if *criticalDutiesSlotsFlag {
89129
criticalDutiesEpochs := state.NewCriticalDutiesEpochs(*criticalDutiesEpochCountFlag, networkState)
90130
fmt.Fprintf(os.Stderr, "Critical duties epochs to check: %d\n", len(criticalDutiesEpochs.CriticalDuties))

0 commit comments

Comments
 (0)