[][src]Trait sn_farming::calculation::RewardAlgo

pub trait RewardAlgo {
    fn set(&mut self, base_cost: Money);
fn work_cost(&self, reward_units: u64) -> Money;
fn total_reward(&self, factor: f64, work_cost: Money) -> Money;
fn distribute(
        &self,
        total_reward: Money,
        accounts_work: HashMap<AccountId, Work>
    ) -> HashMap<AccountId, Money>; }

This algo allows for setting a base cost together with a cost proportional to some work, as measured by a minimum work unit.

Required methods

fn set(&mut self, base_cost: Money)

Set the base cost of work.

fn work_cost(&self, reward_units: u64) -> Money

Get the cost of work for the specified number of reward units. It can be simple, 1 RU == 1 unit of money (+ base cost). Or something else.

fn total_reward(&self, factor: f64, work_cost: Money) -> Money

Get the total reward implied by the work cost, as scaled by a factor representing a function of parameters relevant to the implementing layer.

fn distribute(
    &self,
    total_reward: Money,
    accounts_work: HashMap<AccountId, Work>
) -> HashMap<AccountId, Money>

Returns the distribution of the total_reward, between the accounts supplied, proportionally to their accumulated work.

Loading content...

Implementors

impl RewardAlgo for StorageRewards[src]

Explanation A unit of Work is defined as, and registered, based on what ever scheme the implementing layer decides.

New rewards are paid proportionally to Work performed.

Implications of StorageRewards design StorageRewards does not define Work, and thus what increases the participants registered Work.

It could be that p.work += rewards[p.id] it could also be that p.work += 1 for everytime they get a(ny) reward. But it could actually be anything.

The current implementation in accumulation.rs uses p.work += 1 for every reward received (any amount). The implications of this, is that no matter how small your reward is, your contribution is recorded as equal to any other. This means, that we are defining a WorkUnit as a measurement of time participating. In our context, that means that we decide how much the value of you storing x bytes is, depending on for how long you have been around doing that - relative to everyone else.

Receiving some data when new, is not as appreciated as after having been there relatively long. Because, after all, maybe you're just disappearing shortly, and introducing a lot of work to the others to replicate the data you were supposed to hold. Still though, it is rewarded higher to receive more data, than less data, regardless of how new/old you are, which reflects in the total rewards being higher for more data. In other words: even though the newer participant's share is still smaller relatively to the others, it is higher absolutely, compared to if they'd all be receiving less data.

This is the rationale and reasoning behind accumulation.rs defining a WorkUnit as having received data (no matter how much). The WorkUnit is closely related to NodeAge, and is a way to capture the higher level design decision of rewards being proportional to NodeAge, while decoupling it from the actual implementation of NodeAge (which is low granular).

Another implementation of RewardAlgo, might want to use something else than NodeAge, and thus use another way to account for Work; another definition of a WorkUnit.

fn set(&mut self, base_cost: Money)[src]

Use this to update the base cost, as per any desired formula and frequency.

fn work_cost(&self, num_bytes: u64) -> Money[src]

Here, reward units are the number of bytes to store.

fn total_reward(&self, factor: f64, work_cost: Money) -> Money[src]

Use the factor to scale the reward per any desired function of parameters relevant to the implementing layer. In SAFE Network context, the factor could be the output of a function of node count, section count, percent filled etc. etc.

fn distribute(
    &self,
    total_reward: Money,
    accounts_work: HashMap<AccountId, Work>
) -> HashMap<AccountId, Money>
[src]

Distribute the reward according to the accumulated work associated with the ids. Also returns those who got 0 reward (when their work or total_reward wasn't high enough).

Loading content...