Skip to content

Commit

Permalink
rusk: Split Block Generator reward into fixed reward and extra reward
Browse files Browse the repository at this point in the history
  • Loading branch information
goshawk-3 committed Jul 4, 2024
1 parent 70891b0 commit 233c18b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
24 changes: 18 additions & 6 deletions rusk/src/lib/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,31 @@ impl RuskNode {
/// Calculates the value that the coinbase notes should contain.
///
/// 10% of the reward value goes to the Dusk address (rounded down).
/// 80% of the reward value goes to the Block generator (rounded up).
/// 70% of the reward value is considered fixed reward for Block Generator.
/// 10% of the reward value is considered extra reward for Block Generator.
/// 10% of the reward value goes to the all validators/voters of previous block
/// (rounded down).
const fn coinbase_value(
block_height: u64,
dusk_spent: u64,
) -> (Dusk, Dusk, Dusk) {
) -> (Dusk, Dusk, Dusk, Dusk) {
let value = emission_amount(block_height) + dusk_spent;
let dusk_value = value / 10;
let voters_value = dusk_value;
let generator_value = value - dusk_value - voters_value;

(dusk_value, generator_value, voters_value)
let one_tenth_reward = value / 10;

let dusk_value = one_tenth_reward;
let voters_value = one_tenth_reward;
let generator_extra_value = one_tenth_reward;

let generator_fixed_value =
value - dusk_value - voters_value - generator_extra_value;

(
dusk_value,
generator_fixed_value,
generator_extra_value,
voters_value,
)
}

/// This implements the emission schedule described in the economic paper.
Expand Down
32 changes: 23 additions & 9 deletions rusk/src/lib/chain/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,21 @@ fn reward_slash_and_update_root(
slashing: &[StakePublicKey],
voters: Option<&[(StakePublicKey, usize)]>,
) -> Result<Vec<Event>> {
let (dusk_value, generator_reward, voters_reward) =
coinbase_value(block_height, dusk_spent);

if let Some(voters) = voters {
let credits: usize = voters.iter().map(|(_, credits)| credits).sum();
if credits == 0 && block_height > 1 {
return Err(InvalidCreditsCount(block_height, 0));
}
let (
dusk_value,
generator_fixed_reward,
generator_extra_reward,
voters_reward,
) = coinbase_value(block_height, dusk_spent);

let credits = voters
.unwrap_or_default()
.iter()
.map(|(_, credits)| *credits as u64)
.sum::<u64>();

if voters.is_some() && credits == 0 && block_height > 1 {
return Err(InvalidCreditsCount(block_height, 0));
}

let credit_reward = voters_reward / 64 * 2;
Expand All @@ -569,6 +576,11 @@ fn reward_slash_and_update_root(
reward = dusk_value
);

let reward_per_quota = generator_extra_reward / (21 * 2);
let generator_curr_extra_reward =
credits.saturating_sub(43 * 2) * reward_per_quota;

let generator_reward = generator_fixed_reward + generator_curr_extra_reward;
let r = session.call::<_, ()>(
STAKE_CONTRACT,
"reward",
Expand All @@ -580,7 +592,9 @@ fn reward_slash_and_update_root(
debug!(
event = "generator rewarded",
voter = to_bs58(generator),
reward = generator_reward
total_reward = generator_reward,
extra_reward = generator_curr_extra_reward,
credits,
);

for (to_voter, credits) in voters.unwrap_or_default() {
Expand Down

0 comments on commit 233c18b

Please sign in to comment.