Skip to content

fix(cli): Wait for program confirmation before IDL init during deploy#3976

Merged
jacobcreech merged 2 commits into
otter-sec:masterfrom
GuiBibeau:fix/deploy-race-condition
Oct 9, 2025
Merged

fix(cli): Wait for program confirmation before IDL init during deploy#3976
jacobcreech merged 2 commits into
otter-sec:masterfrom
GuiBibeau:fix/deploy-race-condition

Conversation

@GuiBibeau

@GuiBibeau GuiBibeau commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Fixes race condition in anchor deploy where IDL operations fail during deployment and redeployment.

Issues Fixed

  1. Initial deployment: Program not yet available in validator cache when IDL init is attempted
  2. Redeployment: IDL account already exists, causing "account already in use" error

Changes

  • Add polling loop to wait for program confirmation before IDL operations
  • Check if IDL account exists and call idl_upgrade (if exists) or idl_init (if new)
  • Reduce retry count from 30 to 5 for faster feedback

Testing Steps

  1. Build the CLI from this branch:

    git fetch origin pull/3976/head:fix/deploy-race-condition
    git checkout fix/deploy-race-condition
    cargo build --release
  2. Start a fresh localnet validator:

    solana-test-validator --reset
  3. Create and deploy a new project using the built CLI:

    cd /tmp
    ./path/to/anchor/target/release/anchor init test-project
    cd test-project
    ./path/to/anchor/target/release/anchor build
    ./path/to/anchor/target/release/anchor deploy

    Expected: "Idl account created"

  4. Make a code change and redeploy:

    # Add a new instruction to programs/test-project/src/lib.rs
    ./path/to/anchor/target/release/anchor build
    ./path/to/anchor/target/release/anchor deploy

    Expected: "Idl account successfully upgraded"

Before

  • Initial deploy: Failed with "Program is not deployed"
  • Redeploy: Failed with "account already in use"

After

  • Initial deploy: Waits for program confirmation, then creates IDL
  • Redeploy: Detects existing IDL account and upgrades it

@vercel

vercel Bot commented Oct 9, 2025

Copy link
Copy Markdown

@GuiBibeau is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Oct 9, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
anchor-docs Ignored Ignored Preview Oct 9, 2025 9:29pm

On redeployment, the IDL account already exists. This commit checks if the
IDL account exists and calls idl_upgrade if it does, or idl_init if it
doesn't. Also reduces retry count from 30 to 5 for faster feedback.
@jacobcreech jacobcreech merged commit 059bc20 into otter-sec:master Oct 9, 2025
105 of 106 checks passed
@tobySolutions

Copy link
Copy Markdown

Cooked!

WilfredAlmeida pushed a commit to KartikSoneji/anchor that referenced this pull request Oct 22, 2025
…otter-sec#3976)

* fix(cli): Wait for program confirmation before IDL init during deploy

* fix(cli): Check for existing IDL account and upgrade instead of create

On redeployment, the IDL account already exists. This commit checks if the
IDL account exists and calls idl_upgrade if it does, or idl_init if it
doesn't. Also reduces retry count from 30 to 5 for faster feedback.
Otter-0x4ka5h pushed a commit to Otter-0x4ka5h/anchor that referenced this pull request Mar 25, 2026
…otter-sec#3976)

* fix(cli): Wait for program confirmation before IDL init during deploy

* fix(cli): Check for existing IDL account and upgrade instead of create

On redeployment, the IDL account already exists. This commit checks if the
IDL account exists and calls idl_upgrade if it does, or idl_init if it
doesn't. Also reduces retry count from 30 to 5 for faster feedback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants