Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/hot-cougars-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@nomicfoundation/ignition-core": patch
"@nomicfoundation/hardhat-ignition-ethers": patch
"@nomicfoundation/hardhat-ignition-viem": patch
"@nomicfoundation/hardhat-ignition": patch
---

Expose ignition retry loop variables in user config ([#7303](https://github.com/NomicFoundation/hardhat/issues/7303))
6 changes: 6 additions & 0 deletions v-next/hardhat-ignition-core/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export async function deploy<
maxPriorityFeePerGas,
gasPrice,
disableFeeBumping,
maxRetries,
retryInterval,
}: {
config?: Partial<DeployConfig>;
artifactResolver: ArtifactResolver;
Expand All @@ -74,6 +76,8 @@ export async function deploy<
maxPriorityFeePerGas?: bigint;
gasPrice?: bigint;
disableFeeBumping?: boolean;
maxRetries?: number;
retryInterval?: number;
}): Promise<DeploymentResult> {
const executionStrategy: ExecutionStrategy = resolveStrategy(
strategy,
Expand Down Expand Up @@ -131,6 +135,8 @@ export async function deploy<
? DEFAULT_AUTOMINE_REQUIRED_CONFIRMATIONS
: config.requiredConfirmations ?? defaultConfig.requiredConfirmations,
disableFeeBumping: disableFeeBumping ?? defaultConfig.disableFeeBumping,
maxRetries: maxRetries ?? defaultConfig.maxRetries,
retryInterval: retryInterval ?? defaultConfig.retryInterval,
...config,
};

Expand Down
2 changes: 2 additions & 0 deletions v-next/hardhat-ignition-core/src/internal/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const defaultConfig: DeployConfig = {
maxFeeBumps: 4,
requiredConfirmations: 5,
disableFeeBumping: false,
maxRetries: 10,
retryInterval: 1_000,
};

/**
Expand Down
2 changes: 2 additions & 0 deletions v-next/hardhat-ignition-core/src/internal/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ export class Deployer {
this._config.maxFeeBumps,
this._config.blockPollingInterval,
this._config.disableFeeBumping,
this._config.maxRetries,
this._config.retryInterval,
);

deploymentState = await executionEngine.executeModule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class ExecutionEngine {
private readonly _maxFeeBumps: number,
private readonly _blockPollingInterval: number,
private readonly _disableFeeBumping: boolean,
private readonly _maxRetries: number,
private readonly _retryInterval: number,
) {}

/**
Expand Down Expand Up @@ -107,6 +109,8 @@ export class ExecutionEngine {
deploymentParameters,
defaultSender,
this._disableFeeBumping,
this._maxRetries,
this._retryInterval,
);

const futures = getFuturesFromModule(module);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export class FutureProcessor {
private readonly _deploymentParameters: DeploymentParameters,
private readonly _defaultSender: string,
private readonly _disableFeeBumping: boolean,
private readonly _maxRetries: number,
private readonly _retryInterval: number,
) {}

/**
Expand Down Expand Up @@ -214,7 +216,10 @@ export class FutureProcessor {
this._requiredConfirmations,
this._millisecondBeforeBumpingFees,
this._maxFeeBumps,
undefined,
{
maxRetries: this._maxRetries,
retryInterval: this._retryInterval,
},
this._disableFeeBumping,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type {
OnchainInteractionTimeoutMessage,
TransactionConfirmMessage,
} from "../../types/messages.js";
import type { OnchainInteraction } from "../../types/network-interaction.js";
import type {
GetTransactionRetryConfig,
OnchainInteraction,
} from "../../types/network-interaction.js";

import { HardhatError } from "@nomicfoundation/hardhat-errors";
import setupDebug from "debug";
Expand All @@ -22,11 +25,6 @@ import { NetworkInteractionType } from "../../types/network-interaction.js";

const debug = setupDebug("hardhat-ignition:onchain-interaction-monitor");

export interface GetTransactionRetryConfig {
maxRetries: number;
retryInterval: number;
}

/**
* Checks the transactions of the latest network interaction of the execution state,
* and returns a message, or undefined if we need to wait for more confirmations.
Expand All @@ -50,7 +48,7 @@ export interface GetTransactionRetryConfig {
* of a transaction.
* @param maxFeeBumps The maximum number of times we can bump the fees of a transaction
* before considering the onchain interaction timed out.
* @param getTransactionRetryConfig This is really only a parameter to help with testing this function
* @param getTransactionRetryConfig Configuration for retrying getTransaction calls.
* @param disableFeeBumping Disables fee bumping for all transactions.
* @returns A message indicating the result of checking the transactions of the latest
* network interaction.
Expand All @@ -74,9 +72,10 @@ export async function monitorOnchainInteraction(
| undefined
> {
const lastNetworkInteraction = exState.networkInteractions.at(-1);
const getTransactionRetryConfig = givenGetTransactionRetryConfig ?? {
const getTransactionRetryConfig: GetTransactionRetryConfig = {
maxRetries: 10,
retryInterval: 1000,
...givenGetTransactionRetryConfig,
};

assertIgnitionInvariant(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,11 @@ export interface StaticCall {
from: string;
result?: RawStaticCallResult;
}

/**
* Configuration for the retry loop when trying to fetch a transaction from the node.
*/
export interface GetTransactionRetryConfig {
maxRetries: number;
retryInterval: number;
}
12 changes: 12 additions & 0 deletions v-next/hardhat-ignition-core/src/types/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ export interface DeployConfig {
* Disables fee bumping for all transactions.
*/
disableFeeBumping: boolean;

/**
* The maximum number of times to retry a call to getTransactionReceipt
* when monitoring the status of a transaction.
*/
maxRetries: number;

/**
* The interval, in milliseconds, between retries when calling
* getTransactionReceipt.
*/
retryInterval: number;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe("ExecutionEngine", () => {
5,
5,
false,
10,
1000,
);

const deploymentState = await loadDeploymentState(deploymentLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { HardhatError } from "@nomicfoundation/hardhat-errors";
import { assertRejectsWithHardhatError } from "@nomicfoundation/hardhat-test-utils";
import { assert } from "chai";

import {
GetTransactionRetryConfig,
monitorOnchainInteraction,
} from "../../../../src/internal/execution/future-processor/handlers/monitor-onchain-interaction.js";
import { monitorOnchainInteraction } from "../../../../src/internal/execution/future-processor/handlers/monitor-onchain-interaction.js";
import { decodeSimulationResult } from "../../../../src/internal/execution/future-processor/helpers/decode-simulation-result.js";
import {
TRANSACTION_SENT_TYPE,
Expand Down Expand Up @@ -49,6 +46,7 @@ import {
NetworkInteractionType,
OnchainInteraction,
StaticCall,
GetTransactionRetryConfig,
} from "../../../../src/internal/execution/types/network-interaction.js";
import { FutureType } from "../../../../src/types/module.js";
import { exampleAccounts } from "../../../helpers.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export async function setupFutureProcessor(
{},
getDefaultSender(exampleAccounts),
false, // disableFeeBumping
10, // maxRetries
1000, // retryInterval
);

return { processor, storedDeployedAddresses };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ export class EthersIgnitionHelperImpl<ChainTypeT extends ChainType | string>
this.#connection.networkConfig?.ignition.maxFeePerGasLimit,
maxPriorityFeePerGas:
this.#connection.networkConfig?.ignition.maxPriorityFeePerGas,
maxRetries:
resolvedConfig.maxRetries ??
this.#connection.networkConfig?.ignition.maxRetries,
retryInterval:
resolvedConfig.retryInterval ??
this.#connection.networkConfig?.ignition.retryInterval,
});

if (result.type !== DeploymentResultType.SUCCESSFUL_DEPLOYMENT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ export class ViemIgnitionHelperImpl<ChainTypeT extends ChainType | string>
this.#connection.networkConfig?.ignition.maxFeePerGasLimit,
maxPriorityFeePerGas:
this.#connection.networkConfig?.ignition.maxPriorityFeePerGas,
maxRetries:
resolvedConfig.maxRetries ??
this.#connection.networkConfig?.ignition.maxRetries,
retryInterval:
resolvedConfig.retryInterval ??
this.#connection.networkConfig?.ignition.retryInterval,
});

if (result.type !== DeploymentResultType.SUCCESSFUL_DEPLOYMENT) {
Expand Down
2 changes: 2 additions & 0 deletions v-next/hardhat-ignition/src/internal/hook-handlers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export async function resolveUserConfig(
gasPrice: givenIgnition.gasPrice,
disableFeeBumping: givenIgnition.disableFeeBumping,
explorerUrl: givenIgnition.explorerUrl,
maxRetries: givenIgnition.maxRetries,
retryInterval: givenIgnition.retryInterval,
},
},
];
Expand Down
6 changes: 6 additions & 0 deletions v-next/hardhat-ignition/src/internal/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ const taskDeploy: NewTaskActionFunction<TaskDeployArguments> = async (
disableFeeBumping:
hre.config.ignition.disableFeeBumping ??
hre.config.networks[connection.networkName]?.ignition.disableFeeBumping,
maxRetries:
hre.config.ignition.maxRetries ??
hre.config.networks[connection.networkName]?.ignition.maxRetries,
retryInterval:
hre.config.ignition.retryInterval ??
hre.config.networks[connection.networkName]?.ignition.retryInterval,
});

if (result.type === "SUCCESSFUL_DEPLOYMENT" && verify) {
Expand Down
8 changes: 8 additions & 0 deletions v-next/hardhat-ignition/src/type-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ declare module "hardhat/types/config" {
gasPrice?: bigint;
disableFeeBumping?: boolean;
explorerUrl?: string;
maxRetries?: number;
retryInterval?: number;
};
}

Expand All @@ -31,6 +33,8 @@ declare module "hardhat/types/config" {
gasPrice?: bigint;
disableFeeBumping?: boolean;
explorerUrl?: string;
maxRetries?: number;
retryInterval?: number;
};
}

Expand All @@ -41,6 +45,8 @@ declare module "hardhat/types/config" {
gasPrice?: bigint;
disableFeeBumping?: boolean;
explorerUrl?: string;
maxRetries?: number;
retryInterval?: number;
};
}

Expand All @@ -51,6 +57,8 @@ declare module "hardhat/types/config" {
gasPrice?: bigint;
disableFeeBumping?: boolean;
explorerUrl?: string;
maxRetries?: number;
retryInterval?: number;
};
}

Expand Down
4 changes: 4 additions & 0 deletions v-next/hardhat-ignition/test/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ describe("config", () => {
},
},
disableFeeBumping: true,
maxRetries: 10,
retryInterval: 1000,
},
});

Expand Down Expand Up @@ -98,7 +100,9 @@ describe("config", () => {
"blockPollingInterval",
"disableFeeBumping",
"maxFeeBumps",
"maxRetries",
"requiredConfirmations",
"retryInterval",
"strategyConfig",
"timeBeforeBumpingFees",
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const defaultTestConfig: DeployConfig = {
blockPollingInterval: 200,
requiredConfirmations: 1,
disableFeeBumping: false,
maxRetries: 10,
retryInterval: 1000,
};

// todo: whenever these tests are migrated to node:test,
Expand Down
Loading