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

Renaming #414

Merged
merged 4 commits into from
Nov 8, 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
103 changes: 50 additions & 53 deletions packages/core/src/Ponder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import { buildDatabase } from "@/config/database";
import { type Network, buildNetwork } from "@/config/networks";
import { type Options } from "@/config/options";
import { UserErrorService } from "@/errors/service";
import { EventAggregatorService } from "@/event-aggregator/service";
import { PostgresEventStore } from "@/event-store/postgres/store";
import { SqliteEventStore } from "@/event-store/sqlite/store";
import { type EventStore } from "@/event-store/store";
import { HistoricalSyncService } from "@/historical-sync/service";
import { IndexingService } from "@/indexing/service";
import { PostgresIndexingStore } from "@/indexing-store/postgres/store";
import { SqliteIndexingStore } from "@/indexing-store/sqlite/store";
import { type IndexingStore } from "@/indexing-store/store";
import { LoggerService } from "@/logs/service";
import { MetricsService } from "@/metrics/service";
import { RealtimeSyncService } from "@/realtime-sync/service";
import { ServerService } from "@/server/service";
import { SyncGateway } from "@/sync-gateway/service";
import { HistoricalSyncService } from "@/sync-historical/service";
import { RealtimeSyncService } from "@/sync-realtime/service";
import { PostgresSyncStore } from "@/sync-store/postgres/store";
import { SqliteSyncStore } from "@/sync-store/sqlite/store";
import { type SyncStore } from "@/sync-store/store";
import { TelemetryService } from "@/telemetry/service";
import { UiService } from "@/ui/service";
import { PostgresUserStore } from "@/user-store/postgres/store";
import { SqliteUserStore } from "@/user-store/sqlite/store";
import { type UserStore } from "@/user-store/store";

import { hydrateIndexingFunctions } from "./build/functions";
import { buildSources, Source } from "./config/sources";
Expand All @@ -42,17 +42,17 @@ export class Ponder {
sources: Source[] = undefined!;

// Sync services
eventStore: EventStore = undefined!;
syncStore: SyncStore = undefined!;
syncServices: {
network: Network;
sources: Source[];
historical: HistoricalSyncService;
realtime: RealtimeSyncService;
}[] = undefined!;
eventAggregatorService: EventAggregatorService = undefined!;
syncGatewayService: SyncGateway = undefined!;

// Indexing services
userStore: UserStore = undefined!;
indexingStore: IndexingStore = undefined!;
indexingService: IndexingService = undefined!;

// Misc services
Expand All @@ -75,12 +75,12 @@ export class Ponder {
}

async setup({
eventStore,
userStore,
syncStore,
indexingStore,
}: {
// These options are only used for testing.
eventStore?: EventStore;
userStore?: UserStore;
syncStore?: SyncStore;
indexingStore?: IndexingStore;
} = {}) {
this.common.logger.debug({
service: "app",
Expand All @@ -103,17 +103,17 @@ export class Ponder {
}

const database = buildDatabase({ common: this.common, config });
this.eventStore =
eventStore ??
this.syncStore =
syncStore ??
(database.kind === "sqlite"
? new SqliteEventStore({ db: database.db })
: new PostgresEventStore({ pool: database.pool }));
? new SqliteSyncStore({ db: database.db })
: new PostgresSyncStore({ pool: database.pool }));

this.userStore =
userStore ??
this.indexingStore =
indexingStore ??
(database.kind === "sqlite"
? new SqliteUserStore({ db: database.db })
: new PostgresUserStore({ pool: database.pool }));
? new SqliteIndexingStore({ db: database.db })
: new PostgresIndexingStore({ pool: database.pool }));

this.sources = buildSources({ config });

Expand Down Expand Up @@ -142,36 +142,36 @@ export class Ponder {
sources: sourcesForNetwork,
historical: new HistoricalSyncService({
common: this.common,
eventStore: this.eventStore,
syncStore: this.syncStore,
network,
sources: sourcesForNetwork,
}),
realtime: new RealtimeSyncService({
common: this.common,
eventStore: this.eventStore,
syncStore: this.syncStore,
network,
sources: sourcesForNetwork,
}),
});
});
this.eventAggregatorService = new EventAggregatorService({
this.syncGatewayService = new SyncGateway({
common: this.common,
eventStore: this.eventStore,
syncStore: this.syncStore,
networks: networksToSync,
sources: this.sources,
});

this.indexingService = new IndexingService({
common: this.common,
eventStore: this.eventStore,
userStore: this.userStore,
eventAggregatorService: this.eventAggregatorService,
syncStore: this.syncStore,
indexingStore: this.indexingStore,
syncGatewayService: this.syncGatewayService,
sources: this.sources,
});

this.serverService = new ServerService({
common: this.common,
userStore: this.userStore,
indexingStore: this.indexingStore,
});
this.codegenService = new CodegenService({
common: this.common,
Expand All @@ -190,7 +190,7 @@ export class Ponder {
this.codegenService.generateAppFile();

// One-time setup for some services.
await this.eventStore.migrateUp();
await this.syncStore.migrateUp();
await this.serverService.start();

// Finally, load the schema + indexing functions which will trigger
Expand All @@ -205,7 +205,7 @@ export class Ponder {
properties: {
command: "ponder dev",
contractCount: this.sources.length,
databaseKind: this.eventStore.kind,
databaseKind: this.syncStore.kind,
},
});

Expand All @@ -226,7 +226,7 @@ export class Ponder {
properties: {
command: "ponder start",
contractCount: this.sources.length,
databaseKind: this.eventStore.kind,
databaseKind: this.syncStore.kind,
},
});

Expand Down Expand Up @@ -254,7 +254,7 @@ export class Ponder {
}

async kill() {
this.eventAggregatorService.clearListeners();
this.syncGatewayService.clearListeners();

this.common.telemetry.record({
event: "App Killed",
Expand All @@ -276,8 +276,8 @@ export class Ponder {
await this.serverService.kill();
await this.common.telemetry.kill();

await this.userStore.kill();
await this.eventStore.kill();
await this.indexingStore.kill();
await this.syncStore.kill();

this.common.logger.debug({
service: "app",
Expand Down Expand Up @@ -326,50 +326,47 @@ export class Ponder {
const { chainId } = network;

historical.on("historicalCheckpoint", ({ blockTimestamp }) => {
this.eventAggregatorService.handleNewHistoricalCheckpoint({
this.syncGatewayService.handleNewHistoricalCheckpoint({
chainId,
timestamp: blockTimestamp,
});
});

historical.on("syncComplete", () => {
this.eventAggregatorService.handleHistoricalSyncComplete({
this.syncGatewayService.handleHistoricalSyncComplete({
chainId,
});
});

realtime.on("realtimeCheckpoint", ({ blockTimestamp }) => {
this.eventAggregatorService.handleNewRealtimeCheckpoint({
this.syncGatewayService.handleNewRealtimeCheckpoint({
chainId,
timestamp: blockTimestamp,
});
});

realtime.on("finalityCheckpoint", ({ blockTimestamp }) => {
this.eventAggregatorService.handleNewFinalityCheckpoint({
this.syncGatewayService.handleNewFinalityCheckpoint({
chainId,
timestamp: blockTimestamp,
});
});

realtime.on("shallowReorg", ({ commonAncestorBlockTimestamp }) => {
this.eventAggregatorService.handleReorg({
this.syncGatewayService.handleReorg({
commonAncestorTimestamp: commonAncestorBlockTimestamp,
});
});
});

this.eventAggregatorService.on("newCheckpoint", async () => {
this.syncGatewayService.on("newCheckpoint", async () => {
await this.indexingService.processEvents();
});

this.eventAggregatorService.on(
"reorg",
async ({ commonAncestorTimestamp }) => {
await this.indexingService.handleReorg({ commonAncestorTimestamp });
await this.indexingService.processEvents();
}
);
this.syncGatewayService.on("reorg", async ({ commonAncestorTimestamp }) => {
await this.indexingService.handleReorg({ commonAncestorTimestamp });
await this.indexingService.processEvents();
});

this.indexingService.on("eventsProcessed", ({ toTimestamp }) => {
if (this.serverService.isHistoricalIndexingComplete) return;
Expand All @@ -378,8 +375,8 @@ export class Ponder {
// the new toTimestamp is greater than the historical sync completion timestamp,
// historical event processing is complete, and the server should begin responding as healthy.
if (
this.eventAggregatorService.historicalSyncCompletedAt &&
toTimestamp >= this.eventAggregatorService.historicalSyncCompletedAt
this.syncGatewayService.historicalSyncCompletedAt &&
toTimestamp >= this.syncGatewayService.historicalSyncCompletedAt
) {
this.serverService.setIsHistoricalIndexingComplete();
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/_test/art-gobblers/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { rmSync } from "node:fs";
import request from "supertest";
import { type TestContext, afterEach, beforeEach, expect, test } from "vitest";

import { setupEventStore, setupUserStore } from "@/_test/setup";
import { setupIndexingStore, setupSyncStore } from "@/_test/setup";
import { buildOptions } from "@/config/options";
import { Ponder } from "@/Ponder";

beforeEach((context) => setupEventStore(context));
beforeEach((context) => setupUserStore(context));
beforeEach((context) => setupSyncStore(context));
beforeEach((context) => setupIndexingStore(context));

const setup = async ({ context }: { context: TestContext }) => {
const options = buildOptions({
Expand All @@ -25,8 +25,8 @@ const setup = async ({ context }: { context: TestContext }) => {

const ponder = new Ponder({ options: testOptions });
await ponder.setup({
eventStore: context.eventStore,
userStore: context.userStore,
syncStore: context.syncStore,
indexingStore: context.indexingStore,
});

await ponder.start();
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/_test/ens/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { rmSync } from "node:fs";
import request from "supertest";
import { type TestContext, afterEach, beforeEach, expect, test } from "vitest";

import { setupEventStore, setupUserStore } from "@/_test/setup";
import { setupIndexingStore, setupSyncStore } from "@/_test/setup";
import { buildOptions } from "@/config/options";
import { Ponder } from "@/Ponder";

beforeEach((context) => setupEventStore(context));
beforeEach((context) => setupUserStore(context));
beforeEach((context) => setupSyncStore(context));
beforeEach((context) => setupIndexingStore(context));

const setup = async ({ context }: { context: TestContext }) => {
const options = buildOptions({
Expand All @@ -26,8 +26,8 @@ const setup = async ({ context }: { context: TestContext }) => {

const ponder = new Ponder({ options: testOptions });
await ponder.setup({
eventStore: context.eventStore,
userStore: context.userStore,
syncStore: context.syncStore,
indexingStore: context.indexingStore,
});

await ponder.start();
Expand Down
Loading
Loading