Skip to content

Commit edb6f19

Browse files
Merge branch 'devnet-ready' into refactor-extension2
2 parents 5be820e + 1ead833 commit edb6f19

File tree

27 files changed

+744
-50
lines changed

27 files changed

+744
-50
lines changed

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile-localnet

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ COPY --from=builder /build/snapshot.json /snapshot.json
5252
COPY --from=builder /build/scripts/localnet.sh scripts/localnet.sh
5353
RUN chmod +x /scripts/localnet.sh
5454

55+
# Copy WebAssembly artifacts
56+
COPY --from=builder /build/target/fast-runtime/release/wbuild/node-subtensor-runtime/node_subtensor_runtime.compact.compressed.wasm target/fast-runtime/release/node_subtensor_runtime.compact.compressed.wasm
57+
COPY --from=builder /build/target/non-fast-runtime/release/wbuild/node-subtensor-runtime/node_subtensor_runtime.compact.compressed.wasm target/non-fast-runtime/release/node_subtensor_runtime.compact.compressed.wasm
58+
5559
## Ubdate certificates
5660
RUN apt-get update && apt-get install -y ca-certificates
5761

evm-tests/src/substrate.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,30 +168,31 @@ export async function waitForTransactionCompletion(api: TypedApi<typeof devnet>,
168168
// })
169169
}
170170

171+
171172
export async function getTransactionWatchPromise(tx: Transaction<{}, string, string, void>, signer: PolkadotSigner,) {
172173
return new Promise<void>((resolve, reject) => {
173174
// store the txHash, then use it in timeout. easier to know which tx is not finalized in time
174175
let txHash = ""
175176
const subscription = tx.signSubmitAndWatch(signer).subscribe({
176177
next(value) {
177-
console.log("Event:", value);
178178
txHash = value.txHash
179179

180180
// TODO investigate why finalized not for each extrinsic
181181
if (value.type === "finalized") {
182182
console.log("Transaction is finalized in block:", value.txHash);
183183
subscription.unsubscribe();
184+
clearTimeout(timeoutId);
184185
if (!value.ok) {
185186
console.log("Transaction threw an error:", value.dispatchError)
186187
}
187188
// Resolve the promise when the transaction is finalized
188189
resolve();
189-
190190
}
191191
},
192192
error(err) {
193193
console.error("Transaction failed:", err);
194194
subscription.unsubscribe();
195+
clearTimeout(timeoutId);
195196
// Reject the promise in case of an error
196197
reject(err);
197198

@@ -201,7 +202,7 @@ export async function getTransactionWatchPromise(tx: Transaction<{}, string, str
201202
}
202203
});
203204

204-
setTimeout(() => {
205+
const timeoutId = setTimeout(() => {
205206
subscription.unsubscribe();
206207
console.log('unsubscribed because of timeout for tx {}', txHash);
207208
reject()
File renamed without changes.

pallets/admin-utils/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,21 @@ pub mod pallet {
16731673
pallet_subtensor::Pallet::<T>::set_commit_reveal_weights_version(version);
16741674
Ok(())
16751675
}
1676+
1677+
/// Sets the number of immune owner neurons
1678+
#[pallet::call_index(72)]
1679+
#[pallet::weight(Weight::from_parts(15_000_000, 0)
1680+
.saturating_add(<T as frame_system::Config>::DbWeight::get().reads(1_u64))
1681+
.saturating_add(<T as frame_system::Config>::DbWeight::get().writes(1_u64)))]
1682+
pub fn sudo_set_owner_immune_neuron_limit(
1683+
origin: OriginFor<T>,
1684+
netuid: NetUid,
1685+
immune_neurons: u16,
1686+
) -> DispatchResult {
1687+
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;
1688+
pallet_subtensor::Pallet::<T>::set_owner_immune_neuron_limit(netuid, immune_neurons)?;
1689+
Ok(())
1690+
}
16761691
}
16771692
}
16781693

pallets/subtensor/src/coinbase/reveal_commits.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ impl<T: Config> Pallet<T> {
4545
let reveal_epoch = cur_epoch.saturating_sub(reveal_period);
4646

4747
// Clean expired commits
48-
for (epoch, _) in CRV3WeightCommitsV2::<T>::iter_prefix(netuid) {
48+
for (epoch, _) in TimelockedWeightCommits::<T>::iter_prefix(netuid) {
4949
if epoch < reveal_epoch {
50-
CRV3WeightCommitsV2::<T>::remove(netuid, epoch);
50+
TimelockedWeightCommits::<T>::remove(netuid, epoch);
5151
}
5252
}
5353

@@ -57,7 +57,7 @@ impl<T: Config> Pallet<T> {
5757
return Ok(());
5858
}
5959

60-
let mut entries = CRV3WeightCommitsV2::<T>::take(netuid, reveal_epoch);
60+
let mut entries = TimelockedWeightCommits::<T>::take(netuid, reveal_epoch);
6161
let mut unrevealed = VecDeque::new();
6262

6363
// Keep popping items off the front of the queue until we successfully reveal a commit.
@@ -185,11 +185,11 @@ impl<T: Config> Pallet<T> {
185185
continue;
186186
}
187187

188-
Self::deposit_event(Event::CRV3WeightsRevealed(netuid, who));
188+
Self::deposit_event(Event::TimelockedWeightsRevealed(netuid, who));
189189
}
190190

191191
if !unrevealed.is_empty() {
192-
CRV3WeightCommitsV2::<T>::insert(netuid, reveal_epoch, unrevealed);
192+
TimelockedWeightCommits::<T>::insert(netuid, reveal_epoch, unrevealed);
193193
}
194194

195195
Ok(())

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,47 @@ impl<T: Config> Pallet<T> {
426426
(prop_alpha_dividends, tao_dividends)
427427
}
428428

429+
fn get_immune_owner_hotkeys(netuid: NetUid, coldkey: &T::AccountId) -> Vec<T::AccountId> {
430+
// Gather (block, uid, hotkey) only for hotkeys that have a UID and a registration block.
431+
let mut triples: Vec<(u64, u16, T::AccountId)> = OwnedHotkeys::<T>::get(coldkey)
432+
.into_iter()
433+
.filter_map(|hotkey| {
434+
// Uids must exist, filter_map ignores hotkeys without UID
435+
Uids::<T>::get(netuid, &hotkey).map(|uid| {
436+
let block = BlockAtRegistration::<T>::get(netuid, uid);
437+
(block, uid, hotkey)
438+
})
439+
})
440+
.collect();
441+
442+
// Sort by BlockAtRegistration (descending), then by uid (ascending)
443+
// Recent registration is priority so that we can let older keys expire (get non-immune)
444+
triples.sort_by(|(b1, u1, _), (b2, u2, _)| b2.cmp(b1).then(u1.cmp(u2)));
445+
446+
// Keep first ImmuneOwnerUidsLimit
447+
let limit = ImmuneOwnerUidsLimit::<T>::get(netuid).into();
448+
if triples.len() > limit {
449+
triples.truncate(limit);
450+
}
451+
452+
// Project to just hotkeys
453+
let mut immune_hotkeys: Vec<T::AccountId> =
454+
triples.into_iter().map(|(_, _, hk)| hk).collect();
455+
456+
// Insert subnet owner hotkey in the beginning of the list if valid and not
457+
// already present
458+
if let Ok(owner_hk) = SubnetOwnerHotkey::<T>::try_get(netuid) {
459+
if Uids::<T>::get(netuid, &owner_hk).is_some() && !immune_hotkeys.contains(&owner_hk) {
460+
immune_hotkeys.insert(0, owner_hk);
461+
if immune_hotkeys.len() > limit {
462+
immune_hotkeys.truncate(limit);
463+
}
464+
}
465+
}
466+
467+
immune_hotkeys
468+
}
469+
429470
pub fn distribute_dividends_and_incentives(
430471
netuid: NetUid,
431472
owner_cut: AlphaCurrency,
@@ -454,17 +495,20 @@ impl<T: Config> Pallet<T> {
454495
}
455496

456497
// Distribute mining incentives.
498+
let subnet_owner_coldkey = SubnetOwner::<T>::get(netuid);
499+
let owner_hotkeys = Self::get_immune_owner_hotkeys(netuid, &subnet_owner_coldkey);
500+
log::debug!("incentives: owner hotkeys: {owner_hotkeys:?}");
457501
for (hotkey, incentive) in incentives {
458502
log::debug!("incentives: hotkey: {incentive:?}");
459503

460-
if let Ok(owner_hotkey) = SubnetOwnerHotkey::<T>::try_get(netuid) {
461-
if hotkey == owner_hotkey {
462-
log::debug!(
463-
"incentives: hotkey: {hotkey:?} is SN owner hotkey, skipping {incentive:?}"
464-
);
465-
continue; // Skip/burn miner-emission for SN owner hotkey.
466-
}
504+
// Skip/burn miner-emission for immune keys
505+
if owner_hotkeys.contains(&hotkey) {
506+
log::debug!(
507+
"incentives: hotkey: {hotkey:?} is SN owner hotkey or associated hotkey, skipping {incentive:?}"
508+
);
509+
continue;
467510
}
511+
468512
// Increase stake for miner.
469513
Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
470514
&hotkey.clone(),

pallets/subtensor/src/epoch/run_epoch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ impl<T: Config> Pallet<T> {
607607
}
608608

609609
// ---------- v3 ------------------------------------------------------
610-
for (_epoch, q) in CRV3WeightCommitsV2::<T>::iter_prefix(netuid) {
610+
for (_epoch, q) in TimelockedWeightCommits::<T>::iter_prefix(netuid) {
611611
for (who, cb, ..) in q.iter() {
612612
if !Self::is_commit_expired(netuid, *cb) {
613613
if let Some(i) = uid_of(who) {

pallets/subtensor/src/lib.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,26 @@ pub mod pallet {
14571457
pub type SubtokenEnabled<T> =
14581458
StorageMap<_, Identity, NetUid, bool, ValueQuery, DefaultFalse<T>>;
14591459

1460+
#[pallet::type_value]
1461+
/// Default value for burn keys limit
1462+
pub fn DefaultImmuneOwnerUidsLimit<T: Config>() -> u16 {
1463+
1
1464+
}
1465+
#[pallet::type_value]
1466+
/// Maximum value for burn keys limit
1467+
pub fn MaxImmuneOwnerUidsLimit<T: Config>() -> u16 {
1468+
10
1469+
}
1470+
#[pallet::type_value]
1471+
/// Minimum value for burn keys limit
1472+
pub fn MinImmuneOwnerUidsLimit<T: Config>() -> u16 {
1473+
1
1474+
}
1475+
#[pallet::storage]
1476+
/// --- MAP ( netuid ) --> Burn key limit
1477+
pub type ImmuneOwnerUidsLimit<T> =
1478+
StorageMap<_, Identity, NetUid, u16, ValueQuery, DefaultImmuneOwnerUidsLimit<T>>;
1479+
14601480
/// =======================================
14611481
/// ==== Subnetwork Consensus Storage ====
14621482
/// =======================================
@@ -1657,6 +1677,23 @@ pub mod pallet {
16571677
OptionQuery,
16581678
>;
16591679
#[pallet::storage]
1680+
/// MAP (netuid, epoch) → VecDeque<(who, commit_block, ciphertext, reveal_round)>
1681+
/// Stores a queue of weight commits for an account on a given subnet.
1682+
pub type TimelockedWeightCommits<T: Config> = StorageDoubleMap<
1683+
_,
1684+
Twox64Concat,
1685+
NetUid,
1686+
Twox64Concat,
1687+
u64, // epoch key
1688+
VecDeque<(
1689+
T::AccountId,
1690+
u64, // commit_block
1691+
BoundedVec<u8, ConstU32<MAX_CRV3_COMMIT_SIZE_BYTES>>,
1692+
RoundNumber,
1693+
)>,
1694+
ValueQuery,
1695+
>;
1696+
#[pallet::storage]
16601697
/// MAP (netuid, epoch) → VecDeque<(who, ciphertext, reveal_round)>
16611698
/// DEPRECATED for CRV3WeightCommitsV2
16621699
pub type CRV3WeightCommits<T: Config> = StorageDoubleMap<
@@ -1674,7 +1711,7 @@ pub mod pallet {
16741711
>;
16751712
#[pallet::storage]
16761713
/// MAP (netuid, epoch) → VecDeque<(who, commit_block, ciphertext, reveal_round)>
1677-
/// Stores a queue of v3 commits for an account on a given netuid.
1714+
/// DEPRECATED for TimelockedWeightCommits
16781715
pub type CRV3WeightCommitsV2<T: Config> = StorageDoubleMap<
16791716
_,
16801717
Twox64Concat,

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ mod dispatches {
693693
/// - Attempting to set prometheus information withing the rate limit min.
694694
///
695695
#[pallet::call_index(4)]
696-
#[pallet::weight((Weight::from_parts(33_780_000, 0)
696+
#[pallet::weight((Weight::from_parts(33_010_000, 0)
697697
.saturating_add(T::DbWeight::get().reads(4))
698698
.saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Normal, Pays::No))]
699699
pub fn serve_axon(
@@ -2201,7 +2201,7 @@ mod dispatches {
22012201
/// * commit_reveal_version (`u16`):
22022202
/// - The client (bittensor-drand) version
22032203
#[pallet::call_index(113)]
2204-
#[pallet::weight((Weight::from_parts(64_220_000, 0)
2204+
#[pallet::weight((Weight::from_parts(64_530_000, 0)
22052205
.saturating_add(T::DbWeight::get().reads(7_u64))
22062206
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
22072207
pub fn commit_timelocked_weights(

0 commit comments

Comments
 (0)