Skip to content

Commit

Permalink
NDEV-3096. Add db request: get_accounts_in_transaction for tracer deb…
Browse files Browse the repository at this point in the history
…ug_traceTransaction
  • Loading branch information
ancientmage committed Aug 19, 2024
1 parent d256719 commit 9ea986d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 13 deletions.
2 changes: 1 addition & 1 deletion evm_loader/lib/src/commands/emulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub async fn execute<T: Tracer>(
}
}

if emulate_request.provide_account_info.unwrap_or(false) {
if emulate_request.provide_account_info {
result.0.accounts_data = Some(provide_account_data(&storage, &result.0.solana_accounts));
}

Expand Down
5 changes: 3 additions & 2 deletions evm_loader/lib/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub struct EmulateRequest {
pub accounts: Vec<Pubkey>,
#[serde_as(as = "Option<HashMap<DisplayFromStr,_>>")]
pub solana_overrides: Option<HashMap<Pubkey, Option<SerializedAccount>>>,
pub provide_account_info: Option<bool>,
pub provide_account_info: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -382,7 +382,8 @@ mod tests {
"rent_epoch": 0,
"data": "0102030405"
}
}
},
"provide_account_info": false
}
"#;

Expand Down
48 changes: 42 additions & 6 deletions evm_loader/lib/src/types/tracer_ch_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::collections::BTreeMap;
use std::time::Instant;
use thiserror::Error;

use crate::account_data::AccountData;

pub const ROOT_BLOCK_DELAY: u8 = 100;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -73,6 +75,16 @@ pub struct AccountRow {
pub txn_signature: Vec<Option<u8>>,
}

#[derive(Row, serde::Deserialize, Clone)]
pub struct AccountDataRow {
pub pubkey: Vec<u8>,
pub owner: Vec<u8>,
pub lamports: u64,
pub data: Vec<u8>,
pub executable: bool,
pub rent_epoch: u64,
}

impl fmt::Debug for AccountRow {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut debug_struct = f.debug_struct("AccountRow");
Expand Down Expand Up @@ -101,16 +113,20 @@ impl fmt::Debug for AccountRow {
}
}

fn pubkey_from(src: Vec<u8>) -> Result<Pubkey, String> {
Pubkey::try_from(src).map_err(|src| {
format!(
"Incorrect slice length ({}) while converting owner from: {src:?}",
src.len(),
)
})
}

impl TryInto<Account> for AccountRow {
type Error = String;

fn try_into(self) -> Result<Account, Self::Error> {
let owner = Pubkey::try_from(self.owner).map_err(|src| {
format!(
"Incorrect slice length ({}) while converting owner from: {src:?}",
src.len(),
)
})?;
let owner = pubkey_from(self.owner)?;

Ok(Account {
lamports: self.lamports,
Expand All @@ -122,6 +138,26 @@ impl TryInto<Account> for AccountRow {
}
}

impl TryInto<AccountData> for AccountDataRow {
type Error = String;

fn try_into(self) -> Result<AccountData, Self::Error> {
let owner = pubkey_from(self.owner)?;
let pubkey = pubkey_from(self.pubkey)?;

Ok(AccountData::new_from_account(
pubkey,
&Account {
lamports: self.lamports,
data: self.data,
owner,
rent_epoch: self.rent_epoch,
executable: self.executable,
},
))
}
}

pub enum EthSyncStatus {
Syncing(EthSyncing),
Synced,
Expand Down
28 changes: 27 additions & 1 deletion evm_loader/lib/src/types/tracer_ch_db.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::{
commands::get_neon_elf::get_elf_parameter,
types::tracer_ch_common::{AccountRow, ChError, RevisionRow, SlotParent, ROOT_BLOCK_DELAY},
types::tracer_ch_common::{
AccountDataRow, AccountRow, ChError, RevisionRow, SlotParent, ROOT_BLOCK_DELAY,
},
};

use super::tracer_ch_common::{ChResult, EthSyncStatus, EthSyncing, RevisionMap, SlotParentRooted};

use crate::account_data::AccountData;
use crate::types::ChDbConfig;
use clickhouse::Client;
use log::{debug, error, info};
Expand Down Expand Up @@ -363,6 +366,29 @@ impl ClickHouseDb {
Ok(account)
}

pub async fn get_accounts_in_transaction(&self, sol_sig: &[u8]) -> ChResult<Vec<AccountData>> {
info!("get_accounts_in_transaction {{signature: {sol_sig:?} }}");

let query = r"
SELECT pubkey, owner, lamports, data, executable, rent_epoch
FROM events.update_account_distributed
WHERE txn_signature = ?";

let rows = self
.client
.query(query)
.bind(sol_sig)
.fetch_all::<AccountDataRow>()
.await?;

rows.into_iter()
.map(|row: AccountDataRow| {
row.try_into()
.map_err(|err| ChError::Db(clickhouse::error::Error::Custom(err)))
})
.collect()
}

async fn get_older_account_row_at(
&self,
pubkey: &str,
Expand Down
6 changes: 3 additions & 3 deletions evm_loader/program/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use crate::{account_storage::FAKE_OPERATOR, config::ACCOUNT_SEED_VERSION};

pub use ether_balance::{BalanceAccount, Header as BalanceHeader};
pub use ether_contract::{AllocateResult, ContractAccount, Header as ContractHeader};
pub use ether_storage::{Header as StorageCellHeader, StorageCell, StorageCellAddress};
pub use ether_storage::{Cell, Header as StorageCellHeader, StorageCell, StorageCellAddress};
pub use holder::{Header as HolderHeader, Holder};
pub use incinerator::Incinerator;
pub use operator::Operator;
Expand All @@ -20,8 +20,8 @@ pub use treasury::{MainTreasury, Treasury};
use self::program::System;

mod ether_balance;
pub mod ether_contract;
pub mod ether_storage;
mod ether_contract;
mod ether_storage;
mod holder;
mod incinerator;
pub mod legacy;
Expand Down

0 comments on commit 9ea986d

Please sign in to comment.