Skip to content

Commit

Permalink
Revert Helium Lib 2 (#957)
Browse files Browse the repository at this point in the history
* Revert "update helium-lib to correctly calculate epoch info key (#950)"

This reverts commit 59e3a88.

* Revert "Add skip_preflight setting for solana rpc (#949)"

This reverts commit 22d0393.

* Revert "Do not log RPC url (#948)"

This reverts commit 66bf4c1.

* Revert "Min Priority Fee Setting (#947)"

This reverts commit 72fe9b4.

* Revert "use the correct subdao when finding delegate and escrow accounts (#946)"

This reverts commit 41e48fb.

* Revert "update helium-lib to take router_key as a string (#943)"

This reverts commit fc57aaa.

* Revert "read solana keypair, convert to helium keypair (#942)"

This reverts commit 6e7b65b.

* Revert "Helium Lib attempt: 2 (#930)"

This reverts commit dfa2c08.
  • Loading branch information
michaeldjeffrey authored and macpie committed Feb 28, 2025
1 parent 911d34e commit c5d7fd9
Show file tree
Hide file tree
Showing 24 changed files with 1,544 additions and 2,164 deletions.
544 changes: 444 additions & 100 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ sqlx = { version = "0", features = [
"runtime-tokio-rustls",
] }
helium-anchor-gen = { git = "https://github.com/helium/helium-anchor-gen.git" }
helium-crypto = { version = "0.8.4", features = ["multisig", "solana"] }
helium-crypto = { version = "0.8.4", features = ["multisig"] }
helium-lib = { git = "https://github.com/helium/helium-wallet-rs.git", branch = "master" }
hextree = { git = "https://github.com/jaykickliter/HexTree", branch = "main", features = [
"disktree",
Expand Down Expand Up @@ -128,13 +128,10 @@ sqlx = { git = "https://github.com/launchbadge/sqlx.git", rev = "42dd78fe931df65

# When attempting to test proto changes without needing to push a branch you can
# patch the github url to point to your local proto repo.
#
#
# Patching for beacon must point directly to the crate, it will not look in the
# repo for sibling crates.
#
#
# [patch.'https://github.com/helium/proto']
# helium-proto = { path = "../proto" }
# beacon = { path = "../proto/beacon" }

# [patch.'https://github.com/helium/helium-wallet-rs.git']
# helium-lib = { path = "../helium-wallet-rs/helium-lib" }
# helium-proto = { path = "../../proto" }
# beacon = { path = "../../proto" }
10 changes: 3 additions & 7 deletions boost_manager/tests/integrations/updater_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct MockTransaction {

pub struct MockSolanaConnection {
submitted: Mutex<Vec<MockTransaction>>,
error: Option<tonic::Status>,
error: Option<String>,
}

impl MockSolanaConnection {
Expand All @@ -34,7 +34,7 @@ impl MockSolanaConnection {
fn with_error(error: String) -> Self {
Self {
submitted: Mutex::new(vec![]),
error: Some(tonic::Status::internal(error)),
error: Some(error),
}
}
}
Expand All @@ -58,11 +58,7 @@ impl SolanaNetwork for MockSolanaConnection {

self.error
.as_ref()
.map(|err| {
Err(SolanaRpcError::HeliumLib(solana::error::Error::Grpc(
err.to_owned(),
)))
})
.map(|err| Err(SolanaRpcError::Test(err.to_owned())))
.unwrap_or(Ok(()))
}

Expand Down
5 changes: 0 additions & 5 deletions iot_packet_verifier/src/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use tokio::sync::Mutex;

/// Caches balances fetched from the solana chain and debits made by the
/// packet verifier.
#[derive(Clone)]
pub struct BalanceCache<S> {
payer_accounts: BalanceStore,
solana: S,
Expand Down Expand Up @@ -56,10 +55,6 @@ impl<S> BalanceCache<S> {
pub fn balances(&self) -> BalanceStore {
self.payer_accounts.clone()
}

pub async fn get_payer_balance(&self, payer: &PublicKeyBinary) -> Option<PayerAccount> {
self.payer_accounts.lock().await.get(payer).cloned()
}
}

#[async_trait::async_trait]
Expand Down
158 changes: 29 additions & 129 deletions iot_packet_verifier/src/burner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use crate::{
},
};
use futures::{future::LocalBoxFuture, TryFutureExt};
use helium_crypto::PublicKeyBinary;
use solana::{burn::SolanaNetwork, sender, SolanaRpcError};
use solana::{burn::SolanaNetwork, GetSignature, SolanaRpcError};
use std::time::Duration;
use task_manager::ManagedTask;
use tokio::time::{self, MissedTickBehavior};
use tracing::Instrument;

pub struct Burner<P, S> {
pending_tables: P,
Expand All @@ -21,7 +19,7 @@ pub struct Burner<P, S> {

impl<P, S> ManagedTask for Burner<P, S>
where
P: PendingTables,
P: PendingTables + Send + Sync + 'static,
S: SolanaNetwork,
{
fn start_task(
Expand Down Expand Up @@ -78,9 +76,9 @@ where

loop {
tokio::select! {
biased;
_ = shutdown.clone() => break,
_ = burn_timer.tick() => {
biased;
_ = shutdown.clone() => break,
_ = burn_timer.tick() => {
match self.burn().await {
Ok(()) => continue,
Err(err) => {
Expand All @@ -96,147 +94,49 @@ where
}

pub async fn burn(&mut self) -> Result<(), BurnError> {
// There should only be a single pending txn at a time
let pending_txns = self.pending_tables.fetch_all_pending_txns().await?;
if !pending_txns.is_empty() {
tracing::info!(pending_txns = pending_txns.len(), "skipping burn");
return Ok(());
}

// Fetch the next payer and amount that should be burn. If no such burn
// exists, perform no action.
let Some(Burn { payer, amount }) = self.pending_tables.fetch_next_burn().await? else {
tracing::info!("no pending burns");
return Ok(());
};

tracing::info!(%amount, %payer, "Burning DC");

// Create a burn transaction and execute it:
let txn = self
.solana
.make_burn_transaction(&payer, amount)
.await
.map_err(BurnError::SolanaError)?;

let store = BurnTxnStore::new(
self.pending_tables.clone(),
self.balances.clone(),
payer.clone(),
amount,
);

let burn_span = tracing::info_span!("burn_txn", %payer, amount);
self.pending_tables
.add_pending_transaction(&payer, amount, txn.get_signature())
.await?;
self.solana
.submit_transaction(&txn, &store)
.map_err(BurnError::SolanaError)
.instrument(burn_span)
.submit_transaction(&txn)
.await
}
}

pub struct BurnTxnStore<PT> {
pool: PT,
balances: BalanceStore,
payer: PublicKeyBinary,
amount: u64,
}

impl<PT: PendingTables + Clone> BurnTxnStore<PT> {
pub fn new(pool: PT, balances: BalanceStore, payer: PublicKeyBinary, amount: u64) -> Self {
Self {
pool,
balances,
payer,
amount,
}
}
}

#[async_trait::async_trait]
impl<PT: PendingTables> sender::TxnStore for BurnTxnStore<PT> {
async fn on_prepared(&self, txn: &solana::Transaction) -> sender::SenderResult<()> {
tracing::info!("txn prepared");

let signature = txn.get_signature();
let add_pending = self
.pool
.add_pending_transaction(&self.payer, self.amount, signature);

let Ok(()) = add_pending.await else {
tracing::error!("failed to add pending transcation");
return Err(sender::SenderError::preparation(
"could not add pending transaction",
));
};

Ok(())
}

async fn on_finalized(&self, txn: &solana::Transaction) {
tracing::info!("txn finalized");

let Ok(mut db_txn) = self.pool.begin().await else {
tracing::error!("failed to start finalized txn db transaction");
return;
};

let signature = txn.get_signature();
let Ok(()) = db_txn.remove_pending_transaction(signature).await else {
tracing::error!("failed to remove pending");
return;
};
.map_err(BurnError::SolanaError)?;

let Ok(()) = db_txn
.subtract_burned_amount(&self.payer, self.amount)
.await
else {
tracing::error!("failed to subtract burned amount");
return;
};
// Removing the pending transaction and subtract the burn amount
// now that we have confirmation that the burn transaction is confirmed
// on chain:
let mut pending_tables_txn = self.pending_tables.begin().await?;
pending_tables_txn
.remove_pending_transaction(txn.get_signature())
.await?;
pending_tables_txn
.subtract_burned_amount(&payer, amount)
.await?;
pending_tables_txn.commit().await?;

// Subtract balances from map before submitted db txn
let mut balance_lock = self.balances.lock().await;
let payer_account = balance_lock.get_mut(&self.payer).unwrap();
// Reduce the pending burn amount and the payer's balance by the amount we've burned
payer_account.burned = payer_account.burned.saturating_sub(self.amount);
payer_account.balance = payer_account.balance.saturating_sub(self.amount);
let payer_account = balance_lock.get_mut(&payer).unwrap();
// Reduce the pending burn amount and the payer's balance by the amount
// we've burned.
payer_account.burned = payer_account.burned.saturating_sub(amount);
payer_account.balance = payer_account.balance.saturating_sub(amount);

let Ok(()) = db_txn.commit().await else {
tracing::error!("failed to commit finalized txn db transaction");
return;
};
metrics::counter!("burned", "payer" => payer.to_string()).increment(amount);

metrics::counter!(
"burned",
"payer" => self.payer.to_string(),
"success" => "true"
)
.increment(self.amount);
}

async fn on_error(&self, txn: &solana::Transaction, err: sender::SenderError) {
tracing::warn!(?err, "txn failed");
let Ok(mut db_txn) = self.pool.begin().await else {
tracing::error!("failed to start error transaction");
return;
};

let signature = txn.get_signature();
let Ok(()) = db_txn.remove_pending_transaction(signature).await else {
tracing::error!("failed to remove pending transaction on error");
return;
};

let Ok(()) = db_txn.commit().await else {
tracing::error!("failed to commit on error transaction");
return;
};

metrics::counter!(
"burned",
"payer" => self.payer.to_string(),
"success" => "false"
)
.increment(self.amount);
Ok(())
}
}
2 changes: 1 addition & 1 deletion iot_packet_verifier/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Cmd {
bail!("Missing solana section in settings");
};
// Set up the solana RpcClient:
Some(SolanaRpc::new(solana_settings, solana::SubDao::Iot).await?)
Some(SolanaRpc::new(solana_settings).await?)
} else {
None
};
Expand Down
Loading

0 comments on commit c5d7fd9

Please sign in to comment.