Skip to content

Commit

Permalink
PR review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CjS77 committed Feb 9, 2024
1 parent 9f40d8d commit 1f3b1b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 56 deletions.
58 changes: 7 additions & 51 deletions base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,15 +934,14 @@ mod test {
#[cfg(not(tari_feature_mainnet_emission))]
use std::convert::TryFrom;

#[cfg(not(tari_feature_mainnet_emission))]
use crate::{
consensus::{
emission::{Emission, EmissionSchedule},
ConsensusConstants,
},
transactions::{
tari_amount::{uT, MicroMinotari},
transaction_components::{OutputType, RangeProofType},
},
consensus::emission::{Emission, EmissionSchedule},
transactions::tari_amount::{uT, MicroMinotari},
};
use crate::{
consensus::ConsensusConstants,
transactions::transaction_components::{OutputType, RangeProofType},
};

#[test]
Expand All @@ -955,49 +954,6 @@ mod test {
ConsensusConstants::mainnet();
}

// Comment out the feature flag to run this test
#[test]
#[cfg(feature = "schedule_get_constants")]
fn esmeralda_schedule_get_constants() {
let mut esmeralda = ConsensusConstants::esmeralda();
loop {
let schedule = EmissionSchedule::new(
esmeralda[0].emission_initial,
esmeralda[0].emission_decay,
esmeralda[0].emission_tail,
);
// No genesis block coinbase
assert_eq!(schedule.block_reward(0), MicroMinotari(0));
// Coinbases starts at block 1
let coinbase_offset = 1;
let first_reward = schedule.block_reward(coinbase_offset);
assert_eq!(first_reward, esmeralda[0].emission_initial * uT);
assert_eq!(schedule.supply_at_block(coinbase_offset), first_reward);
// Tail emission starts after block 3,255,552 + coinbase_offset
let mut rewards = schedule
.iter()
.skip(3_255_552 + usize::try_from(coinbase_offset).unwrap());
let supply = loop {
let (block_num, reward, supply) = rewards.next().unwrap();
let total_supply = supply + esmeralda[0].faucet_value;
println!(
"Initial: {}, Block: {}, Reward: {}, Supply: {}, Total supply: {}",
esmeralda[0].emission_initial, block_num, reward, supply, total_supply
);
if reward == esmeralda[0].emission_tail {
break supply;
}
};
let total_supply_up_to_tail_emission = supply + esmeralda[0].faucet_value;
if total_supply_up_to_tail_emission >= 21_000_000_800_000_000 * uT {
println!("Total supply up to tail emission: {}", total_supply_up_to_tail_emission);
break;
}
esmeralda[0].emission_initial = esmeralda[0].emission_initial + MicroMinotari(1);
}
panic!("\n\nThis test may not pass in CI\n\n");
}

#[test]
#[cfg(not(tari_feature_mainnet_emission))]
fn esmeralda_schedule() {
Expand Down
9 changes: 4 additions & 5 deletions base_layer/core/src/consensus/emission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ impl<'a> EmissionRate<'a> {

#[cfg(tari_feature_mainnet_emission)]
fn new_tail_emission(&self) -> MicroMinotari {
let epoch_issuance = self.supply / 100 * self.schedule.inflation_bips;
let epoch_issuance = (self.supply.as_u64() / 100).saturating_mul(self.schedule.inflation_bips);
let reward = epoch_issuance / self.schedule.epoch_length; // in uT
(reward / 1_000_000) * 1_000_000 // truncate to nearest whole XTR
MicroMinotari::from((reward / 1_000_000) * 1_000_000) // truncate to nearest whole XTR
}

#[cfg(tari_feature_mainnet_emission)]
Expand Down Expand Up @@ -350,10 +350,8 @@ impl Emission for EmissionSchedule {

#[cfg(test)]
mod test {
#[cfg(not(tari_feature_mainnet_emission))]
use crate::consensus::emission::Emission;
use crate::{
consensus::emission::EmissionSchedule,
consensus::emission::{Emission, EmissionSchedule},
transactions::tari_amount::{MicroMinotari, T},
};

Expand All @@ -376,6 +374,7 @@ mod test {

#[test]
#[cfg(tari_feature_mainnet_emission)]
#[allow(clippy::cast_possible_truncation)]
fn mainnet_emission() {
let epoch_length = 30 * 24 * 366;
let halflife = 3 * 30 * 24 * 365;
Expand Down
3 changes: 3 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ toml = "0.5.8"
[build-dependencies]
tari_features = { path = "./tari_features"}
env_logger = "0.11.1"

[package.metadata.cargo-machete]
ignored = ["env_logger"]

0 comments on commit 1f3b1b6

Please sign in to comment.