-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add CommitFinalizeFromBuffer #137
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| use solana_program::instruction::Instruction; | ||
| use solana_program::system_program; | ||
| use solana_program::{instruction::AccountMeta, pubkey::Pubkey}; | ||
|
|
||
| use crate::args::{CommitBumps, CommitFinalizeArgs}; | ||
| use crate::discriminator::DlpDiscriminator; | ||
| use crate::pod_view::PodView; | ||
| use crate::{ | ||
| delegation_metadata_seeds_from_delegated_account, | ||
| delegation_record_seeds_from_delegated_account, total_size_budget, | ||
| validator_fees_vault_seeds_from_validator, AccountSizeClass, DLP_PROGRAM_DATA_SIZE_CLASS, | ||
| }; | ||
|
|
||
| /// Builds a commit state from buffer instruction. | ||
| /// See [crate::processor::process_commit_diff_from_buffer] for docs. | ||
| pub fn commit_finalize_from_buffer( | ||
| validator: Pubkey, | ||
| delegated_account: Pubkey, | ||
| data_buffer: Pubkey, | ||
| commit_args: &mut CommitFinalizeArgs, | ||
| ) -> (Instruction, super::CommitPDAs) { | ||
| let delegation_record = Pubkey::find_program_address( | ||
| delegation_record_seeds_from_delegated_account!(delegated_account), | ||
| &crate::id(), | ||
| ); | ||
|
|
||
| let validator_fees_vault = Pubkey::find_program_address( | ||
| validator_fees_vault_seeds_from_validator!(validator), | ||
| &crate::id(), | ||
| ); | ||
|
|
||
| let delegation_metadata = Pubkey::find_program_address( | ||
| delegation_metadata_seeds_from_delegated_account!(delegated_account), | ||
| &crate::id(), | ||
| ); | ||
|
|
||
| // save the bumps in the args | ||
| commit_args.bumps = CommitBumps { | ||
| delegation_record: delegation_record.1, | ||
| delegation_metadata: delegation_metadata.1, | ||
| validator_fees_vault: validator_fees_vault.1, | ||
| }; | ||
|
|
||
| ( | ||
| Instruction { | ||
| program_id: crate::id(), | ||
| accounts: vec![ | ||
| AccountMeta::new_readonly(validator, true), | ||
| AccountMeta::new(delegated_account, false), | ||
| AccountMeta::new_readonly(delegation_record.0, false), | ||
| AccountMeta::new(delegation_metadata.0, false), | ||
| AccountMeta::new_readonly(data_buffer, false), | ||
| AccountMeta::new_readonly(validator_fees_vault.0, false), | ||
| AccountMeta::new_readonly(system_program::id(), false), | ||
| ], | ||
| data: [ | ||
| DlpDiscriminator::CommitFinalizeFromBuffer.to_vec(), | ||
| commit_args.to_bytes(), | ||
| ] | ||
| .concat(), | ||
| }, | ||
| super::CommitPDAs { | ||
| delegation_record: delegation_record.0, | ||
| delegation_metadata: delegation_metadata.0, | ||
| validator_fees_vault: validator_fees_vault.0, | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| /// | ||
| /// Returns accounts-data-size budget for commit_diff_from_buffer instruction. | ||
| /// | ||
| /// This value can be used with ComputeBudgetInstruction::SetLoadedAccountsDataSizeLimit | ||
| /// | ||
| pub fn commit_finalize_from_buffer_size_budget(delegated_account: AccountSizeClass) -> u32 { | ||
| total_size_budget(&[ | ||
| DLP_PROGRAM_DATA_SIZE_CLASS, | ||
| AccountSizeClass::Tiny, // validator | ||
| delegated_account, // delegated_account | ||
| AccountSizeClass::Tiny, // delegation_record_pda | ||
| AccountSizeClass::Tiny, // delegation_metadata_pda | ||
| delegated_account, // data_buffer | ||
| AccountSizeClass::Tiny, // validator_fees_vault_pda | ||
| AccountSizeClass::Tiny, // program_config_pda | ||
| AccountSizeClass::Tiny, // system_program | ||
| ]) | ||
| } | ||
snawaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| use pinocchio::{account_info::AccountInfo, pubkey::Pubkey, ProgramResult}; | ||
| use pinocchio_log::log; | ||
|
|
||
| use crate::args::CommitFinalizeArgs; | ||
| use crate::pod_view::PodView; | ||
| use crate::processor::fast::internal::{ | ||
| process_commit_finalize_internal, CommitFinalizeInternalArgs, | ||
| }; | ||
| use crate::processor::fast::NewState; | ||
| use crate::{require_n_accounts, DiffSet}; | ||
|
|
||
| /// Commit a new state of a delegated PDA | ||
| /// | ||
| /// Accounts: | ||
| /// | ||
| /// 0: `[signer]` the validator requesting the commit | ||
| /// 1: `[]` the delegated account | ||
| /// 2: `[writable]` the PDA storing the new state | ||
| /// 3: `[writable]` the PDA storing the commit record | ||
| /// 4: `[]` the delegation record | ||
| /// 5: `[writable]` the delegation metadata | ||
| /// 6: `[]` the validator fees vault | ||
| /// | ||
| /// Instruction Data: CommitFinalizeArgs | ||
| /// | ||
| /// Requirements: | ||
| /// | ||
| /// - delegation record is initialized | ||
| /// - delegation metadata is initialized | ||
| /// - validator fees vault is initialized | ||
| /// - program config is initialized | ||
| /// - commit state is uninitialized | ||
| /// - commit record is uninitialized | ||
| /// - delegated account holds at least the lamports indicated in the delegation record | ||
| /// - account was not committed at a later slot | ||
| /// | ||
| /// Steps: | ||
| /// 1. Check that the pda is delegated | ||
| /// 2. Init a new PDA to store the new state | ||
| /// 3. Copy the new state to the new PDA | ||
| /// 4. Init a new PDA to store the record of the new state commitment | ||
snawaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pub fn process_commit_finalize_from_buffer( | ||
| _program_id: &Pubkey, | ||
| accounts: &[AccountInfo], | ||
| data: &[u8], | ||
| ) -> ProgramResult { | ||
| let [ | ||
| validator, // force multi-line | ||
| delegated_account, | ||
| delegation_record_account, | ||
| delegation_metadata_account, | ||
| data_account, // full bytes or diff | ||
| validator_fees_vault, | ||
| _system_program, | ||
| ] = require_n_accounts!(accounts, 7); | ||
|
|
||
| let args = CommitFinalizeArgs::try_view_from(data)?; | ||
|
|
||
| let data = data_account.try_borrow_data()?; | ||
| let commit_args = CommitFinalizeInternalArgs { | ||
| bumps: &args.bumps, | ||
| new_state: if args.data_is_diff.is_true() { | ||
| let diffset = DiffSet::try_new(data.as_ref())?; | ||
| if diffset.segments_count() == 0 { | ||
| log!("WARN: noop; empty diff sent"); | ||
| } | ||
| NewState::Diff(diffset) | ||
| } else { | ||
| NewState::FullBytes(&data) | ||
| }, | ||
| commit_id: args.commit_id, | ||
| allow_undelegation: args.allow_undelegation.is_true(), | ||
| validator, | ||
| delegated_account, | ||
| delegation_record_account, | ||
| delegation_metadata_account, | ||
| validator_fees_vault, | ||
| }; | ||
|
|
||
| process_commit_finalize_internal(commit_args) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.