diff --git a/src/common/Config.ts b/src/common/Config.ts index eec2f4148..81a3a7091 100644 --- a/src/common/Config.ts +++ b/src/common/Config.ts @@ -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, @@ -44,7 +43,20 @@ export class CommonConfig { ARWEAVE_GATEWAY, } = env; + const mergeConfig = (config: T, envVar: string): T => { + const shallowCopy = { ...config }; + Object.entries(JSON.parse(envVar ?? "{}")).forEach(([k, v]) => { + assert( + typeof v === typeof shallowCopy[k] || !isDefined(shallowCopy[k]), + `Invalid ${envVar} configuration on key ${k} (${typeof v} != ${typeof shallowCopy[k]})` + ); + shallowCopy[k] = v; + }); + return shallowCopy; + }; + this.version = ACROSS_BOT_VERSION ?? "unknown"; + this.hubPoolChainId = Number(HUB_CHAIN_ID ?? CHAIN_IDs.MAINNET); this.timeToCache = Number(HUB_POOL_TIME_TO_CACHE ?? 60 * 60); // 1 hour by default. if (Number.isNaN(this.timeToCache) || this.timeToCache < 0) { @@ -57,22 +69,18 @@ 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 = mergeConfig(Constants.BUNDLE_END_BLOCK_BUFFERS, BLOCK_RANGE_END_BLOCK_BUFFER); 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 + 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 = mergeConfig(Constants.CHAIN_MAX_BLOCK_LOOKBACK, MAX_BLOCK_LOOK_BACK); + this.sendingTransactionsEnabled = SEND_TRANSACTIONS === "true"; // Load the Arweave gateway from the environment. diff --git a/src/relayer/RelayerConfig.ts b/src/relayer/RelayerConfig.ts index 3af672aa4..03e0a8add 100644 --- a/src/relayer/RelayerConfig.ts +++ b/src/relayer/RelayerConfig.ts @@ -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);