Skip to content

Commit 604e0af

Browse files
committed
feat: add cmd to show das column distribution based on input key file
1 parent 2c9034e commit 604e0af

2 files changed

Lines changed: 148 additions & 4 deletions

File tree

README.md

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@ nodekey-tools generate --das-columns 1,2,3
2929
From private key:
3030

3131
```bash
32-
nodekey-tools info --priv-key 000bbc3112bd249176b12e0f40ecaa1ec2c6b89e8b6d9cd244e609693a891b7b
32+
$ nodekey-tools info --priv-key 000bbc3112bd249176b12e0f40ecaa1ec2c6b89e8b6d9cd244e609693a891b7b
3333
```
3434

35-
From node id:
35+
From node ID:
3636

3737
```bash
38-
nodekey-tools info --node-id e23005d5754cb0c4ca88ba99a8462e31ba8ae7b57f585db73a4b0dacd2415c1b
38+
$ nodekey-tools info --node-id e23005d5754cb0c4ca88ba99a8462e31ba8ae7b57f585db73a4b0dacd2415c1b --custody-column-count 8
39+
40+
# Output
41+
+---------------------+------------------------------------------------------------------+
42+
| FIELD | VALUE |
43+
+---------------------+------------------------------------------------------------------+
44+
| Node ID | e23005d5754cb0c4ca88ba99a8462e31ba8ae7b57f585db73a4b0dacd2415c1b |
45+
+---------------------+------------------------------------------------------------------+
46+
| DAS Custody Columns | [55, 61, 65, 82, 90, 108, 111, 124] |
47+
+---------------------+------------------------------------------------------------------+
48+
3949
```
4050

4151

@@ -46,5 +56,62 @@ This command is useful to generate nodekeys for a DAS network. It will try to ge
4656
This will generate 18 nodekeys across a 128 column network and save them to the `result.json` file.
4757

4858
```bash
49-
nodekey-tools generate-network --node-count 18 --column-count 128 --output-file result.json
59+
# Try 18 nodes first. This should be quite fast to generate.
60+
$ nodekey-tools generate-network --node-count 18 --column-count 128 --output-file result-18.json
61+
62+
# If you want the "optimal" size of 16 (128 columns / 8 columns per node) then you can run
63+
# the following command. This can take hours/days.
64+
$ nodekey-tools generate-network --node-count 16 --column-count 128 --output-file result-16.json
5065
```
66+
67+
### Show information about a generated network based on the JSON file
68+
69+
```bash
70+
$ nodekey-tools info-network --input-file result-16.json
71+
72+
# Output
73+
Loaded network information for 16 nodes from result-16.json
74+
75+
Column Coverage Table:
76+
=====================
77+
+------+----------+ +------+----------+ +------+----------+ +------+----------+
78+
| Col | Nodes | | Col | Nodes | | Col | Nodes | | Col | Nodes |
79+
+------+----------+ +------+----------+ +------+----------+ +------+----------+
80+
| 0 | 12 | | 32 | 6 | | 64 | 15 | | 96 | 16 |
81+
| 1 | 15 | | 33 | 6 | | 65 | 14 | | 97 | 7 |
82+
| 2 | 6 | | 34 | 12 | | 66 | 3 | | 98 | 9 |
83+
| 3 | 7 | | 35 | 2 | | 67 | 15 | | 99 | 4 |
84+
| 4 | 13 | | 36 | 12 | | 68 | 11 | | 100 | 16 |
85+
| 5 | 6 | | 37 | 14 | | 69 | 3 | | 101 | 2 |
86+
| 6 | 11 | | 38 | 10 | | 70 | 3 | | 102 | 16 |
87+
| 7 | 14 | | 39 | 12 | | 71 | 14 | | 103 | 1 |
88+
| 8 | 10 | | 40 | 8 | | 72 | 13 | | 104 | 16 |
89+
| 9 | 4 | | 41 | 9 | | 73 | 13 | | 105 | 4 |
90+
| 10 | 5 | | 42 | 8 | | 74 | 7 | | 106 | 16 |
91+
| 11 | 12 | | 43 | 9 | | 75 | 11 | | 107 | 2 |
92+
| 12 | 14 | | 44 | 11 | | 76 | 1 | | 108 | 13 |
93+
| 13 | 7 | | 45 | 14 | | 77 | 3 | | 109 | 11 |
94+
| 14 | 5 | | 46 | 15 | | 78 | 2 | | 110 | 11 |
95+
| 15 | 13 | | 47 | 9 | | 79 | 10 | | 111 | 5 |
96+
| 16 | 3 | | 48 | 7 | | 80 | 2 | | 112 | 10 |
97+
| 17 | 1 | | 49 | 6 | | 81 | 11 | | 113 | 1 |
98+
| 18 | 6 | | 50 | 7 | | 82 | 4 | | 114 | 2 |
99+
| 19 | 15 | | 51 | 1 | | 83 | 6 | | 115 | 3 |
100+
| 20 | 15 | | 52 | 1 | | 84 | 14 | | 116 | 4 |
101+
| 21 | 15 | | 53 | 8 | | 85 | 5 | | 117 | 1 |
102+
| 22 | 10 | | 54 | 9 | | 86 | 5 | | 118 | 1 |
103+
| 23 | 16 | | 55 | 13 | | 87 | 8 | | 119 | 7 |
104+
| 24 | 2 | | 56 | 9 | | 88 | 13 | | 120 | 8 |
105+
| 25 | 3 | | 57 | 3 | | 89 | 8 | | 121 | 7 |
106+
| 26 | 12 | | 58 | 8 | | 90 | 5 | | 122 | 2 |
107+
| 27 | 12 | | 59 | 16 | | 91 | 10 | | 123 | 4 |
108+
| 28 | 13 | | 60 | 10 | | 92 | 9 | | 124 | 15 |
109+
| 29 | 11 | | 61 | 5 | | 93 | 10 | | 125 | 4 |
110+
| 30 | 4 | | 62 | 8 | | 94 | 6 | | 126 | 5 |
111+
| 31 | 14 | | 63 | 9 | | 95 | 12 | | 127 | 16 |
112+
+------+----------+ +------+----------+ +------+----------+ +------+----------+
113+
```
114+
115+
## License
116+
117+
This project is licensed under the GPL-3.0 license. See the [LICENSE](LICENSE) file for details.

cmd/info_network.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package cmd
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var (
12+
inputFile string
13+
)
14+
15+
var infoNetworkCmd = &cobra.Command{
16+
Use: "info-network",
17+
Short: "Display information about a network from a JSON file generated by generate-network",
18+
RunE: runInfoNetwork,
19+
}
20+
21+
func init() {
22+
rootCmd.AddCommand(infoNetworkCmd)
23+
infoNetworkCmd.Flags().StringVar(&inputFile, "input-file", "", "Path to the JSON file containing network information")
24+
infoNetworkCmd.Flags().Uint64Var(&columnCount, "column-count", 128, "Amount of columns for DAS custody columns")
25+
infoNetworkCmd.MarkFlagRequired("input-file")
26+
}
27+
28+
func runInfoNetwork(cmd *cobra.Command, args []string) error {
29+
// Read the JSON file
30+
jsonData, err := os.ReadFile(inputFile)
31+
if err != nil {
32+
return fmt.Errorf("failed to read input file: %v", err)
33+
}
34+
35+
// Parse the JSON data
36+
var nodes []NodeOutput
37+
if err := json.Unmarshal(jsonData, &nodes); err != nil {
38+
return fmt.Errorf("failed to parse JSON data: %v", err)
39+
}
40+
41+
fmt.Printf("Loaded network information for %d nodes from %s\n", len(nodes), inputFile)
42+
43+
// Convert NodeOutput to nodeInfo for compatibility with printColumnCoverageTable
44+
nodeInfos := make([]nodeInfo, 0, len(nodes))
45+
for _, node := range nodes {
46+
nodeInfos = append(nodeInfos, nodeInfo{
47+
nodeID: node.NodeID,
48+
columns: node.Columns,
49+
})
50+
}
51+
52+
// Print the column coverage table
53+
printColumnCoverageTable(nodeInfos, columnCount)
54+
55+
// Count covered columns
56+
coveredColumns := make(map[uint64]bool)
57+
for _, node := range nodeInfos {
58+
for _, col := range node.columns {
59+
coveredColumns[col] = true
60+
}
61+
}
62+
63+
fmt.Printf("\nTotal columns covered: %d/%d\n", len(coveredColumns), columnCount)
64+
65+
// Print uncovered columns if any
66+
if len(coveredColumns) < int(columnCount) {
67+
uncoveredColumns := make([]uint64, 0)
68+
for i := uint64(0); i < columnCount; i++ {
69+
if !coveredColumns[i] {
70+
uncoveredColumns = append(uncoveredColumns, i)
71+
}
72+
}
73+
fmt.Printf("Uncovered columns: %v\n", uncoveredColumns)
74+
}
75+
76+
return nil
77+
}

0 commit comments

Comments
 (0)