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

PDA Inference Fails with Seeds Outside of Scope #1550

Closed
callensm opened this issue Mar 3, 2022 · 4 comments
Closed

PDA Inference Fails with Seeds Outside of Scope #1550

callensm opened this issue Mar 3, 2022 · 4 comments
Labels
bug Something isn't working idl related to the IDL, either program or client side

Comments

@callensm
Copy link
Member

callensm commented Mar 3, 2022

In the current pda-derivation test case, the IDL is properly populated with the PDA seeds since the seeds are declared and referenced within the same module/scope as the Accounts structs.

If you move the seeds outside of the scope of the struct:

mod seeds {
    #[constant]
    pub const MY_SEED: &[u8] = b"my_pda_seed";
}

#[derive(Accounts)]
pub struct Init<'info> {
    #[account(
        seeds = [
            seeds::MY_SEED,
            // ...
        ],
        bump,
        // ...
    )]
    pub my_pda: Account<'info, X>,

    // ...
}

This will fail to parse and translate the seeds into the IDL with:

WARNING: unexpected seed: Path(ExprPath { attrs: [], qself: None, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident(seeds), arguments: None }, Colon2, PathSegment { ident: Ident(MY_SEED), arguments: None }] } })

...and if you use the seed into the module (use seeds::MY_SEED) and remove the module scope prefix, it will still fail with the appropriately modified ident parsing error.

It seems that only seeds defined within the same scope at the Accounts struct that is using them will parse correctly.

@GuidoDipietro
Copy link

This is especially annoying if you use some external constant from a common program such as mpl_token_metadata, it can generate many many warnings.

@DevMilk
Copy link

DevMilk commented Oct 7, 2022

I thought same way to write seeds and got same error. It is not possible for now i guess.

@AnderUstarroz
Copy link

This really needs a review, aiming for a more flexible way to generate seeds without breaking IDL or generating the mentioned annoying warnings.

@acheroncrypto acheroncrypto mentioned this issue Feb 25, 2024
@acheroncrypto acheroncrypto added bug Something isn't working idl related to the IDL, either program or client side labels Mar 10, 2024
@acheroncrypto
Copy link
Collaborator

Fixed by #2824.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working idl related to the IDL, either program or client side
Projects
None yet
Development

No branches or pull requests

5 participants