From 8660c664252876f7cc1e8e96e1bd93adf6f8738c Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Fri, 13 Feb 2026 11:12:41 +0000 Subject: [PATCH] fix: wait for RPC nonce sync between multi-step deployments When deploying with --with-app-impl, Step 1 (DstackApp) and Step 2 (DstackKms proxy) run back-to-back. Public RPC endpoints may return a stale nonce after Step 1's transaction is mined, causing Step 2 to fail with "nonce too low". Poll getTransactionCount("latest") until it reflects the Step 1 nonce before proceeding. --- kms/auth-eth/hardhat.config.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kms/auth-eth/hardhat.config.ts b/kms/auth-eth/hardhat.config.ts index 66274ecb..87a955ea 100644 --- a/kms/auth-eth/hardhat.config.ts +++ b/kms/auth-eth/hardhat.config.ts @@ -108,8 +108,19 @@ task("kms:deploy", "Deploy the DstackKms contract") await appContractImpl.waitForDeployment(); appImplementation = await appContractImpl.getAddress(); console.log("✅ DstackApp implementation deployed to:", appImplementation); + + // Wait for RPC nonce to catch up (public RPCs may return stale nonce) + const tx = appContractImpl.deploymentTransaction(); + if (tx) { + const expectedNonce = tx.nonce + 1; + for (let i = 0; i < 10; i++) { + const latestNonce = await ethers.provider.getTransactionCount(deployerAddress, "latest"); + if (latestNonce >= expectedNonce) break; + await new Promise(r => setTimeout(r, 1500)); + } + } } - + if (appImplementation !== ethers.ZeroAddress) { console.log("Setting DstackApp implementation during initialization:", appImplementation); }