diff --git a/Cargo.lock b/Cargo.lock index 7297ba324..1db619def 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1118,7 +1118,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "beacon" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=master#d86b3e3394e8d9f014fcef3ee08740b3fe269e99" +source = "git+https://github.com/helium/proto?branch=andymck/enrich-invalid-beacon-report#10fc377fbf42614c1d2931e213b15075c3ed7b96" dependencies = [ "base64 0.21.0", "byteorder", @@ -2944,7 +2944,7 @@ dependencies = [ [[package]] name = "helium-proto" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=master#d86b3e3394e8d9f014fcef3ee08740b3fe269e99" +source = "git+https://github.com/helium/proto?branch=andymck/enrich-invalid-beacon-report#10fc377fbf42614c1d2931e213b15075c3ed7b96" dependencies = [ "bytes", "prost", diff --git a/Cargo.toml b/Cargo.toml index fd747c1d0..56dae0c6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/file_store/src/iot_invalid_poc.rs b/file_store/src/iot_invalid_poc.rs index 74d527260..d137ba516 100644 --- a/file_store/src/iot_invalid_poc.rs +++ b/file_store/src/iot_invalid_poc.rs @@ -17,6 +17,9 @@ pub struct IotInvalidBeaconReport { pub received_timestamp: DateTime, pub reason: InvalidReason, pub report: IotBeaconReport, + pub location: Option, + pub gain: i32, + pub elevation: i32, } #[derive(Serialize, Clone)] @@ -75,6 +78,9 @@ impl TryFrom 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, }) } } @@ -87,6 +93,12 @@ impl From 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, } } } diff --git a/iot_verifier/src/purger.rs b/iot_verifier/src/purger.rs index b565fbef4..31dfd445b 100644 --- a/iot_verifier/src/purger.rs +++ b/iot_verifier/src/purger.rs @@ -198,6 +198,9 @@ impl Purger { received_timestamp, reason: InvalidReason::Stale, report: beacon.clone(), + location: None, + gain: 0, + elevation: 0, } .into(); diff --git a/iot_verifier/src/runner.rs b/iot_verifier/src/runner.rs index 1fe336fca..602dde389 100644 --- a/iot_verifier/src/runner.rs +++ b/iot_verifier/src/runner.rs @@ -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; @@ -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, ) @@ -418,9 +423,9 @@ impl Runner { async fn handle_invalid_poc( &self, + beacon_verify_result: VerifyBeaconResult, beacon_report: &IotBeaconIngestReport, witness_reports: Vec, - invalid_reason: InvalidReason, iot_invalid_beacon_sink: &FileSinkClient, iot_invalid_witness_sink: &FileSinkClient, ) -> anyhow::Result<()> { @@ -428,10 +433,22 @@ impl Runner { 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 @@ -439,7 +456,7 @@ impl Runner { 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 { @@ -459,7 +476,7 @@ 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 = @@ -467,7 +484,7 @@ impl Runner { 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 {