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

Adds gzip compression for RPC requests. #165

Closed
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
22 changes: 11 additions & 11 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ export const SCRAPER_MODE: ScraperMode =
process.env.SCRAPER_MODE === undefined
? DEFAULT_SCRAPER_MODE
: process.env.SCRAPER_MODE === 'BLOCKS'
? 'BLOCKS'
: process.env.SCRAPER_MODE === 'EVENTS'
? 'EVENTS'
: throwError('Wrong SCRAPER_MODE');
? 'BLOCKS'
: process.env.SCRAPER_MODE === 'EVENTS'
? 'EVENTS'
: throwError('Wrong SCRAPER_MODE');
export const METRICS_PATH = process.env.METRICS_PATH || DEFAULT_METRICS_PATH;

export const PROMETHEUS_PORT = getIntConfig('PROMETHEUS_PORT', DEFAULT_PROMETHEUS_PORT);
Expand Down Expand Up @@ -389,13 +389,13 @@ export const FEAT_UNISWAP_V2_PAIR_CREATED_EVENT = getBoolConfig(
export const UNISWAP_V2_PAIR_CREATED_PROTOCOL_CONTRACT_ADDRESSES_AND_START_BLOCKS = process.env
.UNISWAP_V2_PAIR_CREATED_PROTOCOL_CONTRACT_ADDRESSES_AND_START_BLOCKS
? process.env.UNISWAP_V2_PAIR_CREATED_PROTOCOL_CONTRACT_ADDRESSES_AND_START_BLOCKS.split(',').map((contract) => {
const [name, factoryAddress, startBlock] = contract.split(':');
return {
name,
factoryAddress,
startBlock: parseInt(startBlock),
};
})
const [name, factoryAddress, startBlock] = contract.split(':');
return {
name,
factoryAddress,
startBlock: parseInt(startBlock),
};
})
: [];

if (
Expand Down
10 changes: 9 additions & 1 deletion src/data_sources/events/web3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ export interface ContractCallInfo {
data: string;
}

const web3HttpOptions = {
providerOptions: {
headers: {
'Accept-Encoding': 'gzip',
},
} as RequestInit,
};

export class Web3Source {
private readonly _web3Wrapper: Web3Wrapper;
private readonly _web3: any;
constructor(provider: Web3ProviderEngine, wsProvider: string) {
this._web3Wrapper = new Web3Wrapper(provider);
this._web3 = new Web3(wsProvider);
this._web3 = new Web3(new Web3.providers.HttpProvider(wsProvider, web3HttpOptions));

if (BLOCK_RECEIPTS_MODE === 'standard') {
this._web3.eth.extend({
Expand Down
22 changes: 22 additions & 0 deletions src/utils/retry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { logger } from './logger';

export async function retry<T extends (...arg0: any[]) => any>(
fn: T,
args: Parameters<T>,
maxTry: number,
retryCount = 1,
): Promise<Awaited<ReturnType<T>>> {
const currRetry = typeof retryCount === 'number' ? retryCount : 1;
try {
logger.info(`Attempt #${currRetry}.`);
const result = await fn(...args);
return result;
} catch (e) {
logger.info(`Retry ${currRetry} failed.`);
if (currRetry > maxTry) {
logger.info(`All ${maxTry} retry attempts exhausted`);
throw e;
}
return retry(fn, args, maxTry, currRetry + 1);
}
}
Loading