-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
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
michaeldjeffrey
requested review from
macpie,
andymck,
bbalser and
jeffgrunewald
September 21, 2024 00:19
michaeldjeffrey
force-pushed
the
mj/sp-rewards-in-perc
branch
from
September 30, 2024 19:11
3f26bfa
to
464e9f4
Compare
3 tasks
michaeldjeffrey
force-pushed
the
mj/sp-rewards-in-perc
branch
from
September 30, 2024 21:45
a5ff23a
to
213b79a
Compare
michaeldjeffrey
force-pushed
the
mj/sp-rewards-in-perc
branch
3 times, most recently
from
September 30, 2024 22:52
3ef7cd2
to
998cf2c
Compare
bbalser
approved these changes
Oct 1, 2024
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.
- 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
Otherwise inserting a new reward would match on the address and continually change the reward_type column for no reason.
Default trait impls cannot be added to functions, but they can be added to structs. This struct keeps us from needing to do the gross blank generic filling in when we want a continuous file source with a decode other than MsgDecodeFileInfoPollerParser.
Rather than always dealing with conrete numbers, now that Service Providers can allocate a percentage of their rewards to promotions for subscribers or gateways, it becomes easier to speak of everything in percentages. This is a quick overview of what a more detailed overview you will find in the PR. For every Service Provider (SP) we figure out how much of the total rewards allocation they are being awarded for data transfer. We get the percent they have allocated for promotions (essentially from solana, but really s3), and we determine which percentage of the _total rewards allocation_ that is. If a SP is getting 50% of the total rewards, and they allocate 20% of those rewards to promotions, then the SP will receive 40% of the total, and promotions from them will represent 10% of the total. We do that for all SPs. The unallocated percentage is then distributed to the promotions of each SP. If there is more than enough unallocated left over, each SP get's a matched percentage of the whole to what they set aside. When there is not enough, they get a percentage equal to their initial rewards percentage. This is to keep a service provider from getting the bulk of extra rewards by settings aside a large amount for promotions, and receiving little in rewards for data transfer, but getting more for matching. A SP may never receive more in matched rewards than they have allocated themselves.
This makes invocations of rewarding look very consistent
because we're dealing with percentages, and not doing bankers rounding or nearest even, the likelihood that a calculation comes out extremely close to a hole number then gets rounded down is increased. Especially when dealing with percentages to the 7th decimal point and a base number in the trillions.
I'm hoping there's an easy way to do this someone can point me to
it get a bit verbose with all the service_provider flying around, but I think it will be rather helpful when you only have the type and it hasn't been aliased.
truncating to 5 decimal places for a % can result in the summed allocation exceeding 100%. Thanks proptest
It has been noted that in tests a single bone is okay, as long as we're not going over the allocated bones
let's not have the worst of both worlds where we comment out unused code. Remove the printlns, they're not hard to add back in if you need them.
For accounting reasons, Service Providers can have multiple payer keys listed. We need to ensuure all their dc transfer are accumulated into their service provider entry when we are generating rewards.
michaeldjeffrey
force-pushed
the
mj/sp-rewards-in-perc
branch
from
October 2, 2024 17:21
8f54040
to
1abf203
Compare
macpie
reviewed
Oct 2, 2024
macpie
approved these changes
Oct 2, 2024
andymck
approved these changes
Oct 3, 2024
- Add settings `promotion_ingest`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Service Provider Promotion Rewards
HIP-114, Pre-req PR, Proto PR
Where do Funds come from?
Service Providers update their
incentive_escrow_fund_bps
on Solana. Thepromotion_fund
workspace is configured to check Solana for updates to Service Provider Accounts, and output new reports to S3 when values change.bps
stands for Basis Points. They represent a percentage to 2 decimal places00.00%
. A bps of 500 is equal to 5%. 10,000 equals 100%.mobile-verifier
watches that file and saves it's values to it's db. This means rewards can be run without needing to talk to Solana. S3 acts as the history of values for Service Providers, andmobile-verifier
hangs on to the latest value.A
promotions
subcommand has been added tomobile-verifier
.Calculating with percentages
Now that Service Providers can set aside a percentage of their rewards for promotions, it becomes easier to think of calculating rewards in only percentages. There are 5 percentages we track.
1.
dc_perc
:: Service Provider DC percentage of total rewards poolThis percentage is derived from the amount of DC transfer a Service Provider facilitated during the reward period.
2.
allocated_promo_perc
:: Percentage the Service Provider has set aside for promotionsThis is the percentage representation of
incentive_escrow_fund_bps
.3.
realized_promo_perc
:: Promotions as a percentage of total rewards poolTo get this percentage we take the
allocated_promo_perc
ofdc_perc
. If a Service Provider has 60% of the total rewards pool and has set aside 20% of their rewards for promotions60% x 20% = 12%
, that Service Provider's promotion rewards represent 12% of the total rewards pool.In he case where a Service Provider has no promotions to give out, this percentage will be
0%
.4.
realized_dc_perc
:: Service Provider rewards as a percentage of total rewards poolThis percentage is
dc_perc - realized_promo_perc
. It is the subset of the total rewards pool that is going to the Service Provider. Continuing the example from above,60% - 12% = 48%
, that Service Provider's rewards represent 48% of the total rewards pool.In the case where a Service Provider has no rewards this percentage will be equal to
dc_perc
.5.
matched_promo_perc
:: Matched promotion from Unallocated as a percentage of total rewards poolThis percentage is the amount of the total rewards pool going towards matching a Service Provider's promotions. This value is extrapolated in the next section.
How does matching work?
Thus far, the unallocated service provider rewards can be found by removing all service provider's
dc_perc
from 100%. Continuing the above example with a single service provider, there is 40% of the rewards pool unallocated and available for matching promotion rewards.Matched rewards can never exceed the amount a service provider has allocated for promotions. And matched rewards can never go towards anything other than promotions.
If a Service Provider has no promotions for the reward period, they are not considered in any of the matching situations.
Unallocated % is greater than all promotions
If you take take the sum of all Service Provider's
realized_promo_perc
, and it is less than the remaining unallocated rewards, each service provider receives an equal amount of matched rewards.realized_promo_perc == matched_promo_perc
.With the ongoing example, 12% would be used to match the 12% promotion rewards from the Service Provider, and the remaining unallocated amount would be 28%. Remember all these percentages are relative to the total rewards pool.
Unallocated % is less than all promotions
In this situation, the unallocated rewards are distributed amongst the service providers in portions relative to their
dc_perc
.Let's have an example where
Total Rewards Allocation: 100,000
The realized promotion percentage for both Service Providers is 45%.
(50% of 80%) + (50% of 10%)
.To dive up the remaining 10% of rewards, we split on the % of DC Transfer.
Now, 100% of the total service provider rewards should be accounted for.
dc_perc
allocated_promo_perc
realized_promo_perc
realized_dc_perc
matched_promo_perc
40% + 40% + 8.8% + 5% + 5% + 1.2% = 100%
Distributing Promotions
Service Providers submit promotion rewards by assigning a number of shares to the recipient (
Entity
in code). To distribute the rewards, we do a familiar calculation where we find therewards_per_share
by doingtotal_shares / total_rewards
, then each recipient is given theirshares * rewards_per_share
.total_rewards
in this case is a Service Proviers(realized_promo_perc + matched_promo_perc) * total_rewards_pool
.Rounding
Generally, when dealing with reward calculations that result in fractional values, oralces always down. This is to prevent any chance of over allocation. In dealing with very large numbers and the way computers do math, we may not always end up with nice round numbers.
There are a couple tests where the math in any online calculator will come out to an even 60,000. The DC Transfer in the test represent some
0.00000073%
of rewards above8 trillion
. The resulting multiplication when using percentages comes out to5,999.9999999976
(estimation). This gets rounded down, and the missing reward is moved to the unallocated pool.Errors like this are reduced when dealing with larger allocations of the total rewards pool.
Something like Bankers rounding wouldn't necessarily alleviate this problem, because we have no reason to think that promotion values will be randomly distributed. Assuming promotion shares could all be the same for a reward period, they would all round in the same direction, and if that direction is up, we could end up allocating more rewards than what exists.
So we remain safe and round down.