Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions src/cli/sync-modules/sync-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ export class AccountSynchronizer extends Synchronizer<IAccount> {
private accountCollection?: Collection<IAccount>;
private contractAccounts: string[] = [];
private tokenContracts: string[] = [];
private totalScopes: number = 0;
private processedScopes: number = 0;
private totalScopesToProcess: number = 0;
private completedContracts: number = 0;
private totalContracts: number = 0;
private currentContractIndex: number = 0;
private currentContract: string = '';
private currentScope: string = '';
private currentContractScopes: number = 0; // holder scopes processed in the current contract
private totalScopesProcessed: number = 0; // holder scopes processed across all contracts
private contractFilter?: string;

constructor(chain: string, contractFilter?: string) {
Expand Down Expand Up @@ -109,6 +110,7 @@ export class AccountSynchronizer extends Synchronizer<IAccount> {
const contract = this.tokenContracts[i];
this.currentContract = contract;
this.currentContractIndex = i;
this.currentContractScopes = 0;
Comment on lines 110 to +113

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.

console.log(`[DEBUG] Starting contract ${i + 1}/${this.tokenContracts.length}: ${contract}`);

let lowerBound: string = '';
Expand Down Expand Up @@ -143,12 +145,14 @@ export class AccountSynchronizer extends Synchronizer<IAccount> {
} catch (e: any) {
console.log(`Failed to check balance ${row.scope}@${contract} - ${e.message}`);
}
this.currentContractScopes++;
this.totalScopesProcessed++;
}
lowerBound = scopes.more;
} while (lowerBound !== '');

// Mark this contract as processed
this.processedScopes = i + 1;
this.completedContracts = i + 1;
console.log(`[DEBUG] Completed contract ${i + 1}/${this.tokenContracts.length}: ${contract}`);
}
console.log(`[DEBUG] All contracts processed`);
Expand All @@ -169,7 +173,7 @@ export class AccountSynchronizer extends Synchronizer<IAccount> {

await this.scanABIs();
console.log(`Number of validated token contracts: ${this.tokenContracts.length}`);
this.totalScopesToProcess = this.tokenContracts.length;
this.totalContracts = this.tokenContracts.length;

await this.setupMongo();

Expand All @@ -184,17 +188,24 @@ export class AccountSynchronizer extends Synchronizer<IAccount> {
}
return;
}
const progressPercent = this.totalScopesToProcess > 0 ? ((this.processedScopes / this.totalScopesToProcess) * 100).toFixed(2) : '0.00';

let statusMessage = '';
if (this.processedScopes >= this.totalScopesToProcess) {
// Percentage is driven by completed contracts (the only total known up front).
// The holder/balance counters below move continuously so a long single-contract
// sync no longer looks stuck at 0%.
const progressPercent = this.totalContracts > 0 ? ((this.completedContracts / this.totalContracts) * 100).toFixed(1) : '0.0';

let statusMessage: string;
if (this.completedContracts >= this.totalContracts) {
statusMessage = 'finalizing database writes...';
Comment on lines +197 to 199

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.

} else if (this.currentContract) {
// currentContractIndex is 0-based and set when a contract starts, so +1 reflects the contract in progress
const contractPos = Math.min(this.currentContractIndex + 1, this.totalContracts);
statusMessage = `contract ${contractPos}/${this.totalContracts} ${this.currentContract} (${this.currentContractScopes} holders) - current: ${this.currentScope || '...'}`;
} else {
statusMessage = this.currentContract ? `${this.currentScope}@${this.currentContract}` : 'initializing...';
statusMessage = 'initializing...';
}

const timestamp = new Date().toISOString().split('T')[1].split('.')[0]; // HH:MM:SS format
console.log(`[${timestamp}] Progress: ${this.processedScopes}/${this.totalScopesToProcess} (${progressPercent}%) - ${statusMessage} - ${this.totalItems} accounts`);
console.log(`[${timestamp}] ${progressPercent}% | holders scanned: ${this.totalScopesProcessed} | balances: ${this.totalItems} | ${statusMessage}`);
}, 1000);

try {
Expand Down
Loading