Skip to content

Commit

Permalink
Merge branch 'master' into pxrl/relayerRefactorEvaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl authored Mar 21, 2024
2 parents 5a246b9 + e4f6229 commit 4816ba4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/common/ContractAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,9 @@ export const CONTRACT_ADDRESSES: {
},
],
},
eth: {
address: "0x0000000000000000000000000000000000000000",
},
},
// Testnets
11155111: {
Expand Down
48 changes: 48 additions & 0 deletions src/utils/ProviderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class RateLimitedProvider extends ethers.providers.StaticJsonRpcProvider {
// of the list.
constructor(
maxConcurrency: number,
readonly pctRpcCallsLogged: number,
...cacheConstructorParams: ConstructorParameters<typeof ethers.providers.StaticJsonRpcProvider>
) {
super(...cacheConstructorParams);
Expand All @@ -59,6 +60,45 @@ class RateLimitedProvider extends ethers.providers.StaticJsonRpcProvider {
}, maxConcurrency);
}

async wrapSendWithLog(method: string, params: Array<any>) {
if (this.pctRpcCallsLogged <= 0 || Math.random() > this.pctRpcCallsLogged / 100) {
// Non sample path: no logging or timing, just issue the request.
return super.send(method, params);
} else {
const loggerArgs = {
at: "ProviderUtils",
message: "Provider response sample",
provider: getOriginFromURL(this.connection.url),
method,
params,
};

// In this path we log an rpc response sample.
// Note: use performance.now() to ensure a purely monotonic clock.
const startTime = performance.now();
try {
const result = await super.send(method, params);
const elapsedTimeS = (performance.now() - startTime) / 1000;
logger.debug({
...loggerArgs,
success: true,
timeElapsed: elapsedTimeS,
});
return result;
} catch (error) {
// Log errors as well.
// For now, to keep logs light, don't log the error itself, just propogate and let it be handled higher up.
const elapsedTimeS = (performance.now() - startTime) / 1000;
logger.debug({
...loggerArgs,
success: false,
timeElapsed: elapsedTimeS,
});
throw error;
}
}
}

override async send(method: string, params: Array<any>): Promise<any> {
// This simply creates a promise and adds the arguments and resolve and reject handlers to the task.
return new Promise<any>((resolve, reject) => {
Expand Down Expand Up @@ -273,6 +313,7 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
readonly delay: number,
readonly maxConcurrency: number,
providerCacheNamespace: string,
pctRpcCallsLogged: number,
redisClient?: RedisClient,
standardTtlBlockDistance?: number,
noTtlBlockDistance?: number
Expand All @@ -288,6 +329,7 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider {
standardTtlBlockDistance,
noTtlBlockDistance,
maxConcurrency,
pctRpcCallsLogged,
...inputs
)
);
Expand Down Expand Up @@ -555,6 +597,7 @@ export async function getProvider(chainId: number, logger?: winston.Logger, useC
NODE_PROVIDER_CACHE_NAMESPACE,
NODE_LOG_EVERY_N_RATE_LIMIT_ERRORS,
NODE_DISABLE_INFINITE_TTL_PROVIDER_CACHING,
NODE_PCT_RPC_CALLS_LOGGED,
} = process.env;

const timeout = Number(process.env[`NODE_TIMEOUT_${chainId}`] || NODE_TIMEOUT || defaultTimeout);
Expand Down Expand Up @@ -604,6 +647,10 @@ export async function getProvider(chainId: number, logger?: winston.Logger, useC

const logEveryNRateLimitErrors = Number(NODE_LOG_EVERY_N_RATE_LIMIT_ERRORS || "100");

const pctRpcCallsLogged = Number(
process.env[`NODE_PCT_RPC_CALLS_LOGGED_${chainId}`] || NODE_PCT_RPC_CALLS_LOGGED || "0"
);

// Custom delay + logging for RPC rate-limiting.
let rateLimitLogCounter = 0;
const rpcRateLimited =
Expand Down Expand Up @@ -651,6 +698,7 @@ export async function getProvider(chainId: number, logger?: winston.Logger, useC
retryDelay,
nodeMaxConcurrency,
providerCacheNamespace,
pctRpcCallsLogged,
redisClient,
disableProviderCache ? undefined : standardTtlBlockDistance,
disableNoTtlCaching ? undefined : noTtlBlockDistance
Expand Down

0 comments on commit 4816ba4

Please sign in to comment.