Skip to content

Commit

Permalink
enrich invalid beacon reports with gateway metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Aug 9, 2023
1 parent 033bf5b commit 965f619
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions file_store/src/iot_invalid_poc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub struct IotInvalidBeaconReport {
pub received_timestamp: DateTime<Utc>,
pub reason: InvalidReason,
pub report: IotBeaconReport,
pub location: Option<u64>,
pub gain: i32,
pub elevation: i32,
}

#[derive(Serialize, Clone)]
Expand Down Expand Up @@ -75,6 +78,9 @@ impl TryFrom<LoraInvalidBeaconReportV1> for IotInvalidBeaconReport {
.report
.ok_or_else(|| Error::not_found("iot invalid beacon report v1"))?
.try_into()?,
location: v.location.parse().ok(),
gain: v.gain,
elevation: v.elevation,
})
}
}
Expand All @@ -87,6 +93,12 @@ impl From<IotInvalidBeaconReport> for LoraInvalidBeaconReportV1 {
received_timestamp,
reason: v.reason as i32,
report: Some(report),
location: v
.location
.map(|l| l.to_string())
.unwrap_or_else(String::new),
gain: v.gain,
elevation: v.elevation,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions iot_verifier/src/purger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ impl Purger {
received_timestamp,
reason: InvalidReason::Stale,
report: beacon.clone(),
location: None,
gain: 0,
elevation: 0,
}
.into();

Expand Down
37 changes: 27 additions & 10 deletions iot_verifier/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use crate::{
gateway_cache::GatewayCache, hex_density::HexDensityMap, last_beacon::LastBeacon, poc::Poc,
poc_report::Report, region_cache::RegionCache, reward_share::GatewayPocShare, telemetry,
Settings,
gateway_cache::GatewayCache,
hex_density::HexDensityMap,
last_beacon::LastBeacon,
poc::{Poc, VerifyBeaconResult},
poc_report::Report,
region_cache::RegionCache,
reward_share::GatewayPocShare,
telemetry, Settings,
};
use chrono::{Duration as ChronoDuration, Utc};
use denylist::DenyList;
Expand Down Expand Up @@ -149,7 +154,7 @@ impl Runner {
match self.handle_denylist_tick().await {
Ok(()) => (),
Err(err) => {
tracing::error!("fatal loader error, denylist_tick triggered: {err:?}");
tracing::error!("error whilst handling denylist tick: {err:?}");
}
},
_ = db_timer.tick() =>
Expand Down Expand Up @@ -404,9 +409,9 @@ impl Runner {
VerificationStatus::Invalid => {
// the beacon is invalid, which in turn renders all witnesses invalid
self.handle_invalid_poc(
beacon_verify_result,
&beacon_report,
witnesses,
beacon_verify_result.invalid_reason,
iot_invalid_beacon_sink,
iot_invalid_witness_sink,
)
Expand All @@ -418,28 +423,40 @@ impl Runner {

async fn handle_invalid_poc(
&self,
beacon_verify_result: VerifyBeaconResult,
beacon_report: &IotBeaconIngestReport,
witness_reports: Vec<IotWitnessIngestReport>,
invalid_reason: InvalidReason,
iot_invalid_beacon_sink: &FileSinkClient,
iot_invalid_witness_sink: &FileSinkClient,
) -> anyhow::Result<()> {
// the beacon is invalid, which in turn renders all witnesses invalid
let beacon = &beacon_report.report;
let beacon_id = beacon.data.clone();
let beacon_report_id = beacon_report.ingest_id();

let (location, elevation, gain) = match beacon_verify_result.gateway_info {
Some(gateway_info) => match gateway_info.metadata {
Some(metadata) => (Some(metadata.location), metadata.elevation, metadata.gain),
None => (None, 0, 0),
},
None => (None, 0, 0),
};

let invalid_poc: IotInvalidBeaconReport = IotInvalidBeaconReport {
received_timestamp: beacon_report.received_timestamp,
reason: invalid_reason,
reason: beacon_verify_result.invalid_reason,
report: beacon.clone(),
location,
elevation,
gain,
};
let invalid_poc_proto: LoraInvalidBeaconReportV1 = invalid_poc.into();
// save invalid poc to s3, if write fails update attempts and go no further
// allow the poc to be reprocessed next tick
match iot_invalid_beacon_sink
.write(
invalid_poc_proto,
&[("reason", invalid_reason.as_str_name())],
&[("reason", beacon_verify_result.invalid_reason.as_str_name())],
)
.await
{
Expand All @@ -459,15 +476,15 @@ impl Runner {
let invalid_witness_report: IotInvalidWitnessReport = IotInvalidWitnessReport {
received_timestamp: witness_report.received_timestamp,
report: witness_report.report,
reason: invalid_reason,
reason: beacon_verify_result.invalid_reason,
participant_side: InvalidParticipantSide::Beaconer,
};
let invalid_witness_report_proto: LoraInvalidWitnessReportV1 =
invalid_witness_report.into();
match iot_invalid_witness_sink
.write(
invalid_witness_report_proto,
&[("reason", invalid_reason.as_str_name())],
&[("reason", beacon_verify_result.invalid_reason.as_str_name())],
)
.await
{
Expand Down

0 comments on commit 965f619

Please sign in to comment.