Skip to content

Commit 38182dc

Browse files
committed
Get account using RpcClient
1 parent d390db9 commit 38182dc

File tree

4 files changed

+78
-39
lines changed

4 files changed

+78
-39
lines changed

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/tasks/args_task.rs

Lines changed: 70 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
use dlp::args::{CallHandlerArgs, CommitDiffArgs, CommitStateArgs};
2+
use solana_account::ReadableAccount;
23
use solana_pubkey::Pubkey;
3-
use solana_sdk::instruction::{AccountMeta, Instruction};
4+
use solana_rpc_client::rpc_client::RpcClient;
5+
use solana_sdk::{
6+
commitment_config::CommitmentConfig,
7+
instruction::{AccountMeta, Instruction},
8+
};
49

510
#[cfg(test)]
611
use crate::tasks::TaskStrategy;
7-
use crate::tasks::{
8-
buffer_task::{BufferTask, BufferTaskType},
9-
visitor::Visitor,
10-
BaseActionTask, BaseTask, BaseTaskError, BaseTaskResult, CommitTask,
11-
FinalizeTask, PreparationState, TaskType, UndelegateTask,
12+
use crate::{
13+
config::ChainConfig,
14+
diff::compute_diff,
15+
tasks::{
16+
buffer_task::{BufferTask, BufferTaskType},
17+
visitor::Visitor,
18+
BaseActionTask, BaseTask, BaseTaskError, BaseTaskResult, CommitTask,
19+
FinalizeTask, PreparationState, TaskType, UndelegateTask,
20+
},
21+
ComputeBudgetConfig,
1222
};
1323

1424
/// Task that will be executed on Base layer via arguments
@@ -59,44 +69,63 @@ impl BaseTask for ArgsTask {
5969
args,
6070
)
6171
}
62-
// algo:
63-
// - delegated_account, prev
64-
// - changed delegated_account
65-
// - diff = prev - delegated_account
66-
// - commit
67-
// - prev = delegated_account
68-
// - update cache with prev
69-
//
70-
// relevant files/modules/crates:
71-
// -
72-
// - https://docs.rs/scc/latest/scc/#hashcache
73-
//
74-
// diff:
75-
// - [offset1][offset2]data
76-
//
77-
// 100
78-
//
79-
// 11..15
80-
//
81-
// 31...40
82-
//
83-
// - complete: [2] [5][11] [10][31] [11..15 31 ..40]
84-
//
85-
// - [3][8][11..15 31 ..40]
86-
//
8772
ArgsTaskType::CommitDiff(value) => {
73+
let chain_config =
74+
ChainConfig::local(ComputeBudgetConfig::new(1_000_000));
75+
76+
log::info!(
77+
"Fetch account from the main chain: {}",
78+
value.committed_account.pubkey
79+
);
80+
let rpc_client = RpcClient::new_with_commitment(
81+
chain_config.rpc_uri.to_string(),
82+
CommitmentConfig {
83+
commitment: chain_config.commitment,
84+
},
85+
);
86+
87+
let account = match rpc_client
88+
.get_account(&value.committed_account.pubkey)
89+
{
90+
Ok(account) => {
91+
log::info!("Account Found: {:?}", account);
92+
account
93+
}
94+
Err(e) => {
95+
log::error!("error while receiving account: {}", e);
96+
let args = CommitStateArgs {
97+
nonce: value.commit_id,
98+
lamports: value.committed_account.account.lamports,
99+
data: value.committed_account.account.data.clone(),
100+
allow_undelegation: value.allow_undelegation,
101+
};
102+
return dlp::instruction_builder::commit_state(
103+
*validator,
104+
value.committed_account.pubkey,
105+
value.committed_account.account.owner,
106+
args,
107+
);
108+
}
109+
};
88110
let args = CommitDiffArgs {
89111
nonce: value.commit_id,
90112
lamports: value.committed_account.account.lamports,
91-
diff: vec![], // compute diff for this field
113+
diff: compute_diff(
114+
//&vec![0; value.committed_account.account.data().len()],
115+
account.data(),
116+
value.committed_account.account.data(),
117+
),
92118
allow_undelegation: value.allow_undelegation,
93119
};
94-
dlp::instruction_builder::commit_diff(
120+
log::info!("commit_diff: create instruction");
121+
let ix = dlp::instruction_builder::commit_diff(
95122
*validator,
96123
value.committed_account.pubkey,
97124
value.committed_account.account.owner,
98125
args,
99-
)
126+
);
127+
log::info!("commit_diff: created instruction");
128+
ix
100129
}
101130
ArgsTaskType::Finalize(value) => {
102131
dlp::instruction_builder::finalize(
@@ -147,8 +176,10 @@ impl BaseTask for ArgsTask {
147176
BufferTaskType::Commit(value),
148177
)))
149178
}
150-
ArgsTaskType::CommitDiff(_)
151-
| ArgsTaskType::BaseAction(_)
179+
ArgsTaskType::CommitDiff(_) => {
180+
panic!("ArgsTaskType::CommitDiff not handled")
181+
}
182+
ArgsTaskType::BaseAction(_)
152183
| ArgsTaskType::Finalize(_)
153184
| ArgsTaskType::Undelegate(_) => Err(self),
154185
}
@@ -174,7 +205,7 @@ impl BaseTask for ArgsTask {
174205
fn compute_units(&self) -> u32 {
175206
match &self.task_type {
176207
ArgsTaskType::Commit(_) => 65_000,
177-
ArgsTaskType::CommitDiff(_) => 40_000,
208+
ArgsTaskType::CommitDiff(_) => 65_000,
178209
ArgsTaskType::BaseAction(task) => task.action.compute_units,
179210
ArgsTaskType::Undelegate(_) => 70_000,
180211
ArgsTaskType::Finalize(_) => 40_000,
@@ -191,7 +222,7 @@ impl BaseTask for ArgsTask {
191222
ArgsTaskType::Commit(_) => TaskType::Commit,
192223
// TODO (snawaz): What should we use here? Commit (in the sense of "category of task"), or add a
193224
// new variant "CommitDiff" to indicate a specific instruction?
194-
ArgsTaskType::CommitDiff(_) => TaskType::Commit,
225+
ArgsTaskType::CommitDiff(_) => unimplemented!("task_type"), //TaskType::Commit,
195226
ArgsTaskType::BaseAction(_) => TaskType::Action,
196227
ArgsTaskType::Undelegate(_) => TaskType::Undelegate,
197228
ArgsTaskType::Finalize(_) => TaskType::Finalize,
@@ -206,6 +237,7 @@ impl BaseTask for ArgsTask {
206237
fn reset_commit_id(&mut self, commit_id: u64) {
207238
// TODO (snawaz): handle CommitDiff as well?
208239
let ArgsTaskType::Commit(commit_task) = &mut self.task_type else {
240+
log::error!("reset_commit_id");
209241
return;
210242
};
211243

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub enum TaskStrategy {
5454
pub trait BaseTask: Send + Sync + DynClone {
5555
/// Gets all pubkeys that involved in Task's instruction
5656
fn involved_accounts(&self, validator: &Pubkey) -> Vec<Pubkey> {
57+
// TODO (snawaz): can be optimized.
58+
// currently it is slow as it discards lots of computations and memory allocations.
5759
self.instruction(validator)
5860
.accounts
5961
.iter()

run-schedulecommit-ephm.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#!/bin/bash
22

3-
RUST_LOG_STYLE="EPHEM" VALIDATOR_KEYPAIR="62LxqpAW6SWhp7iKBjCQneapn1w6btAhW7xHeREWSpPzw3xZbHCfAFesSR4R76ejQXCLWrndn37cKCCLFvx6Swps" "cargo" "run" "--" "/Users/snawaz/projects/mb/magicblock-validator/test-integration/configs/schedulecommit-conf-fees.ephem.toml"
3+
set -x
4+
5+
cd test-integration && cargo build-sbf && cd -
6+
7+
RUST_LOG=info RUST_LOG_STYLE="EPHEM" VALIDATOR_KEYPAIR="62LxqpAW6SWhp7iKBjCQneapn1w6btAhW7xHeREWSpPzw3xZbHCfAFesSR4R76ejQXCLWrndn37cKCCLFvx6Swps" "cargo" "run" "--" "/Users/snawaz/projects/mb/magicblock-validator/test-integration/configs/schedulecommit-conf-fees.ephem.toml"

0 commit comments

Comments
 (0)