diff --git a/beacon/src/region.rs b/beacon/src/region.rs index 04487b32..f5c027e3 100644 --- a/beacon/src/region.rs +++ b/beacon/src/region.rs @@ -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}; @@ -92,6 +91,9 @@ pub struct RegionParams { pub gain: Decimal, pub region: Region, pub params: Vec, + // Timestamp the region params were attested by the config service, in + // seconds since unix epoch + pub timestamp: u64, } impl AsRef<[BlockchainRegionParamV1]> for RegionParams { @@ -106,38 +108,6 @@ impl PartialEq for RegionParams { } } -impl TryFrom for RegionParams { - type Error = Error; - fn try_from(value: GatewayRegionParamsStreamedRespV1) -> Result { - 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 for RegionParams { - type Error = Error; - fn try_from(value: GatewayRegionParamsRespV1) -> Result { - 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 for RegionParams { type Error = Error; fn try_from(value: GatewayRegionParamsResV1) -> Result { @@ -146,10 +116,12 @@ impl TryFrom 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, }) } } @@ -160,18 +132,20 @@ impl From for RegionParams { region, gain: 0.into(), params: vec![], + timestamp: 0, } } } impl RegionParams { - pub fn from_bytes(region: Region, gain: u64, data: &[u8]) -> Result { + pub fn from_bytes(region: Region, gain: u64, data: &[u8], timestamp: u64) -> Result { let params = BlockchainRegionParamsV1::decode(data)?.region_params; let gain = Decimal::new(gain as i64, 1); Ok(Self { region, gain, params, + timestamp, }) } @@ -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") diff --git a/build-cpp.sh b/build-cpp.sh index b014a516..c720c22c 100644 --- a/build-cpp.sh +++ b/build-cpp.sh @@ -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" diff --git a/build.rs b/build.rs index e18dfdcc..c74ecd1c 100644 --- a/build.rs +++ b/build.rs @@ -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", diff --git a/src/lib.rs b/src/lib.rs index 72dccc4b..7b65eed8 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -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")); diff --git a/src/service/gateway.proto b/src/service/gateway.proto deleted file mode 100644 index fdfb8981..00000000 --- a/src/service/gateway.proto +++ /dev/null @@ -1,238 +0,0 @@ -syntax = "proto3"; - -package helium; - -import "blockchain_routing_address.proto"; -import "blockchain_txn_state_channel_close_v1.proto"; -import "blockchain_txn_vars_v1.proto"; -import "blockchain_poc_core_v1.proto"; -import "blockchain_region_param_v1.proto"; -import "region.proto"; - -// defines the various close states of an SC -enum close_state { - close_state_closable = 0; - close_state_closing = 1; - close_state_closed = 2; - close_state_dispute = 3; -} - -/* general */ - -message gateway_success_resp {} - -message gateway_error_resp { - bytes error = 1; - bytes details = 2; -} - -message gateway_config_req_v1 { repeated string keys = 1; } -message gateway_config_resp_v1 { repeated blockchain_var_v1 result = 1; } - -message gateway_config_update_req_v1 {} -message gateway_config_update_streamed_resp_v1 { repeated string keys = 1; } - -message gateway_validators_req_v1 { uint32 quantity = 1; } -message gateway_validators_resp_v1 { repeated routing_address result = 1; } - -message gateway_region_params_streamed_resp_v1 { - bytes address = 1; - region region = 2; - blockchain_region_params_v1 params = 3; - uint64 gain = 4; -} - -message gateway_region_params_update_req_v1 { - bytes address = 1; - bytes signature = 2; -} - -message gateway_region_params_req_v1 { - region region = 1; - bytes address = 2; - bytes signature = 3; -} - -message gateway_region_params_resp_v1 { - region region = 1; - blockchain_region_params_v1 params = 2; - uint64 gain = 3; -} - -message gateway_resp_v1 { - uint64 height = 1; - bytes signature = 2; - oneof msg { - gateway_sc_is_active_resp_v1 is_active_resp = 3; - gateway_sc_is_overpaid_resp_v1 is_overpaid_resp = 4; - gateway_sc_close_resp_v1 close_resp = 5; - gateway_sc_follow_streamed_resp_v1 follow_streamed_resp = 6; - gateway_routing_streamed_resp_v1 routing_streamed_resp = 7; - gateway_config_resp_v1 config_resp = 8; - gateway_config_update_streamed_resp_v1 config_update_streamed_resp = 9; - gateway_validators_resp_v1 validators_resp = 12; - gateway_region_params_streamed_resp_v1 region_params_streamed_resp = 13; - gateway_success_resp success_resp = 14; - gateway_error_resp error_resp = 15; - gateway_poc_challenge_notification_resp_v1 poc_challenge_resp = 16; - gateway_poc_check_challenge_target_resp_v1 poc_check_target_resp = 17; - gateway_public_routing_data_resp_v1 public_route = 18; - gateway_version_resp_v1 version = 19; - gateway_region_params_resp_v1 region_params_resp = 20; - } - uint64 block_time = 10; - uint64 block_age = 11; -} - -/* version */ - -message gateway_version_req_v1 {} - -message gateway_version_resp_v1 { uint64 version = 1; } - -/* state channels */ - -message gateway_sc_is_active_req_v1 { - bytes sc_id = 1; - bytes sc_owner = 2; -} - -message gateway_sc_is_active_resp_v1 { - bytes sc_id = 1; - bytes sc_owner = 2; - bool active = 3; - uint64 sc_expiry_at_block = 4; - uint64 sc_original_dc_amount = 5; -} - -message gateway_sc_is_overpaid_req_v1 { - bytes sc_id = 1; - bytes sc_owner = 2; - uint64 total_dcs = 3; -} - -message gateway_sc_is_overpaid_resp_v1 { - bytes sc_id = 1; - bytes sc_owner = 2; - bool overpaid = 3; -} - -message gateway_sc_close_req_v1 { - blockchain_txn_state_channel_close_v1 close_txn = 1; -} -message gateway_sc_close_resp_v1 { - bytes sc_id = 1; - bytes response = 2; -} - -message gateway_sc_follow_req_v1 { - bytes sc_id = 1; - bytes sc_owner = 2; -} -message gateway_sc_follow_streamed_resp_v1 { - bytes sc_id = 1; - bytes sc_owner = 2; - close_state close_state = 3; -} - -/* routing */ - -message routing { - uint32 oui = 1; - bytes owner = 2; - repeated routing_address addresses = 3; - repeated bytes filters = 4; - repeated bytes subnets = 5; -} - -message gateway_routing_req_v1 { uint64 height = 1; } -message gateway_routing_streamed_resp_v1 { repeated routing routings = 1; } - -/* POCs */ - -message gateway_poc_req_v1 { - bytes address = 1; - bytes signature = 2; -} - -// streaming notification sent by a validator to a light gateway to notify it of -// a new challenge -message gateway_poc_challenge_notification_resp_v1 { - routing_address challenger = 1; - bytes block_hash = 2; - bytes onion_key_hash = 3; -} - -// request sent by a light gateway to a challenging validator to check if they -// are the target -message gateway_poc_check_challenge_target_req_v1 { - bytes address = 1; - bytes challenger = 2; - bytes block_hash = 3; - bytes onion_key_hash = 4; - uint64 height = 5; - bytes notifier = 6; - bytes notifier_sig = 7; - bytes challengee_sig = 8; -} - -// response to the requestor's 'gateway_poc_check_challenge_target_req_v1' -// request if the requestor is the target -message gateway_poc_check_challenge_target_resp_v1 { - bool target = 1; - bytes onion = 2; -} - -// request sent by a light gateway to a consensus group member containing the -// observing gateways receipt or witness report -message gateway_poc_report_req_v1 { - bytes onion_key_hash = 1; - oneof msg { - blockchain_poc_receipt_v1 receipt = 2; - blockchain_poc_witness_v1 witness = 3; - } -} - -// request to translate the specified pubkeybin to the assocaited nodes public -// grpc routing data -message gateway_address_routing_data_req_v1 { bytes address = 1; } - -// request to translate the specified POC onion key the to the associated -// challengers public grpc routing data -message gateway_poc_key_routing_data_req_v1 { bytes key = 1; } - -message gateway_public_routing_data_resp_v1 { - bytes address = 1; - routing_address public_uri = 2; -} - -/* Gateway Service */ - -service gateway { - rpc version(gateway_version_req_v1) returns (gateway_resp_v1); - - rpc follow_sc(stream gateway_sc_follow_req_v1) - returns (stream gateway_resp_v1); - rpc routing(gateway_routing_req_v1) returns (stream gateway_resp_v1); - rpc stream_poc(gateway_poc_req_v1) returns (stream gateway_resp_v1); - rpc config_update(gateway_config_update_req_v1) - returns (stream gateway_resp_v1); - - rpc is_active_sc(gateway_sc_is_active_req_v1) returns (gateway_resp_v1); - rpc is_overpaid_sc(gateway_sc_is_overpaid_req_v1) returns (gateway_resp_v1); - rpc close_sc(gateway_sc_close_req_v1) returns (gateway_resp_v1); - - rpc check_challenge_target(gateway_poc_check_challenge_target_req_v1) - returns (gateway_resp_v1); - rpc send_report(gateway_poc_report_req_v1) returns (gateway_resp_v1); - rpc address_to_public_uri(gateway_address_routing_data_req_v1) - returns (gateway_resp_v1); - rpc poc_key_to_public_uri(gateway_poc_key_routing_data_req_v1) - returns (gateway_resp_v1); - - rpc config(gateway_config_req_v1) returns (gateway_resp_v1); - rpc validators(gateway_validators_req_v1) returns (gateway_resp_v1); - rpc region_params_update(gateway_region_params_update_req_v1) - returns (stream gateway_resp_v1); - rpc region_params(gateway_region_params_req_v1) returns (gateway_resp_v1); -} diff --git a/src/service/iot_config.proto b/src/service/iot_config.proto index 81b254c0..b7d5bc97 100644 --- a/src/service/iot_config.proto +++ b/src/service/iot_config.proto @@ -18,8 +18,6 @@ import "region.proto"; // are signed by the config service to allow the recipient to validate // the authenticity of the data returned. // -// - Every `timestamp` is in milliseconds since unix epoch -// // - Every key called `owner`, `payer` and `delegate_keys` are binary // encoded public keys, Rust encoding example here: // https://github.com/helium/helium-crypto-rs/blob/main/src/public_key.rs#L347-L354 @@ -142,7 +140,7 @@ message org_list_req_v1 {} message org_list_res_v1 { repeated org_v1 orgs = 1; - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 2; // pubkey binary of the signing keypair bytes signer = 3; @@ -219,7 +217,7 @@ message org_res_v1 { org_v1 org = 1; uint32 net_id = 2; repeated devaddr_constraint_v1 devaddr_constraints = 3; - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 4; // pubkey binary of the signing keypair bytes signer = 5; @@ -238,7 +236,7 @@ message org_disable_req_v1 { message org_disable_res_v1 { uint64 oui = 1; - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 2; // pubkey binary of the signing keypair bytes signer = 3; @@ -257,7 +255,7 @@ message org_enable_req_v1 { message org_enable_res_v1 { uint64 oui = 1; - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 2; // pubkey binary of the signing keypair bytes signer = 3; @@ -276,7 +274,7 @@ message route_list_req_v1 { message route_list_res_v1 { repeated route_v1 routes = 1; - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 2; // pubkey binary of the signing keypair bytes signer = 3; @@ -323,7 +321,7 @@ message route_delete_req_v1 { message route_res_v1 { route_v1 route = 1; - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 2; // pubkey binary of the signing keypair bytes signer = 3; @@ -351,7 +349,7 @@ message route_update_euis_req_v1 { } message route_euis_res_v1 { - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 1; // pubkey binary of the signing keypair bytes signer = 2; @@ -379,7 +377,7 @@ message route_update_devaddr_ranges_req_v1 { } message route_devaddr_ranges_res_v1 { - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 1; // pubkey binary of the signing keypair bytes signer = 2; @@ -396,7 +394,7 @@ message route_stream_req_v1 { } message route_stream_res_v1 { - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 1; // pubkey binary of the signing keypair bytes signer = 2; @@ -458,7 +456,7 @@ message route_skf_update_req_v1 { } message route_skf_update_res_v1 { - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 1; // pubkey binary of the signing keypair bytes signer = 2; @@ -478,7 +476,7 @@ message gateway_region_params_res_v1 { uint64 gain = 3; // Signature over the response by the config service bytes signature = 4; - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 5; // pubkey binary of the signing keypair bytes signer = 6; @@ -493,7 +491,7 @@ message gateway_location_req_v1 { message gateway_location_res_v1 { string location = 1; - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 2; // pubkey binary of the signing keypair bytes signer = 3; @@ -513,7 +511,7 @@ message admin_load_region_req_v1 { } message admin_load_region_res_v1 { - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 1; // pubkey binary of the signing keypair bytes signer = 2; @@ -550,7 +548,7 @@ message admin_remove_key_req_v1 { } message admin_key_res_v1 { - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 1; // pubkey binary of the signing keypair bytes signer = 2; @@ -590,7 +588,7 @@ message gateway_info_req_v1 { } message gateway_info_res_v1 { - /// Timestamp of response + /// Timestamp of response in seconds since unix epoch uint64 timestamp = 1; gateway_info info = 2; /// sig from the config service @@ -610,7 +608,7 @@ message gateway_info_stream_req_v1 { /// Active gateway info streaming response containing a batch of gateways message gateway_info_stream_res_v1 { - /// Timestamp of response + /// Timestamp of response in seconds since unix epoch uint64 timestamp = 1; /// batch of gateways repeated gateway_info gateways = 2; @@ -635,7 +633,7 @@ message region_params_res_v1 { bytes signature = 3; // pubkey binary of the signing keypair bytes signer = 4; - // in milliseconds since unix epoch + // in seconds since unix epoch uint64 timestamp = 5; }