Skip to content

Consensus modes devnet#2202

Open
konrad0960 wants to merge 7 commits intoopentensor:devnet-readyfrom
konrad0960:consensus-modes-devnet
Open

Consensus modes devnet#2202
konrad0960 wants to merge 7 commits intoopentensor:devnet-readyfrom
konrad0960:consensus-modes-devnet

Conversation

@konrad0960
Copy link
Contributor

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Additional Notes

This is my first Subtensor contribution so please review it carefully and be lenient.

@sam0x17 sam0x17 added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Dec 1, 2025
@sam0x17
Copy link
Contributor

sam0x17 commented Dec 1, 2025

needs to merge in latest devnet-ready

Comment on lines 1433 to 1440
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()
Copy link
Collaborator

@l0r1s l0r1s Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated below, should be extracted to a function

Comment on lines 214 to 222
let diff = if *res > expected {
*res - expected
} else {
expected - *res
};
assert!(
diff < I32F32::from_num(0.001),
"Values should be approximately equal"
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_abs_diff_eq! can be useful here

Comment on lines 260 to 268
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"
);
Copy link
Collaborator

@l0r1s l0r1s Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_abs_diff_eq! can be useful here

Copy link
Collaborator

@l0r1s l0r1s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it is missing a dispatch call

konrad0960 and others added 7 commits February 7, 2026 17:39
- 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
@panniki panniki force-pushed the consensus-modes-devnet branch from 958be6e to 92b39a0 Compare February 8, 2026 12:52
Weight::from_parts(10_000, 0)
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1)),
DispatchClass::Operational,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be normal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants