Skip to content

Commit

Permalink
rusk: Update coinbase_value
Browse files Browse the repository at this point in the history
  • Loading branch information
goshawk-3 committed Jun 21, 2024
1 parent 192be7e commit 39a249b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
12 changes: 9 additions & 3 deletions rusk/src/lib/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ impl RuskNode {
///
/// 90% of the total value goes to the generator (rounded up).
/// 10% of the total value goes to the Dusk address (rounded down).
const fn coinbase_value(block_height: u64, dusk_spent: u64) -> (Dusk, Dusk) {
const fn coinbase_value(
block_height: u64,
dusk_spent: u64,
) -> (Dusk, Dusk, Dusk) {
let value = emission_amount(block_height) + dusk_spent;

let dusk_value = value / 10;
let generator_value = value - dusk_value;
let reward = value - dusk_value;

(dusk_value, generator_value)
let voters_value = reward / 10;
let generator_value = reward - voters_value;

(dusk_value, generator_value, voters_value)
}

/// This implements the emission schedule described in the economic paper.
Expand Down
23 changes: 17 additions & 6 deletions rusk/src/lib/chain/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use sha3::{Digest, Sha3_256};
use tokio::task;
use tracing::{debug, info, warn};

use dusk_bytes::DeserializableSlice;
use dusk_bytes::{DeserializableSlice, Serializable};
use dusk_consensus::operations::{
CallParams, VerificationOutput, VoterWithCredits,
};
Expand Down Expand Up @@ -551,13 +551,12 @@ fn reward_slash_and_update_root(
dusk_spent: Dusk,
generator: &StakePublicKey,
slashing: &[StakePublicKey],
voters: &[(StakePublicKey, u8)],
voters: &[(StakePublicKey, usize)],
) -> Result<Vec<Event>> {
let (dusk_value, reward_value) = coinbase_value(block_height, dusk_spent);

let voters_reward = reward_value.checked_div(10).expect("valid reward");
let generator_reward = reward_value.checked_sub(voters_reward);
let (dusk_value, generator_reward, voters_reward) =
coinbase_value(block_height, dusk_spent);


let credits = voters.iter().map(|(_, credits)| credits).sum();
let credit_reward = match credits {
0 => 0,
Expand All @@ -581,6 +580,12 @@ fn reward_slash_and_update_root(
)?;
events.extend(r.events);

info!(
event = "generator rewarded",
voter = ?bs58::encode(&generator.to_bytes()).into_string(),
reward = generator_reward
);

if credit_reward > 0 {
for (to_voter, credits) in voters {
let voter_reward = *credits as u64 * credit_reward;
Expand All @@ -591,6 +596,12 @@ fn reward_slash_and_update_root(
u64::MAX,
)?;
events.extend(r.events);

info!(
event = "voter rewarded",
voter = ?bs58::encode(&to_voter.to_bytes()).into_string(),
reward = voter_reward
)
}
}

Expand Down

0 comments on commit 39a249b

Please sign in to comment.