Skip to content

Commit

Permalink
Add timestamp to RegionParams (#369)
Browse files Browse the repository at this point in the history
* Add timestamp to beacon RegionParams
* Remove legacy gateway service (validator-era)
* Fix iot_config response proto timestamp comments
  • Loading branch information
madninja committed Sep 6, 2023
1 parent cab2b57 commit 983596a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 298 deletions.
46 changes: 10 additions & 36 deletions beacon/src/region.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use super::{Error, Result};
use helium_proto::{
services::iot_config::GatewayRegionParamsResV1, BlockchainRegionParamV1,
BlockchainRegionParamsV1, DataRate, GatewayRegionParamsRespV1,
GatewayRegionParamsStreamedRespV1, Message, Region as ProtoRegion, RegionSpreading,
BlockchainRegionParamsV1, DataRate, Message, Region as ProtoRegion, RegionSpreading,
};
use rust_decimal::prelude::{Decimal, ToPrimitive};
use serde::{de, Deserialize, Deserializer};
Expand Down Expand Up @@ -92,6 +91,9 @@ pub struct RegionParams {
pub gain: Decimal,
pub region: Region,
pub params: Vec<BlockchainRegionParamV1>,
// Timestamp the region params were attested by the config service, in
// seconds since unix epoch
pub timestamp: u64,
}

impl AsRef<[BlockchainRegionParamV1]> for RegionParams {
Expand All @@ -106,38 +108,6 @@ impl PartialEq for RegionParams {
}
}

impl TryFrom<GatewayRegionParamsStreamedRespV1> for RegionParams {
type Error = Error;
fn try_from(value: GatewayRegionParamsStreamedRespV1) -> Result<Self> {
let region = Region::from_i32(value.region)?;
let params = value
.params
.ok_or_else(Error::no_region_params)?
.region_params;
Ok(Self {
gain: Decimal::new(value.gain as i64, 1),
params,
region,
})
}
}

impl TryFrom<GatewayRegionParamsRespV1> for RegionParams {
type Error = Error;
fn try_from(value: GatewayRegionParamsRespV1) -> Result<Self> {
let region = Region::from_i32(value.region)?;
let params = value
.params
.ok_or_else(Error::no_region_params)?
.region_params;
Ok(Self {
gain: Decimal::new(value.gain as i64, 1),
params,
region,
})
}
}

impl TryFrom<GatewayRegionParamsResV1> for RegionParams {
type Error = Error;
fn try_from(value: GatewayRegionParamsResV1) -> Result<Self> {
Expand All @@ -146,10 +116,12 @@ impl TryFrom<GatewayRegionParamsResV1> for RegionParams {
.params
.ok_or_else(Error::no_region_params)?
.region_params;
let timestamp = value.timestamp;
Ok(Self {
gain: Decimal::new(value.gain as i64, 1),
params,
region,
timestamp,
})
}
}
Expand All @@ -160,18 +132,20 @@ impl From<Region> for RegionParams {
region,
gain: 0.into(),
params: vec![],
timestamp: 0,
}
}
}

impl RegionParams {
pub fn from_bytes(region: Region, gain: u64, data: &[u8]) -> Result<Self> {
pub fn from_bytes(region: Region, gain: u64, data: &[u8], timestamp: u64) -> Result<Self> {
let params = BlockchainRegionParamsV1::decode(data)?.region_params;
let gain = Decimal::new(gain as i64, 1);
Ok(Self {
region,
gain,
params,
timestamp,
})
}

Expand Down Expand Up @@ -295,7 +269,7 @@ mod test {
#[test]
fn test_select_datarate() {
let region = ProtoRegion::Eu868.into();
let params = RegionParams::from_bytes(region, 12, EU868_PARAMS).expect("region params");
let params = RegionParams::from_bytes(region, 12, EU868_PARAMS, 0).expect("region params");
assert_eq!(
DataRate::Sf12bw125,
params.select_datarate(30).expect("datarate")
Expand Down
2 changes: 1 addition & 1 deletion build-cpp.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

SERVICES=$(echo src/service/{iot_config,mobile_config,downlink,multi_buy,follower,gateway,local,packet_router,poc_lora,poc_mobile,router,state_channel,transaction}.proto)
SERVICES=$(echo src/service/{iot_config,mobile_config,downlink,multi_buy,follower,local,packet_router,poc_lora,poc_mobile,router,state_channel,transaction}.proto)
MESSAGES=$(echo src/{blockchain_txn,entropy,data_rate,region,mapper,price_report}.proto)
SRC_FILES="$SERVICES $MESSAGES"

Expand Down
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const SERVICES: &[&str] = &[
"src/service/router.proto",
"src/service/state_channel.proto",
"src/service/local.proto",
"src/service/gateway.proto",
"src/service/transaction.proto",
"src/service/follower.proto",
"src/service/poc_mobile.proto",
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ pub mod services {
include!(concat!(env!("OUT_DIR"), "/helium.packet_router.rs"));
pub use packet_client::PacketClient as PacketRouterClient;
}
pub mod gateway {
pub use crate::gateway_client::GatewayClient as Client;
}

pub mod local {
include!(concat!(env!("OUT_DIR"), "/helium.local.rs"));
Expand Down
238 changes: 0 additions & 238 deletions src/service/gateway.proto

This file was deleted.

Loading

0 comments on commit 983596a

Please sign in to comment.