Skip to content

Commit

Permalink
keep sp promotions from reaching prime time
Browse files Browse the repository at this point in the history
- do not write sp allocations to reward manifest.
- always return nothing from the database when asking for promotion
  rewards

These two things will effectively keep promotion rewards from being
released. The Service Provider Reward calculations will continue as
planned thinking there are no promotio rewards to give out.
  • Loading branch information
michaeldjeffrey committed Oct 8, 2024
1 parent 853d7aa commit cfea511
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 74 deletions.
2 changes: 1 addition & 1 deletion mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ where
boosted_poc_bones_per_reward_share: Some(helium_proto::Decimal {
value: poc_dc_shares.boost.to_string(),
}),
sp_allocations: service_provider::reward_data_sp_allocations(&self.pool).await?,
// sp_allocations: service_provider::reward_data_sp_allocations(&self.pool).await?,
};
self.reward_manifests
.write(
Expand Down
93 changes: 23 additions & 70 deletions mobile_verifier/src/service_provider/promotions/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use std::ops::Range;

use chrono::{DateTime, Utc};
use file_store::promotion_reward::{Entity, PromotionReward};
use futures::TryStreamExt;
use helium_crypto::PublicKeyBinary;

use mobile_config::client::{carrier_service_client::CarrierServiceVerifier, ClientError};
use rust_decimal::Decimal;
use sqlx::{postgres::PgRow, PgPool, Postgres, Row, Transaction};
use sqlx::{PgPool, Postgres, Transaction};

use crate::service_provider::ServiceProviderId;

Expand Down Expand Up @@ -95,52 +94,6 @@ pub async fn save_promotion_reward(
Ok(())
}

pub async fn fetch_promotion_rewards(
pool: &PgPool,
carrier: &impl CarrierServiceVerifier<Error = ClientError>,
epoch: &Range<DateTime<Utc>>,
) -> anyhow::Result<ServiceProviderPromotions> {
let rewards = sqlx::query_as(
r#"
SELECT
subscriber_id, NULL as gateway_key, SUM(shares)::bigint as shares, carrier_key
FROM
subscriber_promotion_rewards
WHERE
time_of_reward >= $1 AND time_of_reward < $2
GROUP BY
subscriber_id, carrier_key
UNION
SELECT
NULL as subscriber_id, gateway_key, SUM(shares)::bigint as shares, carrier_key
FROM
gateway_promotion_rewards
WHERE
time_of_reward >= $1 AND time_of_reward < $2
GROUP
BY gateway_key, carrier_key
"#,
)
.bind(epoch.start)
.bind(epoch.end)
.fetch(pool)
.map_err(anyhow::Error::from)
.and_then(|x: DbPromotionRewardShares| async move {
let service_provider_id = carrier
.payer_key_to_service_provider(&x.carrier_key.to_string())
.await?;
Ok(PromotionRewardShare {
service_provider_id: service_provider_id as ServiceProviderId,
rewardable_entity: x.rewardable_entity,
shares: x.shares,
})
})
.try_collect()
.await?;

Ok(ServiceProviderPromotions(rewards))
}

pub async fn clear_promotion_rewards(
tx: &mut Transaction<'_, Postgres>,
timestamp: &DateTime<Utc>,
Expand Down Expand Up @@ -204,24 +157,24 @@ pub async fn fetch_promotion_rewards(
// Ok(ServiceProviderPromotions(rewards))
}

struct DbPromotionRewardShares {
pub carrier_key: PublicKeyBinary,
pub rewardable_entity: Entity,
pub shares: u64,
}

impl sqlx::FromRow<'_, PgRow> for DbPromotionRewardShares {
fn from_row(row: &PgRow) -> sqlx::Result<Self> {
let subscriber_id: Option<Vec<u8>> = row.try_get("subscriber_id")?;
let shares: i64 = row.try_get("shares")?;
Ok(Self {
rewardable_entity: if let Some(subscriber_id) = subscriber_id {
Entity::SubscriberId(subscriber_id)
} else {
Entity::GatewayKey(row.try_get("gateway_key")?)
},
shares: shares as u64,
carrier_key: row.try_get("carrier_key")?,
})
}
}
// struct DbPromotionRewardShares {
// pub carrier_key: PublicKeyBinary,
// pub rewardable_entity: Entity,
// pub shares: u64,
// }

// impl sqlx::FromRow<'_, PgRow> for DbPromotionRewardShares {
// fn from_row(row: &PgRow) -> sqlx::Result<Self> {
// let subscriber_id: Option<Vec<u8>> = row.try_get("subscriber_id")?;
// let shares: i64 = row.try_get("shares")?;
// Ok(Self {
// rewardable_entity: if let Some(subscriber_id) = subscriber_id {
// Entity::SubscriberId(subscriber_id)
// } else {
// Entity::GatewayKey(row.try_get("gateway_key")?)
// },
// shares: shares as u64,
// carrier_key: row.try_get("carrier_key")?,
// })
// }
// }
3 changes: 0 additions & 3 deletions mobile_verifier/src/service_provider/reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ mod tests {

let sp_2 = sp_infos.single_sp_rewards(1);
assert_eq!(sp_2.amount, 0);


// let (promo_1, sp_1) = sp_infos.single_sp_rewards(0);
// assert_eq!(promo_1.service_provider_amount, 6);
Expand Down Expand Up @@ -625,8 +624,6 @@ mod tests {
// assert_eq!(promo_rewards[1].matched_amount, 6);
// }



// trait PromoRewardFiltersExt {
// fn only_promotion_rewards(&self) -> Vec<PromotionReward>;
// }
Expand Down

0 comments on commit cfea511

Please sign in to comment.