Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sequential RPC method requests when Nitro payments is configured #5

Merged
merged 3 commits into from
Oct 4, 2023
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
18 changes: 14 additions & 4 deletions packages/core/src/Ponder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
)
);
Expand Down Expand Up @@ -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();
}
}
)
);
Expand Down Expand Up @@ -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 }) => {
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/config/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/realtime-sync/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export class RealtimeSyncService extends Emittery<RealtimeSyncEvents> {
);

// 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 () => {
Expand Down