-
Notifications
You must be signed in to change notification settings - Fork 178
feat: add helper commands to the zetatools #4559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
ccd0d1d
0542412
f25d627
b71e590
01f048f
4123005
1c8d5d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "context" | ||
| "fmt" | ||
| "os" | ||
| "sort" | ||
| "sync" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
|
|
@@ -72,6 +73,8 @@ const ( | |
| FlagMigrationAmounts = "migration-amounts" | ||
| // FlagShowNonces is the flag to show pending nonce low and high columns | ||
| FlagShowNonces = "show-nonces" | ||
| // FlagTSSNumber is the flag to select a specific TSS by position (1 = oldest, N = latest) | ||
| FlagTSSNumber = "tss-number" | ||
| ) | ||
|
|
||
| // NewTSSBalancesCMD creates a new command to check TSS address balances across all chains | ||
|
|
@@ -91,13 +94,16 @@ Examples: | |
| zetatool tss-balances 7000 | ||
| zetatool tss-balances zeta_mainnet | ||
| zetatool tss-balances zeta_testnet --config custom_config.json | ||
| zetatool tss-balances zeta_testnet --raw-amounts`, | ||
| zetatool tss-balances zeta_testnet --raw-amounts | ||
| zetatool tss-balances zeta_mainnet --tss-number 1 # oldest TSS | ||
| zetatool tss-balances zeta_mainnet --tss-number 3 # 3rd TSS (use total count for latest)`, | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: getTSSBalances, | ||
| } | ||
|
|
||
| cmd.Flags().Bool(FlagMigrationAmounts, false, "Show migration amount and raw migration amount columns") | ||
| cmd.Flags().Bool(FlagShowNonces, false, "Show pending nonce low and high columns") | ||
| cmd.Flags().Int(FlagTSSNumber, 0, "Show only the Nth TSS ordered by finalized height (1 = oldest, N = latest)") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
@@ -127,6 +133,11 @@ func getTSSBalances(cmd *cobra.Command, args []string) error { | |
| return fmt.Errorf("failed to read value for flag %s: %w", FlagShowNonces, err) | ||
| } | ||
|
|
||
| tssNumber, err := cmd.Flags().GetInt(FlagTSSNumber) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to read value for flag %s: %w", FlagTSSNumber, err) | ||
| } | ||
|
|
||
| cfg, err := config.GetConfigByNetwork(network, configFile) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get config: %w", err) | ||
|
|
@@ -153,11 +164,25 @@ func getTSSBalances(cmd *cobra.Command, args []string) error { | |
| return fmt.Errorf("no TSS entries found") | ||
| } | ||
|
|
||
| for i, tss := range tssHistoryRes.TssList { | ||
| // Sort TSS list by finalized zeta height ascending (oldest first, so TSS 1 = oldest, TSS N = latest) | ||
| tssList := tssHistoryRes.TssList | ||
| sort.Slice(tssList, func(i, j int) bool { | ||
| return tssList[i].FinalizedZetaHeight < tssList[j].FinalizedZetaHeight | ||
| }) | ||
|
|
||
| // Filter to a specific TSS if --tss-number is set | ||
| if tssNumber > 0 { | ||
| if tssNumber > len(tssList) { | ||
| return fmt.Errorf("TSS number %d out of range, only %d TSS entries available", tssNumber, len(tssList)) | ||
| } | ||
| tssList = []observertypes.TSS{tssList[tssNumber-1]} | ||
| } | ||
|
|
||
| for i, tss := range tssList { | ||
| if i > 0 { | ||
| fmt.Println() // Add spacing between TSS entries | ||
| } | ||
| fmt.Printf("=== TSS %d of %d ===\n", i+1, len(tssHistoryRes.TssList)) | ||
| fmt.Printf("=== TSS %d of %d ===\n", i+1, len(tssList)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Misleading TSS header when filtering by tss-numberLow Severity When Additional Locations (1)
Comment on lines
+193
to
+205
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Display counter loses original TSS count after filtering. After filtering to a single TSS at line 178, Proposed fix to preserve original count // Sort TSS list by finalized zeta height ascending (oldest first, so TSS 1 = oldest, TSS N = latest)
tssList := tssHistoryRes.TssList
sort.Slice(tssList, func(i, j int) bool {
return tssList[i].FinalizedZetaHeight < tssList[j].FinalizedZetaHeight
})
+ totalTSSCount := len(tssList)
// Filter to a specific TSS if --tss-number is set
+ selectedTSSNumber := 0
if tssNumber > 0 {
if tssNumber > len(tssList) {
return fmt.Errorf("TSS number %d out of range, only %d TSS entries available", tssNumber, len(tssList))
}
+ selectedTSSNumber = tssNumber
tssList = []observertypes.TSS{tssList[tssNumber-1]}
}
for i, tss := range tssList {
if i > 0 {
fmt.Println() // Add spacing between TSS entries
}
- fmt.Printf("=== TSS %d of %d ===\n", i+1, len(tssList))
+ displayNum := i + 1
+ if selectedTSSNumber > 0 {
+ displayNum = selectedTSSNumber
+ }
+ fmt.Printf("=== TSS %d of %d ===\n", displayNum, totalTSSCount)🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine its an internal tool , i would rather have simplicity of code
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🧠 Learnings used |
||
|
|
||
| if err := printTSSBalances( | ||
| ctx, | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 7529
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 1323
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 102
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 88
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 961
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 408
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 1624
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 3031
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 289
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 815
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 4874
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 3523
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 3272
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 7307
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 661
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 476
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 3420
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 2148
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 739
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 517
🏁 Script executed:
Repository: zeta-chain/node
Length of output: 1833
Remove redundant client-side sorting—the server already returns sorted results.
The server-side
TssHistoryquery (x/observer/keeper/grpc_query_tss.go:36–38) sorts TSS entries byFinalizedZetaHeightascending before returning them. The client-side re-sort at lines 169–171 is unnecessary and violates the DRY principle.Additionally,
FinalizedZetaHeightis always set toctx.BlockHeight()when a TSS is finalized (x/observer/keeper/msg_server_vote_tss.go:126), which is ≥ 1 for all actual transactions. The scenario ofFinalizedZetaHeight == 0cannot occur in practice, so the original ordering concern is not a functional risk.Remove the client-side sort entirely to simplify the code and rely on the server's pre-sorted response:
Proposed fix: Remove redundant sort
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine , there is no harm is sorting again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kingpinXD, understood — a defensive re-sort is indeed harmless and adds a degree of resilience against any future change to the server-side ordering. Happy to defer to your judgement here.(◕ᴥ◕ )
🧠 Learnings used