Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build IDL because of duplicate discriminator in declare_program macro #3562

Open
CanardMandarin opened this issue Feb 17, 2025 · 0 comments

Comments

@CanardMandarin
Copy link
Contributor

When using the declare_program macro, account name collisions can occur because many programs use generic names for accounts.

For example, if I have an account named vault and the IDL of the external program also defines a vault account, the following code will result in an IDL build error:

use crate::external::accounts::Vault as ExternalVault;

#[derive(Accounts)]
pub struct Init<'info> {
    pub vault: AccountLoader<'info, Vault>,
    pub external_vault: AccountLoader<'info, ExternalVault>,
} 

This will throw the following:

Error: Ambiguous discriminators for accounts Vault and ExternalVault

I'm seeing multiple solution here:

  1. Add a skip-idl-verify flag for advanced use of anchor
  2. Make discriminators program dependent
"accounts": [
  {
    "name": "Vault",
    "discriminator": [],
    "programId": "11111111111111111111111111111111"
  },
  {
    "name": "Mint",
    "discriminator": [],
    "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
  }
],
  1. Exclude external accounts (from declare_program macro) from the IDL generation? (I'm afraid it might break stuff)
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

No branches or pull requests

1 participant