Skip to content

Commit

Permalink
Fix burning
Browse files Browse the repository at this point in the history
  • Loading branch information
maplant committed Jul 26, 2023
1 parent dd903fe commit c6fc18a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions iot_packet_verifier/src/burner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,28 @@ where

let amount = amount as u64;

let mut balance_lock = self.balances.lock().await;

self.solana
.burn_data_credits(&payer, amount)
.await
.map_err(BurnError::SolanaError)?;

// Now that we have successfully executed the burn and are no long in
// sync land, we can remove the amount burned.
// Now that we have successfully executed the burn and are no longer in
// sync land, we can remove the amount burned:
self.pending_burns
.subtract_burned_amount(&payer, amount)
.await
.map_err(BurnError::SqlError)?;

let mut balance_lock = self.balances.lock().await;
let balances = balance_lock.get_mut(&payer).unwrap();
balances.burned -= amount;
// Zero the balance in order to force a reset:
balances.balance = 0;
let payer_account = balance_lock.get_mut(&payer).unwrap();
payer_account.burned -= amount;
// Reset the balance of the payer:
payer_account.balance = self
.solana
.payer_balance(&payer)
.await
.map_err(BurnError::SolanaError)?;

metrics::counter!("burned", amount, "payer" => payer.to_string());

Expand Down

0 comments on commit c6fc18a

Please sign in to comment.