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

processor: allocate #40

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

processor: allocate #40

wants to merge 3 commits into from

Conversation

buffalojoec
Copy link
Contributor

@buffalojoec buffalojoec commented Feb 27, 2025

This PR implements the Allocate instruction processor in the BPF version of the System builtin program.

See #38 for a draft overview of the implemented base processor (no nonce instructions).


As you can see from the comment within the allocate function in the processor, we have immediately encountered one of two obstacles preventing us from migrating this program to BPF. Account resizing (realloc) in the VM is much more constrained than resizing in host memory, so we'll need to come up with a solution for expanding that.

In the meantime, I think this should land with the current implementation, so we can begin implementing, profiling and testing the rest of program. For more context on account resizing, see #30.


macro_rules! accounts {
( $infos:ident, $signers:ident, $( $i:literal => $name:ident ),* $(,)? ) => {
let mut $signers = HashSet::new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to "predict" how many signers to expect? It would be better to have this as with_capacity to avoid reallocations – better yet if we can avoid using a std::collections::HashSet. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think for all non-nonce instructions the number of signers is either 1 or 2. Perhaps I can rewrite this a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know what you think of my latest commit!

}

fn process_allocate(accounts: &[AccountInfo], space: u64) -> ProgramResult {
accounts!(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I am wondering if there is a gain in using a macro over something like:

let [account_info, _remaining @ ..] = accounts else {
        return Err(ProgramError::NotEnoughAccountKeys);
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For a single account access, like in this instruction, no there's probably not much of a gain. But for the other ones coming up after this PR, I think it's worth doing.

}

pub fn process(_program_id: &Pubkey, accounts: &[AccountInfo], input: &[u8]) -> ProgramResult {
match solana_bincode::limited_deserialize::<SystemInstruction>(input, MAX_INPUT_LEN)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we be using bincode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really don't want to, but for now, limited_deserialize is the de facto way to deserialize builtin entrypoints. That being said, this program doesn't seem to have unbounded instruction parameters (such as a collection), so we may be able to factor this out via pack/unpack methods on the instruction enum itself.

Copy link
Contributor

@febo febo left a comment

Choose a reason for hiding this comment

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

Looks good! Just left one nit and a question.

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.

2 participants