Skip to content

Commit e44fc81

Browse files
committed
Make it work again
1 parent c59f17a commit e44fc81

File tree

12 files changed

+214
-161
lines changed

12 files changed

+214
-161
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
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-committor-service/src/tasks/args_task.rs

Lines changed: 16 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
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
@@ -57,68 +45,12 @@ impl BaseTask for ArgsTask {
5745
fn instruction(&self, validator: &Pubkey) -> Instruction {
5846
match &self.task_type {
5947
ArgsTaskType::Commit(value) => {
60-
let args = CommitStateArgs {
61-
nonce: value.commit_id,
62-
lamports: value.committed_account.account.lamports,
63-
data: value.committed_account.account.data.clone(),
64-
allow_undelegation: value.allow_undelegation,
65-
};
66-
dlp::instruction_builder::commit_state(
67-
*validator,
68-
value.committed_account.pubkey,
69-
value.committed_account.account.owner,
70-
args,
71-
)
48+
if value.is_commit_diff() {
49+
value.create_commit_diff_ix(validator)
50+
} else {
51+
value.create_commit_state_ix(validator)
52+
}
7253
}
73-
// ArgsTaskType::CommitDiff(value) => {
74-
// let chain_config =
75-
// ChainConfig::local(ComputeBudgetConfig::new(1_000_000));
76-
77-
// let rpc_client = RpcClient::new_with_commitment(
78-
// chain_config.rpc_uri.to_string(),
79-
// CommitmentConfig {
80-
// commitment: chain_config.commitment,
81-
// },
82-
// );
83-
84-
// let account = match rpc_client
85-
// .get_account(&value.committed_account.pubkey)
86-
// {
87-
// Ok(account) => account,
88-
// Err(e) => {
89-
// 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);
90-
// let args = CommitStateArgs {
91-
// nonce: value.commit_id,
92-
// lamports: value.committed_account.account.lamports,
93-
// data: value.committed_account.account.data.clone(),
94-
// allow_undelegation: value.allow_undelegation,
95-
// };
96-
// return dlp::instruction_builder::commit_state(
97-
// *validator,
98-
// value.committed_account.pubkey,
99-
// value.committed_account.account.owner,
100-
// args,
101-
// );
102-
// }
103-
// };
104-
105-
// let args = CommitDiffArgs {
106-
// nonce: value.commit_id,
107-
// lamports: value.committed_account.account.lamports,
108-
// diff: compute_diff(
109-
// account.data(),
110-
// value.committed_account.account.data(),
111-
// )
112-
// .to_vec(),
113-
// allow_undelegation: value.allow_undelegation,
114-
// };
115-
// dlp::instruction_builder::commit_diff(
116-
// *validator,
117-
// value.committed_account.pubkey,
118-
// value.committed_account.account.owner,
119-
// args,
120-
// )
121-
// }
12254
ArgsTaskType::Finalize(value) => {
12355
dlp::instruction_builder::finalize(
12456
*validator,
@@ -162,6 +94,10 @@ impl BaseTask for ArgsTask {
16294
self: Box<Self>,
16395
) -> Result<Box<dyn BaseTask>, Box<dyn BaseTask>> {
16496
match self.task_type {
97+
ArgsTaskType::Commit(ref value) if value.is_commit_diff() => {
98+
// We do not currently support executing CommitDiff as BufferTask
99+
Err(self)
100+
}
165101
ArgsTaskType::Commit(value) => {
166102
Ok(Box::new(BufferTask::new_preparation_required(
167103
BufferTaskType::Commit(value),

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

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
use dlp::{
2+
args::{CommitDiffArgs, CommitStateArgs},
3+
compute_diff,
4+
};
15
use dyn_clone::DynClone;
26
use magicblock_committor_program::{
37
instruction_builder::{
@@ -13,11 +17,17 @@ use magicblock_committor_program::{
1317
use magicblock_program::magic_scheduled_base_intent::{
1418
BaseAction, CommittedAccount,
1519
};
20+
use solana_account::ReadableAccount;
1621
use solana_pubkey::Pubkey;
17-
use solana_sdk::instruction::Instruction;
22+
use solana_rpc_client::rpc_client::RpcClient;
23+
use solana_sdk::{
24+
commitment_config::CommitmentConfig, instruction::Instruction,
25+
};
1826
use thiserror::Error;
1927

20-
use crate::tasks::visitor::Visitor;
28+
use crate::{
29+
config::ChainConfig, tasks::visitor::Visitor, ComputeBudgetConfig,
30+
};
2131

2232
pub mod args_task;
2333
pub mod buffer_task;
@@ -106,6 +116,68 @@ pub struct CommitTask {
106116
pub committed_account: CommittedAccount,
107117
}
108118

119+
impl CommitTask {
120+
const COMMIT_STATE_SIZE_THRESHOLD: usize = 200;
121+
122+
pub fn is_commit_diff(&self) -> bool {
123+
self.committed_account.account.data.len()
124+
> CommitTask::COMMIT_STATE_SIZE_THRESHOLD
125+
}
126+
127+
pub fn create_commit_state_ix(&self, validator: &Pubkey) -> Instruction {
128+
let args = CommitStateArgs {
129+
nonce: self.commit_id,
130+
lamports: self.committed_account.account.lamports,
131+
data: self.committed_account.account.data.clone(),
132+
allow_undelegation: self.allow_undelegation,
133+
};
134+
dlp::instruction_builder::commit_state(
135+
*validator,
136+
self.committed_account.pubkey,
137+
self.committed_account.account.owner,
138+
args,
139+
)
140+
}
141+
pub fn create_commit_diff_ix(&self, validator: &Pubkey) -> Instruction {
142+
let chain_config =
143+
ChainConfig::local(ComputeBudgetConfig::new(1_000_000));
144+
145+
let rpc_client = RpcClient::new_with_commitment(
146+
chain_config.rpc_uri.to_string(),
147+
CommitmentConfig {
148+
commitment: chain_config.commitment,
149+
},
150+
);
151+
152+
let account = match rpc_client
153+
.get_account(&self.committed_account.pubkey)
154+
{
155+
Ok(account) => account,
156+
Err(e) => {
157+
log::warn!("Fallback to commit_state and send full-bytes, as rpc failed to fetch the delegated-account from base chain, commmit_id: {} , error: {}", self.commit_id, e);
158+
return self.create_commit_state_ix(validator);
159+
}
160+
};
161+
162+
let args = CommitDiffArgs {
163+
nonce: self.commit_id,
164+
lamports: self.committed_account.account.lamports,
165+
diff: compute_diff(
166+
account.data(),
167+
self.committed_account.account.data(),
168+
)
169+
.to_vec(),
170+
allow_undelegation: self.allow_undelegation,
171+
};
172+
dlp::instruction_builder::commit_diff(
173+
*validator,
174+
self.committed_account.pubkey,
175+
self.committed_account.account.owner,
176+
args,
177+
)
178+
}
179+
}
180+
109181
#[derive(Clone)]
110182
pub struct UndelegateTask {
111183
pub delegated_account: Pubkey,

0 commit comments

Comments
 (0)