Skip to content

Commit

Permalink
Update heartbeats to not validate coverage objects
Browse files Browse the repository at this point in the history
  • Loading branch information
maplant committed Aug 1, 2023
1 parent d95f40d commit a662860
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
28 changes: 17 additions & 11 deletions mobile_verifier/src/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,37 +445,41 @@ impl CoverageClaimTimeCache {
cbsd_id: &str,
coverage_object: &Option<Uuid>,
exec: &mut Transaction<'_, Postgres>,
) -> Result<DateTime<Utc>, sqlx::Error> {
) -> Result<Option<DateTime<Utc>>, sqlx::Error> {
let key = (cbsd_id.to_string(), *coverage_object);
if let Some(coverage_claim_time) = self.cache.get(&key).await {
Ok(*coverage_claim_time)
Ok(Some(*coverage_claim_time))
} else {
let coverage_claim_time: DateTime<Utc> = sqlx::query_scalar(
let coverage_claim_time: Option<DateTime<Utc>> = sqlx::query_scalar(
r#"
SELECT coverage_claim_time FROM hex_coverage WHERE cbsd_id = $1 AND uuid = $2 LIMIT 1
"#,
)
.bind(cbsd_id)
.bind(coverage_object)
.fetch_one(&mut *exec)
.fetch_optional(&mut *exec)
.await?;
self.cache
.insert(
key,
coverage_claim_time,
std::time::Duration::from_secs(60 * 60 * 24),
)
.await;
if let Some(coverage_claim_time) = coverage_claim_time {
self.cache
.insert(
key,
coverage_claim_time,
std::time::Duration::from_secs(60 * 60 * 24),
)
.await;
}
Ok(coverage_claim_time)
}
}
}

#[allow(dead_code)]
pub struct CoveredHexCache {
pool: Pool<Postgres>,
covered_hexes: Arc<Cache<Uuid, CachedCoverage>>,
}

#[allow(dead_code)]
impl CoveredHexCache {
pub fn new(pool: &Pool<Postgres>) -> Self {
let cache = Arc::new(Cache::new());
Expand Down Expand Up @@ -524,11 +528,13 @@ impl CoveredHexCache {
}

#[derive(Clone)]
#[allow(dead_code)]
pub struct CachedCoverage {
pub cbsd_id: String,
coverage: Vec<CellIndex>,
}

#[allow(dead_code)]
impl CachedCoverage {
pub fn max_distance_km(&self, latlng: LatLng) -> f64 {
self.coverage.iter().fold(0.0, |curr_max, curr_cov| {
Expand Down
27 changes: 17 additions & 10 deletions mobile_verifier/src/heartbeats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use futures::{
stream::{Stream, StreamExt, TryStreamExt},
TryFutureExt,
};
use h3o::LatLng;
// use h3o::LatLng;
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile as proto;
use mobile_config::{gateway_info::GatewayInfoResolver, GatewayClient};
Expand Down Expand Up @@ -132,16 +132,22 @@ impl HeartbeatDaemon {

while let Some(heartbeat) = validated_heartbeats.next().await.transpose()? {
if heartbeat.is_valid() && heartbeat.coverage_object.is_some() {
let coverage_claim_time = coverage_claim_time_cache
if let Some(coverage_claim_time) = coverage_claim_time_cache
.fetch_coverage_claim_time(
&heartbeat.cbsd_id,
&heartbeat.coverage_object,
&mut transaction,
)
.await?;
heartbeat
.update_seniority(coverage_claim_time, &self.seniority_sink, &mut transaction)
.await?;
.await?
{
heartbeat
.update_seniority(
coverage_claim_time,
&self.seniority_sink,
&mut transaction,
)
.await?;
}
}

heartbeat.write(&self.heartbeat_sink).await?;
Expand Down Expand Up @@ -414,9 +420,9 @@ impl Heartbeat {
async fn validate_heartbeat(
heartbeat: &CellHeartbeatIngestReport,
gateway_client: &GatewayClient,
coverage_cache: &CoveredHexCache,
_coverage_cache: &CoveredHexCache,
epoch: &Range<DateTime<Utc>>,
max_distance: f64,
_max_distance: f64,
) -> anyhow::Result<(Option<CellType>, proto::HeartbeatValidity)> {
let cell_type = match CellType::from_cbsd_id(&heartbeat.report.cbsd_id) {
Some(ty) => Some(ty),
Expand All @@ -439,9 +445,9 @@ async fn validate_heartbeat(
return Ok((cell_type, proto::HeartbeatValidity::GatewayOwnerNotFound));
}

/*
let Some(coverage_object) = heartbeat.report.coverage_object() else {
return Ok((cell_type, proto::HeartbeatValidity::Valid));
// return Ok((cell_type, proto::HeartbeatValidity::BadCoverageObject));
return Ok((cell_type, proto::HeartbeatValidity::BadCoverageObject));
};
let Some(coverage) = coverage_cache.fetch_coverage(&coverage_object).await? else {
Expand All @@ -459,6 +465,7 @@ async fn validate_heartbeat(
if coverage.max_distance_km(latlng) > max_distance {
return Ok((cell_type, proto::HeartbeatValidity::TooFarFromCoverage));
}
*/

Ok((cell_type, proto::HeartbeatValidity::Valid))
}

0 comments on commit a662860

Please sign in to comment.