From 88a6fc554cdce43fd3d2b76ad0e59808192c67a4 Mon Sep 17 00:00:00 2001 From: Marc Nijdam Date: Fri, 1 Sep 2023 22:44:35 -0700 Subject: [PATCH] Add timestamp to RegionParams Remove legacy gateway service (validator-era) --- beacon/src/region.rs | 45 ++----- build-cpp.sh | 2 +- build.rs | 1 - src/lib.rs | 3 - src/service/gateway.proto | 238 -------------------------------------- 5 files changed, 10 insertions(+), 279 deletions(-) delete mode 100644 src/service/gateway.proto diff --git a/beacon/src/region.rs b/beacon/src/region.rs index 04487b32..21bd6468 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,8 @@ pub struct RegionParams { pub gain: Decimal, pub region: Region, pub params: Vec, + // Timestamp the region params were attested by the config service + pub timestamp: u64, } impl AsRef<[BlockchainRegionParamV1]> for RegionParams { @@ -106,38 +107,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 +115,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 +131,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 +268,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); -}