From 6fda110520684b0e860339b95cdf72214c633fed Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Tue, 2 Jun 2026 12:31:22 +0900 Subject: [PATCH 1/3] make block batch size configurable --- packages/api-sync/source/defaults.ts | 5 +++++ packages/api-sync/source/restore.ts | 8 ++++++-- packages/api-sync/source/service-provider.ts | 6 ++++++ packages/constants/source/environment-variables.ts | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/api-sync/source/defaults.ts b/packages/api-sync/source/defaults.ts index 30cff9899..426a66ed0 100644 --- a/packages/api-sync/source/defaults.ts +++ b/packages/api-sync/source/defaults.ts @@ -3,6 +3,11 @@ import { Environment } from "@mainsail/kernel"; export const defaults = { enabled: Environment.isTrue(EnvironmentVariables.MAINSAIL_API_SYNC_ENABLED), + restore: { + blocks: { + batchSize: Environment.get(EnvironmentVariables.MAINSAIL_API_SYNC_RESTORE_BLOCKS_BATCH_SIZE, 1000), + }, + }, syncInterval: Environment.get(EnvironmentVariables.MAINSAIL_API_SYNC_INTERVAL, 8000), tokenCacheSize: Environment.get(EnvironmentVariables.MAINSAIL_API_SYNC_TOKEN_CACHE_SIZE, 256), tokenWhitelistRefreshInterval: Environment.get( diff --git a/packages/api-sync/source/restore.ts b/packages/api-sync/source/restore.ts index 738a998f0..e3ecbc9ad 100644 --- a/packages/api-sync/source/restore.ts +++ b/packages/api-sync/source/restore.ts @@ -159,6 +159,10 @@ export class Restore { @optional() private readonly snapshotImporter?: Contracts.Snapshot.LegacyImporter; + @inject(Identifiers.ServiceProvider.Configuration) + @tagged("plugin", "api-sync") + private readonly pluginConfiguration!: Contracts.Kernel.PluginConfiguration; + public async restore(): Promise { const isEmpty = await this.databaseService.isEmpty(); const mostRecentCommit = await (isEmpty @@ -299,8 +303,8 @@ export class Restore { validatorRounds, } = context; - const BATCH_SIZE = 1000; - const CHUNK_SIZE = 1000; + const BATCH_SIZE = this.pluginConfiguration.getRequired("restore.blocks.batchSize"); + const CHUNK_SIZE = BATCH_SIZE; const t0 = performance.now(); const genesisBlockNumber = this.configuration.getGenesisHeight(); diff --git a/packages/api-sync/source/service-provider.ts b/packages/api-sync/source/service-provider.ts index 2ead4ba4a..fb6107075 100644 --- a/packages/api-sync/source/service-provider.ts +++ b/packages/api-sync/source/service-provider.ts @@ -39,8 +39,14 @@ export class ServiceProvider extends Providers.ServiceProvider { public configSchema(): Joi.ObjectSchema { return Joi.object({ + restore: Joi.object({ + blocks: Joi.object({ + batchSize: Joi.number().integer().positive().required(), + }), + }), syncInterval: Joi.number().integer().positive().required(), tokenCacheSize: Joi.number().integer().positive().required(), + tokenWhitelistRefreshInterval: Joi.number().integer().positive().required(), }).unknown(true); } diff --git a/packages/constants/source/environment-variables.ts b/packages/constants/source/environment-variables.ts index cdce0d795..75ce98fc5 100644 --- a/packages/constants/source/environment-variables.ts +++ b/packages/constants/source/environment-variables.ts @@ -81,6 +81,8 @@ export const EnvironmentVariableNames = [ "MAINSAIL_API_SYNC_TOKEN_WHITELIST_REMOTE_URL", "MAINSAIL_API_SYNC_LOG_EXTRA", + "MAINSAIL_API_SYNC_RESTORE_BLOCKS_BATCH_SIZE", + // Transaction pool API "MAINSAIL_API_TRANSACTION_POOL_TRUST_PROXY", "MAINSAIL_API_TRANSACTION_POOL_DISABLED", From d0bd99f01e61cc427d2355d75d676dae65a0a454 Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Tue, 2 Jun 2026 12:32:07 +0900 Subject: [PATCH 2/3] fix validator round resetting after batch commit --- packages/api-sync/source/restore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api-sync/source/restore.ts b/packages/api-sync/source/restore.ts index e3ecbc9ad..bc80f15e7 100644 --- a/packages/api-sync/source/restore.ts +++ b/packages/api-sync/source/restore.ts @@ -312,6 +312,7 @@ export class Restore { let ingestedBlocks = 0; let ingestedTransactions = 0; + let totalRound = 0; const multiPaymentContractAddress = this.app.get( EvmConsensusIdentifiers.Contracts.Addresses.MultiPayment, @@ -387,7 +388,6 @@ export class Restore { } }; - let totalRound = 0; for await (const { block, proof } of commits) { blocks.push({ commitRound: proof.round, From c5b7a29779db5509b3285f12618cda190170600f Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Tue, 2 Jun 2026 12:32:29 +0900 Subject: [PATCH 3/3] add regression test --- tests/functional/resync/source/resync.test.ts | 2 +- tests/functional/resync/source/setup.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/functional/resync/source/resync.test.ts b/tests/functional/resync/source/resync.test.ts index 4cd73113f..1410dcec5 100644 --- a/tests/functional/resync/source/resync.test.ts +++ b/tests/functional/resync/source/resync.test.ts @@ -23,7 +23,7 @@ describe<{ }); it("should be ok", async ({ syncNode }) => { - await waitBlock(syncNode, 5); + await waitBlock(syncNode, 54); }); it("should be ok with votes", async ({ syncNode }) => { diff --git a/tests/functional/resync/source/setup.ts b/tests/functional/resync/source/setup.ts index 7e91f9def..018033a52 100644 --- a/tests/functional/resync/source/setup.ts +++ b/tests/functional/resync/source/setup.ts @@ -120,6 +120,11 @@ const setupNode = async (app: Application, dataDirectory: string, configDirector }, "@mainsail/api-sync": { maxSyncAttempts: 1, + restore: { + blocks: { + batchSize: 5, + }, + }, syncInterval: 250, truncateDatabase: "1", },