From 3e74afdd1aeb94302cf9e561a6f3a1e5d894aceb Mon Sep 17 00:00:00 2001 From: Andrew McKenzie Date: Mon, 16 Dec 2024 12:33:05 +0000 Subject: [PATCH] rebase artifacts --- Cargo.lock | 53 +++++++------------ Cargo.toml | 4 +- iot_verifier/src/reward_share.rs | 1 - iot_verifier/src/rewarder.rs | 2 - mobile_verifier/src/reward_shares.rs | 4 +- mobile_verifier/src/rewarder.rs | 4 +- .../tests/integrations/rewarder_poc_dc.rs | 32 ++++++----- 7 files changed, 44 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a89634a5d..11d603510 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1619,7 +1619,7 @@ source = "git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-sup dependencies = [ "base64 0.21.7", "byteorder", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "prost", "rand 0.8.5", "rand_chacha 0.3.0", @@ -1788,7 +1788,7 @@ dependencies = [ "file-store", "futures", "futures-util", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "http 0.2.11", "http-serde", "humantime-serde", @@ -2630,7 +2630,7 @@ dependencies = [ "axum 0.7.4", "bs58 0.4.0", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "http 0.2.11", "notify", "serde", @@ -3212,7 +3212,7 @@ dependencies = [ "futures-util", "h3o", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "hex-literal", "http 0.2.11", "lazy_static", @@ -3794,7 +3794,7 @@ dependencies = [ "h3o", "helium-anchor-gen", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=master)", + "helium-proto", "hex", "hex-literal", "itertools", @@ -3821,23 +3821,6 @@ dependencies = [ [[package]] name = "helium-proto" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support#fffce9d335b1e5d74ffd5da27ddba6e60b6d9d7c" -dependencies = [ - "bytes", - "prost", - "prost-build", - "serde", - "serde_json", - "strum", - "strum_macros", - "tonic", - "tonic-build", -] - -[[package]] -name = "helium-proto" -version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=master#c5c67f5631b69ef696961995045c0a41f9a5b936" dependencies = [ "bytes", "prost", @@ -3891,7 +3874,7 @@ dependencies = [ "async-trait", "chrono", "derive_builder", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "hextree", "rust_decimal", "rust_decimal_macros", @@ -4307,7 +4290,7 @@ dependencies = [ "futures", "futures-util", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "http 0.2.11", "humantime-serde", "metrics", @@ -4377,7 +4360,7 @@ dependencies = [ "futures", "futures-util", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "hextree", "http 0.2.11", "http-serde", @@ -4419,7 +4402,7 @@ dependencies = [ "futures", "futures-util", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "http 0.2.11", "http-serde", "humantime-serde", @@ -4461,7 +4444,7 @@ dependencies = [ "futures-util", "h3o", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "http-serde", "humantime-serde", "iot-config", @@ -5050,7 +5033,7 @@ dependencies = [ "futures", "futures-util", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "hextree", "http 0.2.11", "http-serde", @@ -5093,7 +5076,7 @@ dependencies = [ "futures", "h3o", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "mobile-config", "prost", "rand 0.8.5", @@ -5129,7 +5112,7 @@ dependencies = [ "futures", "futures-util", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "http 0.2.11", "http-serde", "humantime-serde", @@ -5174,7 +5157,7 @@ dependencies = [ "h3o", "helium-crypto", "helium-lib", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "hex-assignments", "hextree", "http-serde", @@ -5858,7 +5841,7 @@ dependencies = [ "futures", "futures-util", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "http 0.2.11", "hyper 0.14.28", "jsonrpsee", @@ -5941,7 +5924,7 @@ dependencies = [ "futures-util", "helium-anchor-gen", "helium-lib", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "humantime-serde", "metrics", "metrics-exporter-prometheus", @@ -6082,7 +6065,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80b776a1b2dc779f5ee0641f8ade0125bc1298dd41a9a0c16d8bd57b42d222b1" dependencies = [ "bytes", - "heck 0.5.0", + "heck 0.4.0", "itertools", "log", "multimap", @@ -6580,7 +6563,7 @@ dependencies = [ "futures", "futures-util", "helium-crypto", - "helium-proto 0.1.0 (git+https://github.com/helium/proto?branch=andymck%2Fsub-dao-epoch-support)", + "helium-proto", "humantime-serde", "lazy_static", "metrics", diff --git a/Cargo.toml b/Cargo.toml index acac87a64..fae3f6697 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -132,6 +132,6 @@ sqlx = { git = "https://github.com/launchbadge/sqlx.git", rev = "42dd78fe931df65 # Patching for beacon must point directly to the crate, it will not look in the # repo for sibling crates. # -# [patch.'https://github.com/helium/proto'] -# helium-proto = { path = "../../proto" } + [patch.'https://github.com/helium/proto'] + helium-proto = { path = "../../proto" } # beacon = { path = "../../proto" } diff --git a/iot_verifier/src/reward_share.rs b/iot_verifier/src/reward_share.rs index f35cdb55a..eeb7dfb4a 100644 --- a/iot_verifier/src/reward_share.rs +++ b/iot_verifier/src/reward_share.rs @@ -286,7 +286,6 @@ impl GatewayShares { start_period: reward_period.start.encode_timestamp(), end_period: reward_period.end.encode_timestamp(), reward: Some(ProtoReward::GatewayReward(gateway_reward)), - epoch: 0, // placeholder, todo: remove }, ) }) diff --git a/iot_verifier/src/rewarder.rs b/iot_verifier/src/rewarder.rs index e72f0bbd3..c3b886362 100644 --- a/iot_verifier/src/rewarder.rs +++ b/iot_verifier/src/rewarder.rs @@ -304,7 +304,6 @@ pub async fn reward_operational( start_period: reward_period.start.encode_timestamp(), end_period: reward_period.end.encode_timestamp(), reward: Some(ProtoReward::OperationalReward(op_fund_reward)), - epoch: 0, // placeholder, todo: remove }, [], ) @@ -368,7 +367,6 @@ async fn write_unallocated_reward( reward_type: unallocated_type as i32, amount: unallocated_amount, })), - epoch: 0, // placeholder, todo: remove }; rewards_sink.write(unallocated_reward, []).await?.await??; }; diff --git a/mobile_verifier/src/reward_shares.rs b/mobile_verifier/src/reward_shares.rs index 72c1dbbf9..8591ccc9a 100644 --- a/mobile_verifier/src/reward_shares.rs +++ b/mobile_verifier/src/reward_shares.rs @@ -2232,8 +2232,10 @@ mod test { let mut owner_rewards = HashMap::::new(); let duration = Duration::hours(1); let epoch = (now - duration)..now; + let rewards_info = default_rewards_info(3_424_657_534_247, Duration::hours(1)); - let reward_shares = DataTransferAndPocAllocatedRewardBuckets::new_poc_only(&epoch); + let reward_shares = + DataTransferAndPocAllocatedRewardBuckets::new_poc_only(rewards_info.epoch_emissions); let unique_connection_counts = HashMap::from([(gw1.clone(), 42)]); for (_reward_amount, _mobile_reward_v1, mobile_reward_v2) in CoverageShares::new( &hex_coverage, diff --git a/mobile_verifier/src/rewarder.rs b/mobile_verifier/src/rewarder.rs index 288ebb5b8..d423da2e1 100644 --- a/mobile_verifier/src/rewarder.rs +++ b/mobile_verifier/src/rewarder.rs @@ -11,7 +11,7 @@ use crate::{ sp_boosted_rewards_bans, speedtests, speedtests_average::SpeedtestAverages, subscriber_location, subscriber_verified_mapping_event, telemetry, unique_connections, - Settings, MOBILE_SUB_DAO_ONCHAIN_ADDRESS, PriceInfo + PriceInfo, Settings, MOBILE_SUB_DAO_ONCHAIN_ADDRESS, }; use anyhow::bail; use chrono::{DateTime, TimeZone, Utc}; @@ -474,7 +474,7 @@ async fn reward_poc( ) .await?; - let unique_connections = unique_connections::db::get(pool, reward_period).await?; + let unique_connections = unique_connections::db::get(pool, &reward_info.epoch_period).await?; let coverage_shares = CoverageShares::new( pool, diff --git a/mobile_verifier/tests/integrations/rewarder_poc_dc.rs b/mobile_verifier/tests/integrations/rewarder_poc_dc.rs index f0d1fd6a1..428c27c11 100644 --- a/mobile_verifier/tests/integrations/rewarder_poc_dc.rs +++ b/mobile_verifier/tests/integrations/rewarder_poc_dc.rs @@ -3,7 +3,7 @@ use std::ops::Range; use crate::common::{ self, default_rewards_info, MockFileSinkReceiver, MockHexBoostingClient, RadioRewardV2Ext, }; -use chrono::{DateTime, Duration as ChronoDuration, Utc}; +use chrono::{DateTime, Duration as ChronoDuration, Duration, Utc}; use file_store::{ coverage::{CoverageObject as FSCoverageObject, KeyType, RadioHexSignalLevel}, speedtest::CellSpeedtest, @@ -150,29 +150,35 @@ async fn test_qualified_wifi_poc_rewards(pool: PgPool) -> anyhow::Result<()> { let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink(); let (speedtest_avg_client, _speedtest_avg_server) = common::create_file_sink(); - let now = Utc::now(); - let epoch = (now - ChronoDuration::hours(24))..now; + + let reward_info = default_rewards_info(82_191_780_821_917, Duration::hours(24)); + let pubkey: PublicKeyBinary = HOTSPOT_3.to_string().parse().unwrap(); // wifi hotspot // seed all the things let mut txn = pool.clone().begin().await?; - seed_heartbeats(epoch.start, &mut txn).await?; - seed_speedtests(epoch.end, &mut txn).await?; - seed_data_sessions(epoch.start, &mut txn).await?; + seed_heartbeats(reward_info.epoch_period.start, &mut txn).await?; + seed_speedtests(reward_info.epoch_period.end, &mut txn).await?; + seed_data_sessions(reward_info.epoch_period.start, &mut txn).await?; txn.commit().await?; update_assignments_bad(&pool).await?; // Run rewards with no unique connections, no poc rewards, expect unallocated let boosted_hexes = vec![]; let hex_boosting_client = MockHexBoostingClient::new(boosted_hexes); + + let price_info = PriceInfo::new(10000000000000000, 8); + assert_eq!(price_info.price_per_token, dec!(100000000)); + assert_eq!(price_info.price_per_bone, dec!(1)); + let (_, _rewards) = tokio::join!( rewarder::reward_poc_and_dc( &pool, &hex_boosting_client, &mobile_rewards_client, &speedtest_avg_client, - &epoch, - dec!(0.0001) + &reward_info, + price_info.clone() ), // expecting NO poc rewards, expecting unallocated receive_expected_rewards_with_counts(&mut mobile_rewards, 3, 0, true) @@ -180,12 +186,12 @@ async fn test_qualified_wifi_poc_rewards(pool: PgPool) -> anyhow::Result<()> { // seed single unique conections report within epoch let mut txn = pool.begin().await?; - seed_unique_connections(&mut txn, &[(pubkey.clone(), 42)], &epoch).await?; + seed_unique_connections(&mut txn, &[(pubkey.clone(), 42)], &reward_info.epoch_period).await?; txn.commit().await?; // SP ban radio, unique connections should supersede banning let mut txn = pool.begin().await?; - ban_wifi_radio_for_epoch(&mut txn, pubkey.clone(), &epoch).await?; + ban_wifi_radio_for_epoch(&mut txn, pubkey.clone(), &reward_info.epoch_period).await?; txn.commit().await?; let (_, rewards) = tokio::join!( @@ -195,8 +201,8 @@ async fn test_qualified_wifi_poc_rewards(pool: PgPool) -> anyhow::Result<()> { &hex_boosting_client, &mobile_rewards_client, &speedtest_avg_client, - &epoch, - dec!(0.0001) + &reward_info, + price_info ), // expecting single radio with poc rewards, no unallocated receive_expected_rewards_with_counts(&mut mobile_rewards, 3, 1, false) @@ -209,7 +215,7 @@ async fn test_qualified_wifi_poc_rewards(pool: PgPool) -> anyhow::Result<()> { let dc_sum: u64 = dc_rewards.iter().map(|r| r.dc_transfer_reward).sum(); let total = poc_sum + dc_sum; - let expected_sum = reward_shares::get_scheduled_tokens_for_poc(epoch.end - epoch.start) + let expected_sum = reward_shares::get_scheduled_tokens_for_poc(reward_info.epoch_emissions) .to_u64() .unwrap(); assert_eq!(expected_sum, total);