From 01e8692fde3c50e9239b6bb6b48bd1f58433bc8e Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:31:10 +0900 Subject: [PATCH] ingest votes --- packages/api-sync/source/restore.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/api-sync/source/restore.ts b/packages/api-sync/source/restore.ts index 889e20186..999ff6b94 100644 --- a/packages/api-sync/source/restore.ts +++ b/packages/api-sync/source/restore.ts @@ -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 { const mostRecentCommit = await this.databaseService.getLastCommit(); Utils.assert.defined(mostRecentCommit); @@ -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((resolve) => setImmediate(resolve)); // Log might stuck if this line is removed } @@ -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 {