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

fix: Fix optional accounts in declare_program! #2967

Merged
merged 15 commits into from
May 20, 2024

Conversation

cryptopapi997
Copy link
Contributor

@cryptopapi997 cryptopapi997 commented May 13, 2024

When using optional accounts with declare_program! the generated code results in the account being set to crate::ID when the account is None. This means we get two scenarios:

  • If our program A is called from another program B via CPI, it will set the optional account to B if it's none because from that scope the current crate::ID is that of the calling program.
  • If our program A is used from someplace that isn't another program, the macro blows up because crate::ID isn't defined anywhere.

Both of these are the wrong thing to happen, but the fix is easy - just pass in super::__ID instead, which is what this PR does.

Copy link

vercel bot commented May 13, 2024

@cryptopapi997 is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto added lang next Required for the next release fix Bug fix PR labels May 14, 2024
@cryptopapi997
Copy link
Contributor Author

wdyt @acheroncrypto

Copy link
Collaborator

@acheroncrypto acheroncrypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt @acheroncrypto

Small comment, looks great otherwise.

Copy link
Collaborator

@acheroncrypto acheroncrypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@acheroncrypto acheroncrypto merged commit b76d1bf into coral-xyz:master May 20, 2024
48 of 49 checks passed
@cryptopapi997 cryptopapi997 deleted the fix-program-id-optionals branch May 20, 2024 20:40
@cryptopapi997
Copy link
Contributor Author

Thanks for merging! Do you already have an ETA for the next patch release that will include these?

@acheroncrypto
Copy link
Collaborator

ETA is early next month, but you can already use it from git if you don't publish crates:

[dependencies]
anchor-lang = { git = "https://github.com/coral-xyz/anchor", rev = "b76d1bf" }

and in Anchor.toml:

anchor_version = "0.30.0-b76d1bf"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix PR lang next Required for the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants