Skip to content

Commit 5f0081c

Browse files
committed
Make it work again
1 parent 209897d commit 5f0081c

File tree

6 files changed

+151
-118
lines changed

6 files changed

+151
-118
lines changed

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

Lines changed: 14 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,14 @@ 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.committed_account.account.data.len()
49+
<= CommitTask::COMMIT_STATE_SIZE_THRESHOLD
50+
{
51+
value.create_commit_state_ix(validator)
52+
} else {
53+
value.create_commit_diff_ix(validator)
54+
}
7255
}
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-
// }
12256
ArgsTaskType::Finalize(value) => {
12357
dlp::instruction_builder::finalize(
12458
*validator,

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

Lines changed: 69 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,63 @@ 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 create_commit_state_ix(&self, validator: &Pubkey) -> Instruction {
123+
let args = CommitStateArgs {
124+
nonce: self.commit_id,
125+
lamports: self.committed_account.account.lamports,
126+
data: self.committed_account.account.data.clone(),
127+
allow_undelegation: self.allow_undelegation,
128+
};
129+
dlp::instruction_builder::commit_state(
130+
*validator,
131+
self.committed_account.pubkey,
132+
self.committed_account.account.owner,
133+
args,
134+
)
135+
}
136+
pub fn create_commit_diff_ix(&self, validator: &Pubkey) -> Instruction {
137+
let chain_config =
138+
ChainConfig::local(ComputeBudgetConfig::new(1_000_000));
139+
140+
let rpc_client = RpcClient::new_with_commitment(
141+
chain_config.rpc_uri.to_string(),
142+
CommitmentConfig {
143+
commitment: chain_config.commitment,
144+
},
145+
);
146+
147+
let account = match rpc_client
148+
.get_account(&self.committed_account.pubkey)
149+
{
150+
Ok(account) => account,
151+
Err(e) => {
152+
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);
153+
return self.create_commit_state_ix(validator);
154+
}
155+
};
156+
157+
let args = CommitDiffArgs {
158+
nonce: self.commit_id,
159+
lamports: self.committed_account.account.lamports,
160+
diff: compute_diff(
161+
account.data(),
162+
self.committed_account.account.data(),
163+
)
164+
.to_vec(),
165+
allow_undelegation: self.allow_undelegation,
166+
};
167+
dlp::instruction_builder::commit_diff(
168+
*validator,
169+
self.committed_account.pubkey,
170+
self.committed_account.account.owner,
171+
args,
172+
)
173+
}
174+
}
175+
109176
#[derive(Clone)]
110177
pub struct UndelegateTask {
111178
pub delegated_account: Pubkey,

0 commit comments

Comments
 (0)