Skip to content

Commit

Permalink
Improve block processing time and GQL queries in uniswap-info-watcher (
Browse files Browse the repository at this point in the history
…#366)

* Implement cache for latest updated entities to be used in mapping code

* Get latest entity in frothy region from cache

* Add logs for time breakup

* Load relations according to GQL query

* Implement distinctOn query to improve performance for suitable entity tables

* Add metrics for cache and DB hits in event processing

* Use cached entities for getFactory

* Avoid use of a loop for power operation on big decimal

* Use distinctOn queries for pool and token entities

* Fix updating cache with pruned entities

* Performance improvement for singular entity queries

* Add metric for eth_calls made in event processing

Co-authored-by: prathamesh0 <[email protected]>
  • Loading branch information
nikugogoi and prathamesh0 authored Oct 4, 2022
1 parent b4917fd commit f0c71e2
Show file tree
Hide file tree
Showing 14 changed files with 953 additions and 686 deletions.
4 changes: 4 additions & 0 deletions packages/erc20-watcher/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ export class Indexer {
await this.triggerIndexingOnEvent(event);
}

async processBlock (blockProgress: BlockProgress): Promise<void> {
// Method for processing on indexing new block.
}

parseEventNameAndArgs (kind: string, logObj: any): any {
let eventName = UNKNOWN_EVENT_NAME;
let eventInfo = {};
Expand Down
18 changes: 16 additions & 2 deletions packages/ipld-eth-client/src/eth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export class EthClient {
async getStorageAt ({ blockHash, contract, slot }: { blockHash: string, contract: string, slot: string }): Promise<{ value: string, proof: { data: string } }> {
slot = `0x${padKey(slot)}`;

console.time(`time:eth-client#getStorageAt-${JSON.stringify({ blockHash, contract, slot })}`);
const result = await this._getCachedOrFetch('getStorageAt', { blockHash, contract, slot });
console.timeEnd(`time:eth-client#getStorageAt-${JSON.stringify({ blockHash, contract, slot })}`);
const { getStorageAt: { value, cid, ipldBlock } } = result;

return {
Expand All @@ -63,27 +65,37 @@ export class EthClient {
}

async getBlockWithTransactions ({ blockNumber, blockHash }: { blockNumber?: number, blockHash?: string }): Promise<any> {
return this._graphqlClient.query(
console.time(`time:eth-client#getBlockWithTransactions-${JSON.stringify({ blockNumber, blockHash })}`);
const result = await this._graphqlClient.query(
ethQueries.getBlockWithTransactions,
{
blockNumber: blockNumber?.toString(),
blockHash
}
);
console.timeEnd(`time:eth-client#getBlockWithTransactions-${JSON.stringify({ blockNumber, blockHash })}`);

return result;
}

async getBlocks ({ blockNumber, blockHash }: { blockNumber?: number, blockHash?: string }): Promise<any> {
return this._graphqlClient.query(
console.time(`time:eth-client#getBlocks-${JSON.stringify({ blockNumber, blockHash })}`);
const result = await this._graphqlClient.query(
ethQueries.getBlocks,
{
blockNumber: blockNumber?.toString(),
blockHash
}
);
console.timeEnd(`time:eth-client#getBlocks-${JSON.stringify({ blockNumber, blockHash })}`);

return result;
}

async getBlockByHash (blockHash?: string): Promise<any> {
console.time(`time:eth-client#getBlockByHash-${blockHash}`);
const result = await this._graphqlClient.query(ethQueries.getBlockByHash, { blockHash });
console.timeEnd(`time:eth-client#getBlockByHash-${blockHash}`);

return {
block: {
Expand All @@ -95,7 +107,9 @@ export class EthClient {
}

async getLogs (vars: Vars): Promise<any> {
console.time(`time:eth-client#getLogs-${JSON.stringify(vars)}`);
const result = await this._getCachedOrFetch('getLogs', vars);
console.timeEnd(`time:eth-client#getLogs-${JSON.stringify(vars)}`);
const {
getLogs: resultLogs,
block: {
Expand Down
Loading

0 comments on commit f0c71e2

Please sign in to comment.