Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
df21554
Ensure we only reset BondsMovingAverage to 975000 only if it exceeds
keithtensor May 6, 2025
8bec162
Fixes
keithtensor May 6, 2025
4610c8b
cargo fmt
keithtensor May 6, 2025
8493bbf
Introduce SameSubnetId error for move and swap stake extrinsics.
shamil-gadelshin May 2, 2025
f974a94
Rename error SameSubnetId -> SameNetuid
shamil-gadelshin May 6, 2025
5862a43
keep track of contributors count and allow a maximum of contributors,…
l0r1s May 5, 2025
774a5fc
fix tests
l0r1s May 5, 2025
d347707
fix migration name
l0r1s May 5, 2025
017f3ff
added migration test
l0r1s May 5, 2025
2918789
cargo clippy
l0r1s May 5, 2025
ae65d49
cargo fmt
l0r1s May 5, 2025
d3c05ee
move contributors count to Crowdloan struct and update migration
l0r1s May 6, 2025
677749a
fix benchmark
l0r1s May 6, 2025
8d23896
fix arithmetic
l0r1s May 6, 2025
f736382
added freeze_struct to OldCrowdloanInfo
l0r1s May 7, 2025
b43e332
have Dockerfile use a local user instead of root
sam0x17 May 7, 2025
7ca5bcb
clean up
sam0x17 May 7, 2025
04a86f8
add yuma4 scenario test
andreea-popescu-reef Feb 4, 2025
4a16441
fix alpha values
andreea-popescu-reef Feb 5, 2025
5cd7527
tests cleanup
andreea-popescu-reef Feb 11, 2025
1b541e6
add BondsResetOn param
andreea-popescu-reef Feb 17, 2025
5d14a1b
add OnMetadataCommitment hook
andreea-popescu-reef Feb 17, 2025
c054429
add bonds reset
andreea-popescu-reef Feb 20, 2025
249901a
add ResetBondsFlag check for set_commitment
andreea-popescu-reef Feb 26, 2025
6222e21
fix bonds reset
andreea-popescu-reef Mar 21, 2025
59bcbf1
fix rebase
andreea-popescu-reef Mar 25, 2025
6ae811b
increased commitment fields to allow for reset_bonds flag
andreea-popescu-reef Apr 4, 2025
f122920
add LastBondsReset tracking
andreea-popescu-reef May 6, 2025
b2e7ba5
Merge remote-tracking branch 'origin/devnet-ready' into feat/reset-bo…
sam0x17 May 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hyperparameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ MaxRegistrationsPerBlock: u16 = 1;
PruningScore : u16 = u16::MAX;
BondsMovingAverage: u64 = 900_000;
BondsPenalty: u16 = 0;
BondsResetOn: bool = false;
WeightsVersionKey: u64 = 1020;
MinDifficulty: u64 = 10_000_000;
MaxDifficulty: u64 = u64::MAX / 4;
Expand Down Expand Up @@ -74,6 +75,7 @@ MaxRegistrationsPerBlock: u16 = 1;
PruningScore : u16 = u16::MAX;
BondsMovingAverage: u64 = 900_000;
BondsPenalty: u16 = 0;
BondsResetOn: bool = false;
WeightsVersionKey: u64 = 400;
MinDifficulty: u64 = 10_000_000;
MaxDifficulty: u64 = u64::MAX / 4;
Expand Down
2 changes: 2 additions & 0 deletions pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ parameter_types! {
pub const InitialMaxAllowedUids: u16 = 2;
pub const InitialBondsMovingAverage: u64 = 900_000;
pub const InitialBondsPenalty: u16 = u16::MAX;
pub const InitialBondsResetOn: bool = false;
pub const InitialStakePruningMin: u16 = 0;
pub const InitialFoundationDistribution: u64 = 0;
pub const InitialDefaultDelegateTake: u16 = 11_796; // 18% honest number.
Expand Down Expand Up @@ -171,6 +172,7 @@ impl pallet_subtensor::Config for Test {
type InitialPruningScore = InitialPruningScore;
type InitialBondsMovingAverage = InitialBondsMovingAverage;
type InitialBondsPenalty = InitialBondsPenalty;
type InitialBondsResetOn = InitialBondsResetOn;
type InitialMaxAllowedValidators = InitialMaxAllowedValidators;
type InitialDefaultDelegateTake = InitialDefaultDelegateTake;
type InitialMinDelegateTake = InitialMinDelegateTake;
Expand Down
38 changes: 36 additions & 2 deletions pallets/commitments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub mod pallet {
/// Interface to access-limit metadata commitments
type CanCommit: CanCommit<Self::AccountId>;

/// Interface to trigger other pallets when metadata is committed
type OnMetadataCommitment: OnMetadataCommitment<Self::AccountId>;

/// The maximum number of additional fields that can be added to a commitment
#[pallet::constant]
type MaxFields: Get<u32> + TypeInfo + 'static;
Expand All @@ -72,7 +75,7 @@ pub mod pallet {
type TempoInterface: GetTempoInterface;
}

/// Used to retreive the given subnet's tempo
/// Used to retreive the given subnet's tempo
pub trait GetTempoInterface {
/// Used to retreive the epoch index for the given subnet.
fn get_epoch_index(netuid: u16, cur_block: u64) -> u64;
Expand Down Expand Up @@ -148,6 +151,19 @@ pub mod pallet {
BlockNumberFor<T>,
OptionQuery,
>;

#[pallet::storage]
#[pallet::getter(fn last_bonds_reset)]
pub(super) type LastBondsReset<T: Config> = StorageDoubleMap<
_,
Identity,
u16,
Twox64Concat,
T::AccountId,
BlockNumberFor<T>,
OptionQuery,
>;

#[pallet::storage]
#[pallet::getter(fn revealed_commitments)]
pub(super) type RevealedCommitments<T: Config> = StorageDoubleMap<
Expand Down Expand Up @@ -193,7 +209,7 @@ pub mod pallet {
netuid: u16,
info: Box<CommitmentInfo<T::MaxFields>>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let who = ensure_signed(origin.clone())?;
ensure!(
T::CanCommit::can_commit(netuid, &who),
Error::<T>::AccountNotAllowedCommit
Expand Down Expand Up @@ -224,6 +240,16 @@ pub mod pallet {
usage.used_space = 0;
}

// check if ResetBondsFlag is set in the fields
for field in info.fields.iter() {
if let Data::ResetBondsFlag = field {
// track when bonds reset was last triggered
<LastBondsReset<T>>::insert(netuid, &who, cur_block);
T::OnMetadataCommitment::on_metadata_commitment(netuid, &who);
break;
}
}

let max_allowed = MaxSpace::<T>::get() as u64;
ensure!(
usage.used_space.saturating_add(required_space) <= max_allowed,
Expand Down Expand Up @@ -349,6 +375,14 @@ impl<A> CanCommit<A> for () {
}
}

pub trait OnMetadataCommitment<AccountId> {
fn on_metadata_commitment(netuid: u16, account: &AccountId);
}

impl<A> OnMetadataCommitment<A> for () {
fn on_metadata_commitment(_: u16, _: &A) {}
}

/************************************************************
CallType definition
************************************************************/
Expand Down
1 change: 1 addition & 0 deletions pallets/commitments/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl pallet_commitments::Config for Test {
type FieldDeposit = ConstU64<0>;
type InitialDeposit = ConstU64<0>;
type TempoInterface = MockTempoInterface;
type OnMetadataCommitment = ();
}

pub struct MockTempoInterface;
Expand Down
3 changes: 3 additions & 0 deletions pallets/commitments/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn manual_data_type_info() {
Data::ShaThree256(_) => "ShaThree256".to_string(),
Data::Raw(bytes) => format!("Raw{}", bytes.len()),
Data::TimelockEncrypted { .. } => "TimelockEncrypted".to_string(),
Data::ResetBondsFlag => "ResetBondsFlag".to_string(),
};
if let scale_info::TypeDef::Variant(variant) = &type_info.type_def {
let variant = variant
Expand Down Expand Up @@ -63,6 +64,7 @@ fn manual_data_type_info() {
let reveal_round_len = reveal_round.encode().len() as u32; // Typically 8 bytes
encrypted_len + reveal_round_len
}
Data::ResetBondsFlag => 0,
};
assert_eq!(
encoded.len() as u32 - 1, // Subtract variant byte
Expand All @@ -89,6 +91,7 @@ fn manual_data_type_info() {
Data::Sha256(Default::default()),
Data::Keccak256(Default::default()),
Data::ShaThree256(Default::default()),
Data::ResetBondsFlag,
];

// Add Raw instances for all possible sizes
Expand Down
12 changes: 10 additions & 2 deletions pallets/commitments/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub enum Data {
encrypted: BoundedVec<u8, ConstU32<MAX_TIMELOCK_COMMITMENT_SIZE_BYTES>>,
reveal_round: u64,
},
/// Flag to trigger bonds reset for subnet
ResetBondsFlag,
}

impl Data {
Expand All @@ -79,6 +81,7 @@ impl Data {
| Data::Keccak256(arr)
| Data::ShaThree256(arr) => arr.len() as u64,
Data::TimelockEncrypted { encrypted, .. } => encrypted.len() as u64,
Data::ResetBondsFlag => 0,
}
}
}
Expand Down Expand Up @@ -108,6 +111,7 @@ impl Decode for Data {
reveal_round,
}
}
135 => Data::ResetBondsFlag,
_ => return Err(codec::Error::from("invalid leading byte")),
})
}
Expand Down Expand Up @@ -136,6 +140,7 @@ impl Encode for Data {
r.extend_from_slice(&reveal_round.encode());
r
}
Data::ResetBondsFlag => vec![135],
}
}
}
Expand All @@ -158,7 +163,9 @@ impl TypeInfo for Data {
type Identity = Self;

fn type_info() -> Type {
let variants = Variants::new().variant("None", |v| v.index(0));
let variants = Variants::new()
.variant("None", |v| v.index(0))
.variant("ResetBondsFlag", |v| v.index(135));

// create a variant for all sizes of Raw data from 0-32
let variants = data_raw_variants!(
Expand Down Expand Up @@ -321,7 +328,8 @@ impl TypeInfo for Data {
})
.field(|f| f.name("reveal_round").ty::<u64>()),
)
});
})
.variant("ResetBondsFlag", |v| v.index(135));

Type::builder()
.path(Path::new("Data", module_path!()))
Expand Down
6 changes: 3 additions & 3 deletions pallets/commitments/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn set_rate_limit() -> Weight {
Weight::from_parts(10_000_000, 2000)
.saturating_add(RocksDbWeight::get().reads(1_u64))
}
}
}

// For backwards compatibility and tests.
Expand All @@ -76,5 +76,5 @@ impl WeightInfo for () {
fn set_rate_limit() -> Weight {
Weight::from_parts(10_000_000, 2000)
.saturating_add(RocksDbWeight::get().reads(1_u64))
}
}
}
}
35 changes: 35 additions & 0 deletions pallets/subtensor/src/epoch/run_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,4 +1319,39 @@ impl<T: Config> Pallet<T> {
);
Ok(())
}

pub fn do_reset_bonds(netuid: u16, account_id: &T::AccountId) -> Result<(), DispatchError> {
// check bonds reset enabled for this subnet
let bonds_reset_enabled: bool = Self::get_bonds_reset(netuid);
if !bonds_reset_enabled {
return Ok(());
}

if let Ok(uid) = Self::get_uid_for_net_and_hotkey(netuid, account_id) {
for (i, bonds_vec) in
<Bonds<T> as IterableStorageDoubleMap<u16, u16, Vec<(u16, u16)>>>::iter_prefix(
netuid,
)
{
Bonds::<T>::insert(
netuid,
i,
bonds_vec
.clone()
.iter()
.filter(|(j, _)| *j != uid)
.collect::<Vec<&(u16, u16)>>(),
);
}
log::debug!("Reset bonds for {:?}, netuid {:?}", account_id, netuid);
} else {
log::warn!(
"Uid not found for {:?}, netuid {:?} - skipping bonds reset",
account_id,
netuid
);
}

Ok(())
}
}
10 changes: 9 additions & 1 deletion pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,13 @@ pub mod pallet {
pub fn DefaultBondsPenalty<T: Config>() -> u16 {
T::InitialBondsPenalty::get()
}
/// Default value for bonds reset - will not reset bonds
#[pallet::type_value]
pub fn DefaultBondsResetOn<T: Config>() -> bool {
T::InitialBondsResetOn::get()
}
/// Default validator prune length.
#[pallet::type_value]
pub fn DefaultValidatorPruneLen<T: Config>() -> u64 {
T::InitialValidatorPruneLen::get()
}
Expand Down Expand Up @@ -814,7 +819,6 @@ pub mod pallet {
pub fn DefaultAlphaValues<T: Config>() -> (u16, u16) {
(45875, 58982)
}

#[pallet::type_value]
/// Default value for coldkey swap schedule duration
pub fn DefaultColdkeySwapScheduleDuration<T: Config>() -> BlockNumberFor<T> {
Expand Down Expand Up @@ -1384,6 +1388,10 @@ pub mod pallet {
/// --- MAP ( netuid ) --> bonds_penalty
pub type BondsPenalty<T> =
StorageMap<_, Identity, u16, u16, ValueQuery, DefaultBondsPenalty<T>>;
#[pallet::storage]
/// --- MAP ( netuid ) --> bonds_reset
pub type BondsResetOn<T> =
StorageMap<_, Identity, u16, bool, ValueQuery, DefaultBondsResetOn<T>>;
/// --- MAP ( netuid ) --> weights_set_rate_limit
#[pallet::storage]
pub type WeightsSetRateLimit<T> =
Expand Down
3 changes: 3 additions & 0 deletions pallets/subtensor/src/macros/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ mod config {
/// Initial bonds penalty.
#[pallet::constant]
type InitialBondsPenalty: Get<u16>;
/// Initial bonds reset.
#[pallet::constant]
type InitialBondsResetOn: Get<bool>;
/// Initial target registrations per interval.
#[pallet::constant]
type InitialTargetRegistrationsPerInterval: Get<u16>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/macros/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ mod errors {
InvalidRecoveredPublicKey,
/// SubToken disabled now
SubtokenDisabled,
/// Estimating the maximum stake for limited staking operations returned zero.
/// Zero max stake amount
ZeroMaxStakeAmount,
/// Invalid netuid duplication
SameNetuid,
Expand Down
2 changes: 2 additions & 0 deletions pallets/subtensor/src/macros/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ mod events {
BondsMovingAverageSet(u16, u64),
/// bonds penalty is set for a subnet.
BondsPenaltySet(u16, u16),
/// bonds reset is set for a subnet.
BondsResetOnSet(u16, bool),
/// setting the max number of allowed validators on a subnet.
MaxAllowedValidatorsSet(u16, u16),
/// the axon server information is added to the network.
Expand Down
Loading
Loading