Skip to content

Commit

Permalink
Deprecate postgraphile usage (#359)
Browse files Browse the repository at this point in the history
* Remove use of postgraphile endpoint

* Remove subscription queries from eth-client

* Remove postgraphile config and client from watchers
  • Loading branch information
nikugogoi authored Jun 8, 2022
1 parent 8410da4 commit 548e156
Show file tree
Hide file tree
Showing 56 changed files with 108 additions and 303 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/
out/
.vscode
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ The default config files used by the watchers assume the following services are

* `vulcanize/go-ethereum` on port 8545
* `vulcanize/ipld-eth-server` with native GQL API enabled on port 8082 and RPC API on port 8081
* `postgraphile` on the `vulcanize/ipld-eth-server` database, on port 5000

To check whether the endpoints in watcher config are working, run:

Expand All @@ -31,8 +30,6 @@ yarn check-config --config-file ../erc20-watcher/environments/local.toml
yarn check-config --config-file ../uni-watcher/environments/local.toml
# vulcanize:check-config Checking ipld-eth-server GQL endpoint http://127.0.0.1:8082/graphql +0ms
# vulcanize:check-config ipld-eth-server GQL endpoint working +33ms
# vulcanize:check-config Checking postgraphile GQL endpoint http://127.0.0.1:5000/graphql +1ms
# vulcanize:check-config postgraphile GQL endpoint working +12ms
# vulcanize:check-config Checking RPC endpoint http://127.0.0.1:8081 +1ms
# vulcanize:check-config RPC endpoint working +25ms
```
Expand Down
2 changes: 1 addition & 1 deletion packages/address-watcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ createdb address-watcher

Update `environments/local.toml` with database connection settings for both the databases.

Update the `upstream` config in `environments/local.toml` and provide the `ipld-eth-server` GQL API, the `indexer-db` postgraphile and the tracing API (`debug_traceTransaction` RPC provider) endpoints.
Update the `upstream` config in `environments/local.toml` and provide the `ipld-eth-server` GQL API and the tracing API (`debug_traceTransaction` RPC provider) endpoints.

## Run

Expand Down
1 change: 0 additions & 1 deletion packages/address-watcher/environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

[upstream.ethServer]
gqlApiEndpoint = "http://127.0.0.1:8082/graphql"
gqlPostgraphileEndpoint = "http://127.0.0.1:5000/graphql"

[upstream.cache]
name = "requests"
Expand Down
7 changes: 3 additions & 4 deletions packages/address-watcher/src/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ export const main = async (): Promise<any> => {
await db.init();

assert(upstream, 'Missing upstream config');
const { ethServer: { gqlPostgraphileEndpoint }, traceProviderEndpoint, cache: cacheConfig } = upstream;
assert(gqlPostgraphileEndpoint, 'Missing upstream ethServer.gqlPostgraphileEndpoint');
const { ethServer: { gqlApiEndpoint }, traceProviderEndpoint, cache: cacheConfig } = upstream;
assert(gqlApiEndpoint, 'Missing upstream ethServer.gqlApiEndpoint');
assert(traceProviderEndpoint, 'Missing upstream traceProviderEndpoint');

const cache = await getCache(cacheConfig);
const ethClient = new EthClient({
gqlEndpoint: gqlPostgraphileEndpoint,
gqlSubscriptionEndpoint: gqlPostgraphileEndpoint,
gqlEndpoint: gqlApiEndpoint,
cache
});

Expand Down
4 changes: 1 addition & 3 deletions packages/address-watcher/src/job-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ export const main = async (): Promise<any> => {
await db.init();

assert(upstream, 'Missing upstream config');
const { ethServer: { gqlApiEndpoint, gqlPostgraphileEndpoint }, traceProviderEndpoint, cache: cacheConfig } = upstream;
const { ethServer: { gqlApiEndpoint }, traceProviderEndpoint, cache: cacheConfig } = upstream;
assert(gqlApiEndpoint, 'Missing upstream ethServer.gqlApiEndpoint');
assert(gqlPostgraphileEndpoint, 'Missing upstream ethServer.gqlPostgraphileEndpoint');
assert(traceProviderEndpoint, 'Missing upstream traceProviderEndpoint');

const cache = await getCache(cacheConfig);
const ethClient = new EthClient({
gqlEndpoint: gqlApiEndpoint,
gqlSubscriptionEndpoint: gqlPostgraphileEndpoint,
cache
});

Expand Down
4 changes: 1 addition & 3 deletions packages/address-watcher/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ export const main = async (): Promise<any> => {
await db.init();

assert(upstream, 'Missing upstream config');
const { ethServer: { gqlApiEndpoint, gqlPostgraphileEndpoint }, traceProviderEndpoint, cache: cacheConfig } = upstream;
const { ethServer: { gqlApiEndpoint }, traceProviderEndpoint, cache: cacheConfig } = upstream;
assert(gqlApiEndpoint, 'Missing upstream ethServer.gqlApiEndpoint');
assert(gqlPostgraphileEndpoint, 'Missing upstream ethServer.gqlPostgraphileEndpoint');
assert(traceProviderEndpoint, 'Missing upstream traceProviderEndpoint');

const cache = await getCache(cacheConfig);
const ethClient = new EthClient({
gqlEndpoint: gqlApiEndpoint,
gqlSubscriptionEndpoint: gqlPostgraphileEndpoint,
cache
});

Expand Down
11 changes: 6 additions & 5 deletions packages/address-watcher/src/tx-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ export class TxWatcher {
}
});

this._watchTxSubscription = await this._ethClient.watchTransactions(async (value) => {
const { txHash, ethHeaderCidByHeaderId: { blockHash, blockNumber } } = _.get(value, 'data.listen.relatedNode');
log('watchTransaction', JSON.stringify({ txHash, blockHash, blockNumber }, null, 2));
await this._jobQueue.pushJob(QUEUE_TX_TRACING, { txHash, blockHash, publish: true });
});
// TODO: Update to pull based watcher.
// this._watchTxSubscription = await this._ethClient.watchTransactions(async (value) => {
// const { txHash, ethHeaderCidByHeaderId: { blockHash, blockNumber } } = _.get(value, 'data.listen.relatedNode');
// log('watchTransaction', JSON.stringify({ txHash, blockHash, blockNumber }, null, 2));
// await this._jobQueue.pushJob(QUEUE_TX_TRACING, { txHash, blockHash, publish: true });
// });
}

async publishAddressEventToSubscribers (txHash: string, timeElapsedInSeconds: number): Promise<void> {
Expand Down
1 change: 0 additions & 1 deletion packages/codegen/src/templates/config-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
[upstream]
[upstream.ethServer]
gqlApiEndpoint = "http://127.0.0.1:8082/graphql"
gqlPostgraphileEndpoint = "http://127.0.0.1:5000/graphql"
rpcProviderEndpoint = "http://127.0.0.1:8081"
blockDelayInMilliSecs = 2000

Expand Down
4 changes: 2 additions & 2 deletions packages/codegen/src/templates/events-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export class EventWatcher {
_pubsub: PubSub
_jobQueue: JobQueue

constructor (upstreamConfig: UpstreamConfig, ethClient: EthClient, postgraphileClient: EthClient, indexer: Indexer, pubsub: PubSub, jobQueue: JobQueue) {
constructor (upstreamConfig: UpstreamConfig, ethClient: EthClient, indexer: Indexer, pubsub: PubSub, jobQueue: JobQueue) {
assert(ethClient);
assert(indexer);

this._ethClient = ethClient;
this._indexer = indexer;
this._pubsub = pubsub;
this._jobQueue = jobQueue;
this._baseEventWatcher = new BaseEventWatcher(upstreamConfig, this._ethClient, postgraphileClient, this._indexer, this._pubsub, this._jobQueue);
this._baseEventWatcher = new BaseEventWatcher(upstreamConfig, this._ethClient, this._indexer, this._pubsub, this._jobQueue);
}

getEventIterator (): AsyncIterator<any> {
Expand Down
15 changes: 4 additions & 11 deletions packages/codegen/src/templates/fill-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,12 @@ export const main = async (): Promise<any> => {
await db.init();

assert(upstream, 'Missing upstream config');
const { ethServer: { gqlApiEndpoint, gqlPostgraphileEndpoint, rpcProviderEndpoint, blockDelayInMilliSecs }, cache: cacheConfig } = upstream;
assert(gqlPostgraphileEndpoint, 'Missing upstream ethServer.gqlPostgraphileEndpoint');
const { ethServer: { gqlApiEndpoint, rpcProviderEndpoint, blockDelayInMilliSecs }, cache: cacheConfig } = upstream;

const cache = await getCache(cacheConfig);

const ethClient = new EthClient({
gqlEndpoint: gqlApiEndpoint,
gqlSubscriptionEndpoint: gqlPostgraphileEndpoint,
cache
});

const postgraphileClient = new EthClient({
gqlEndpoint: gqlPostgraphileEndpoint,
cache
});

Expand All @@ -75,19 +68,19 @@ export const main = async (): Promise<any> => {
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
const pubsub = new PubSub();
const indexer = new Indexer(db, ethClient, postgraphileClient, ethProvider);
const indexer = new Indexer(db, ethClient, ethProvider);

const { dbConnectionString, maxCompletionLagInSecs } = jobQueueConfig;
assert(dbConnectionString, 'Missing job queue db connection string');

const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();

const eventWatcher = new EventWatcher(upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue);
const eventWatcher = new EventWatcher(upstream, ethClient, indexer, pubsub, jobQueue);

assert(jobQueueConfig, 'Missing job queue config');

await fillBlocks(jobQueue, indexer, postgraphileClient, eventWatcher, blockDelayInMilliSecs, argv);
await fillBlocks(jobQueue, indexer, eventWatcher, blockDelayInMilliSecs, argv);
};

main().catch(err => {
Expand Down
8 changes: 3 additions & 5 deletions packages/codegen/src/templates/indexer-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,20 @@ export class Indexer {
_db: Database
_ethClient: EthClient
_ethProvider: BaseProvider
_postgraphileClient: EthClient;
_baseIndexer: BaseIndexer

_abi: JsonFragment[]
_storageLayout: StorageLayout
_contract: ethers.utils.Interface

constructor (db: Database, ethClient: EthClient, postgraphileClient: EthClient, ethProvider: BaseProvider) {
constructor (db: Database, ethClient: EthClient, ethProvider: BaseProvider) {
assert(db);
assert(ethClient);

this._db = db;
this._ethClient = ethClient;
this._postgraphileClient = postgraphileClient;
this._ethProvider = ethProvider;
this._baseIndexer = new BaseIndexer(this._db, this._ethClient, this._postgraphileClient, this._ethProvider);
this._baseIndexer = new BaseIndexer(this._db, this._ethClient, this._ethProvider);

const { abi, storageLayout } = artifacts;

Expand Down Expand Up @@ -306,7 +304,7 @@ export class Indexer {
}
]
}
} = await this._postgraphileClient.getBlockWithTransactions({ blockHash });
} = await this._ethClient.getBlockWithTransactions({ blockHash });

const transactionMap = transactions.reduce((acc: {[key: string]: any}, transaction: {[key: string]: any}) => {
acc[transaction.txHash] = transaction;
Expand Down
11 changes: 2 additions & 9 deletions packages/codegen/src/templates/job-runner-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,18 @@ export const main = async (): Promise<any> => {
await db.init();

assert(upstream, 'Missing upstream config');
const { ethServer: { gqlApiEndpoint, gqlPostgraphileEndpoint, rpcProviderEndpoint }, cache: cacheConfig } = upstream;
const { ethServer: { gqlApiEndpoint, rpcProviderEndpoint }, cache: cacheConfig } = upstream;
assert(gqlApiEndpoint, 'Missing upstream ethServer.gqlApiEndpoint');
assert(gqlPostgraphileEndpoint, 'Missing upstream ethServer.gqlPostgraphileEndpoint');

const cache = await getCache(cacheConfig);

const ethClient = new EthClient({
gqlEndpoint: gqlApiEndpoint,
gqlSubscriptionEndpoint: gqlPostgraphileEndpoint,
cache
});

const postgraphileClient = new EthClient({
gqlEndpoint: gqlPostgraphileEndpoint,
cache
});

const ethProvider = getCustomProvider(rpcProviderEndpoint);
const indexer = new Indexer(db, ethClient, postgraphileClient, ethProvider);
const indexer = new Indexer(db, ethClient, ethProvider);

assert(jobQueueConfig, 'Missing job queue config');

Expand Down
4 changes: 2 additions & 2 deletions packages/codegen/src/templates/readme-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@

* Update the [config](./environments/local.toml) with database connection settings.

* Update the `upstream` config in the [config file](./environments/local.toml) and provide the `ipld-eth-server` GQL API and the `indexer-db` postgraphile endpoints.
* Update the `upstream` config in the [config file](./environments/local.toml) and provide the `ipld-eth-server` GQL API endpoint.

## Customize

* Indexing on an event:

* Edit the custom hook function `handleEvent` (triggered on an event) in [hooks.ts](./src/hooks.ts) to perform corresponding indexing using the `Indexer` object.

* Refer to [hooks.example.ts](./src/hooks.example.ts) for an example hook function for events in an ERC20 contract.

## Run
Expand Down
13 changes: 3 additions & 10 deletions packages/codegen/src/templates/server-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,19 @@ export const main = async (): Promise<any> => {
await db.init();

assert(upstream, 'Missing upstream config');
const { ethServer: { gqlApiEndpoint, gqlPostgraphileEndpoint, rpcProviderEndpoint }, cache: cacheConfig } = upstream;
const { ethServer: { gqlApiEndpoint, rpcProviderEndpoint }, cache: cacheConfig } = upstream;
assert(gqlApiEndpoint, 'Missing upstream ethServer.gqlApiEndpoint');
assert(gqlPostgraphileEndpoint, 'Missing upstream ethServer.gqlPostgraphileEndpoint');

const cache = await getCache(cacheConfig);

const ethClient = new EthClient({
gqlEndpoint: gqlApiEndpoint,
gqlSubscriptionEndpoint: gqlPostgraphileEndpoint,
cache
});

const postgraphileClient = new EthClient({
gqlEndpoint: gqlPostgraphileEndpoint,
cache
});

const ethProvider = getCustomProvider(rpcProviderEndpoint);

const indexer = new Indexer(db, ethClient, postgraphileClient, ethProvider);
const indexer = new Indexer(db, ethClient, ethProvider);

// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
Expand All @@ -81,7 +74,7 @@ export const main = async (): Promise<any> => {

const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });

const eventWatcher = new EventWatcher(upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue);
const eventWatcher = new EventWatcher(upstream, ethClient, indexer, pubsub, jobQueue);

if (watcherKind === KIND_ACTIVE) {
await jobQueue.start();
Expand Down
2 changes: 1 addition & 1 deletion packages/erc20-watcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ createdb erc20-watcher

Update `environments/local.toml` with database connection settings for both the databases.

Update the `upstream` config in `environments/local.toml` and provide the `ipld-eth-server` GQL API and the `indexer-db` postgraphile endpoints.
Update the `upstream` config in `environments/local.toml` and provide the `ipld-eth-server` GQL API endpoint.

## Run

Expand Down
1 change: 0 additions & 1 deletion packages/erc20-watcher/environments/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
[upstream]
[upstream.ethServer]
gqlApiEndpoint = "http://127.0.0.1:8082/graphql"
gqlPostgraphileEndpoint = "http://127.0.0.1:5000/graphql"
rpcProviderEndpoint = "http://127.0.0.1:8081"
blockDelayInMilliSecs = 2000

Expand Down
4 changes: 2 additions & 2 deletions packages/erc20-watcher/src/cli/reset-cmds/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const handler = async (argv: any): Promise<void> => {
const config = await getConfig(argv.configFile);
await resetJobs(config);
const { jobQueue: jobQueueConfig } = config;
const { dbConfig, serverConfig, ethClient, postgraphileClient, ethProvider } = await getResetConfig(config);
const { dbConfig, serverConfig, ethClient, ethProvider } = await getResetConfig(config);

// Initialize database.
const db = new Database(dbConfig);
Expand All @@ -44,7 +44,7 @@ export const handler = async (argv: any): Promise<void> => {

const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });

const indexer = new Indexer(db, ethClient, postgraphileClient, ethProvider, jobQueue, serverConfig.mode);
const indexer = new Indexer(db, ethClient, ethProvider, jobQueue, serverConfig.mode);

const syncStatus = await indexer.getSyncStatus();
assert(syncStatus, 'Missing syncStatus');
Expand Down
4 changes: 2 additions & 2 deletions packages/erc20-watcher/src/cli/watch-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { Indexer } from '../indexer';

const config: Config = await getConfig(argv.configFile);
const { database: dbConfig, server: { mode }, jobQueue: jobQueueConfig } = config;
const { ethClient, postgraphileClient, ethProvider } = await getResetConfig(config);
const { ethClient, ethProvider } = await getResetConfig(config);

assert(dbConfig);

Expand All @@ -53,7 +53,7 @@ import { Indexer } from '../indexer';
const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();

const indexer = new Indexer(db, ethClient, postgraphileClient, ethProvider, jobQueue, mode);
const indexer = new Indexer(db, ethClient, ethProvider, jobQueue, mode);

await indexer.watchContract(argv.address, argv.startingBlock);

Expand Down
4 changes: 2 additions & 2 deletions packages/erc20-watcher/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export class EventWatcher {
_pubsub: PubSub
_jobQueue: JobQueue

constructor (upstreamConfig: UpstreamConfig, ethClient: EthClient, postgraphileClient: EthClient, indexer: Indexer, pubsub: PubSub, jobQueue: JobQueue) {
constructor (upstreamConfig: UpstreamConfig, ethClient: EthClient, indexer: Indexer, pubsub: PubSub, jobQueue: JobQueue) {
assert(ethClient);
assert(indexer);

this._ethClient = ethClient;
this._indexer = indexer;
this._pubsub = pubsub;
this._jobQueue = jobQueue;
this._baseEventWatcher = new BaseEventWatcher(upstreamConfig, this._ethClient, postgraphileClient, this._indexer, this._pubsub, this._jobQueue);
this._baseEventWatcher = new BaseEventWatcher(upstreamConfig, this._ethClient, this._indexer, this._pubsub, this._jobQueue);
}

getEventIterator (): AsyncIterator<any> {
Expand Down
13 changes: 3 additions & 10 deletions packages/erc20-watcher/src/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,11 @@ export const main = async (): Promise<any> => {
await db.init();

assert(upstream, 'Missing upstream config');
const { ethServer: { gqlApiEndpoint, gqlPostgraphileEndpoint, rpcProviderEndpoint, blockDelayInMilliSecs }, cache: cacheConfig } = upstream;
assert(gqlPostgraphileEndpoint, 'Missing upstream ethServer.gqlPostgraphileEndpoint');
const { ethServer: { gqlApiEndpoint, rpcProviderEndpoint, blockDelayInMilliSecs }, cache: cacheConfig } = upstream;

const cache = await getCache(cacheConfig);
const ethClient = new EthClient({
gqlEndpoint: gqlApiEndpoint,
gqlSubscriptionEndpoint: gqlPostgraphileEndpoint,
cache
});

const postgraphileClient = new EthClient({
gqlEndpoint: gqlPostgraphileEndpoint,
cache
});

Expand All @@ -94,9 +87,9 @@ export const main = async (): Promise<any> => {
const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();

const indexer = new Indexer(db, ethClient, postgraphileClient, ethProvider, jobQueue, mode);
const indexer = new Indexer(db, ethClient, ethProvider, jobQueue, mode);

const eventWatcher = new EventWatcher(upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue);
const eventWatcher = new EventWatcher(upstream, ethClient, indexer, pubsub, jobQueue);

assert(jobQueueConfig, 'Missing job queue config');

Expand Down
Loading

0 comments on commit 548e156

Please sign in to comment.