From 7b4dfd827ba5bc0d994baeb1bcdc0487795c123a Mon Sep 17 00:00:00 2001 From: Alexey Shchur Date: Tue, 28 Apr 2026 12:53:12 +0300 Subject: [PATCH] accomodate faster local deploy --- .../host-chain/utils/deployCreateX.ts | 22 ++++++++++++++++++- contracts/internal/host-chain/utils/fund.ts | 8 ++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/contracts/internal/host-chain/utils/deployCreateX.ts b/contracts/internal/host-chain/utils/deployCreateX.ts index 09d333e..14f53f2 100644 --- a/contracts/internal/host-chain/utils/deployCreateX.ts +++ b/contracts/internal/host-chain/utils/deployCreateX.ts @@ -1,6 +1,7 @@ import chalk from "chalk"; import * as fs from "fs" import * as path from "path" +import { TransactionReceipt } from "ethers"; import type { HardhatRuntimeEnvironment } from "hardhat/types"; import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers"; @@ -16,6 +17,25 @@ export const isAlreadyDeployed = async function (hre: HardhatRuntimeEnvironment, return code !== "0x"; } +async function waitForReceiptWithIndexRetry(txHash: string, hre: HardhatRuntimeEnvironment): Promise { + for (;;) { + try { + const receipt = await hre.ethers.provider.getTransactionReceipt(txHash); + if (receipt) { + return receipt; + } + } catch (error) { + const message = error instanceof Error ? error.message : String(error); + // Local geth can briefly reject receipt lookups while its tx indexer warms up + // right after startup. Retrying here avoids failing the entire deployer on boot. + if (!message.includes("transaction indexing is in progress")) { + throw error; + } + } + await new Promise((resolve) => setTimeout(resolve, 1000)); + } +} + export const deployCreateX = async function (hre: HardhatRuntimeEnvironment, signer: HardhatEthersSigner): Promise { const { ethers } = hre; @@ -47,7 +67,7 @@ export const deployCreateX = async function (hre: HardhatRuntimeEnvironment, sig // deploy proxy contract const txResponse = await ethers.provider.broadcastTransaction(transaction); - const receipt = await txResponse.wait(); + const receipt = await waitForReceiptWithIndexRetry(txResponse.hash, hre); if (receipt?.contractAddress !== proxyTransactionDetails.address) { console.log( "Failed to deploy createX contract, resulting address", diff --git a/contracts/internal/host-chain/utils/fund.ts b/contracts/internal/host-chain/utils/fund.ts index 8b01d93..b38737b 100644 --- a/contracts/internal/host-chain/utils/fund.ts +++ b/contracts/internal/host-chain/utils/fund.ts @@ -23,7 +23,13 @@ export async function fundAccount( ): Promise { if ((await hre.ethers.provider.getBalance(signer.address)).toString() === "0") { if (hre.network.name === "localfhenixk8s") { - await getFunds(signer.address, "http://hostchain:3000"); + // Local CoFHE hostchain now relies on prefunded genesis accounts instead of + // the old faucet service, so a zero balance here means the hostchain state + // was initialized from the wrong image/genesis and deployment cannot proceed. + throw new Error( + `Account ${signer.address} has zero balance on localfhenixk8s. ` + + "This devnet no longer exposes hostchain:3000/faucet; rebuild the hostchain image and wipe the hostchain/beacon volumes so the prefunded genesis accounts are applied." + ); } else if (hre.network.name === "localfhenix") { await hre.fhenixjs.getFunds(signer.address); console.log(