From 6af342aadc9a4cb2c0293a61073f3d3e75390d71 Mon Sep 17 00:00:00 2001 From: Matthew Plant Date: Wed, 19 Apr 2023 11:14:37 -0400 Subject: [PATCH] Solana debugging stuff (#474) * Add cmd line for looking up escrow accounts, remove debug logs * Use disable preflight for debugging, burn after one minute * Add bin --- Cargo.lock | 9 ++++---- mobile_packet_verifier/src/daemon.rs | 3 ++- solana/Cargo.toml | 3 ++- solana/src/lib.rs | 26 ++++++++++++--------- solana/src/main.rs | 34 ++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 solana/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index c82772551..229324863 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4370,9 +4370,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.16.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "opaque-debug" @@ -5884,11 +5884,12 @@ dependencies = [ "anchor-client", "anchor-lang", "async-trait", + "clap 3.2.23", "data-credits", "helium-crypto", "helium-sub-daos", "serde", - "sha2 0.9.9", + "sha2 0.10.6", "solana-client", "solana-program", "solana-sdk", @@ -7408,7 +7409,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", - "rand 0.7.3", + "rand 0.8.5", "static_assertions", ] diff --git a/mobile_packet_verifier/src/daemon.rs b/mobile_packet_verifier/src/daemon.rs index d88b171b3..3a3a954c9 100644 --- a/mobile_packet_verifier/src/daemon.rs +++ b/mobile_packet_verifier/src/daemon.rs @@ -47,7 +47,8 @@ where S: SolanaNetwork, { pub async fn run(mut self, shutdown: &triggered::Listener) -> Result<()> { - let mut burn_time = Instant::now() + self.burn_period; + // Set the initial burn period to one minute + let mut burn_time = Instant::now() + Duration::from_secs(60); loop { tokio::select! { file = self.reports.recv() => { diff --git a/solana/Cargo.toml b/solana/Cargo.toml index 7b452024a..0dc5c57b8 100644 --- a/solana/Cargo.toml +++ b/solana/Cargo.toml @@ -21,4 +21,5 @@ sha2 = {workspace = true} tokio = {workspace = true} helium-crypto = {workspace = true, features = ["solana"]} thiserror = {workspace = true} -tracing = {workspace = true} \ No newline at end of file +tracing = {workspace = true} +clap = {workspace = true} diff --git a/solana/src/lib.rs b/solana/src/lib.rs index 5e78b6ace..8e1bda8bf 100644 --- a/solana/src/lib.rs +++ b/solana/src/lib.rs @@ -6,7 +6,10 @@ use helium_crypto::PublicKeyBinary; use helium_sub_daos::{DaoV0, SubDaoV0}; use serde::Deserialize; use sha2::{Digest, Sha256}; -use solana_client::{client_error::ClientError, nonblocking::rpc_client::RpcClient}; +use solana_client::{ + client_error::ClientError, nonblocking::rpc_client::RpcClient, + rpc_config::RpcSendTransactionConfig, +}; use solana_sdk::{ commitment_config::CommitmentConfig, program_pack::Pack, @@ -97,14 +100,11 @@ impl SolanaNetwork for SolanaRpc { type Error = SolanaRpcError; async fn payer_balance(&self, payer: &PublicKeyBinary) -> Result { - tracing::debug!("Fetching balance for payer: {payer}"); let ddc_key = delegated_data_credits(&self.program_cache.sub_dao, payer); - tracing::debug!("DDC key: {ddc_key}"); let (escrow_account, _) = Pubkey::find_program_address( &["escrow_dc_account".as_bytes(), &ddc_key.to_bytes()], &data_credits::ID, ); - tracing::debug!("escrow_account: {escrow_account}"); let Ok(account_data) = self.provider.get_account_data(&escrow_account).await else { // If the account is empty, it has no DC tracing::info!("{payer} has no account, therefore no balance"); @@ -188,7 +188,17 @@ impl SolanaNetwork for SolanaRpc { blockhash, ); - let signature = self.provider.send_and_confirm_transaction(&tx).await?; + let signature = self + .provider + .send_and_confirm_transaction_with_spinner_and_config( + &tx, + CommitmentConfig::finalized(), + RpcSendTransactionConfig { + skip_preflight: true, + ..Default::default() + }, + ) + .await?; tracing::info!( "Successfully burned data credits. Transaction: {}", @@ -216,26 +226,20 @@ impl BurnProgramCache { dc_mint: Pubkey, dnt_mint: Pubkey, ) -> Result { - tracing::debug!("dc_mint = {dc_mint}"); - tracing::debug!("dnt_mint = {dnt_mint}"); let (account_payer, _) = Pubkey::find_program_address(&["account_payer".as_bytes()], &data_credits::ID); - tracing::debug!("account_payer = {account_payer}"); let (data_credits, _) = Pubkey::find_program_address(&["dc".as_bytes(), dc_mint.as_ref()], &data_credits::ID); - tracing::debug!("data_credits = {data_credits}"); let (sub_dao, _) = Pubkey::find_program_address( &["sub_dao".as_bytes(), dnt_mint.as_ref()], &helium_sub_daos::ID, ); - tracing::debug!("sub_dao = {sub_dao}"); let (dao, dc_burn_authority) = { let account_data = provider.get_account_data(&sub_dao).await?; let mut account_data = account_data.as_ref(); let sub_dao = SubDaoV0::try_deserialize(&mut account_data)?; (sub_dao.dao, sub_dao.dc_burn_authority) }; - tracing::debug!("dao = {dao}"); let registrar = { let account_data = provider.get_account_data(&dao).await?; let mut account_data = account_data.as_ref(); diff --git a/solana/src/main.rs b/solana/src/main.rs new file mode 100644 index 000000000..46f9baacf --- /dev/null +++ b/solana/src/main.rs @@ -0,0 +1,34 @@ +use clap::Parser; +use helium_crypto::{PublicKey, PublicKeyBinary}; +use sha2::{Digest, Sha256}; +use solana_sdk::pubkey::Pubkey; + +#[derive(Parser)] +#[clap(about = "Look up the DC escrow account for a Payer account")] +struct Cli { + payer: PublicKey, +} + +fn main() { + let Cli { payer } = Cli::parse(); + let sub_dao: Pubkey = "39Lw1RH6zt8AJvKn3BTxmUDofzduCM2J3kSaGDZ8L7Sk" + .parse() + .unwrap(); + let payer = PublicKeyBinary::from(payer); + let mut hasher = Sha256::new(); + hasher.update(payer.to_string()); + let sha_digest = hasher.finalize(); + let (ddc_key, _) = Pubkey::find_program_address( + &[ + "delegated_data_credits".as_bytes(), + sub_dao.as_ref(), + &sha_digest, + ], + &data_credits::ID, + ); + let (escrow_account, _) = Pubkey::find_program_address( + &["escrow_dc_account".as_bytes(), &ddc_key.to_bytes()], + &data_credits::ID, + ); + println!("https://explorer.solana.com/address/{escrow_account}"); +}