-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[WIP]lang: Remove program info from CpiContext #965
[WIP]lang: Remove program info from CpiContext #965
Conversation
5eee797
to
cbec165
Compare
00947f5
to
b683771
Compare
@armaniferrante this is now almost done. There are some instances where I didn't know what to do which I have marked with |
@@ -12,6 +12,3 @@ pub mod dex; | |||
|
|||
#[cfg(feature = "governance")] | |||
pub mod governance; | |||
|
|||
#[cfg(feature = "shmem")] | |||
pub mod shmem; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was shmem
removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the change broke the shmem program and armani told me (offline) that instead of fixing it I can just delete it cause it's not used by anyone. In addition, solana will allow for CPIs to return values soon so this program wont be needed anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove it.
lang/attribute/interface/src/lib.rs
Outdated
/// let cpi_program = ctx.accounts.auth_program.clone(); | ||
/// let cpi_ctx = CpiContext::new(cpi_program, Empty {}); | ||
/// | ||
/// //TODO[paulx]: what to do with this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the problem here? This seems fine, though I prefer moving the cpi_ctx above where it previously was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea I think the todo in the is_realized
function is the only one that actually matters. There the program comes from a remaining account instead of the Accounts struct so wasn't sure whether I can just add it as a proper field to the Account struct without breaking something because Im not super familiar yet with the #[access_control]
and #[interface]
attributes
also sure, I'll move cpi_ctx in back to where it was. I actually did this in a lot of places. My way of thinking about this has been that moving things into variables if they are not a) mutated or b) used at least twice is not a good idea because variables imply to the reader that either a) or b) is going to happen and it confuses the reader if neither happens (with the exception where a function call or struct becomes too confusing to read). curious what u think about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we actually need the cpi_program
variable for #[interface]
because the interface CPI "client" doesn't actually know what program ID to use, so it needs to be provided. See https://github.com/project-serum/anchor/blob/master/lang/attribute/interface/src/lib.rs#L216
For all other CPI's, however, this is not the case, since the program address is hardcoded in the CPI client for security reasons (facilitated with the use of declare_id
)
So our options are
- Keep The old API with
CpiContext::new(cpi_program, cpi_accounts)
and only usecpi_program
with the#[interface]
client. - Use the new api, and make
cpi_program
an option insideCpiContext
, e.g.,CpiContext::new(cpi_accounts).with_program(cpi_program)
.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3..) for interface cpi calls, add a program arg after the cpi_context and before the args expansion in the function signature
1..) if we keep the old api, wouldnt all calls use cpi_program, not just interface ones? im probably misunderstanding
2..) I like this too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- No because the cpi clients hardcode the program_id when constructing the
Instruction
struct for CPI. This is done via thecrate::ID
variable defined bydeclare_id
in all Anchor programs.
I'm not a big fan of 3). But am happy with both 1 and 2. Maybe we go with 1) for now to avoid the breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
ah what I meant is that callers would still use cpi_program in all programs to pass it into new (even tho it is not used for the actual call)
-
seems ok to me, better break things now than later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we go with 2 maybe instead of an option, there could be a new type InterfaceCpiContext. for normal cpi calls u should not be able to change the program whereas for interface calls you always need to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fanatid thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not have strong thoughts about Cpi/interface 😐
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to not introduce a new type, avoid the breaking change, and revisit this once we address #454, which will determine the future of #[interface]
.
Commented on all the remaining TODOs. |
It unfortunate this was never merged. Given that the main blocker From the sounds of it the advantages are
Cons are
Also it looks like shmem is still in the anchor spl library even though we now have return values from CPI. I don't know too much about that but i would have thought shmem would have just been removed in a separate PR. |
Closing as stale. |
closes #522