Skip to content

Commit

Permalink
Deprecate postgraphile usage (#122)
Browse files Browse the repository at this point in the history
* Deprecate postgraphile usage

* Change endpoint in watcher config

* Remove subscription queries from eth-client

* Remove postgraphile config and client from watchers

Co-authored-by: nabarun <nabarun@deepstacksoft.com>
  • Loading branch information
prathamesh0 and nikugogoi authored Jun 8, 2022
1 parent e4b9596 commit 71d3433
Show file tree
Hide file tree
Showing 90 changed files with 207 additions and 321 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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
* `postgraphile` on the `vulcanize/ipld-eth-server` database, on port 5000

### Note

Expand Down
1 change: 0 additions & 1 deletion ipld-demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

* [vulcanize/go-ethereum](https://github.com/vulcanize/go-ethereum) ([v1.10.17-statediff-3.2.0](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.17-statediff-3.2.0)) on port 8545.
* [vulcanize/ipld-eth-server](https://github.com/vulcanize/ipld-eth-server) ([v3.0.0](https://github.com/vulcanize/ipld-eth-server/releases/tag/v3.0.0)) with native GQL API enabled on port 8082 and RPC API enabled on port 8081.
* [postgraphile](https://github.com/vulcanize/postgraphile) ([v1.1.1](https://github.com/vulcanize/postgraphile/releases/tag/v1.1.1)) on the `vulcanize/ipld-eth-server` database, on port 5000

* Deploy `Example` contract:

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
6 changes: 3 additions & 3 deletions packages/codegen/src/templates/checkpoint-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ const main = async (): Promise<void> => {
}).argv;

const config: Config = await getConfig(argv.configFile);
const { ethClient, postgraphileClient, ethProvider } = await initClients(config);
const { ethClient, ethProvider } = await initClients(config);

const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);

const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
Expand All @@ -60,7 +60,7 @@ const main = async (): Promise<void> => {
const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();

const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, jobQueue, graphWatcher);
const indexer = new Indexer(config.server, db, ethClient, ethProvider, jobQueue, graphWatcher);
await indexer.init();

graphWatcher.setIndexer(indexer);
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 @@ -30,7 +30,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 @@ -32,15 +32,15 @@ export class EventWatcher implements EventWatcherInterface {
_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
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ const main = async (): Promise<void> => {
}).argv;

const config: Config = await getConfig(argv.configFile);
const { ethClient, postgraphileClient, ethProvider } = await initClients(config);
const { ethClient, ethProvider } = await initClients(config);

const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);

const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
Expand All @@ -57,7 +57,7 @@ const main = async (): Promise<void> => {
const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();

const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, jobQueue, graphWatcher);
const indexer = new Indexer(config.server, db, ethClient, ethProvider, jobQueue, graphWatcher);
await indexer.init();

graphWatcher.setIndexer(indexer);
Expand Down
8 changes: 4 additions & 4 deletions packages/codegen/src/templates/fill-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export const main = async (): Promise<any> => {
}).argv;

const config: Config = await getConfig(argv.configFile);
const { ethClient, postgraphileClient, ethProvider } = await initClients(config);
const { ethClient, ethProvider } = await initClients(config);

const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);

const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
Expand All @@ -72,7 +72,7 @@ export const main = async (): Promise<any> => {
const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();

const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, jobQueue, graphWatcher);
const indexer = new Indexer(config.server, db, ethClient, ethProvider, jobQueue, graphWatcher);
await indexer.init();

graphWatcher.setIndexer(indexer);
Expand All @@ -84,7 +84,7 @@ export const main = async (): Promise<any> => {
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
const pubsub = new PubSub();

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

await fillBlocks(jobQueue, indexer, eventWatcher, config.upstream.ethServer.blockDelayInMilliSecs, argv);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ export const main = async (): Promise<any> => {
}).argv;

const config: Config = await getConfig(argv.configFile);
const { ethClient, postgraphileClient, ethProvider } = await initClients(config);
const { ethClient, ethProvider } = await initClients(config);

const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);

// 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 @@ -65,15 +65,15 @@ export const main = async (): Promise<any> => {
const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();

const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, jobQueue, graphWatcher);
const indexer = new Indexer(config.server, db, ethClient, ethProvider, jobQueue, graphWatcher);
await indexer.init();

graphWatcher.setIndexer(indexer);
{{#if subgraphPath}}
await graphWatcher.init();
{{/if}}

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

// Import data.
const importFilePath = path.resolve(argv.importFile);
Expand Down
9 changes: 3 additions & 6 deletions packages/codegen/src/templates/indexer-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export class Indexer implements IPLDIndexerInterface {
_db: Database
_ethClient: EthClient
_ethProvider: BaseProvider
_postgraphileClient: EthClient
_baseIndexer: BaseIndexer
_serverConfig: ServerConfig
_graphWatcher: GraphWatcher;
Expand All @@ -113,18 +112,16 @@ export class Indexer implements IPLDIndexerInterface {
_entityTypesMap: Map<string, { [key: string]: string }>
_relationsMap: Map<any, { [key: string]: any }>

constructor (serverConfig: ServerConfig, db: Database, ethClient: EthClient, postgraphileClient: EthClient, ethProvider: BaseProvider, jobQueue: JobQueue, graphWatcher: GraphWatcher) {
constructor (serverConfig: ServerConfig, db: Database, ethClient: EthClient, ethProvider: BaseProvider, jobQueue: JobQueue, graphWatcher: GraphWatcher) {
assert(db);
assert(ethClient);
assert(postgraphileClient);

this._db = db;
this._ethClient = ethClient;
this._postgraphileClient = postgraphileClient;
this._ethProvider = ethProvider;
this._serverConfig = serverConfig;
this._ipfsClient = new IPFSClient(this._serverConfig.ipfsApiAddr);
this._baseIndexer = new BaseIndexer(this._serverConfig, this._db, this._ethClient, this._postgraphileClient, this._ethProvider, jobQueue, this._ipfsClient);
this._baseIndexer = new BaseIndexer(this._serverConfig, this._db, this._ethClient, this._ethProvider, jobQueue, this._ipfsClient);
this._graphWatcher = graphWatcher;

this._abiMap = new Map();
Expand Down Expand Up @@ -707,7 +704,7 @@ export class Indexer implements IPLDIndexerInterface {
assert(blockHash);

const logsPromise = this._ethClient.getLogs({ blockHash });
const transactionsPromise = this._postgraphileClient.getBlockWithTransactions({ blockHash });
const transactionsPromise = this._ethClient.getBlockWithTransactions({ blockHash });

let [
{ block, logs },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ const main = async (): Promise<void> => {
}).argv;

const config: Config = await getConfig(argv.configFile);
const { ethClient, postgraphileClient, ethProvider } = await initClients(config);
const { ethClient, ethProvider } = await initClients(config);

const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);

const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
Expand All @@ -57,7 +57,7 @@ const main = async (): Promise<void> => {
const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();

const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, jobQueue, graphWatcher);
const indexer = new Indexer(config.server, db, ethClient, ethProvider, jobQueue, graphWatcher);
await indexer.init();

graphWatcher.setIndexer(indexer);
Expand Down
6 changes: 3 additions & 3 deletions packages/codegen/src/templates/job-runner-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ export const main = async (): Promise<any> => {
.argv;

const config: Config = await getConfig(argv.f);
const { ethClient, postgraphileClient, ethProvider } = await initClients(config);
const { ethClient, ethProvider } = await initClients(config);

const db = new Database(config.database);
await db.init();

const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);

const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
Expand All @@ -267,7 +267,7 @@ export const main = async (): Promise<any> => {
const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();

const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, jobQueue, graphWatcher);
const indexer = new Indexer(config.server, db, ethClient, ethProvider, jobQueue, graphWatcher);
await indexer.init();

graphWatcher.setIndexer(indexer);
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/src/templates/readme-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

* Update the database connection settings.

* Update the `upstream` config and provide the `ipld-eth-server` GQL API and the `indexer-db` postgraphile endpoints.
* Update the `upstream` config and provide the `ipld-eth-server` GQL API endpoint.

* Update the `server` config with state checkpoint settings and provide the IPFS API address.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const builder = {
export const handler = async (argv: any): Promise<void> => {
const config = await getConfig(argv.configFile);
await resetJobs(config);
const { ethClient, postgraphileClient, ethProvider } = await initClients(config);
const { ethClient, ethProvider } = await initClients(config);

// Initialize database.
const db = new Database(config.database);
Expand All @@ -42,7 +42,7 @@ export const handler = async (argv: any): Promise<void> => {
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*'));
await graphDb.init();

const graphWatcher = new GraphWatcher(graphDb, postgraphileClient, ethProvider, config.server);
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server);

const jobQueueConfig = config.jobQueue;
assert(jobQueueConfig, 'Missing job queue config');
Expand All @@ -53,7 +53,7 @@ export const handler = async (argv: any): Promise<void> => {
const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs });
await jobQueue.start();

const indexer = new Indexer(config.server, db, ethClient, postgraphileClient, ethProvider, jobQueue, graphWatcher);
const indexer = new Indexer(config.server, db, ethClient, ethProvider, jobQueue, graphWatcher);
await indexer.init();

graphWatcher.setIndexer(indexer);
Expand Down
Loading

0 comments on commit 71d3433

Please sign in to comment.