From 0dfdbd5a389c5d7278b5c106c319cf16cc378187 Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Sat, 7 Dec 2024 17:25:06 +0000 Subject: [PATCH 1/4] refactor(config): Cleanup & permit selective override Permit certain config objects (i.e. MAX_BLOCK_LOOK_BACK) to be selectively overridden, rather than requiring a complete definition. This will slightly improve new chain automation. Also simplify a few instances of config parsing. --- src/common/Config.ts | 24 ++++++++++++++---------- src/relayer/RelayerConfig.ts | 8 ++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/common/Config.ts b/src/common/Config.ts index eec2f4148..be92a7c2c 100644 --- a/src/common/Config.ts +++ b/src/common/Config.ts @@ -45,6 +45,7 @@ export class CommonConfig { } = env; 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 +58,25 @@ 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 }; + Object.entries(JSON.parse(BLOCK_RANGE_END_BLOCK_BUFFER ?? "{}")).forEach((_chainId, buffer) => + this.blockRangeEndBlockBuffer[Number(_chainId)] = 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 = { ...Constants.CHAIN_MAX_BLOCK_LOOKBACK }; + const maxBlockLookBack = JSON.parse(MAX_BLOCK_LOOK_BACK ?? "{}"); + Object.entries(JSON.parse(MAX_BLOCK_LOOK_BACK ?? "{}")).forEach((_chainId, lookback) => + this.maxBlockLookBack[Number(_chainId)] = lookback + ); + 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); From 676a892d87b07f79aa59d5aca04d86ef2914a861 Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:44:02 +0000 Subject: [PATCH 2/4] lint --- src/common/Config.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/common/Config.ts b/src/common/Config.ts index be92a7c2c..8629d52d1 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, @@ -59,8 +58,8 @@ export class CommonConfig { assert(!isNaN(this.maxConfigVersion), `Invalid maximum config version: ${this.maxConfigVersion}`); this.blockRangeEndBlockBuffer = { ...Constants.BUNDLE_END_BLOCK_BUFFERS }; - Object.entries(JSON.parse(BLOCK_RANGE_END_BLOCK_BUFFER ?? "{}")).forEach((_chainId, buffer) => - this.blockRangeEndBlockBuffer[Number(_chainId)] = buffer + Object.entries(JSON.parse(BLOCK_RANGE_END_BLOCK_BUFFER ?? "{}")).forEach( + (_chainId, buffer) => (this.blockRangeEndBlockBuffer[Number(_chainId)] = buffer) ); this.ignoredAddresses = JSON.parse(IGNORED_ADDRESSES ?? "[]").map((address) => ethers.utils.getAddress(address)); @@ -72,9 +71,8 @@ export class CommonConfig { // Inherit the default eth_getLogs block range config, then sub in any env-based overrides. this.maxBlockLookBack = { ...Constants.CHAIN_MAX_BLOCK_LOOKBACK }; - const maxBlockLookBack = JSON.parse(MAX_BLOCK_LOOK_BACK ?? "{}"); - Object.entries(JSON.parse(MAX_BLOCK_LOOK_BACK ?? "{}")).forEach((_chainId, lookback) => - this.maxBlockLookBack[Number(_chainId)] = lookback + Object.entries(JSON.parse(MAX_BLOCK_LOOK_BACK ?? "{}")).forEach( + (_chainId, lookback) => (this.maxBlockLookBack[Number(_chainId)] = lookback) ); this.sendingTransactionsEnabled = SEND_TRANSACTIONS === "true"; From 0c78797b8559b496f6d3d35164e0d08b7f4c9fac Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:05:10 +0000 Subject: [PATCH 3/4] Consolidate --- src/common/Config.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/common/Config.ts b/src/common/Config.ts index 8629d52d1..151ae2a89 100644 --- a/src/common/Config.ts +++ b/src/common/Config.ts @@ -43,6 +43,9 @@ export class CommonConfig { ARWEAVE_GATEWAY, } = env; + const updateConfig = (envVar: string, config: Record) => + Object.entries(JSON.parse(envVar ?? "{}")).forEach(([k, v]) => (config[k] = v)); + this.version = ACROSS_BOT_VERSION ?? "unknown"; this.hubPoolChainId = Number(HUB_CHAIN_ID ?? CHAIN_IDs.MAINNET); @@ -58,9 +61,7 @@ export class CommonConfig { assert(!isNaN(this.maxConfigVersion), `Invalid maximum config version: ${this.maxConfigVersion}`); this.blockRangeEndBlockBuffer = { ...Constants.BUNDLE_END_BLOCK_BUFFERS }; - Object.entries(JSON.parse(BLOCK_RANGE_END_BLOCK_BUFFER ?? "{}")).forEach( - (_chainId, buffer) => (this.blockRangeEndBlockBuffer[Number(_chainId)] = buffer) - ); + updateConfig(BLOCK_RANGE_END_BLOCK_BUFFER, this.blockRangeEndBlockBuffer); this.ignoredAddresses = JSON.parse(IGNORED_ADDRESSES ?? "[]").map((address) => ethers.utils.getAddress(address)); @@ -71,9 +72,7 @@ export class CommonConfig { // Inherit the default eth_getLogs block range config, then sub in any env-based overrides. this.maxBlockLookBack = { ...Constants.CHAIN_MAX_BLOCK_LOOKBACK }; - Object.entries(JSON.parse(MAX_BLOCK_LOOK_BACK ?? "{}")).forEach( - (_chainId, lookback) => (this.maxBlockLookBack[Number(_chainId)] = lookback) - ); + updateConfig(MAX_BLOCK_LOOK_BACK, this.maxBlockLookBack); this.sendingTransactionsEnabled = SEND_TRANSACTIONS === "true"; From 75566e5c087f54ed85554463ebb7f3b966a1ba7e Mon Sep 17 00:00:00 2001 From: Paul <108695806+pxrl@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:56:26 +0000 Subject: [PATCH 4/4] Use shallow copy --- src/common/Config.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/common/Config.ts b/src/common/Config.ts index 151ae2a89..81a3a7091 100644 --- a/src/common/Config.ts +++ b/src/common/Config.ts @@ -43,8 +43,17 @@ export class CommonConfig { ARWEAVE_GATEWAY, } = env; - const updateConfig = (envVar: string, config: Record) => - Object.entries(JSON.parse(envVar ?? "{}")).forEach(([k, v]) => (config[k] = v)); + 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); @@ -60,8 +69,7 @@ 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 = { ...Constants.BUNDLE_END_BLOCK_BUFFERS }; - updateConfig(BLOCK_RANGE_END_BLOCK_BUFFER, this.blockRangeEndBlockBuffer); + 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)); @@ -71,8 +79,7 @@ export class CommonConfig { 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.maxBlockLookBack = mergeConfig(Constants.CHAIN_MAX_BLOCK_LOOKBACK, MAX_BLOCK_LOOK_BACK); this.sendingTransactionsEnabled = SEND_TRANSACTIONS === "true";