-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add promotion funds workspace This workspace is all about dealing with Service Provider Promotion Fund allocation. HIP-114 https://github.com/helium/HIP/blob/main/0114-incentive-escrow-fund-for-subscriber-referrals.md Service Provider Promotions are stored in CarrierV0 on Solana. To keep the mobile-verifier from talking to a chain, this service will periodically check Solana and compare Service Providers allocations to what is stored in S3. If the values have changed, a new file will be output to a bucket for the mobile-verifier rewarder to read from. NOTE: Allocation Values are stored in Bps (Basis Points) https://www.investopedia.com/terms/b/basispoint.asp ** Commands *** ./promotion_fund write-solana Fetch Allocation values from Solana and write them to S3. This command _always_ writes an S3 file. *** ./promotion_fund print-s3 Using the lookback time in the provided settings file, show the Allocation values this service would start up with. *** ./promotion_fund server Start a server that reads from S3, then checks with Solana periodically for updated Allocatino values. Writing new files when needed. * Supporting material for promotion_fund workspace - ingest promotion rewards, nothing will be done with them until the processor is added into mobile-verifier. - dump reward files - add sp_allocations dummy field to rewarder output - reward indexer mobile promotion type added * use existing reward_types for reward_indexer Otherwise inserting a new reward would match on the address and continually change the reward_type column for no reason. * add lookback start after for s3 on start We may not always want to read from the beginning of time in s3 to get the latest values * update proto
- Loading branch information
1 parent
21708cd
commit ac73044
Showing
21 changed files
with
993 additions
and
49 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use crate::{ | ||
traits::{MsgDecode, TimestampDecode, TimestampEncode}, | ||
Error, Result, | ||
}; | ||
use chrono::{DateTime, Utc}; | ||
use helium_crypto::PublicKeyBinary; | ||
use helium_proto::services::poc_mobile::{ | ||
self as proto, PromotionRewardIngestReportV1, PromotionRewardReqV1, | ||
}; | ||
|
||
#[derive(Debug, Clone, PartialEq, Hash)] | ||
pub enum Entity { | ||
SubscriberId(Vec<u8>), | ||
GatewayKey(PublicKeyBinary), | ||
} | ||
|
||
impl From<proto::promotion_reward_req_v1::Entity> for Entity { | ||
fn from(entity: proto::promotion_reward_req_v1::Entity) -> Self { | ||
match entity { | ||
proto::promotion_reward_req_v1::Entity::SubscriberId(v) => Entity::SubscriberId(v), | ||
proto::promotion_reward_req_v1::Entity::GatewayKey(k) => Entity::GatewayKey(k.into()), | ||
} | ||
} | ||
} | ||
|
||
impl From<Entity> for proto::promotion_reward_req_v1::Entity { | ||
fn from(entity: Entity) -> Self { | ||
match entity { | ||
Entity::SubscriberId(v) => proto::promotion_reward_req_v1::Entity::SubscriberId(v), | ||
Entity::GatewayKey(k) => proto::promotion_reward_req_v1::Entity::GatewayKey(k.into()), | ||
} | ||
} | ||
} | ||
|
||
impl From<Entity> for proto::promotion_reward::Entity { | ||
fn from(entity: Entity) -> Self { | ||
match entity { | ||
Entity::SubscriberId(v) => proto::promotion_reward::Entity::SubscriberId(v), | ||
Entity::GatewayKey(k) => proto::promotion_reward::Entity::GatewayKey(k.into()), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct PromotionReward { | ||
pub entity: Entity, | ||
pub shares: u64, | ||
pub timestamp: DateTime<Utc>, | ||
pub received_timestamp: DateTime<Utc>, | ||
pub carrier_pub_key: PublicKeyBinary, | ||
pub signature: Vec<u8>, | ||
} | ||
|
||
impl MsgDecode for PromotionReward { | ||
type Msg = PromotionRewardIngestReportV1; | ||
} | ||
|
||
impl TryFrom<PromotionRewardIngestReportV1> for PromotionReward { | ||
type Error = Error; | ||
|
||
fn try_from(v: PromotionRewardIngestReportV1) -> Result<Self> { | ||
let received_timestamp = v.received_timestamp.to_timestamp_millis()?; | ||
let Some(v) = v.report else { | ||
return Err(Error::NotFound("report".to_string())); | ||
}; | ||
Ok(Self { | ||
entity: if let Some(entity) = v.entity { | ||
entity.into() | ||
} else { | ||
return Err(Error::NotFound("entity".to_string())); | ||
}, | ||
shares: v.shares, | ||
timestamp: v.timestamp.to_timestamp()?, | ||
received_timestamp, | ||
carrier_pub_key: v.carrier_pub_key.into(), | ||
signature: v.signature, | ||
}) | ||
} | ||
} | ||
|
||
impl From<PromotionReward> for PromotionRewardReqV1 { | ||
fn from(v: PromotionReward) -> Self { | ||
Self { | ||
entity: Some(v.entity.into()), | ||
shares: v.shares, | ||
timestamp: v.timestamp.encode_timestamp(), | ||
carrier_pub_key: v.carrier_pub_key.into(), | ||
signature: v.signature, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "promotion_fund" | ||
version = "0.1.0" | ||
description = "Service Provider promotion fund tracking for the Helium Network" | ||
authors.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
async-trait = { workspace = true } | ||
chrono = { workspace = true } | ||
clap = { workspace = true } | ||
config = { workspace = true } | ||
futures = { workspace = true } | ||
helium-proto = { workspace = true } | ||
humantime-serde = { workspace = true } | ||
metrics = { workspace = true } | ||
metrics-exporter-prometheus = { workspace = true } | ||
serde = { workspace = true } | ||
tokio = { workspace = true } | ||
tracing = { workspace = true } | ||
tracing-subscriber = { workspace = true } | ||
triggered = { workspace = true } | ||
|
||
custom-tracing = { path = "../custom_tracing" } | ||
file-store = { path = "../file_store" } | ||
poc-metrics = { path = "../metrics" } | ||
solana = { path = "../solana" } | ||
task-manager = { path = "../task_manager" } |
Oops, something went wrong.