Repository navigation
feat: Implement Undelegate for v2 #269
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,8 @@ | ||
| <!-- | ||
| Keep the PR description short. Summarize the change in one or two sentences. | ||
| Do not repeat details already covered by the linked issue. | ||
| --> | ||
|
|
||
| > ⚠️ NOTE: Use notes like this to emphasize something important about the PR. | ||
| > | ||
| > This could include other PRs this PR is built on top of; API breaking changes; reasons for why the PR is on hold; or anything else you would like to draw attention to. | ||
| <Brief summary> | ||
|
|
||
| | Status | Type | ⚠️ Core Change | Issue | | ||
| | :---: | :---: | :---: | :--: | | ||
| | Ready/Hold | Feature/Bug/Tooling/Refactor/Hotfix | Yes/No | [Link](<Issue link here>) | | ||
|
|
||
| ## Problem | ||
|
|
||
| _What problem are you trying to solve?_ | ||
|
|
||
|
|
||
| ## Solution | ||
|
|
||
| _How did you solve the problem?_ | ||
|
|
||
|
|
||
| ## Before & After Screenshots | ||
|
|
||
| _Insert screenshots of example code output_ | ||
|
|
||
| **BEFORE**: | ||
| [insert screenshot here] | ||
|
|
||
| **AFTER**: | ||
| [insert screenshot here] | ||
|
|
||
|
|
||
| ## Other changes (e.g. bug fixes, small refactors) | ||
|
|
||
|
|
||
| ## Deploy Notes | ||
|
|
||
| _Notes regarding deployment of the contained body of work. These should note any | ||
| new dependencies, new scripts, etc._ | ||
|
|
||
| **New scripts**: | ||
|
|
||
| - `script` : script details | ||
|
|
||
| **New dependencies**: | ||
|
|
||
| - `dependency` : dependency details | ||
| Closes #<issue> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| use wheels::variable_offset_layout; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| #[variable_offset_layout(buffer_offset = 1)] | ||
| pub struct UndelegateArgs { | ||
| /// Bump for the temporary DLP-owned undelegation buffer PDA. | ||
| /// Set by the instruction builder. | ||
| pub undelegate_buffer_bump: u8, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| /// Discriminator understood by owner programs during undelegation callbacks. | ||
| pub const EXTERNAL_UNDELEGATE_DISCRIMINATOR: [u8; 8] = | ||
| [196, 28, 41, 206, 48, 37, 51, 167]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| use solana_program::{ | ||
| instruction::{AccountMeta, Instruction}, | ||
| pubkey::Pubkey, | ||
| }; | ||
| use solana_sdk_ids::system_program; | ||
| use wheels::{layout::Encodable, DataLayoutError}; | ||
|
|
||
| use crate::{ | ||
| compat::{Compatize, Modernize}, | ||
| pda::{delegation_state_pda, undelegate_buffer_pda}, | ||
| DlpV2Instruction, UndelegateArgs, | ||
| }; | ||
|
|
||
| /// Builds the shared undelegation instruction. | ||
| pub fn undelegate( | ||
| current_validator: Pubkey, | ||
| delegated_account: Pubkey, | ||
| original_owner: Pubkey, | ||
| delegation_cluster: Pubkey, | ||
| delegation_rent_payer: Pubkey, | ||
| ) -> Result<Instruction, DataLayoutError> { | ||
| let (undelegate_buffer, undelegate_buffer_bump) = | ||
| undelegate_buffer_pda(&delegated_account.compatize()); | ||
|
|
||
| Ok(Instruction { | ||
| program_id: crate::id().modernize(), | ||
| accounts: vec![ | ||
| AccountMeta::new(current_validator, true), | ||
| AccountMeta::new(delegated_account, false), | ||
| AccountMeta::new_readonly(original_owner, false), | ||
| AccountMeta::new(undelegate_buffer.modernize(), false), | ||
| AccountMeta::new( | ||
| delegation_state_pda(&delegated_account.compatize()) | ||
| .modernize(), | ||
| false, | ||
| ), | ||
| AccountMeta::new_readonly(delegation_cluster, false), | ||
| AccountMeta::new(delegation_rent_payer, false), | ||
| AccountMeta::new_readonly(system_program::id(), false), | ||
| ], | ||
| data: [ | ||
| DlpV2Instruction::Undelegate.to_vec(), | ||
| UndelegateArgs { | ||
| undelegate_buffer_bump, | ||
| } | ||
| .encode()?, | ||
| ] | ||
| .concat(), | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -257,6 +257,10 @@ pub fn process_finalize_commitment( | |
| let mut metadata = | ||
| DelegationMetadataFast::from_account(delegation_metadata)?; | ||
| metadata.set_last_commit_id(pending.commit_seq()); | ||
| if pending.allow_undelegation() { | ||
| metadata | ||
| .set_undelegation_requester(UndelegationRequester::Validator); | ||
| } | ||
|
Comment on lines
+260
to
+263
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
# Find every writer and reader of the undelegation requester.
rg -nP --type=rust -C3 'set_undelegation_requester|undelegation_requester' program/src interface/src
# Check whether finalize_commitment or the Challenge flow touches DelegationState.
rg -nP --type=rust -C3 '\bDelegationState\b|delegation_state' program/src/processor/fraud_proofs program/src/processor/delegateRepository: magicblock-labs/delegation-program Length of output: 18852 🏁 Script executed: set -o pipefail
printf '%s\n' '--- finalize_commitment definitions and calls ---'
rg -n -F --glob '*.rs' -e 'commit_finalize' -e 'DelegationState' -e 'delegation_state' program/src/processor/fraud_proofs program/src/processor/internal program/src/processor/undelegate.rs
printf '%s\n' '--- finalize_commitment relevant source ---'
nl -ba program/src/processor/fraud_proofs/finalize_commitment.rs | sed -n '1,290p'
printf '%s\n' '--- internal commit_finalize complete source ---'
nl -ba program/src/processor/internal/commit_finalize.rs | sed -n '1,180p'Repository: magicblock-labs/delegation-program Length of output: 21094 🏁 Script executed: set -o pipefail
printf '%s\n' '--- apply_commit_finalize callers ---'
rg -n -F --glob '*.rs' -- 'apply_commit_finalize(' program/src || test "$?" -eq 1
printf '%s\n' '--- all v2 requester writes ---'
rg -n -F --glob '*.rs' -e 'undelegation_requester_mut' -e 'set_undelegation_requester' -e 'undelegation_requester =' program/src interface/src || test "$?" -eq 1
printf '%s\n' '--- direct caller context ---'
rg -n -F --glob '*.rs' -l -- 'apply_commit_finalize(' program/src | while IFS= read -r file; do
echo "--- $file"
nl -ba "$file" | grep -n -B25 -A35 -F 'apply_commit_finalize('
doneRepository: magicblock-labs/delegation-program Length of output: 8539 Synchronize validator undelegation with Challenge finalization writes
🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| drop(delegation_cluster_data); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| mod commit_finalize; | ||
| mod undelegate; | ||
|
|
||
| pub(crate) use commit_finalize::*; | ||
| pub(crate) use undelegate::*; |
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 660
🏁 Script executed:
Repository: magicblock-labs/delegation-program
Length of output: 14307
Use a visible top-level heading for the summary prompt.
<Brief summary>is parsed as an HTML element, so the prompt text is not visible. The repository also enables markdownlint, whose default MD041 rule requires a top-level heading.Suggested fix
📝 Committable suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.23.3)
[warning] 6-6: First line in a file should be a top-level heading
(MD041, first-line-heading, first-line-h1)
🤖 Prompt for AI Agents