Skip to content

Commit 249b1aa

Browse files
committed
Get account using RpcClient
1 parent d390db9 commit 249b1aa

File tree

4 files changed

+68
-35
lines changed

4 files changed

+68
-35
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: 64 additions & 34 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,64 @@ 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+
};
110+
88111
let args = CommitDiffArgs {
89112
nonce: value.commit_id,
90113
lamports: value.committed_account.account.lamports,
91-
diff: vec![], // compute diff for this field
114+
diff: compute_diff(
115+
//&vec![0; value.committed_account.account.data().len()],
116+
account.data(),
117+
value.committed_account.account.data(),
118+
),
92119
allow_undelegation: value.allow_undelegation,
93120
};
94-
dlp::instruction_builder::commit_diff(
121+
log::info!("commit_diff: create instruction");
122+
let ix = dlp::instruction_builder::commit_diff(
95123
*validator,
96124
value.committed_account.pubkey,
97125
value.committed_account.account.owner,
98126
args,
99-
)
127+
);
128+
log::info!("commit_diff: created instruction");
129+
ix
100130
}
101131
ArgsTaskType::Finalize(value) => {
102132
dlp::instruction_builder::finalize(

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
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+
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)