Skip to content

improve(cli): accurate live progress for sync-accounts#171

Merged
igorls merged 2 commits into
devfrom
improve/sync-accounts-progress
May 29, 2026
Merged

improve(cli): accurate live progress for sync-accounts#171
igorls merged 2 commits into
devfrom
improve/sync-accounts-progress

Conversation

@igorls
Copy link
Copy Markdown
Member

@igorls igorls commented May 29, 2026

Why

Follow-up to #170. An operator running ./hyp-control sync accounts eos token.pcash saw the progress line stuck at 0/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/totalScopesToProcess actually counted contracts), so a single-contract sync only moves 0% → 100% at the very end.

Changes

  • Rename processedScopes/totalScopesToProcesscompletedContracts/totalContracts; remove the unused totalScopes.
  • Track holder scopes processed per-contract (currentContractScopes) and overall (totalScopesProcessed), and surface the running holders scanned + balances counters — these move continuously.
  • Show the contract currently in progress (currentContractIndex + 1) instead of only the last completed one.

The percentage stays contract-granular (the only total known up front — get_table_by_scope gives no cheap holder count), but the moving counters make long single-contract runs legible.

New output

single contract:
  [07:05:40] 0.0% | holders scanned: 433076 | balances: 435000 | contract 1/1 token.pcash (433076 holders) - current: s2hw24.pcash
multi-contract, mid-run:
  [07:05:40] 3.3% | holders scanned: 50000 | balances: 52310 | contract 5/120 eosio.token (1200 holders) - current: bu.klnk
finalizing:
  [07:05:40] 100.0% | holders scanned: 240000 | balances: 251000 | finalizing database writes...

No behavior change to the sync itself. tsc --noEmit passes.

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.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 110 to +113
const contract = this.tokenContracts[i];
this.currentContract = contract;
this.currentContractIndex = i;
this.currentContractScopes = 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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 = '';

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 74f1cce — reset this.currentScope = '' at the start of each contract.

Comment on lines +196 to 198
let statusMessage: string;
if (this.completedContracts >= this.totalContracts) {
statusMessage = 'finalizing database writes...';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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...';

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@igorls igorls merged commit c61c60a into dev May 29, 2026
2 checks passed
@igorls igorls deleted the improve/sync-accounts-progress branch May 29, 2026 08:42
@igorls igorls mentioned this pull request Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant