Skip to content

Commit edda939

Browse files
committed
fix(review): return AxonInfoOf from validate_serve_axon; fix log target; fix doc comments
1 parent 92d114c commit edda939

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

pallets/subtensor/src/extensions/subtensor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ where
256256
*protocol,
257257
*placeholder1,
258258
*placeholder2,
259-
),
259+
)
260+
.map(|_| ()),
260261
0u64,
261262
)
262263
.map(|validity| (validity, (), origin.clone()))

pallets/subtensor/src/migrations/migrate_remove_orphan_axon_prom_cert_v2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub fn migrate_remove_orphan_axon_prom_cert_v2<T: Config>() -> Weight {
7474

7575
if cleaned_axons > 0 || cleaned_prometheus > 0 || cleaned_certificates > 0 {
7676
log::info!(
77+
target: "runtime",
7778
"Cleaned {cleaned_axons} axons, {cleaned_prometheus} prometheus, \
7879
{cleaned_certificates} neuron certificates for network {network}"
7980
);

pallets/subtensor/src/subnets/serving.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ impl<T: Config> Pallet<T> {
7070
// We check the callers (hotkey) signature.
7171
let hotkey_id = ensure_signed(origin)?;
7272

73-
// Validate user input
74-
Self::validate_serve_axon(
73+
// Validate user input and build the axon struct.
74+
let mut prev_axon = Self::validate_serve_axon(
7575
&hotkey_id,
7676
netuid,
7777
version,
@@ -90,17 +90,8 @@ impl<T: Config> Pallet<T> {
9090
NeuronCertificates::<T>::insert(netuid, hotkey_id.clone(), certificate)
9191
}
9292

93-
// We insert the axon meta.
94-
let mut prev_axon = Self::get_axon_info(netuid, &hotkey_id);
93+
// Record the block at insert time.
9594
prev_axon.block = Self::get_current_block_as_u64();
96-
prev_axon.version = version;
97-
prev_axon.ip = ip;
98-
prev_axon.port = port;
99-
prev_axon.ip_type = ip_type;
100-
prev_axon.protocol = protocol;
101-
prev_axon.placeholder1 = placeholder1;
102-
prev_axon.placeholder2 = placeholder2;
103-
10495
Axons::<T>::insert(netuid, hotkey_id.clone(), prev_axon);
10596

10697
// We deposit axon served event.
@@ -137,11 +128,8 @@ impl<T: Config> Pallet<T> {
137128
/// - On successfully serving the axon info.
138129
///
139130
/// # Raises:
140-
/// * 'MechanismDoesNotExist':
141-
/// - Attempting to set weights on a non-existent network.
142-
///
143-
/// * 'NotRegistered':
144-
/// - Attempting to set weights from a non registered account.
131+
/// * 'HotKeyNotRegisteredInNetwork':
132+
/// - Attempting to serve prometheus from a hotkey not registered on the target network.
145133
///
146134
/// * 'InvalidIpType':
147135
/// - The ip type is not 4 or 6.
@@ -321,7 +309,7 @@ impl<T: Config> Pallet<T> {
321309
protocol: u8,
322310
placeholder1: u8,
323311
placeholder2: u8,
324-
) -> Result<(), Error<T>> {
312+
) -> Result<AxonInfoOf, Error<T>> {
325313
// Ensure the hotkey is registered on this specific network.
326314
ensure!(
327315
Self::is_hotkey_registered_on_network(netuid, hotkey_id),
@@ -344,8 +332,8 @@ impl<T: Config> Pallet<T> {
344332
Error::<T>::ServingRateLimitExceeded
345333
);
346334

347-
// Validate axon data with delegate func
348-
prev_axon.block = Self::get_current_block_as_u64();
335+
// Assemble and validate the updated axon state.
336+
prev_axon.block = current_block;
349337
prev_axon.version = version;
350338
prev_axon.ip = ip;
351339
prev_axon.port = port;
@@ -360,6 +348,6 @@ impl<T: Config> Pallet<T> {
360348
axon_validated.err().unwrap_or(Error::<T>::InvalidPort)
361349
);
362350

363-
Ok(())
351+
Ok(prev_axon)
364352
}
365353
}

0 commit comments

Comments
 (0)