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

lang: Consider removing associated keyword #491

Closed
armaniferrante opened this issue Jul 8, 2021 · 3 comments · Fixed by #612
Closed

lang: Consider removing associated keyword #491

armaniferrante opened this issue Jul 8, 2021 · 3 comments · Fixed by #612

Comments

@armaniferrante
Copy link
Member

armaniferrante commented Jul 8, 2021

We should consider removing the associated keyword. I'm a little worried the automagic of adding the __nonce field will cause problems when upgrading account layouts. For example, if one were to add fields to an account, then it's possible one overwrites the __nonce field.

Instead of removing, we can also consider adding a header to the account layout to store such metadata. For example, discriminator || metadata || borsh(struct) or some variant.

Note that seeds can do everything associated can, although it requires manual nonce management/storage. So it's recommended to use seeds until the future of associated is decided.

@armaniferrante armaniferrante changed the title lang: Remove associated keyword lang: Consider removing associated keyword Jul 10, 2021
@fanatid
Copy link
Contributor

fanatid commented Jul 12, 2021

  • We need to change JS api. Is it ok to left associatedAddress but change the returned value to Promise<[PublicKey, number]> or we need to create a new method?
  • seed instead associated need to add b"anchor".as_ref() each time to the seed, is there any easy way to avoid it?

@armaniferrante
Copy link
Member Author

  • We need to change JS api. Is it ok to left associatedAddress but change the returned value to Promise<[PublicKey, number]> or we need to create a new method?
  • seed instead associated need add b"anchor".as_ref() each time to the seed, should we add it magically in generated code?
  • No need to create a new api. We can just remove the associated apis from the js client and use the standard PublicKey.findProgramAddress and PublicKey.createProgramAddress from @solana/web3.js.
  • This isn't necessary because seeds = [<>] in the program doesn't add any seeds. Note that associated = <> added b"anchor" as a prefix to seeds for domain separation, so that seeds wouldn't conflict in the event that one accidently used both associated and seeds in the same program. If we remove associated this is no longer required. Domain separation should be done explicitly, if needed.

@suscd
Copy link
Contributor

suscd commented Jul 14, 2021

Seems fine to me to remove the associated macro.

I do think the most annoying part about using PDAs is dealing with the bump seed, which just seems awkward to pass through. I like the idea of including space for the bump seed in the account header, perhaps for all accounts since its just one byte. That way for account initialization, anchor could use findProgramAddress based on the provided seeds and store the bump inside the header, then for post-init constraint checks it could use createProgramAddress and refer back to the bump seed stored in the account header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants