Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Provider Rewards and Promotions #867

Merged
merged 31 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e6d99c7
Add promotion funds workspace
michaeldjeffrey Sep 19, 2024
19db98f
Supporting material for promotion_fund workspace
michaeldjeffrey Sep 19, 2024
ff39335
use existing reward_types for reward_indexer
michaeldjeffrey Sep 30, 2024
97b0c57
update proto
michaeldjeffrey Sep 30, 2024
882aadb
Add Continuous struct helper for file_source
michaeldjeffrey Sep 20, 2024
eb97f57
Add the Service Provider Promotions Daemon
michaeldjeffrey Sep 20, 2024
754a380
Swap over Service Provider rewards to use percents
michaeldjeffrey Sep 20, 2024
d3a4241
Wrap everything in a service provider type
michaeldjeffrey Sep 20, 2024
1dfe1da
Update tests to use new service_provider code
michaeldjeffrey Sep 20, 2024
be4e610
remove unused code
michaeldjeffrey Sep 20, 2024
1f16e7a
use wrapped types for promotions
michaeldjeffrey Sep 20, 2024
7d44da2
add back promotion_fund cli
michaeldjeffrey Sep 20, 2024
1632262
port over existing tests
michaeldjeffrey Sep 20, 2024
9167d53
service provider reward info collection can hold onto the reward date
michaeldjeffrey Sep 20, 2024
72c7706
add test with seeded promotions
michaeldjeffrey Sep 20, 2024
df41d2c
the nature of the math has changed
michaeldjeffrey Sep 20, 2024
4c0c05e
make sure we're cleaning up promotions
michaeldjeffrey Sep 21, 2024
9c17404
stub for reporting sp allocations
michaeldjeffrey Sep 21, 2024
1012a00
rename collection class for consistency
michaeldjeffrey Sep 21, 2024
4c50dc3
fix up uncompiled tests
michaeldjeffrey Sep 21, 2024
5b972bd
add tests from good examples in original PR
michaeldjeffrey Sep 27, 2024
d088627
if for some reason a key is duplicated, absorb both
michaeldjeffrey Sep 27, 2024
7100362
add proptests for service provider rewards
michaeldjeffrey Sep 27, 2024
02c031a
Found a rounding error
michaeldjeffrey Sep 27, 2024
3ad8630
Discussion has been had
michaeldjeffrey Sep 30, 2024
bd19088
commit commit
michaeldjeffrey Sep 30, 2024
1f48208
fill out service provider reward allocations in reward_manifest
michaeldjeffrey Sep 30, 2024
1abf203
Service Providers can use multiple keys for dc_transfer
michaeldjeffrey Oct 1, 2024
6d0ba72
fixup cargo deps after rebase
michaeldjeffrey Oct 2, 2024
c02d5ca
Change promotion_fund to promotion-fund
bbalser Oct 3, 2024
41ef60e
Read Service Provider Promotion values from unique bucket
michaeldjeffrey Oct 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 83 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 32 additions & 4 deletions file_store/src/file_source.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
use crate::{
file_info_poller::{FileInfoPollerConfigBuilder, MsgDecodeFileInfoPollerParser},
file_info_poller::{
FileInfoPollerConfigBuilder, MsgDecodeFileInfoPollerParser, ProstFileInfoPollerParser,
},
file_sink, BytesMutStream, Error, FileStore,
};
use async_compression::tokio::bufread::GzipDecoder;
use futures::{
stream::{self},
StreamExt, TryFutureExt, TryStreamExt,
};
use std::path::{Path, PathBuf};
use std::{
marker::PhantomData,
path::{Path, PathBuf},
};
use tokio::{fs::File, io::BufReader};
use tokio_util::codec::{length_delimited::LengthDelimitedCodec, FramedRead};

pub struct Continuous<Store, Parser>(PhantomData<(Store, Parser)>);

impl Continuous<FileStore, MsgDecodeFileInfoPollerParser> {
pub fn msg_source<Msg, State>(
) -> FileInfoPollerConfigBuilder<Msg, State, FileStore, MsgDecodeFileInfoPollerParser>
where
Msg: Clone,
{
FileInfoPollerConfigBuilder::<Msg, State, FileStore, MsgDecodeFileInfoPollerParser>::default()
.parser(MsgDecodeFileInfoPollerParser)
}
}

impl Continuous<FileStore, ProstFileInfoPollerParser> {
pub fn prost_source<Msg, State>(
) -> FileInfoPollerConfigBuilder<Msg, State, FileStore, ProstFileInfoPollerParser>
where
Msg: Clone,
{
FileInfoPollerConfigBuilder::<Msg, State, FileStore, ProstFileInfoPollerParser>::default()
.parser(ProstFileInfoPollerParser)
}
}

pub fn continuous_source<T, S>(
) -> FileInfoPollerConfigBuilder<T, S, FileStore, MsgDecodeFileInfoPollerParser>
where
T: Clone,
{
FileInfoPollerConfigBuilder::<T, S, FileStore, MsgDecodeFileInfoPollerParser>::default()
.parser(MsgDecodeFileInfoPollerParser)
Continuous::msg_source::<T, S>()
}

pub fn source<I, P>(paths: I) -> BytesMutStream
Expand Down
1 change: 1 addition & 0 deletions mobile_verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ coverage-map = { path = "../coverage_map" }

[dev-dependencies]
backon = "0"
proptest = "1.5.0"
21 changes: 21 additions & 0 deletions mobile_verifier/migrations/37_sp_promotions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CREATE TABLE IF NOT EXISTS subscriber_promotion_rewards (
time_of_reward TIMESTAMPTZ NOT NULL,
subscriber_id BYTEA NOT NULL,
carrier_key TEXT NOT NULL,
shares BIGINT NOT NULL,
PRIMARY KEY (time_of_reward, subscriber_id, carrier_key)
);

CREATE TABLE IF NOT EXISTS gateway_promotion_rewards (
time_of_reward TIMESTAMPTZ NOT NULL,
gateway_key TEXT NOT NULL,
carrier_key TEXT NOT NULL,
shares BIGINT NOT NULL,
PRIMARY KEY (time_of_reward, gateway_key, carrier_key)
);

CREATE TABLE IF NOT EXISTS service_provider_promotion_funds (
service_provider BIGINT NOT NULL PRIMARY KEY,
basis_points BIGINT NOT NULL,
inserted_at TIMESTAMPTZ NOT NULL
);
1 change: 1 addition & 0 deletions mobile_verifier/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod promotion_funds;
pub mod reward_from_db;
pub mod server;
pub mod verify_disktree;
59 changes: 59 additions & 0 deletions mobile_verifier/src/cli/promotion_funds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use crate::{
service_provider::promotions::funds::{
delete_promotion_fund, fetch_promotion_funds, save_promotion_fund,
},
Settings,
};

#[derive(Debug, clap::Args)]
pub struct Cmd {
#[clap(subcommand)]
sub_command: SubCommand,
}

#[derive(Debug, clap::Subcommand)]
enum SubCommand {
/// Print Service Provider promotions in mobile-verifier db
List,
/// Set Service Provider promotion in mobile-verifier db
Set {
service_provider_id: i32,
basis_points: u16,
},
/// Remove Service Provider promotion allocation from mobile-verifier db
Unset { service_provider_id: i32 },
}

impl Cmd {
pub async fn run(&self, settings: &Settings) -> anyhow::Result<()> {
let pool = settings.database.connect(env!("CARGO_PKG_NAME")).await?;

match self.sub_command {
SubCommand::List => {
let funds = fetch_promotion_funds(&pool).await?;
println!("{funds:?}");
}
SubCommand::Set {
service_provider_id,
basis_points,
} => {
let mut txn = pool.begin().await?;
save_promotion_fund(&mut txn, service_provider_id, basis_points).await?;
txn.commit().await?;

let funds = fetch_promotion_funds(&pool).await?;
println!("{funds:?}");
}
SubCommand::Unset {
service_provider_id,
} => {
delete_promotion_fund(&pool, service_provider_id).await?;

let funds = fetch_promotion_funds(&pool).await?;
println!("{funds:?}");
}
}

Ok(())
}
}
15 changes: 14 additions & 1 deletion mobile_verifier/src/cli/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
heartbeats::{cbrs::CbrsHeartbeatDaemon, wifi::WifiHeartbeatDaemon},
radio_threshold::RadioThresholdIngestor,
rewarder::Rewarder,
service_provider,
sp_boosted_rewards_bans::ServiceProviderBoostedRewardsBanIngestor,
speedtests::SpeedtestDaemon,
subscriber_location::SubscriberLocationIngestor,
Expand Down Expand Up @@ -137,7 +138,7 @@ impl Cmd {
file_upload.clone(),
report_ingest.clone(),
speedtests_avg.clone(),
gateway_client,
gateway_client.clone(),
)
.await?,
)
Expand Down Expand Up @@ -193,6 +194,18 @@ impl Cmd {
)
.await?,
)
.add_task(
service_provider::PromotionDaemon::create_managed_task(
pool.clone(),
settings,
file_upload.clone(),
report_ingest.clone(),
gateway_client.clone(),
auth_client.clone(),
entity_client.clone(),
)
.await?,
)
.add_task(DataSessionIngestor::create_managed_task(pool.clone(), settings).await?)
.add_task(
ServiceProviderBoostedRewardsBanIngestor::create_managed_task(
Expand Down
8 changes: 0 additions & 8 deletions mobile_verifier/src/data_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use futures::{
TryFutureExt,
};
use helium_crypto::PublicKeyBinary;
use helium_proto::ServiceProvider;
use rust_decimal::Decimal;
use sqlx::{PgPool, Pool, Postgres, Row, Transaction};
use std::{collections::HashMap, ops::Range, time::Instant};
use task_manager::{ManagedTask, TaskManager};
Expand All @@ -30,12 +28,6 @@ pub struct HotspotReward {
pub rewardable_dc: u64,
}

#[derive(Clone, Debug)]
pub struct ServiceProviderDataSession {
pub service_provider: ServiceProvider,
pub total_dcs: Decimal,
}

pub type HotspotMap = HashMap<PublicKeyBinary, HotspotReward>;

impl DataSessionIngestor {
Expand Down
Loading
Loading