Skip to content

Commit 361ac9b

Browse files
committed
Redesign the implementation of CommitDiff support
1 parent bedb1af commit 361ac9b

File tree

35 files changed

+673
-615
lines changed

35 files changed

+673
-615
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ magicblock-config-helpers = { path = "./magicblock-config-helpers" }
109109
magicblock-config-macro = { path = "./magicblock-config-macro" }
110110
magicblock-core = { path = "./magicblock-core" }
111111
magicblock-aperture = { path = "./magicblock-aperture" }
112-
magicblock-delegation-program = { path="../delegation-program", features = ["no-entrypoint"] }
112+
magicblock-delegation-program = { git = "https://github.com/magicblock-labs/delegation-program.git", rev = "e8d03936", features = [
113+
"no-entrypoint",
114+
] }
113115
magicblock-geyser-plugin = { path = "./magicblock-geyser-plugin" }
114116
magicblock-ledger = { path = "./magicblock-ledger" }
115117
magicblock-metrics = { path = "./magicblock-metrics" }

magicblock-accounts/src/scheduled_commits_processor.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ impl ScheduledCommitsProcessorImpl {
343343
included_pubkeys: intent_meta.included_pubkeys,
344344
excluded_pubkeys: intent_meta.excluded_pubkeys,
345345
requested_undelegation: intent_meta.requested_undelegation,
346-
commit_diff: intent_meta.commit_diff,
347346
}
348347
}
349348
}
@@ -413,7 +412,6 @@ struct ScheduledBaseIntentMeta {
413412
excluded_pubkeys: Vec<Pubkey>,
414413
intent_sent_transaction: Transaction,
415414
requested_undelegation: bool,
416-
commit_diff: bool,
417415
}
418416

419417
impl ScheduledBaseIntentMeta {
@@ -431,7 +429,6 @@ impl ScheduledBaseIntentMeta {
431429
excluded_pubkeys,
432430
intent_sent_transaction: intent.action_sent_transaction.clone(),
433431
requested_undelegation: intent.is_undelegate(),
434-
commit_diff: intent.is_commit_diff(),
435432
}
436433
}
437434
}

magicblock-committor-service/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ magicblock-metrics = { workspace = true }
2929
magicblock-program = { workspace = true }
3030
magicblock-rpc-client = { workspace = true }
3131
magicblock-table-mania = { workspace = true }
32+
magicblock-config = { workspace = true }
3233
rusqlite = { workspace = true }
3334
solana-account = { workspace = true }
3435
solana-pubkey = { workspace = true }
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use solana_account::Account;
2+
use solana_pubkey::Pubkey;
3+
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
4+
use solana_sdk::commitment_config::CommitmentConfig;
5+
6+
//
7+
// AccountFetcher is used by CommitTask
8+
//
9+
pub struct AccountFetcher {
10+
rpc_client: RpcClient,
11+
}
12+
13+
impl Default for AccountFetcher {
14+
fn default() -> Self {
15+
Self::new()
16+
}
17+
}
18+
19+
impl AccountFetcher {
20+
pub fn new() -> Self {
21+
use crate::{config::ChainConfig, ComputeBudgetConfig};
22+
23+
#[cfg(feature = "dev-context-only-utils")]
24+
let chain_config =
25+
ChainConfig::local(ComputeBudgetConfig::new(1_000_000));
26+
27+
#[cfg(not(feature = "dev-context-only-utils"))]
28+
let chain_config = ChainConfig {
29+
rpc_uri: magicblock_config::MagicBlockConfig::parse_config()
30+
.config
31+
.accounts
32+
.remote
33+
.url
34+
.as_ref()
35+
.map(|url| url.to_string())
36+
.unwrap_or_else(|| {
37+
log::error!(
38+
"Remote URL not configured, falling back to mainnet"
39+
);
40+
"https://api.mainnet-beta.solana.com".to_string()
41+
}),
42+
..ChainConfig::mainnet(ComputeBudgetConfig::new(1_000_000))
43+
};
44+
45+
Self {
46+
rpc_client: RpcClient::new_with_commitment(
47+
chain_config.rpc_uri.to_string(),
48+
CommitmentConfig {
49+
commitment: chain_config.commitment,
50+
},
51+
),
52+
}
53+
}
54+
55+
pub async fn fetch_account(
56+
&self,
57+
pubkey: &Pubkey,
58+
) -> Result<Account, solana_rpc_client_api::client_error::Error> {
59+
self.rpc_client.get_account(pubkey).await
60+
}
61+
}

magicblock-committor-service/src/tasks/args_task.rs

Lines changed: 20 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
1-
use dlp::{
2-
args::{CallHandlerArgs, CommitDiffArgs, CommitStateArgs},
3-
compute_diff,
4-
};
5-
use solana_account::ReadableAccount;
1+
use dlp::args::CallHandlerArgs;
62
use solana_pubkey::Pubkey;
7-
use solana_rpc_client::rpc_client::RpcClient;
8-
use solana_sdk::{
9-
commitment_config::CommitmentConfig,
10-
instruction::{AccountMeta, Instruction},
11-
};
3+
use solana_sdk::instruction::{AccountMeta, Instruction};
124

135
#[cfg(test)]
146
use crate::tasks::TaskStrategy;
15-
use crate::{
16-
config::ChainConfig,
17-
tasks::{
18-
buffer_task::{BufferTask, BufferTaskType},
19-
visitor::Visitor,
20-
BaseActionTask, BaseTask, BaseTaskError, BaseTaskResult, CommitTask,
21-
FinalizeTask, PreparationState, TaskType, UndelegateTask,
22-
},
23-
ComputeBudgetConfig,
7+
use crate::tasks::{
8+
buffer_task::{BufferTask, BufferTaskType},
9+
visitor::Visitor,
10+
BaseActionTask, BaseTask, BaseTaskError, BaseTaskResult, CommitTask,
11+
FinalizeTask, PreparationState, TaskType, UndelegateTask,
2412
};
2513

2614
/// Task that will be executed on Base layer via arguments
2715
#[derive(Clone)]
2816
pub enum ArgsTaskType {
2917
Commit(CommitTask),
30-
CommitDiff(CommitTask),
3118
Finalize(FinalizeTask),
3219
Undelegate(UndelegateTask), // Special action really
3320
BaseAction(BaseActionTask),
@@ -57,69 +44,7 @@ impl ArgsTask {
5744
impl BaseTask for ArgsTask {
5845
fn instruction(&self, validator: &Pubkey) -> Instruction {
5946
match &self.task_type {
60-
ArgsTaskType::Commit(value) => {
61-
let args = CommitStateArgs {
62-
nonce: value.commit_id,
63-
lamports: value.committed_account.account.lamports,
64-
data: value.committed_account.account.data.clone(),
65-
allow_undelegation: value.allow_undelegation,
66-
};
67-
dlp::instruction_builder::commit_state(
68-
*validator,
69-
value.committed_account.pubkey,
70-
value.committed_account.account.owner,
71-
args,
72-
)
73-
}
74-
ArgsTaskType::CommitDiff(value) => {
75-
let chain_config =
76-
ChainConfig::local(ComputeBudgetConfig::new(1_000_000));
77-
78-
let rpc_client = RpcClient::new_with_commitment(
79-
chain_config.rpc_uri.to_string(),
80-
CommitmentConfig {
81-
commitment: chain_config.commitment,
82-
},
83-
);
84-
85-
let account = match rpc_client
86-
.get_account(&value.committed_account.pubkey)
87-
{
88-
Ok(account) => account,
89-
Err(e) => {
90-
log::warn!("Fallback to commit_state and send full-bytes, as rpc failed to fetch the delegated-account from base chain, commmit_id: {} , error: {}", value.commit_id, e);
91-
let args = CommitStateArgs {
92-
nonce: value.commit_id,
93-
lamports: value.committed_account.account.lamports,
94-
data: value.committed_account.account.data.clone(),
95-
allow_undelegation: value.allow_undelegation,
96-
};
97-
return dlp::instruction_builder::commit_state(
98-
*validator,
99-
value.committed_account.pubkey,
100-
value.committed_account.account.owner,
101-
args,
102-
);
103-
}
104-
};
105-
106-
let args = CommitDiffArgs {
107-
nonce: value.commit_id,
108-
lamports: value.committed_account.account.lamports,
109-
diff: compute_diff(
110-
account.data(),
111-
value.committed_account.account.data(),
112-
)
113-
.to_vec(),
114-
allow_undelegation: value.allow_undelegation,
115-
};
116-
dlp::instruction_builder::commit_diff(
117-
*validator,
118-
value.committed_account.pubkey,
119-
value.committed_account.account.owner,
120-
args,
121-
)
122-
}
47+
ArgsTaskType::Commit(value) => value.create_commit_ix(validator),
12348
ArgsTaskType::Finalize(value) => {
12449
dlp::instruction_builder::finalize(
12550
*validator,
@@ -163,13 +88,23 @@ impl BaseTask for ArgsTask {
16388
self: Box<Self>,
16489
) -> Result<Box<dyn BaseTask>, Box<dyn BaseTask>> {
16590
match self.task_type {
91+
ArgsTaskType::Commit(mut value) if value.is_commit_diff() => {
92+
// TODO (snawaz): Currently, we do not support executing CommitDiff
93+
// as BufferTask, which is why we're forcing CommitTask to use CommitState
94+
// before converting this task into BufferTask Once CommitDiff is supported
95+
// by BufferTask, we do not have to force_commit_state and we can remove
96+
// force_commit_state stuff, as it's essentially a downgrade.
97+
98+
value.force_commit_state();
99+
Ok(Box::new(BufferTask::new_preparation_required(
100+
BufferTaskType::Commit(value),
101+
)))
102+
}
166103
ArgsTaskType::Commit(value) => {
167104
Ok(Box::new(BufferTask::new_preparation_required(
168105
BufferTaskType::Commit(value),
169106
)))
170107
}
171-
// TODO (snawaz): discuss this with reviewers
172-
ArgsTaskType::CommitDiff(_) => Err(self),
173108
ArgsTaskType::BaseAction(_)
174109
| ArgsTaskType::Finalize(_)
175110
| ArgsTaskType::Undelegate(_) => Err(self),
@@ -196,7 +131,6 @@ impl BaseTask for ArgsTask {
196131
fn compute_units(&self) -> u32 {
197132
match &self.task_type {
198133
ArgsTaskType::Commit(_) => 70_000,
199-
ArgsTaskType::CommitDiff(_) => 65_000,
200134
ArgsTaskType::BaseAction(task) => task.action.compute_units,
201135
ArgsTaskType::Undelegate(_) => 70_000,
202136
ArgsTaskType::Finalize(_) => 70_000,
@@ -211,9 +145,6 @@ impl BaseTask for ArgsTask {
211145
fn task_type(&self) -> TaskType {
212146
match &self.task_type {
213147
ArgsTaskType::Commit(_) => TaskType::Commit,
214-
// TODO (snawaz): What should we use here? Commit (in the sense of "category of task"), or add a
215-
// new variant "CommitDiff" to indicate a specific instruction?
216-
ArgsTaskType::CommitDiff(_) => TaskType::Commit,
217148
ArgsTaskType::BaseAction(_) => TaskType::Action,
218149
ArgsTaskType::Undelegate(_) => TaskType::Undelegate,
219150
ArgsTaskType::Finalize(_) => TaskType::Finalize,
@@ -226,7 +157,6 @@ impl BaseTask for ArgsTask {
226157
}
227158

228159
fn reset_commit_id(&mut self, commit_id: u64) {
229-
// TODO (snawaz): handle CommitDiff as well? what is it about?
230160
let ArgsTaskType::Commit(commit_task) = &mut self.task_type else {
231161
return;
232162
};

0 commit comments

Comments
 (0)