Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,188 changes: 818 additions & 370 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ magicblock-committor-program = { path = "./magicblock-committor-program", featur
magicblock-committor-service = { path = "./magicblock-committor-service" }
magicblock-config = { path = "./magicblock-config" }
magicblock-core = { path = "./magicblock-core" }
magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "2cb491032f372", features = [
"no-entrypoint",
] }
dlp-api = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "abf340536e88740c290b2b3af4e3d1ff38240f63", package = "magicblock-delegation-program-api" }
magicblock-ledger = { path = "./magicblock-ledger" }
magicblock-magic-program-api = { path = "./magicblock-magic-program-api" }
magicblock-metrics = { path = "./magicblock-metrics" }
Expand Down
56 changes: 49 additions & 7 deletions magicblock-account-cloner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use async_trait::async_trait;
use magicblock_chainlink::{
cloner::{
errors::{ClonerError, ClonerResult},
AccountCloneRequest, Cloner,
AccountCloneRequest, Cloner, DelegationActions,
},
remote_account_provider::program_account::{
LoadedProgram, RemoteProgramLoader,
Expand All @@ -41,7 +41,7 @@ use magicblock_chainlink::{
use magicblock_committor_service::{BaseIntentCommittor, CommittorService};
use magicblock_config::config::ChainLinkConfig;
use magicblock_core::link::transactions::{
with_encoded, TransactionSchedulerHandle,
with_encoded, SanitizeableTransaction, TransactionSchedulerHandle,
};
use magicblock_ledger::LatestBlock;
use magicblock_magic_program_api::{
Expand All @@ -64,7 +64,7 @@ use solana_sdk_ids::{bpf_loader_upgradeable, loader_v4};
use solana_signature::Signature;
use solana_signer::Signer;
use solana_sysvar::rent::Rent;
use solana_transaction::Transaction;
use solana_transaction::{sanitized::SanitizedTransaction, Transaction};
use tracing::*;

/// Max data that fits in a single transaction (~63KB)
Expand Down Expand Up @@ -108,6 +108,15 @@ impl ChainlinkCloner {
Ok(sig)
}

async fn send_sanitized_tx(
&self,
tx: SanitizedTransaction,
) -> ClonerResult<()> {
self.tx_scheduler.execute(tx).await?;
Ok(())
}

// -----------------
fn create_signed_tx(
&self,
ixs: &[Instruction],
Expand Down Expand Up @@ -194,7 +203,6 @@ impl ChainlinkCloner {
}
}

// -----------------
// Account Cloning
// -----------------

Expand Down Expand Up @@ -542,6 +550,31 @@ impl ChainlinkCloner {
}
});
}

async fn send_actions_tx(
&self,
actions: &DelegationActions,
recent_blockhash: Hash,
) -> ClonerResult<Option<()>> {
if actions.is_empty() {
return Ok(None);
}
let mut tx = Transaction::new_with_payer(
&actions.clone().into_iter().collect::<Vec<_>>(),
Some(&validator_authority_id()),
);
tx.partial_sign(&[&validator_authority()], recent_blockhash);

let sanitized_tx = tx.sanitize(false)?;

Ok(Some(
self.send_sanitized_tx(sanitized_tx)
.await
.inspect_err(|err| {
error!("send_sanitized_tx failed to execute actions, with error: {:?}", err);
})?,
))
}
}

/// Shared account metas for clone instructions.
Expand All @@ -564,12 +597,18 @@ impl Cloner for ChainlinkCloner {
// Small account: single tx
if data_len <= MAX_INLINE_DATA_SIZE {
let tx = self.build_small_account_tx(&request, blockhash);
return self.send_tx(tx).await.map_err(|e| {

let signature = self.send_tx(tx).await.map_err(|err| {
ClonerError::FailedToCloneRegularAccount(
request.pubkey,
Box::new(e),
Box::new(err),
)
});
})?;

self.send_actions_tx(&request.delegation_actions, blockhash)
Comment thread
snawaz marked this conversation as resolved.
.await?;

return Ok(signature);
}

// Large account: multi-tx with cleanup on failure
Expand All @@ -591,6 +630,9 @@ impl Cloner for ChainlinkCloner {
}
}

self.send_actions_tx(&request.delegation_actions, blockhash)
.await?;

Ok(last_sig.unwrap_or_default())
}

Expand Down
2 changes: 1 addition & 1 deletion magicblock-accounts/src/scheduled_commits_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl ScheduledCommitsProcessorImpl {
.map(|finalize| vec![commit, finalize])
.unwrap_or(vec![commit])
})
.unwrap_or(vec![])
.unwrap_or_default()
}
};
let patched_errors = result
Expand Down
2 changes: 1 addition & 1 deletion magicblock-api/src/magic_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl MagicValidator {
commitment_config,
&accounts_bank,
&cloner,
config.validator.keypair.pubkey(),
config.validator.keypair.insecure_clone(),
faucet_pubkey,
chainlink_config,
&config.chainlink,
Expand Down
3 changes: 2 additions & 1 deletion magicblock-chainlink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition.workspace = true
arc-swap = "1.7"
async-trait = { workspace = true }
bincode = { workspace = true }
borsh = { workspace = true }
futures-util = { workspace = true }
helius-laserstream = { workspace = true }
tracing = { workspace = true }
Expand All @@ -17,7 +18,7 @@ magicblock-core = { workspace = true }
parking_lot = { workspace = true }
magicblock-magic-program-api = { workspace = true }
magicblock-metrics = { workspace = true }
magicblock-delegation-program = { workspace = true }
dlp-api = { workspace = true }
solana-account = { workspace = true }
solana-account-decoder = { workspace = true }
solana-account-decoder-client-types = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion magicblock-chainlink/src/accounts_bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ pub mod mock {
// NOTE: that the validator will also have to set flip the delegated flag like
// we do here.
// See programs/magicblock/src/schedule_transactions/process_schedule_commit.rs :172
self.set_owner(pubkey, dlp::id()).undelegate(pubkey);
self.set_owner(pubkey, dlp_api::dlp::id())
.undelegate(pubkey);
}

pub fn set_undelegating(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dlp::state::DelegationRecord;
use dlp_api::dlp::state::DelegationRecord;
use solana_pubkey::Pubkey;
use tracing::*;

Expand Down Expand Up @@ -83,7 +83,7 @@ pub(crate) fn account_still_undelegating_on_chain(

#[cfg(test)]
mod tests {
use dlp::state::DelegationRecord;
use dlp_api::dlp::state::DelegationRecord;
use solana_pubkey::Pubkey;

use super::*;
Expand Down
6 changes: 6 additions & 0 deletions magicblock-chainlink/src/chainlink/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub enum ChainlinkError {
#[error("Delegation record could not be decoded: {0} ({1:?})")]
InvalidDelegationRecord(Pubkey, ProgramError),

#[error("Delegation actions could not be decoded: {0} ({1})")]
InvalidDelegationActions(Pubkey, String),

#[error("Failed to resolve one or more accounts {0} when getting delegation records")]
DelegatedAccountResolutionsFailed(String),

Expand All @@ -41,4 +44,7 @@ pub enum ChainlinkError {

#[error("Unexpected number of accounts returned when fetching account with companion: {0}")]
UnexpectedAccountCount(String),

#[error("Missing accounts required by delegation actions: {0:?}")]
MissingDelegationActionAccounts(Vec<Pubkey>),
}
19 changes: 12 additions & 7 deletions magicblock-chainlink/src/chainlink/fetch_cloner/ata_projection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashSet;

use dlp::state::DelegationRecord;
use dlp_api::dlp::state::DelegationRecord;
use futures_util::future::join_all;
use magicblock_accounts_db::traits::AccountsBank;
use magicblock_core::token_programs::try_derive_eata_address_and_bump;
Expand All @@ -12,7 +12,7 @@ use tracing::*;

use super::{delegation, types::AccountWithCompanion, FetchCloner};
use crate::{
cloner::{AccountCloneRequest, Cloner},
cloner::{AccountCloneRequest, Cloner, DelegationActions},
remote_account_provider::{
ChainPubsubClient, ChainRpcClient, ResolvedAccountSharedData,
},
Expand Down Expand Up @@ -166,8 +166,9 @@ where
)
})
});
let deleg_results: Vec<Option<DelegationRecord>> =
join_all(deleg_futures).await;
let deleg_results: Vec<
Option<(DelegationRecord, Option<DelegationActions>)>,
> = join_all(deleg_futures).await;

// Phase 3: Combine results
let mut deleg_iter = deleg_results.into_iter();
Expand All @@ -176,21 +177,24 @@ where
input.ata_account.account_shared_data_cloned();
let mut commit_frequency_ms = None;
let mut delegated_to_other = None;
let mut actions = None;

if let Some(eata_shared) = &input.eata_shared {
if let Some(Some(deleg)) = deleg_iter.next() {
let (deleg_record, delegation_actions) = deleg;
delegated_to_other =
delegation::get_delegated_to_other(this, &deleg);
commit_frequency_ms = Some(deleg.commit_frequency_ms);
delegation::get_delegated_to_other(this, &deleg_record);
commit_frequency_ms = Some(deleg_record.commit_frequency_ms);

if let Some(projected_ata) = this
.maybe_project_delegated_ata_from_eata(
input.ata_account.account_shared_data(),
eata_shared,
&deleg,
&deleg_record,
)
{
account_to_clone = projected_ata;
actions = delegation_actions;
}
}
}
Expand All @@ -199,6 +203,7 @@ where
pubkey: input.ata_pubkey,
account: account_to_clone,
commit_frequency_ms,
delegation_actions: actions.unwrap_or_default(),
delegated_to_other,
});
}
Expand Down
Loading
Loading