improve(cli): accurate live progress for sync-accounts#171
Conversation
The progress line was driven by completed-contract count under misleading names (processedScopes/totalScopesToProcess actually counted contracts), so a single-contract sync sat at "0/1 (0.00%)" the whole time and looked stuck. - Rename to completedContracts/totalContracts; drop unused totalScopes. - Track holder scopes processed per-contract and overall; surface both the running "holders scanned" and "balances" counters, which move continuously. - Show the contract currently in progress (currentContractIndex + 1) instead of only the last completed one. Percentage is still contract-granular (the only total known up front), but the moving counters make long single-contract runs legible. No behavior change to the sync itself.
There was a problem hiding this comment.
Code Review
This pull request refactors the progress tracking in AccountSynchronizer to use contract-based metrics instead of scope-based metrics, preventing the progress indicator from appearing stuck during long-running single-contract syncs. The review feedback highlights two issues: first, this.currentScope is not reset when transitioning to a new contract, which can display stale progress information; second, if this.totalContracts is zero, the progress status will prematurely display 'finalizing database writes...'. Code suggestions are provided to address both issues.
| const contract = this.tokenContracts[i]; | ||
| this.currentContract = contract; | ||
| this.currentContractIndex = i; | ||
| this.currentContractScopes = 0; |
There was a problem hiding this comment.
When transitioning to a new contract, this.currentScope is not reset. As a result, the progress log will display the last processed scope from the previous contract as the current scope for the new contract until the first scope of the new contract is successfully fetched. Resetting this.currentScope to an empty string at the start of each contract avoids this stale/misleading status message.
| const contract = this.tokenContracts[i]; | |
| this.currentContract = contract; | |
| this.currentContractIndex = i; | |
| this.currentContractScopes = 0; | |
| const contract = this.tokenContracts[i]; | |
| this.currentContract = contract; | |
| this.currentContractIndex = i; | |
| this.currentContractScopes = 0; | |
| this.currentScope = ''; |
There was a problem hiding this comment.
Applied in 74f1cce — reset this.currentScope = '' at the start of each contract.
| let statusMessage: string; | ||
| if (this.completedContracts >= this.totalContracts) { | ||
| statusMessage = 'finalizing database writes...'; |
There was a problem hiding this comment.
If this.totalContracts is 0 (e.g., if no validated token contracts are found), the condition this.completedContracts >= this.totalContracts (i.e., 0 >= 0) will evaluate to true. This causes the progress status to prematurely and incorrectly display 'finalizing database writes...' during initialization or when there is nothing to process. Adding a guard for this.totalContracts > 0 ensures the status remains 'initializing...' or handles the zero-contract case gracefully.
| let statusMessage: string; | |
| if (this.completedContracts >= this.totalContracts) { | |
| statusMessage = 'finalizing database writes...'; | |
| let statusMessage: string; | |
| if (this.totalContracts > 0 && this.completedContracts >= this.totalContracts) { | |
| statusMessage = 'finalizing database writes...'; |
There was a problem hiding this comment.
Applied in 74f1cce — guarded with this.totalContracts > 0, so a zero-contract run shows 'initializing...' instead of prematurely finalizing.
…s on zero contracts Address Gemini review on #171: - reset this.currentScope at the start of each contract so the progress line doesn't show the previous contract's last scope until the first fetch lands. - guard the 'finalizing database writes...' status behind totalContracts > 0 so a zero-contract run (no validated token contracts) shows 'initializing...' instead of 0 >= 0 reading as finalized.
Why
Follow-up to #170. An operator running
./hyp-control sync accounts eos token.pcashsaw the progress line stuck at0/1 (0.00%)for the whole run even though it was working (Processed 448550 accounts). The bar was driven by completed-contract count under misleading field names (processedScopes/totalScopesToProcessactually counted contracts), so a single-contract sync only moves 0% → 100% at the very end.Changes
processedScopes/totalScopesToProcess→completedContracts/totalContracts; remove the unusedtotalScopes.currentContractScopes) and overall (totalScopesProcessed), and surface the running holders scanned + balances counters — these move continuously.currentContractIndex + 1) instead of only the last completed one.The percentage stays contract-granular (the only total known up front —
get_table_by_scopegives no cheap holder count), but the moving counters make long single-contract runs legible.New output
No behavior change to the sync itself.
tsc --noEmitpasses.