Skip to content

Commit b07c1ff

Browse files
committed
add events
1 parent f5df0ba commit b07c1ff

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

pallets/subtensor/src/macros/events.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,25 @@ mod events {
204204
ColdkeySwapScheduleDurationSet(BlockNumberFor<T>),
205205
/// The duration of dissolve network has been set
206206
DissolveNetworkScheduleDurationSet(BlockNumberFor<T>),
207+
/// Weights have been successfully committed.
208+
///
209+
/// - **who**: The account ID of the user committing the weights.
210+
/// - **netuid**: The network identifier.
211+
/// - **commit_hash**: The hash representing the committed weights.
212+
WeightsCommitted(T::AccountId, u16, H256),
213+
214+
/// Weights have been successfully revealed.
215+
///
216+
/// - **who**: The account ID of the user revealing the weights.
217+
/// - **netuid**: The network identifier.
218+
/// - **commit_hash**: The hash of the revealed weights.
219+
WeightsRevealed(T::AccountId, u16, H256),
220+
221+
/// Weights have been successfully batch revealed.
222+
///
223+
/// - **who**: The account ID of the user revealing the weights.
224+
/// - **netuid**: The network identifier.
225+
/// - **revealed_hashes**: A vector of hashes representing each revealed weight set.
226+
WeightsBatchRevealed(T::AccountId, u16, Vec<H256>),
207227
}
208228
}

pallets/subtensor/src/subnets/weights.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ impl<T: Config> Pallet<T> {
7373
// --- 9. Store the updated queue back to storage.
7474
*maybe_commits = Some(commits);
7575

76-
// --- 10. Return ok.
76+
// --- 10. Emit the WeightsCommitted event.
77+
Self::deposit_event(Event::WeightsCommitted(who.clone(), netuid, commit_hash));
78+
79+
// --- 11. Return ok.
7780
Ok(())
7881
})
7982
}
@@ -198,9 +201,15 @@ impl<T: Config> Pallet<T> {
198201
}
199202

200203
// --- 12. Proceed to set the revealed weights.
201-
Self::do_set_weights(origin, netuid, uids, values, version_key)
204+
Self::do_set_weights(origin, netuid, uids.clone(), values.clone(), version_key)?;
205+
206+
// --- 13. Emit the WeightsRevealed event.
207+
Self::deposit_event(Event::WeightsRevealed(who.clone(), netuid, provided_hash));
208+
209+
// --- 14. Return ok.
210+
Ok(())
202211
} else {
203-
// --- 13. The provided_hash does not match any non-expired commits.
212+
// --- 15. The provided_hash does not match any non-expired commits.
204213
if expired_hashes.contains(&provided_hash) {
205214
Err(Error::<T>::ExpiredWeightCommit.into())
206215
} else {
@@ -302,6 +311,7 @@ impl<T: Config> Pallet<T> {
302311
// --- 6. Prepare to collect all provided hashes and their corresponding reveals.
303312
let mut provided_hashes = Vec::new();
304313
let mut reveals = Vec::new();
314+
let mut revealed_hashes: Vec<H256> = Vec::with_capacity(num_reveals);
305315

306316
for ((uids, values), (salt, version_key)) in uids_list
307317
.into_iter()
@@ -361,6 +371,9 @@ impl<T: Config> Pallet<T> {
361371

362372
// --- 8c. Proceed to set the revealed weights.
363373
Self::do_set_weights(origin.clone(), netuid, uids, values, version_key)?;
374+
375+
// --- 8d. Collect the revealed hash.
376+
revealed_hashes.push(provided_hash);
364377
} else if expired_hashes.contains(&provided_hash) {
365378
return Err(Error::<T>::ExpiredWeightCommit.into());
366379
} else {
@@ -373,7 +386,14 @@ impl<T: Config> Pallet<T> {
373386
*maybe_commits = None;
374387
}
375388

376-
// --- 10. Return ok.
389+
// --- 10. Emit the WeightsBatchRevealed event with all revealed hashes.
390+
Self::deposit_event(Event::WeightsBatchRevealed(
391+
who.clone(),
392+
netuid,
393+
revealed_hashes,
394+
));
395+
396+
// --- 11. Return ok.
377397
Ok(())
378398
})
379399
}

0 commit comments

Comments
 (0)