-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emission schedule #290
Emission schedule #290
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, few nits
pallets/subtensor/tests/root.rs
Outdated
let total_supply: u64 = pallet_subtensor::TotalSupply::<Test>::get(); | ||
let original_emission: u64 = pallet_subtensor::DefaultBlockEmission::<Test>::get(); | ||
let halving_issuance: u64 = total_supply / 2; | ||
let mut step: usize = original_emission as usize; | ||
|
||
for issuance in (0..=total_supply).step_by(step) { | ||
SubtensorModule::set_total_issuance(issuance); | ||
|
||
let issuance_f64 = issuance as f64; | ||
let h = f64::log2(1.0 / (1.0 - issuance_f64 / (2.0 * halving_issuance as f64))); | ||
let h = h.floor(); | ||
let emission_percentage = f64::powf(2.0, -h); | ||
|
||
let expected_emission: u64 = if issuance < total_supply { | ||
(original_emission as f64 * emission_percentage) as u64 | ||
} else { | ||
0 | ||
}; | ||
assert_eq!( | ||
SubtensorModule::get_block_emission(), | ||
expected_emission, | ||
"Issuance: {}", | ||
issuance_f64 | ||
); | ||
step = expected_emission as usize; | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess as long as this consistently passes this is fine but I suppose if there is ever a hardware difference w.r.t floating points vs the safe implementation this test might fail on some random hardware. Probably fine tho
my preference tho would be that this uses safe math as well if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, pending answer from @unconst about that defensive guard for the scenario where supply exceeds 21 million
No description provided.