Skip to content

Commit

Permalink
ingest votes
Browse files Browse the repository at this point in the history
  • Loading branch information
oXtxNt9U committed Oct 30, 2024
1 parent 606faff commit 01e8692
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/api-sync/source/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export class Restore {
@inject(ApiDatabaseIdentifiers.WalletRepositoryFactory)
private readonly walletRepositoryFactory!: ApiDatabaseContracts.WalletRepositoryFactory;

@inject(Identifiers.Evm.ContractService.Consensus)
private readonly consensusContractService!: Contracts.Evm.ConsensusContractService;

public async restore(): Promise<void> {
const mostRecentCommit = await this.databaseService.getLastCommit();
Utils.assert.defined<Contracts.Crypto.Commit>(mostRecentCommit);
Expand Down Expand Up @@ -279,7 +282,7 @@ export class Restore {

if (currentHeight % 10_000 === 0 || currentHeight + BATCH_SIZE > mostRecentCommit.block.header.height) {
const t1 = performance.now();
this.logger.info(`Restored blocks: ${currentHeight.toLocaleString()} elapsed: ${t1 - t0}ms`);
this.logger.info(`Restored blocks: ${context.lastHeight.toLocaleString()} elapsed: ${t1 - t0}ms`);
await new Promise<void>((resolve) => setImmediate(resolve)); // Log might stuck if this line is removed
}

Expand All @@ -305,10 +308,16 @@ export class Restore {
};
}

// TODO: Consensus.sol#getAllVoters
let totalVotes = 0;
for await (const votes of this.consensusContractService.getVotes()) {
context.userAttributes[votes.voterAddress] = {
vote: votes.validatorAddress,
};
totalVotes++;
}

const t1 = performance.now();
this.logger.info(`Read validators from contract ${t1 - t0}ms`);
this.logger.info(`Read ${validators.length} validators and ${totalVotes} votes from contract ${t1 - t0}ms`);
}

async #ingestWallets(context: RestoreContext): Promise<void> {
Expand Down

0 comments on commit 01e8692

Please sign in to comment.