From 39a249b19e0ab4166ae6ffc1dc2f17b78cb0b4d9 Mon Sep 17 00:00:00 2001 From: goshawk-3 Date: Fri, 21 Jun 2024 16:09:05 +0300 Subject: [PATCH] rusk: Update coinbase_value --- rusk/src/lib/chain.rs | 12 +++++++++--- rusk/src/lib/chain/rusk.rs | 23 +++++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/rusk/src/lib/chain.rs b/rusk/src/lib/chain.rs index 19b0680212..811f5c8853 100644 --- a/rusk/src/lib/chain.rs +++ b/rusk/src/lib/chain.rs @@ -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. diff --git a/rusk/src/lib/chain/rusk.rs b/rusk/src/lib/chain/rusk.rs index 2abf2ae50f..3bccdadd3f 100644 --- a/rusk/src/lib/chain/rusk.rs +++ b/rusk/src/lib/chain/rusk.rs @@ -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, }; @@ -551,13 +551,12 @@ fn reward_slash_and_update_root( dusk_spent: Dusk, generator: &StakePublicKey, slashing: &[StakePublicKey], - voters: &[(StakePublicKey, u8)], + voters: &[(StakePublicKey, usize)], ) -> Result> { - 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, @@ -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; @@ -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 + ) } }