Consensus modes devnet#2202
Conversation
|
needs to merge in latest devnet-ready |
| let previous_consensus_u16 = Consensus::<T>::get(netuid); | ||
| previous_consensus_u16 | ||
| .iter() | ||
| .map(|&c| { | ||
| I32F32::saturating_from_num(c) | ||
| .safe_div(I32F32::saturating_from_num(u16::MAX)) | ||
| }) | ||
| .collect() |
There was a problem hiding this comment.
Duplicated below, should be extracted to a function
| let diff = if *res > expected { | ||
| *res - expected | ||
| } else { | ||
| expected - *res | ||
| }; | ||
| assert!( | ||
| diff < I32F32::from_num(0.001), | ||
| "Values should be approximately equal" | ||
| ); |
There was a problem hiding this comment.
assert_abs_diff_eq! can be useful here
| let diff = if *res > expected { | ||
| *res - expected | ||
| } else { | ||
| expected - *res | ||
| }; | ||
| assert!( | ||
| diff < I32F32::from_num(0.001), | ||
| "Should use previous consensus when bond_penalty == 1" | ||
| ); |
There was a problem hiding this comment.
assert_abs_diff_eq! can be useful here
958be6e to
92b39a0
Compare
|
|
||
| /// Sets up a network with full owner permissions (root registration + network creation) | ||
| /// Returns (netuid, hotkey, coldkey, signer) | ||
| fn setup_network_with_owner() -> (NetUid, U256, U256, RuntimeOrigin) { |
There was a problem hiding this comment.
this helper is generic enough to put it in the mock module. that would prevent local duplications in the future.
There was a problem hiding this comment.
and it makes sense to consider moving there the following two helpers as well
pallets/subtensor/src/utils/misc.rs
Outdated
| (converted_low, converted_high) | ||
| } | ||
|
|
||
| pub fn get_liquid_alpha_consensus_mode(netuid: NetUid) -> ConsensusMode { |
There was a problem hiding this comment.
it's better to omit these kind of getters/setters. the storage api works pretty well and is self-descriptive.
…hip workflow Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Extract duplicated consensus u16->I32F32 conversion to helper function - Replace manual diff assertions with assert_abs_diff_eq! macro - Add dispatchable extrinsic for set_liquid_alpha_consensus_mode
db20d10 to
5701e8c
Compare
|
Rebased this PR onto Addressed the remaining review feedback from
Verification run locally:
|
|
This is continued in #2568 |
Description
Introducing consensus modes for liquid alpha calculations (using previous epoch or current epoch consensus)
The AUTO mode on default sets to CURRENT if bond_penalty != 1 and PREVIOUS if bond_penalty == 1
Type of Change
Checklist
./scripts/fix_rust.shto ensure my code is formatted and linted correctlyAdditional Notes
This is my first Subtensor contribution so please review it carefully and be lenient.