-
Notifications
You must be signed in to change notification settings - Fork 21
fix: enable large commits #202
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
Open
taco-paco
wants to merge
10
commits into
main
Choose a base branch
from
fix/enable-large-commits
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b5723a2
feat: preallocated buffers
taco-paco 90788ae
feat: instrution builder
taco-paco 44618fa
add test
taco-paco d23e894
feat: add tests
taco-paco d3cf58c
fix: unnecessary clippy & ambigious test
taco-paco 3b0ad37
refactor: assert particular error
taco-paco d64cab9
fix: funds leak
taco-paco b5f4daf
fix: branch base on initialization status
taco-paco 7cb18eb
fix: validate account grown correctly
taco-paco 6365d3c
fix: fmt + lint
taco-paco 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,26 @@ | ||
| use borsh::{BorshDeserialize, BorshSerialize}; | ||
|
|
||
| use crate::compat::borsh; | ||
|
|
||
| /// Which DLP-owned buffer (or the delegated account itself) a | ||
| /// `PreallocateBuffer` instruction should grow. | ||
| #[derive( | ||
| Default, Debug, Clone, Copy, PartialEq, Eq, BorshSerialize, BorshDeserialize, | ||
| )] | ||
| pub enum PreallocateBufferKind { | ||
| /// The `commit_state` PDA (seeds: `[COMMIT_STATE_TAG, delegated_account]`). | ||
| #[default] | ||
| CommitState, | ||
| /// The `undelegate_buffer` PDA (seeds: `[UNDELEGATE_BUFFER_TAG, delegated_account]`). | ||
| UndelegateBuffer, | ||
| /// Pre-allocating delegated account itself | ||
| DelegatedAccount, | ||
| } | ||
|
|
||
| #[derive(Default, Debug, BorshSerialize, BorshDeserialize)] | ||
| pub struct PreallocateBufferArgs { | ||
| /// Which buffer to grow. | ||
| pub kind: PreallocateBufferKind, | ||
| /// The final size the buffer should reach | ||
| pub target_size: u32, | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| use dlp::{ | ||
| args::{PreallocateBufferArgs, PreallocateBufferKind}, | ||
| discriminator::DlpDiscriminator, | ||
| pda::{ | ||
| commit_record_pda_from_delegated_account, | ||
| commit_state_pda_from_delegated_account, | ||
| delegation_record_pda_from_delegated_account, | ||
| undelegate_buffer_pda_from_delegated_account, | ||
| validator_fees_vault_pda_from_validator, | ||
| }, | ||
| total_size_budget, AccountSizeClass, DLP_PROGRAM_DATA_SIZE_CLASS, | ||
| }; | ||
| use solana_program::{ | ||
| account_info::MAX_PERMITTED_DATA_INCREASE, | ||
| instruction::{AccountMeta, Instruction}, | ||
| pubkey::Pubkey, | ||
| }; | ||
| use solana_sdk_ids::system_program; | ||
|
|
||
| use crate::compat::{borsh::to_vec, Compatize, Modernize}; | ||
|
|
||
| /// Builds a preallocate buffer instruction. | ||
| /// See [dlp::processor::process_preallocate_buffer] for docs. | ||
| pub fn preallocate_buffer( | ||
| validator: Pubkey, | ||
| delegated_account: Pubkey, | ||
| kind: PreallocateBufferKind, | ||
| target_size: u32, | ||
| ) -> Instruction { | ||
| let args = to_vec(&PreallocateBufferArgs { kind, target_size }).unwrap(); | ||
| let validator_compat = validator.compatize(); | ||
| let delegated_account_compat = delegated_account.compatize(); | ||
| let delegation_record_pda = | ||
| delegation_record_pda_from_delegated_account(&delegated_account_compat) | ||
| .modernize(); | ||
| let commit_record_pda = | ||
| commit_record_pda_from_delegated_account(&delegated_account_compat) | ||
| .modernize(); | ||
| let validator_fees_vault_pda = | ||
| validator_fees_vault_pda_from_validator(&validator_compat).modernize(); | ||
| let buffer_pda = match kind { | ||
| PreallocateBufferKind::CommitState => { | ||
| commit_state_pda_from_delegated_account(&delegated_account_compat) | ||
| .modernize() | ||
| } | ||
| PreallocateBufferKind::UndelegateBuffer => { | ||
| undelegate_buffer_pda_from_delegated_account( | ||
| &delegated_account_compat, | ||
| ) | ||
| .modernize() | ||
| } | ||
| PreallocateBufferKind::DelegatedAccount => delegated_account, | ||
| }; | ||
| Instruction { | ||
| program_id: dlp::id().modernize(), | ||
| accounts: vec![ | ||
| AccountMeta::new(validator, true), | ||
| AccountMeta::new_readonly(delegated_account, false), | ||
| AccountMeta::new(delegation_record_pda, false), | ||
| AccountMeta::new(buffer_pda, false), | ||
| AccountMeta::new_readonly(commit_record_pda, false), | ||
| AccountMeta::new_readonly(validator_fees_vault_pda, false), | ||
| AccountMeta::new_readonly(system_program::id(), false), | ||
| ], | ||
| data: [DlpDiscriminator::PreallocateBuffer.to_vec(), args].concat(), | ||
| } | ||
| } | ||
|
|
||
| /// Returns the sequence of `preallocate_buffer` instructions needed to grow | ||
| /// a buffer of `kind` from `current_size` up to `target_size` | ||
| pub fn preallocate_buffer_chunks( | ||
| validator: Pubkey, | ||
| delegated_account: Pubkey, | ||
| kind: PreallocateBufferKind, | ||
| current_size: u32, | ||
| target_size: u32, | ||
| ) -> Vec<Instruction> { | ||
| let growth = target_size.saturating_sub(current_size); | ||
| let chunks = growth.div_ceil(MAX_PERMITTED_DATA_INCREASE as u32) as usize; | ||
| (0..chunks) | ||
| .map(|_| { | ||
| preallocate_buffer(validator, delegated_account, kind, target_size) | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| /// | ||
| /// Returns accounts-data-size budget for preallocate_buffer instruction. | ||
| /// | ||
| /// This value can be used with ComputeBudgetInstruction::SetLoadedAccountsDataSizeLimit | ||
| /// | ||
| pub fn preallocate_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 | ||
| delegated_account, // buffer_pda | ||
| AccountSizeClass::Tiny, // commit_record_pda | ||
| AccountSizeClass::Tiny, // validator_fees_vault_pda | ||
| AccountSizeClass::Tiny, // system_program | ||
| ]) | ||
| } | ||
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.
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.