Skip to content

Commit 4e319c5

Browse files
committed
Merge remote-tracking branch 'origin/main' into sam-revamp-deployment
2 parents 5e061dd + 40a8321 commit 4e319c5

File tree

7 files changed

+33595
-13
lines changed

7 files changed

+33595
-13
lines changed

.rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
# required_version = "1.5.1"
7676
# unstable_features = false
7777
# disable_all_formatting = false
78-
skip_children = true
78+
# skip_children = true
7979
# hide_parse_errors = false
8080
# error_on_line_overflow = false
8181
# error_on_unformatted = false

docs/running-subtensor-locally.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,31 +174,31 @@ You can now run the public subtensor node either as a lite node or as an archive
174174
To run a lite node connected to the mainchain, execute the below command (note the `--sync=warp` flag which runs the subtensor node in lite mode):
175175

176176
```bash title="With --sync=warp setting, for lite node"
177-
./target/release/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=warp --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 64 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --ws-max-connections 16000 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external --ws-external
177+
./target/release/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=warp --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
178178
```
179179

180180
### Archive node on mainchain
181181

182182
To run an archive node connected to the mainchain, execute the below command (note the `--sync=full` which syncs the node to the full chain and `--pruning archive` flags, which disables the node's automatic pruning of older historical data):
183183

184184
```bash title="With --sync=full and --pruning archive setting, for archive node"
185-
./target/release/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=full --pruning archive --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 64 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --ws-max-connections 16000 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external --ws-external
185+
./target/release/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=full --pruning archive --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /ip4/13.58.175.193/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
186186
```
187187

188188
### Lite node on testchain
189189

190190
To run a lite node connected to the testchain, execute the below command:
191191

192192
```bash title="With bootnodes set to testnet and --sync=warp setting, for lite node."
193-
./target/release/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=warp --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 64 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --ws-max-connections 16000 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external --ws-external
193+
./target/release/node-subtensor --chain raw_testspec.json --base-path /tmp/blockchain --sync=warp --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
194194
```
195195

196196
### Archive node on testchain
197197

198198
To run an archive node connected to the testchain, execute the below command:
199199

200200
```bash title="With bootnodes set to testnet and --sync=full and --pruning archive setting, for archive node"
201-
./target/release/node-subtensor --chain raw_spec.json --base-path /tmp/blockchain --sync=full --pruning archive --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 64 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWDe7g2JbNETiKypcKT1KsCEZJbTzEHCn8hpd4PHZ6pdz5 --ws-max-connections 16000 --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external --ws-external
201+
./target/release/node-subtensor --chain raw_testspec.json --base-path /tmp/blockchain --sync=full --pruning archive --execution wasm --wasm-execution compiled --port 30333 --max-runtime-instances 32 --rpc-max-response-size 2048 --rpc-cors all --rpc-port 9944 --bootnodes /dns/bootnode.test.finney.opentensor.ai/tcp/30333/p2p/12D3KooWPM4mLcKJGtyVtkggqdG84zWrd7Rij6PGQDoijh1X86Vr --no-mdns --in-peers 8000 --out-peers 8000 --prometheus-external --rpc-external
202202
```
203203

204204
## Running on cloud

pallets/subtensor/src/block_step.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ impl<T: Config> Pallet<T> {
109109
pub fn generate_emission(block_number: u64) {
110110
// --- 1. Iterate across each network and add pending emission into stash.
111111
for (netuid, tempo) in <Tempo<T> as IterableStorageMap<u16, u16>>::iter() {
112-
// Skip the root network.
113-
if netuid == Self::get_root_netuid() {
114-
// Root emission is burned.
112+
// Skip the root network or subnets with registrations turned off
113+
if netuid == Self::get_root_netuid() || !Self::is_registration_allowed(netuid) {
114+
// Root emission or subnet emission is burned
115115
continue;
116116
}
117117

pallets/subtensor/src/root.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,24 @@ impl<T: Config> Pallet<T> {
286286
Self::deposit_event(Event::NetworkRateLimitSet(limit));
287287
}
288288

289+
/// Checks if registrations are allowed for a given subnet.
290+
///
291+
/// This function retrieves the subnet hyperparameters for the specified subnet and checks the `registration_allowed` flag.
292+
/// If the subnet doesn't exist or doesn't have hyperparameters defined, it returns `false`.
293+
///
294+
/// # Arguments
295+
///
296+
/// * `netuid` - The unique identifier of the subnet.
297+
///
298+
/// # Returns
299+
///
300+
/// * `bool` - `true` if registrations are allowed for the subnet, `false` otherwise.
301+
pub fn is_registration_allowed(netuid: u16) -> bool {
302+
Self::get_subnet_hyperparams(netuid)
303+
.map(|params| params.registration_allowed)
304+
.unwrap_or(false)
305+
}
306+
289307
// Computes and sets emission values for the root network which determine the emission for all subnets.
290308
//
291309
// This function is responsible for calculating emission based on network weights, stake values,

pallets/subtensor/src/subnet_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct SubnetHyperparams {
4040
weights_rate_limit: Compact<u64>,
4141
adjustment_interval: Compact<u16>,
4242
activity_cutoff: Compact<u16>,
43-
registration_allowed: bool,
43+
pub registration_allowed: bool,
4444
target_regs_per_interval: Compact<u16>,
4545
min_burn: Compact<u64>,
4646
max_burn: Compact<u64>,

pallets/subtensor/tests/block_step.rs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,94 @@ fn test_burn_adjustment_case_e_zero_registrations() {
803803
assert_eq!(adjusted_diff, 5_000);
804804
});
805805
}
806+
807+
#[test]
808+
fn test_emission_based_on_registration_status() {
809+
new_test_ext(1).execute_with(|| {
810+
let n: u16 = 100;
811+
let netuid_off: u16 = 1;
812+
let netuid_on: u16 = 2;
813+
let tempo: u16 = 1;
814+
let netuids: Vec<u16> = vec![netuid_off, netuid_on];
815+
let emissions: Vec<u64> = vec![1000000000, 1000000000];
816+
817+
// Add subnets with registration turned off and on
818+
add_network(netuid_off, tempo, 0);
819+
add_network(netuid_on, tempo, 0);
820+
SubtensorModule::set_max_allowed_uids(netuid_off, n);
821+
SubtensorModule::set_max_allowed_uids(netuid_on, n);
822+
SubtensorModule::set_emission_values(&netuids, emissions).unwrap();
823+
SubtensorModule::set_network_registration_allowed(netuid_off, false);
824+
SubtensorModule::set_network_registration_allowed(netuid_on, true);
825+
826+
// Populate the subnets with neurons
827+
for i in 0..n {
828+
SubtensorModule::append_neuron(netuid_off, &U256::from(i), 0);
829+
SubtensorModule::append_neuron(netuid_on, &U256::from(i), 0);
830+
}
831+
832+
// Generate emission at block 0
833+
let block: u64 = 0;
834+
SubtensorModule::generate_emission(block);
835+
836+
// Verify that no emission tuples are loaded for the subnet with registration off
837+
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_off).is_none());
838+
839+
// Verify that emission tuples are loaded for the subnet with registration on
840+
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_on).is_some());
841+
assert_eq!(
842+
SubtensorModule::get_loaded_emission_tuples(netuid_on)
843+
.unwrap()
844+
.len(),
845+
n as usize
846+
);
847+
848+
// Step to the next epoch block
849+
let epoch_block: u16 = tempo;
850+
step_block(epoch_block);
851+
852+
// Verify that no emission tuples are loaded for the subnet with registration off
853+
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_off).is_none());
854+
log::info!(
855+
"Emissions for netuid with registration off: {:?}",
856+
SubtensorModule::get_loaded_emission_tuples(netuid_off)
857+
);
858+
859+
// Verify that emission tuples are loaded for the subnet with registration on
860+
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_on).is_some());
861+
log::info!(
862+
"Emissions for netuid with registration on: {:?}",
863+
SubtensorModule::get_loaded_emission_tuples(netuid_on)
864+
);
865+
assert_eq!(
866+
SubtensorModule::get_loaded_emission_tuples(netuid_on)
867+
.unwrap()
868+
.len(),
869+
n as usize
870+
);
871+
872+
// drain the emission tuples for the subnet with registration on
873+
SubtensorModule::drain_emission(next_block as u64);
874+
// Turn on registration for the subnet with registration off
875+
SubtensorModule::set_network_registration_allowed(netuid_off, true);
876+
SubtensorModule::set_network_registration_allowed(netuid_on, false);
877+
878+
// Generate emission at the next block
879+
let next_block: u64 = block + 1;
880+
SubtensorModule::generate_emission(next_block);
881+
882+
// Verify that emission tuples are now loaded for the subnet with registration turned on
883+
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_off).is_some());
884+
log::info!(
885+
"Emissions for netuid with registration on: {:?}",
886+
SubtensorModule::get_loaded_emission_tuples(netuid_on)
887+
);
888+
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_on).is_none());
889+
assert_eq!(
890+
SubtensorModule::get_loaded_emission_tuples(netuid_off)
891+
.unwrap()
892+
.len(),
893+
n as usize
894+
);
895+
});
896+
}

0 commit comments

Comments
 (0)