-
Notifications
You must be signed in to change notification settings - Fork 38
feat: Handle post delegation actions: detect actions, parse and execute on the ER #999
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -122,7 +122,7 @@ impl ChainlinkCloner { | |||||||||
| message, | ||||||||||
| ); | ||||||||||
| // Defined positive commit frequency means commits should be scheduled | ||||||||||
| let ixs = match request.commit_frequency_ms { | ||||||||||
| let mut ixs = match request.commit_frequency_ms { | ||||||||||
| // TODO(GabrielePicco): Hotfix. Do not schedule frequency commits until we impose limits. | ||||||||||
| // 1. Allow configuring a higher minimum. | ||||||||||
| // 2. Stop committing accounts if they have been committed more than X times, | ||||||||||
|
|
@@ -162,6 +162,9 @@ impl ChainlinkCloner { | |||||||||
| } | ||||||||||
| _ => vec![modify_ix], | ||||||||||
| }; | ||||||||||
| if !request.delegation_actions.is_empty() { | ||||||||||
| ixs.extend(request.delegation_actions.clone()); | ||||||||||
| } | ||||||||||
|
Comment on lines
+165
to
+167
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. No transaction size guard before appending Appending arbitrary instructions from Consider computing the serialized size of 🤖 Prompt for AI Agents🧹 Nitpick | 🔵 Trivial Unnecessary full-Vec clone; prefer
♻️ Proposed refactor- if !request.delegation_actions.is_empty() {
- ixs.extend(request.delegation_actions.clone());
- }
+ ixs.extend_from_slice(&request.delegation_actions);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
|
|
||||||||||
| let mut tx = | ||||||||||
| Transaction::new_with_payer(&ixs, Some(&validator_authority_id())); | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,31 +5,60 @@ use magicblock_accounts_db::traits::AccountsBank; | |
| use magicblock_core::token_programs::EATA_PROGRAM_ID; | ||
| use magicblock_metrics::metrics; | ||
| use solana_account::ReadableAccount; | ||
| use solana_instruction::Instruction; | ||
| use solana_program::program_error::ProgramError; | ||
| use solana_pubkey::Pubkey; | ||
| use tracing::*; | ||
|
|
||
| use super::FetchCloner; | ||
| use crate::{ | ||
| chainlink::errors::{ChainlinkError, ChainlinkResult}, | ||
| cloner::Cloner, | ||
| cloner::{Cloner, DelegationActions}, | ||
| remote_account_provider::{ | ||
| ChainPubsubClient, ChainRpcClient, MatchSlotsConfig, | ||
| ResolvedAccountSharedData, | ||
| }, | ||
| }; | ||
|
|
||
| /// Parses a delegation record from account data bytes. | ||
| /// Returns the parsed DelegationRecord, or InvalidDelegationRecord error | ||
| /// if parsing fails. | ||
|
Comment on lines
+23
to
+25
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. Update the parser doc comment to include The comment currently documents only 🤖 Prompt for AI Agents |
||
| pub(crate) fn parse_delegation_record( | ||
| data: &[u8], | ||
| delegation_record_pubkey: Pubkey, | ||
| ) -> ChainlinkResult<DelegationRecord> { | ||
| DelegationRecord::try_from_bytes_with_discriminator(data) | ||
| ) -> ChainlinkResult<(DelegationRecord, Option<DelegationActions>)> { | ||
| let delegation_record_size = DelegationRecord::size_with_discriminator(); | ||
| if data.len() < delegation_record_size { | ||
| return Err(ChainlinkError::InvalidDelegationRecord( | ||
| delegation_record_pubkey, | ||
| ProgramError::InvalidAccountData, | ||
| )); | ||
| } | ||
| let record = | ||
| DelegationRecord::try_from_bytes_with_discriminator( | ||
| &data[..delegation_record_size], | ||
| ) | ||
| .copied() | ||
| .map_err(|err| { | ||
| ChainlinkError::InvalidDelegationRecord( | ||
| delegation_record_pubkey, | ||
| err, | ||
| ) | ||
| }) | ||
| })?; | ||
|
|
||
| if data.len() <= delegation_record_size { | ||
| Ok((record, None)) | ||
| } else { | ||
| let actions_data = &data[delegation_record_size..]; | ||
| let actions = bincode::deserialize::<Vec<Instruction>>(actions_data) | ||
| .map_err(|err| { | ||
| ChainlinkError::InvalidDelegationActions( | ||
| delegation_record_pubkey, | ||
| err.to_string(), | ||
| ) | ||
| })?; | ||
| Ok((record, Some(actions.into()))) | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn apply_delegation_record_to_account<T, U, V, C>( | ||
|
|
@@ -87,7 +116,7 @@ pub(crate) async fn fetch_and_parse_delegation_record<T, U, V, C>( | |
| account_pubkey: Pubkey, | ||
| min_context_slot: u64, | ||
| fetch_origin: metrics::AccountFetchOrigin, | ||
| ) -> Option<DelegationRecord> | ||
| ) -> Option<(DelegationRecord, Option<DelegationActions>)> | ||
| where | ||
| T: ChainRpcClient, | ||
| U: ChainPubsubClient, | ||
|
|
||
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.
Local path dependency
../delegation-programwill break CI and isolated checkouts.path = "../delegation-program"references a sibling directory outside this repository. Any developer or CI runner without that exact directory layout will get a build failure. The previous git-based reference (withrev) was portable. This should either stay as a git dependency (possibly pointing to a local branch) or the delegation-program should be vendored/subtree'd into this repo before merging.🤖 Prompt for AI Agents