feat: add consensus mode selection for liquid alpha calculations#2568
Open
ppolewicz wants to merge 4 commits intodevnet-readyfrom
Open
feat: add consensus mode selection for liquid alpha calculations#2568ppolewicz wants to merge 4 commits intodevnet-readyfrom
ppolewicz wants to merge 4 commits intodevnet-readyfrom
Conversation
Introduces ConsensusMode enum (Current/Previous/Auto) with per-subnet storage LiquidAlphaConsensusMode<T> to control which consensus values are used when computing liquid alpha bonding matrices. - Auto (default): uses Previous when bond_penalty==1, else Current - Current: always uses fresh in-memory consensus values - Previous: always uses previous epoch consensus from storage (normalized) Adds do_set_liquid_alpha_consensus_mode callable by subnet owner or root.
a0522b9 to
610fe00
Compare
The add_balance_to_coldkey_account API now takes TaoBalance instead of a plain u64 integer. Use .into() for type coercion.
…dAlphaConsensusModeSet event - Add DecodeWithMemTracking, Copy, MaxEncodedLen derives to ConsensusMode enum - Change bonds_penalty comparison to use integer domain (u16::MAX) - Remove .clone() on ConsensusMode (now Copy) - Make compute_consensus_for_liquid_alpha pub(crate) - Add deposit_event for LiquidAlphaConsensusModeSet - Add LiquidAlphaConsensusModeSet event variant in macros/events.rs - Add sudo_set_liquid_alpha_consensus_mode dispatchable in admin-utils - Add LiquidAlphaConsensusMode = 28 to Hyperparameter enum in rate_limiting.rs - Bump STORAGE_VERSION to 8 - Add integration test test_compute_bonds_uses_previous_consensus_mode - Fix comment in tests/consensus_mode.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces a
ConsensusModeenum and per-subnet storage to allow subnet owners to control which consensus values are used when computing liquid alpha bonding matrices.Motivation
The liquid alpha mechanism uses consensus values to compute per-validator-miner bonding alphas. Previously, only the current in-memory (just-computed) consensus was used. This change adds flexibility to use the previous epoch's consensus from storage, which provides more stable bonding behavior particularly when
bond_penalty == 1.Changes
ConsensusModeenum (Current,Previous,Auto) withAutoas the default:Current: use the freshly-computed in-memory consensus (existing behavior)Previous: use the previous epoch's consensus stored inConsensus<T>storage, normalized from u16 to I32F32Auto: usePreviouswhenbonds_penalty == 1, otherwiseCurrentLiquidAlphaConsensusMode<T>(per-netuid, default:Auto)do_set_liquid_alpha_consensus_mode(callable by subnet owner or root)get/set_liquid_alpha_consensus_modeandcompute_consensus_for_liquid_alphacompute_consensus_for_liquid_alphato select the appropriate consensus vector before passing it tocompute_liquid_alpha_values[_sparse]consensus_modewith full coverage of all three modes, permission checks, and edge casesTest plan
test_set_consensus_mode_liquid_alpha_disabled— can set mode regardless of liquid alpha enable statetest_set_consensus_mode_permissions— non-owner is rejected, owner succeedstest_set_and_get_consensus_modes— round-trip for all three variantstest_compute_consensus_current_mode— returns current in-memory consensustest_compute_consensus_previous_mode— returns normalized previous-epoch consensus from storagetest_compute_consensus_auto_mode— returns current when bond_penalty ≠ 1, previous when bond_penalty == 1test_liquid_alpha_equal_values_against_itselfupdated to setConsensusMode::Currentto preserve original behavior