Skip to content

Commit

Permalink
fix: strategy flag propagation (#5033)
Browse files Browse the repository at this point in the history
### Description

`--strategy` flag was not being propagated through context middleware
properly

### Drive-by changes

<!--
Are there any minor or drive-by changes also included?
-->

### Related issues

<!--
- Fixes #[issue number here]
-->

### Backward compatibility

<!--
Are these changes backward compatible? Are there any infrastructure
implications, e.g. changes that would prohibit deploying older commits
using this infra tooling?

Yes/No
-->

### Testing

warp apply e2e tests
  • Loading branch information
yorhodes authored Dec 18, 2024
1 parent edc4e68 commit 9349ef7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-bulldogs-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperlane-xyz/cli": patch
---

Fix strategy flag propagation
39 changes: 4 additions & 35 deletions typescript/cli/src/config/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ import {
import {
ProtocolType,
assert,
errorToString,
isAddress,
isPrivateKeyEvm,
} from '@hyperlane-xyz/utils';

import { CommandContext } from '../context/types.js';
import { errorRed, log, logBlue, logGreen, logRed } from '../logger.js';
import { errorRed, log, logBlue, logGreen } from '../logger.js';
import { runSingleChainSelectionStep } from '../utils/chains.js';
import {
indentYamlOrJson,
isFile,
readYamlOrJson,
writeYamlOrJson,
} from '../utils/files.js';
Expand All @@ -33,38 +31,9 @@ export async function readChainSubmissionStrategyConfig(
filePath: string,
): Promise<ChainSubmissionStrategy> {
log(`Reading submission strategy in ${filePath}`);
try {
const strategyConfig = readYamlOrJson<ChainSubmissionStrategy>(filePath);

const parseResult = ChainSubmissionStrategySchema.parse(strategyConfig);

return parseResult;
} catch (error) {
logRed(`⛔️ Error reading strategy config:`, errorToString(error));
throw error; // Re-throw to let caller handle the error
}
}

/**
* Safely reads chain submission strategy config, returns empty object if any errors occur
*/
export async function safeReadChainSubmissionStrategyConfig(
filePath: string,
): Promise<ChainSubmissionStrategy> {
try {
const trimmedFilePath = filePath.trim();
if (!isFile(trimmedFilePath)) {
logBlue(`File ${trimmedFilePath} does not exist, returning empty config`);
return {};
}
return await readChainSubmissionStrategyConfig(trimmedFilePath);
} catch (error) {
logRed(
`Failed to read strategy config, defaulting to empty config:`,
errorToString(error),
);
return {};
}
const strategyConfig = readYamlOrJson<ChainSubmissionStrategy>(filePath);
const parseResult = ChainSubmissionStrategySchema.parse(strategyConfig);
return parseResult;
}

export async function createStrategyConfig({
Expand Down
11 changes: 6 additions & 5 deletions typescript/cli/src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import {
} from '@hyperlane-xyz/sdk';
import { isHttpsUrl, isNullish, rootLogger } from '@hyperlane-xyz/utils';

import { DEFAULT_STRATEGY_CONFIG_PATH } from '../commands/options.js';
import { isSignCommand } from '../commands/signCommands.js';
import { safeReadChainSubmissionStrategyConfig } from '../config/strategy.js';
import { readChainSubmissionStrategyConfig } from '../config/strategy.js';
import { PROXY_DEPLOYED_URL } from '../consts.js';
import { forkNetworkToMultiProvider, verifyAnvil } from '../deploy/dry-run.js';
import { logBlue } from '../logger.js';
Expand Down Expand Up @@ -62,9 +61,9 @@ export async function signerMiddleware(argv: Record<string, any>) {

if (!requiresKey) return argv;

const strategyConfig = await safeReadChainSubmissionStrategyConfig(
strategyPath ?? DEFAULT_STRATEGY_CONFIG_PATH,
);
const strategyConfig = strategyPath
? await readChainSubmissionStrategyConfig(strategyPath)
: {};

/**
* Intercepts Hyperlane command to determine chains.
Expand Down Expand Up @@ -106,6 +105,7 @@ export async function getContext({
requiresKey,
skipConfirmation,
disableProxy = false,
strategyPath,
}: ContextSettings): Promise<CommandContext> {
const registry = getRegistry(registryUri, registryOverrideUri, !disableProxy);

Expand All @@ -127,6 +127,7 @@ export async function getContext({
key,
skipConfirmation: !!skipConfirmation,
signerAddress,
strategyPath,
} as CommandContext;
}

Expand Down

0 comments on commit 9349ef7

Please sign in to comment.