Skip to content

Commit

Permalink
use beacon recip table rather than last beacon table for active beaco…
Browse files Browse the repository at this point in the history
…ning gateways
  • Loading branch information
andymck committed Apr 22, 2024
1 parent cb684d2 commit e306d35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions iot_verifier/src/last_beacon_reciprocity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ impl LastBeaconReciprocity {
.await?)
}

pub async fn get_all_since<'c, E>(
executor: E,
timestamp: DateTime<Utc>,
) -> anyhow::Result<Vec<Self>>
where
E: sqlx::Executor<'c, Database = sqlx::Postgres> + 'c,
{
Ok(
sqlx::query_as::<_, Self>(
r#" select * from last_beacon_recip where timestamp >= $1; "#,
)
.bind(timestamp)
.fetch_all(executor)
.await?,
)
}

pub async fn update_last_timestamp(
txn: &mut Transaction<'_, Postgres>,
id: &PublicKeyBinary,
Expand Down
4 changes: 2 additions & 2 deletions iot_verifier/src/tx_scaler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
gateway_updater::MessageReceiver,
hex_density::{compute_hex_density_map, GlobalHexMap, HexDensityMap},
last_beacon::LastBeacon,
last_beacon_reciprocity::LastBeaconReciprocity,
};
use chrono::{DateTime, Duration, Utc};
use futures::future::LocalBoxFuture;
Expand Down Expand Up @@ -103,7 +103,7 @@ impl Server {
) -> anyhow::Result<HashMap<PublicKeyBinary, DateTime<Utc>>> {
let interactivity_deadline = now - Duration::minutes(HIP_17_INTERACTIVITY_LIMIT);
Ok(
LastBeacon::get_all_since(&self.pool, interactivity_deadline)
LastBeaconReciprocity::get_all_since(&self.pool, interactivity_deadline)
.await?
.into_iter()
.map(|beacon| (beacon.id, beacon.timestamp))
Expand Down

0 comments on commit e306d35

Please sign in to comment.