Skip to content

Commit 38e159d

Browse files
authored
refactor(config): Cleanup & permit selective override (#1940)
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, adding some basic type validation along the way.
1 parent 3429663 commit 38e159d

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/common/Config.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export class CommonConfig {
3535
HUB_CHAIN_ID,
3636
POLLING_DELAY,
3737
MAX_BLOCK_LOOK_BACK,
38-
MAX_TX_WAIT_DURATION,
3938
SEND_TRANSACTIONS,
4039
SPOKE_POOL_CHAINS_OVERRIDE,
4140
ACROSS_BOT_VERSION,
@@ -44,7 +43,20 @@ export class CommonConfig {
4443
ARWEAVE_GATEWAY,
4544
} = env;
4645

46+
const mergeConfig = <T>(config: T, envVar: string): T => {
47+
const shallowCopy = { ...config };
48+
Object.entries(JSON.parse(envVar ?? "{}")).forEach(([k, v]) => {
49+
assert(
50+
typeof v === typeof shallowCopy[k] || !isDefined(shallowCopy[k]),
51+
`Invalid ${envVar} configuration on key ${k} (${typeof v} != ${typeof shallowCopy[k]})`
52+
);
53+
shallowCopy[k] = v;
54+
});
55+
return shallowCopy;
56+
};
57+
4758
this.version = ACROSS_BOT_VERSION ?? "unknown";
59+
this.hubPoolChainId = Number(HUB_CHAIN_ID ?? CHAIN_IDs.MAINNET);
4860

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

60-
this.blockRangeEndBlockBuffer = BLOCK_RANGE_END_BLOCK_BUFFER
61-
? JSON.parse(BLOCK_RANGE_END_BLOCK_BUFFER)
62-
: Constants.BUNDLE_END_BLOCK_BUFFERS;
72+
this.blockRangeEndBlockBuffer = mergeConfig(Constants.BUNDLE_END_BLOCK_BUFFERS, BLOCK_RANGE_END_BLOCK_BUFFER);
6373

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

6676
// `maxRelayerLookBack` is how far we fetch events from, modifying the search config's 'fromBlock'
6777
this.maxRelayerLookBack = Number(MAX_RELAYER_DEPOSIT_LOOK_BACK ?? Constants.MAX_RELAYER_DEPOSIT_LOOK_BACK);
68-
this.hubPoolChainId = Number(HUB_CHAIN_ID ?? CHAIN_IDs.MAINNET);
6978
this.pollingDelay = Number(POLLING_DELAY ?? 60);
70-
this.spokePoolChainsOverride = SPOKE_POOL_CHAINS_OVERRIDE ? JSON.parse(SPOKE_POOL_CHAINS_OVERRIDE) : [];
71-
this.maxBlockLookBack = MAX_BLOCK_LOOK_BACK ? JSON.parse(MAX_BLOCK_LOOK_BACK) : {};
72-
if (Object.keys(this.maxBlockLookBack).length === 0) {
73-
this.maxBlockLookBack = Constants.CHAIN_MAX_BLOCK_LOOKBACK;
74-
}
75-
this.maxTxWait = Number(MAX_TX_WAIT_DURATION ?? 180); // 3 minutes
79+
this.spokePoolChainsOverride = JSON.parse(SPOKE_POOL_CHAINS_OVERRIDE ?? "[]");
80+
81+
// Inherit the default eth_getLogs block range config, then sub in any env-based overrides.
82+
this.maxBlockLookBack = mergeConfig(Constants.CHAIN_MAX_BLOCK_LOOKBACK, MAX_BLOCK_LOOK_BACK);
83+
7684
this.sendingTransactionsEnabled = SEND_TRANSACTIONS === "true";
7785

7886
// Load the Arweave gateway from the environment.

src/relayer/RelayerConfig.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,8 @@ export class RelayerConfig extends CommonConfig {
105105
this.relayerDestinationChains = JSON.parse(RELAYER_DESTINATION_CHAINS ?? "[]");
106106

107107
// Empty means all tokens.
108-
this.relayerTokens = RELAYER_TOKENS
109-
? JSON.parse(RELAYER_TOKENS).map((token) => ethers.utils.getAddress(token))
110-
: [];
111-
this.slowDepositors = SLOW_DEPOSITORS
112-
? JSON.parse(SLOW_DEPOSITORS).map((depositor) => ethers.utils.getAddress(depositor))
113-
: [];
108+
this.relayerTokens = JSON.parse(RELAYER_TOKENS ?? "[]").map((token) => ethers.utils.getAddress(token));
109+
this.slowDepositors = JSON.parse(SLOW_DEPOSITORS ?? "[]").map((depositor) => ethers.utils.getAddress(depositor));
114110

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

0 commit comments

Comments
 (0)