Skip to content
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

Merged
merged 15 commits into from
Apr 2, 2024
Merged

Emission schedule #290

merged 15 commits into from
Apr 2, 2024

Conversation

unconst
Copy link
Contributor

@unconst unconst commented Mar 28, 2024

No description provided.

@JohnReedV JohnReedV requested a review from sam0x17 March 29, 2024 02:21
Copy link
Contributor

@sam0x17 sam0x17 left a 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 Show resolved Hide resolved
Comment on lines 764 to 790
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;
}
});
Copy link
Contributor

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

pallets/subtensor/src/utils.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@sam0x17 sam0x17 left a 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

@sam0x17 sam0x17 merged commit 101ce88 into development Apr 2, 2024
1 check passed
@distributedstatemachine distributedstatemachine deleted the emission_schedule branch April 11, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants