Skip to content

Commit ef8cde8

Browse files
committed
Add MagicBlockInstruction::ScheduleCommitDiffAndUndelegate to efficiently commit changes in delegated accounts
1 parent 2bafa8e commit ef8cde8

File tree

31 files changed

+519
-86
lines changed

31 files changed

+519
-86
lines changed

Cargo.lock

Lines changed: 31 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ magicblock-config = { path = "./magicblock-config" }
124124
magicblock-config-helpers = { path = "./magicblock-config-helpers" }
125125
magicblock-config-macro = { path = "./magicblock-config-macro" }
126126
magicblock-core = { path = "./magicblock-core" }
127-
magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "aa1de56d90c", features = [
128-
"no-entrypoint",
129-
] }
127+
magicblock-delegation-program = { path="../delegation-program", features = ["no-entrypoint"] }
130128
magicblock-geyser-plugin = { path = "./magicblock-geyser-plugin" }
131129
magicblock-ledger = { path = "./magicblock-ledger" }
132130
magicblock-metrics = { path = "./magicblock-metrics" }

magicblock-accounts/src/scheduled_commits_processor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ impl<C: BaseIntentCommittor> ScheduledCommitsProcessorImpl<C> {
357357
excluded_pubkeys: intent_meta.excluded_pubkeys,
358358
feepayers: intent_meta.feepayers,
359359
requested_undelegation: intent_meta.requested_undelegation,
360+
commit_diff: intent_meta.commit_diff,
360361
}
361362
}
362363
}
@@ -424,6 +425,7 @@ struct ScheduledBaseIntentMeta {
424425
feepayers: HashSet<FeePayerAccount>,
425426
intent_sent_transaction: Transaction,
426427
requested_undelegation: bool,
428+
commit_diff: bool,
427429
}
428430

429431
impl ScheduledBaseIntentMeta {
@@ -443,6 +445,7 @@ impl ScheduledBaseIntentMeta {
443445
feepayers,
444446
intent_sent_transaction: intent.action_sent_transaction.clone(),
445447
requested_undelegation: intent.is_undelegate(),
448+
commit_diff: intent.is_commit_diff(),
446449
}
447450
}
448451
}

magicblock-api/src/tickers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use tokio_util::sync::CancellationToken;
2020

2121
use crate::slot::advance_slot_and_update_ledger;
2222

23+
// ER chain
2324
pub fn init_slot_ticker<C: ScheduledCommitsProcessor>(
2425
bank: &Arc<Bank>,
2526
committor_processor: &Option<Arc<C>>,
@@ -71,6 +72,7 @@ pub fn init_slot_ticker<C: ScheduledCommitsProcessor>(
7172
})
7273
}
7374

75+
// ER chain
7476
async fn handle_scheduled_commits<C: ScheduledCommitsProcessor>(
7577
bank: &Arc<Bank>,
7678
committor_processor: &Arc<C>,

magicblock-committor-program/src/instruction.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use borsh::{BorshDeserialize, BorshSerialize};
22
use solana_pubkey::Pubkey;
33

4+
// this is deployed on Base chain as user-program
5+
46
#[derive(BorshSerialize, BorshDeserialize, Debug, Clone)]
57
pub enum CommittorInstruction {
68
/// Initializes the buffer and [Chunks] accounts which will be used to

magicblock-committor-service/src/intent_execution_manager/intent_execution_engine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ where
242242
execution_permit: OwnedSemaphorePermit,
243243
result_sender: broadcast::Sender<BroadcastedIntentExecutionResult>,
244244
) {
245+
info!("execute: {:#?}", intent);
245246
let result = executor
246247
.execute(intent.inner.clone(), persister)
247248
.await

magicblock-committor-service/src/intent_executor/mod.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ pub mod single_stage_executor;
44
pub mod task_info_fetcher;
55
pub mod two_stage_executor;
66

7+
use core::slice;
78
use std::{ops::ControlFlow, sync::Arc, time::Duration};
89

910
use async_trait::async_trait;
1011
use futures_util::future::try_join_all;
11-
use log::{error, trace, warn};
12+
use log::{error, info, trace, warn};
1213
use magicblock_program::{
1314
magic_scheduled_base_intent::ScheduledBaseIntent,
1415
validator::validator_authority,
@@ -20,6 +21,7 @@ use magicblock_rpc_client::{
2021
use solana_pubkey::Pubkey;
2122
use solana_rpc_client_api::client_error::ErrorKind;
2223
use solana_sdk::{
24+
instruction::CompiledInstruction,
2325
message::VersionedMessage,
2426
signature::{Keypair, Signature, Signer, SignerError},
2527
transaction::{TransactionError, VersionedTransaction},
@@ -685,9 +687,26 @@ where
685687
// This is needed because DEFAULT_MAX_TIME_TO_PROCESSED is 50 sec
686688
while start.elapsed() < RETRY_FOR || i < MIN_RETRIES {
687689
i += 1;
690+
let message = prepared_message.clone();
691+
let changed = {
692+
let len = message.instructions().len();
693+
let ixs = unsafe {
694+
let ix = message.instructions().as_ptr()
695+
as *mut CompiledInstruction;
696+
slice::from_raw_parts_mut(ix, len)
697+
};
698+
let mut changed = 0;
699+
for ix in ixs.iter_mut() {
700+
if ix.data.len() != 0 && ix.data[0] == 16 {
701+
//ix.data[0] = 1; // CommitState
702+
changed += 1;
703+
}
704+
}
705+
changed
706+
};
707+
info!("> changed [{changed}] prepared_message: {:?}", message);
688708

689-
let result =
690-
self.send_prepared_message(prepared_message.clone()).await;
709+
let result = self.send_prepared_message(message).await;
691710
let flow = match result {
692711
Ok(result) => {
693712
return match result.into_result() {
@@ -708,6 +727,7 @@ where
708727
// TransactionError can be mapped to known set of error
709728
// We return right away to retry recovery, because this can't be fixed with retries
710729
ControlFlow::Break(TransactionStrategyExecutionError::from_transaction_error(err, tasks, |err| {
730+
error!("> ERROR: {:?}", err);
711731
MagicBlockRpcClientError::SentTransactionError(err, signature)
712732
}))
713733
}

magicblock-committor-service/src/intent_executor/single_stage_executor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ where
6262
Err(err) => err,
6363
};
6464

65+
error!("execution_err: {}", execution_err);
66+
6567
// Attempt patching
6668
let flow = self
6769
.patch_strategy(
@@ -79,6 +81,7 @@ where
7981
cleanup
8082
}
8183
ControlFlow::Break(()) => {
84+
info!("base_intent: {:?}", base_intent);
8285
error!("Could not patch failed intent: {}", base_intent.id);
8386
break (execution_err, transaction_strategy);
8487
}

magicblock-committor-service/src/service.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub struct LookupTables {
3030
pub released: Vec<Pubkey>,
3131
}
3232

33+
// this is a part of ER.. and communicates with Base chain
34+
3335
#[derive(Debug)]
3436
pub enum CommittorMessage {
3537
ReservePubkeysForCommittee {

0 commit comments

Comments
 (0)