Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions packages/api-sync/source/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>(EnvironmentVariables.MAINSAIL_API_SYNC_RESTORE_BLOCKS_BATCH_SIZE, 1000),
},
},
syncInterval: Environment.get<number>(EnvironmentVariables.MAINSAIL_API_SYNC_INTERVAL, 8000),
tokenCacheSize: Environment.get<number>(EnvironmentVariables.MAINSAIL_API_SYNC_TOKEN_CACHE_SIZE, 256),
tokenWhitelistRefreshInterval: Environment.get<number>(
Expand Down
10 changes: 7 additions & 3 deletions packages/api-sync/source/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const isEmpty = await this.databaseService.isEmpty();
const mostRecentCommit = await (isEmpty
Expand Down Expand Up @@ -299,15 +303,16 @@ export class Restore {
validatorRounds,
} = context;

const BATCH_SIZE = 1000;
const CHUNK_SIZE = 1000;
const BATCH_SIZE = this.pluginConfiguration.getRequired<number>("restore.blocks.batchSize");
const CHUNK_SIZE = BATCH_SIZE;
const t0 = performance.now();

const genesisBlockNumber = this.configuration.getGenesisHeight();
let currentBlockNumber = genesisBlockNumber;

let ingestedBlocks = 0;
let ingestedTransactions = 0;
let totalRound = 0;

const multiPaymentContractAddress = this.app.get<string>(
EvmConsensusIdentifiers.Contracts.Addresses.MultiPayment,
Expand Down Expand Up @@ -383,7 +388,6 @@ export class Restore {
}
};

let totalRound = 0;
for await (const { block, proof } of commits) {
blocks.push({
commitRound: proof.round,
Expand Down
6 changes: 6 additions & 0 deletions packages/api-sync/source/service-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/constants/source/environment-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/resync/source/resync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
5 changes: 5 additions & 0 deletions tests/functional/resync/source/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
Loading