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 7, 2023
1 parent 9353def commit add5e43
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 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.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ sqlx = {version = "0", features = [
]}

helium-crypto = {version = "0.6.8", features=["sqlx-postgres", "multisig"]}
helium-proto = {git = "https://github.com/helium/proto", branch = "master", features = ["services"]}
helium-proto = {git = "https://github.com/helium/proto", branch = "andymck/enrich-invalid-beacon-report", features = ["services"]}
hextree = "*"
solana-client = "1.14"
solana-sdk = "1.14"
solana-program = "1.11"
spl-token = "3.5.0"
reqwest = {version = "0", default-features=false, features = ["gzip", "json", "rustls-tls"]}
beacon = { git = "https://github.com/helium/proto", branch = "master" }
beacon = { git = "https://github.com/helium/proto", branch = "andymck/enrich-invalid-beacon-report" }
humantime = "2"
metrics = "0"
metrics-exporter-prometheus = "0"
Expand Down
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
35 changes: 26 additions & 9 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 @@ -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 add5e43

Please sign in to comment.