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

refactor(config): Cleanup & permit selective override #1940

Merged
merged 10 commits into from
Jan 2, 2025
23 changes: 12 additions & 11 deletions src/common/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class CommonConfig {
HUB_CHAIN_ID,
POLLING_DELAY,
MAX_BLOCK_LOOK_BACK,
MAX_TX_WAIT_DURATION,
SEND_TRANSACTIONS,
SPOKE_POOL_CHAINS_OVERRIDE,
ACROSS_BOT_VERSION,
Expand All @@ -44,7 +43,11 @@ export class CommonConfig {
ARWEAVE_GATEWAY,
} = env;

const updateConfig = (envVar: string, config: Record<string, unknown>) =>
Object.entries(JSON.parse(envVar ?? "{}")).forEach(([k, v]) => (config[k] = v));
pxrl marked this conversation as resolved.
Show resolved Hide resolved

this.version = ACROSS_BOT_VERSION ?? "unknown";
this.hubPoolChainId = Number(HUB_CHAIN_ID ?? CHAIN_IDs.MAINNET);
james-a-morris marked this conversation as resolved.
Show resolved Hide resolved

this.timeToCache = Number(HUB_POOL_TIME_TO_CACHE ?? 60 * 60); // 1 hour by default.
if (Number.isNaN(this.timeToCache) || this.timeToCache < 0) {
Expand All @@ -57,22 +60,20 @@ export class CommonConfig {
this.maxConfigVersion = Number(ACROSS_MAX_CONFIG_VERSION ?? Constants.CONFIG_STORE_VERSION);
assert(!isNaN(this.maxConfigVersion), `Invalid maximum config version: ${this.maxConfigVersion}`);

this.blockRangeEndBlockBuffer = BLOCK_RANGE_END_BLOCK_BUFFER
? JSON.parse(BLOCK_RANGE_END_BLOCK_BUFFER)
: Constants.BUNDLE_END_BLOCK_BUFFERS;
this.blockRangeEndBlockBuffer = { ...Constants.BUNDLE_END_BLOCK_BUFFERS };
updateConfig(BLOCK_RANGE_END_BLOCK_BUFFER, this.blockRangeEndBlockBuffer);

this.ignoredAddresses = JSON.parse(IGNORED_ADDRESSES ?? "[]").map((address) => ethers.utils.getAddress(address));

// `maxRelayerLookBack` is how far we fetch events from, modifying the search config's 'fromBlock'
this.maxRelayerLookBack = Number(MAX_RELAYER_DEPOSIT_LOOK_BACK ?? Constants.MAX_RELAYER_DEPOSIT_LOOK_BACK);
this.hubPoolChainId = Number(HUB_CHAIN_ID ?? CHAIN_IDs.MAINNET);
this.pollingDelay = Number(POLLING_DELAY ?? 60);
this.spokePoolChainsOverride = SPOKE_POOL_CHAINS_OVERRIDE ? JSON.parse(SPOKE_POOL_CHAINS_OVERRIDE) : [];
this.maxBlockLookBack = MAX_BLOCK_LOOK_BACK ? JSON.parse(MAX_BLOCK_LOOK_BACK) : {};
if (Object.keys(this.maxBlockLookBack).length === 0) {
this.maxBlockLookBack = Constants.CHAIN_MAX_BLOCK_LOOKBACK;
}
this.maxTxWait = Number(MAX_TX_WAIT_DURATION ?? 180); // 3 minutes
pxrl marked this conversation as resolved.
Show resolved Hide resolved
this.spokePoolChainsOverride = JSON.parse(SPOKE_POOL_CHAINS_OVERRIDE ?? "[]");

// Inherit the default eth_getLogs block range config, then sub in any env-based overrides.
this.maxBlockLookBack = { ...Constants.CHAIN_MAX_BLOCK_LOOKBACK };
updateConfig(MAX_BLOCK_LOOK_BACK, this.maxBlockLookBack);

this.sendingTransactionsEnabled = SEND_TRANSACTIONS === "true";

// Load the Arweave gateway from the environment.
Expand Down
8 changes: 2 additions & 6 deletions src/relayer/RelayerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,8 @@ export class RelayerConfig extends CommonConfig {
this.relayerDestinationChains = JSON.parse(RELAYER_DESTINATION_CHAINS ?? "[]");

// Empty means all tokens.
this.relayerTokens = RELAYER_TOKENS
? JSON.parse(RELAYER_TOKENS).map((token) => ethers.utils.getAddress(token))
: [];
this.slowDepositors = SLOW_DEPOSITORS
? JSON.parse(SLOW_DEPOSITORS).map((depositor) => ethers.utils.getAddress(depositor))
: [];
this.relayerTokens = JSON.parse(RELAYER_TOKENS ?? "[]").map((token) => ethers.utils.getAddress(token));
this.slowDepositors = JSON.parse(SLOW_DEPOSITORS ?? "[]").map((depositor) => ethers.utils.getAddress(depositor));

this.minRelayerFeePct = toBNWei(MIN_RELAYER_FEE_PCT || Constants.RELAYER_MIN_FEE_PCT);

Expand Down
Loading