Skip to content

p-token: Add batch instruction #35

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

Merged
merged 12 commits into from
Mar 11, 2025
Merged

p-token: Add batch instruction #35

merged 12 commits into from
Mar 11, 2025

Conversation

febo
Copy link
Contributor

@febo febo commented Mar 7, 2025

This PR adds the batch instruction for p-token – this was originally proposed here.

The purpose is to allow the execution of multiple token instructions in a single program instruction – e.g., it is possible to execute multiple instructions in a single CPI call, which saves at least 1000 CUs (CPI base fee) for each additional instruction.

Note

SInce tests now run without test-sbf, this PR also updates the p-token tests to remove the test-sbf feature.

@febo febo requested a review from joncinque March 7, 2025 01:32
@febo febo force-pushed the febo/fix-jon-comments branch from e058e93 to c12b54f Compare March 10, 2025 14:40
Base automatically changed from febo/fix-jon-comments to main March 10, 2025 14:54
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks really good! I didn't think it would be so simple. Mostly small comments

Comment on lines -37 to -40
let (discriminator, instruction_data) = instruction_data
.split_first()
.ok_or(ProgramError::InvalidInstructionData)?;
let instruction = TokenInstruction::try_from(*discriminator)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Was the usage of TokenInstruction supposed to be reverted?

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, using the TokenInstruction enum increases 20 CUs at least once I added the Batch variant. I could not find a way to make it efficient.

Comment on lines +52 to +57
/// - `0`: `InitializeMint`
/// - `1`: `InitializeAccount`
/// - `3`: `Transfer`
/// - `7`: `MintTo`
/// - `9`: `CloseAccount`
/// - `16`: `InitializeAccount2`
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to make sure, were these updated for better performance as a result of this PR?

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, the idea was to keep all the Initialize*, MintTo, CloseAccount and Transfer on the "faster" path. We can tweak the list if you thing there are other instructions that are more critical.

accounts: &[AccountInfo],
instruction_data: &[u8],
instruction: TokenInstruction,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: was this supposed to be reverted?

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, it is more efficient to use the u8 value directly.

@febo febo requested a review from joncinque March 11, 2025 13:47
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks great! Too bad about the enum

@febo febo merged commit baa5918 into main Mar 11, 2025
11 checks passed
@febo febo deleted the febo/batch branch March 11, 2025 14:21
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