Skip to content

Commit

Permalink
Solana debugging stuff (#474)
Browse files Browse the repository at this point in the history
* Add cmd line for looking up escrow accounts, remove debug logs

* Use disable preflight for debugging, burn after one minute

* Add bin
  • Loading branch information
Matthew Plant authored Apr 19, 2023
1 parent b3c6023 commit 6af342a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 17 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mobile_packet_verifier/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() => {
Expand Down
3 changes: 2 additions & 1 deletion solana/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ sha2 = {workspace = true}
tokio = {workspace = true}
helium-crypto = {workspace = true, features = ["solana"]}
thiserror = {workspace = true}
tracing = {workspace = true}
tracing = {workspace = true}
clap = {workspace = true}
26 changes: 15 additions & 11 deletions solana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -97,14 +100,11 @@ impl SolanaNetwork for SolanaRpc {
type Error = SolanaRpcError;

async fn payer_balance(&self, payer: &PublicKeyBinary) -> Result<u64, Self::Error> {
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");
Expand Down Expand Up @@ -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: {}",
Expand Down Expand Up @@ -216,26 +226,20 @@ impl BurnProgramCache {
dc_mint: Pubkey,
dnt_mint: Pubkey,
) -> Result<Self, SolanaRpcError> {
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();
Expand Down
34 changes: 34 additions & 0 deletions solana/src/main.rs
Original file line number Diff line number Diff line change
@@ -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}");
}

0 comments on commit 6af342a

Please sign in to comment.