diff --git a/packages/core/src/Ponder.ts b/packages/core/src/Ponder.ts index c603719ad..b19f72af7 100644 --- a/packages/core/src/Ponder.ts +++ b/packages/core/src/Ponder.ts @@ -264,9 +264,11 @@ export class Ponder { async ({ historicalSyncService, realtimeSyncService }) => { const blockNumbers = await realtimeSyncService.setup(); await historicalSyncService.setup(blockNumbers); - historicalSyncService.start(); - realtimeSyncService.start(); + + if (!this.paymentService) { + realtimeSyncService.start(); + } } ) ); @@ -301,9 +303,11 @@ export class Ponder { async ({ historicalSyncService, realtimeSyncService }) => { const blockNumbers = await realtimeSyncService.setup(); await historicalSyncService.setup(blockNumbers); - historicalSyncService.start(); - realtimeSyncService.start(); + + if (!this.paymentService) { + realtimeSyncService.start(); + } } ) ); @@ -393,6 +397,12 @@ export class Ponder { this.eventAggregatorService.handleHistoricalSyncComplete({ chainId, }); + + // If payment service is setup, start the realtime sync service after historical sync service. + // This will avoid parallel requests to RPC endpoint + if (this.paymentService) { + realtimeSyncService.start(); + } }); realtimeSyncService.on("realtimeCheckpoint", ({ timestamp }) => { diff --git a/packages/core/src/config/networks.ts b/packages/core/src/config/networks.ts index 2f5ad22d2..a2dbb074c 100644 --- a/packages/core/src/config/networks.ts +++ b/packages/core/src/config/networks.ts @@ -4,7 +4,11 @@ import { mainnet } from "viem/chains"; import type { ResolvedConfig } from "@/config/config"; import { PaymentService } from "@/payment/service"; -const PAID_RPC_METHODS = ["eth_getLogs"]; +const PAID_RPC_METHODS = [ + "eth_getLogs", + "eth_getBlockByNumber", + "eth_getBlockByHash", +]; export type Network = { name: string; diff --git a/packages/core/src/realtime-sync/service.ts b/packages/core/src/realtime-sync/service.ts index 0dee26967..68ead2fdf 100644 --- a/packages/core/src/realtime-sync/service.ts +++ b/packages/core/src/realtime-sync/service.ts @@ -404,7 +404,7 @@ export class RealtimeSyncService extends Emittery { ); // Fetch all missing blocks using a request concurrency limit of 10. - const limit = pLimit(10); + const limit = pLimit(this.network.maxRpcRequestConcurrency); const missingBlockRequests = missingBlockNumbers.map((number) => { return limit(async () => {