Skip to content

Commit

Permalink
fix: use manual nonce management instead
Browse files Browse the repository at this point in the history
  • Loading branch information
karlem committed Nov 11, 2024
1 parent 4220e39 commit 4a33fb4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/contracts-deployment-test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Contracts: Smoke test deployment'
name: "Contracts: Smoke test deployment"

# This workflow is triggered from the main CI workflow.
on:
Expand All @@ -17,8 +17,8 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'pnpm'
node-version: "18.x"
cache: "pnpm"

- name: Install dependencies
run: cd contracts && make deps
Expand All @@ -36,6 +36,6 @@ jobs:
echo "export RPC_URL=http://127.0.0.1:1337" >> .env
echo "export CHAIN_ID=1337" >> .env
export PATH="$PATH:/home/runner/.config/.foundry/bin"
pnpm exec ganache-cli -b 1 -g0 -p1337 --account 0x$PRIVATE_KEY,1001901919191919191 &
pnpm exec ganache-cli -g0 -p1337 --account 0x$PRIVATE_KEY,1001901919191919191 &
sleep 5
make deploy-stack
10 changes: 3 additions & 7 deletions contracts/tasks/deploy-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,8 @@ task('deploy-registry')
creationPrivileges: Number(mode),
}

console.log(`Deploying SubnetRegistryDiamond...`)
const registry = await hre.deployments.deploy('SubnetRegistryDiamond', {
from: deployer,
Deployments.deploy(hre, deployer, {
name: 'SubnetRegistryDiamond',
args: [registryFacets.asFacetCuts(), registryConstructorParams],
log: true,
waitConfirmations: 1,
})
console.log(`SubnetRegistryDiamond deployed at ${registry.address}`)
});
})
34 changes: 12 additions & 22 deletions contracts/tasks/lib/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,19 @@ export class Deployments {
...(contract.libraries || []),
)

// This is a workaround for an issue where the nonce gets reused. This can occur in load-balanced environments
// where transactions are sent to different nodes, and the nonce is not consistently updated across all nodes.
while (true) {
try {
const result = await hre.deployments.deploy(contract.name, {
from: deployer,
log: true,
args: contract.args,
libraries: libraries.addresses,
waitConfirmations: 2,
})
results[contract.name] = result
console.log(`${contract.name} deployed at ${result.address}`)
break
} catch (error) {
if (error instanceof Error &&(error as any).code === "NONCE_EXPIRED") {
console.log(`Nonce expired. Retrying deployment of ${contract.name}`)
// Manually managed nonce due to a Filecoin update, which requires specifying 'pending' with
// getTransactionCount to retrieve the latest nonce.
const nonce = await hre.ethers.provider.getTransactionCount(deployer, "pending");

continue
}
throw error
}
}
const result = await hre.deployments.deploy(contract.name, {
from: deployer,
log: true,
args: contract.args,
libraries: libraries.addresses,
nonce: nonce,
})
results[contract.name] = result
console.log(`${contract.name} deployed at ${result.address}`)
}

return new Deployments(
Expand Down

0 comments on commit 4a33fb4

Please sign in to comment.