-
Notifications
You must be signed in to change notification settings - Fork 165
system: Add create account helper #282
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
base: main
Are you sure you want to change the base?
Conversation
4c01fc7 to
4b87477
Compare
4b87477 to
05f74a9
Compare
programs/system/src/lib.rs
Outdated
| to: account, | ||
| lamports: required_lamports, | ||
| } | ||
| .invoke()?; |
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.
Should we make this .invoke_signed(signers)?; to support the case a PDA acts as the funding account for the transfer?
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.
Yeah, that is a good point. It would only work for PDAs used as signers (i.e., owned by the system program), but it is a good idea to support this scenario.
Made the change on 1466eda and updated the docs.
| Rent::get()?.minimum_balance(space) | ||
| }; | ||
|
|
||
| if account.lamports() == 0 { |
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 do you think about using hints from pinocchio::hint module?
i expect account is not exist, in the majority of cases
| if account.lamports() == 0 { | |
| if likely(account.lamports() == 0) { |
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.
nice
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 do you think about using hints from
pinocchio::hintmodule?i expect account is not exist, in the majority of cases
It made no difference in my tests. Also, I had a look at the asm and it seems the compiler is doing the right thing already. Did you notice a difference?
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 same for the lib (i didn't test it in the real app).
As a part of library it compiles in the expected instructions.
Just wanted to make extra sure this logic won't be miscompiled in the large program.
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 wrote a small program and there was no difference. I think we can leave it as it is and revisit later if we see that there is a change in behaviour.
49fc5db to
1466eda
Compare
grod220
left a comment
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.
LGTM
Problem
Creating accounts funded by a payer account is a common operation. In most cases, the logic needs to be replicated in different programs.
Solution
Add a helper to create accounts. The helper supports creating both PDA and non-PDA accounts.