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

Cache calculated bump seeds in context #1367

Merged
merged 16 commits into from
Jan 27, 2022
Merged

Cache calculated bump seeds in context #1367

merged 16 commits into from
Jan 27, 2022

Conversation

armaniferrante
Copy link
Member

@armaniferrante armaniferrante commented Jan 27, 2022

Closes #1364.

Pre-requisite for #1361. This is needed for non anchor accounts that won't have the account header and so can't store bump seeds directly in the account data (and so the bump needs to be stored in some other associated account).

One can use ctx.bumps.get("<my_account_name>") to get a bump seed already searched for in the accounts context.

@armaniferrante armaniferrante changed the title update Cache calculated bump seeds in context Jan 27, 2022
@armaniferrante armaniferrante marked this pull request as ready for review January 27, 2022 21:36
@billythedummy
Copy link
Contributor

billythedummy commented Feb 9, 2022

Given that we know which accounts require a PDA check at compile-time, would it be more efficient to generate a struct like BumpsAccountStruct instead of using a BTreeMap? For example:

#[derive(Accounts)]
#[derive(bumps)] // hypothetical proc macro for this suggestion
pub struct Example<'info> {
    #[account(
        init,
        seeds = [...],
        bump,
    )]
    pub pda_1: AccountInfo<'info>,

    pub not_pda: AccountInfo<'info>,
}

would generate

pub struct BumpsExample {
  pub pda_1: Option<u8>
} 

With a BTreeMap with string keys, there are no compile-time checks for account name refactors as well. If i change the struct field name from pda_1 to pda_2 but forget to change the code from ctx.bumps.get("pda_1") to ctx.bumps.get("pda_2"), it becomes a runtime error instead

@armaniferrante
Copy link
Member Author

@billythedummy that sounds good. How would you expect to access this from the context?

@billythedummy
Copy link
Contributor

so i think ctx.bumps would be the generated struct instead of a BTreeMap (so BumpsExample in this case). So instead of ctx.bumps.get("pda_1") it will be ctx.bumps.pda_1. This will probably require adding a new generic to Context for this "bumps" type. Haven't looked closely at the lang internals yet so i'm not sure how difficult it would be to implement this.

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.

lang: Add BTreeMap to Context containing all bump seeds found during constraint execution
2 participants