Skip to content

Commit

Permalink
Add debug logs to iot packet verifier (#579)
Browse files Browse the repository at this point in the history
* Add a bunch of debug logs to iot packet verifier

* Fmt
  • Loading branch information
Matthew Plant authored Jul 26, 2023
1 parent e82216d commit a6c0f03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions iot_packet_verifier/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use tokio::{
signal,
sync::{mpsc::Receiver, Mutex},
};
use tracing::debug;

struct Daemon {
pool: Pool<Postgres>,
Expand Down Expand Up @@ -68,7 +69,9 @@ impl Daemon {
&self.invalid_packets,
)
.await?;
debug!("Committing transaction");
transaction.commit().await?;
debug!("Committing files");
self.valid_packets.commit().await?;
self.invalid_packets.commit().await?;

Expand Down
11 changes: 11 additions & 0 deletions iot_packet_verifier/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use tokio::{
task::JoinError,
time::{sleep_until, Duration, Instant},
};
use tracing::debug;

pub struct Verifier<D, C> {
pub debiter: D,
Expand Down Expand Up @@ -64,24 +65,32 @@ where
tokio::pin!(reports);

while let Some(report) = reports.next().await {
debug!(%report.received_timestamp, "Processing packet report");

let debit_amount = payload_size_to_dc(report.payload_size as u64);

debug!(%report.oui, "Fetching payer");
let payer = self
.config_server
.fetch_org(report.oui, &mut org_cache)
.await
.map_err(VerificationError::ConfigError)?;
debug!(%payer, "Debiting payer");
let remaining_balance = self
.debiter
.debit_if_sufficient(&payer, debit_amount)
.await
.map_err(VerificationError::DebitError)?;

if let Some(remaining_balance) = remaining_balance {
debug!(%debit_amount, "Adding debit amount to pending burns");

pending_burns
.add_burned_amount(&payer, debit_amount)
.await
.map_err(VerificationError::BurnError)?;

debug!("Writing valid packet report");
valid_packets
.write(ValidPacket {
packet_timestamp: report.timestamp(),
Expand All @@ -94,12 +103,14 @@ where
.map_err(VerificationError::ValidPacketWriterError)?;

if remaining_balance < minimum_allowed_balance {
debug!(%report.oui, "Disabling org");
self.config_server
.disable_org(report.oui)
.await
.map_err(VerificationError::ConfigError)?;
}
} else {
debug!("Writing invalid packet report");
invalid_packets
.write(InvalidPacket {
payload_size: report.payload_size,
Expand Down

0 comments on commit a6c0f03

Please sign in to comment.