Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into sam-revamp-deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
sam0x17 committed May 28, 2024
2 parents 5e061dd + 40a8321 commit 4e319c5
Show file tree
Hide file tree
Showing 7 changed files with 33,595 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
# required_version = "1.5.1"
# unstable_features = false
# disable_all_formatting = false
skip_children = true
# skip_children = true
# hide_parse_errors = false
# error_on_line_overflow = false
# error_on_unformatted = false
Expand Down
8 changes: 4 additions & 4 deletions docs/running-subtensor-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,31 +174,31 @@ You can now run the public subtensor node either as a lite node or as an archive
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):

```bash title="With --sync=warp setting, for lite node"
./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
./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
```

### Archive node on mainchain

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):

```bash title="With --sync=full and --pruning archive setting, for archive node"
./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
./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
```

### Lite node on testchain

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

```bash title="With bootnodes set to testnet and --sync=warp setting, for lite node."
./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
./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
```

### Archive node on testchain

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

```bash title="With bootnodes set to testnet and --sync=full and --pruning archive setting, for archive node"
./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
./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
```

## Running on cloud
Expand Down
6 changes: 3 additions & 3 deletions pallets/subtensor/src/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ impl<T: Config> Pallet<T> {
pub fn generate_emission(block_number: u64) {
// --- 1. Iterate across each network and add pending emission into stash.
for (netuid, tempo) in <Tempo<T> as IterableStorageMap<u16, u16>>::iter() {
// Skip the root network.
if netuid == Self::get_root_netuid() {
// Root emission is burned.
// Skip the root network or subnets with registrations turned off
if netuid == Self::get_root_netuid() || !Self::is_registration_allowed(netuid) {
// Root emission or subnet emission is burned
continue;
}

Expand Down
18 changes: 18 additions & 0 deletions pallets/subtensor/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,24 @@ impl<T: Config> Pallet<T> {
Self::deposit_event(Event::NetworkRateLimitSet(limit));
}

/// Checks if registrations are allowed for a given subnet.
///
/// This function retrieves the subnet hyperparameters for the specified subnet and checks the `registration_allowed` flag.
/// If the subnet doesn't exist or doesn't have hyperparameters defined, it returns `false`.
///
/// # Arguments
///
/// * `netuid` - The unique identifier of the subnet.
///
/// # Returns
///
/// * `bool` - `true` if registrations are allowed for the subnet, `false` otherwise.
pub fn is_registration_allowed(netuid: u16) -> bool {
Self::get_subnet_hyperparams(netuid)
.map(|params| params.registration_allowed)
.unwrap_or(false)
}

// Computes and sets emission values for the root network which determine the emission for all subnets.
//
// This function is responsible for calculating emission based on network weights, stake values,
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/subnet_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct SubnetHyperparams {
weights_rate_limit: Compact<u64>,
adjustment_interval: Compact<u16>,
activity_cutoff: Compact<u16>,
registration_allowed: bool,
pub registration_allowed: bool,
target_regs_per_interval: Compact<u16>,
min_burn: Compact<u64>,
max_burn: Compact<u64>,
Expand Down
91 changes: 91 additions & 0 deletions pallets/subtensor/tests/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,94 @@ fn test_burn_adjustment_case_e_zero_registrations() {
assert_eq!(adjusted_diff, 5_000);
});
}

#[test]
fn test_emission_based_on_registration_status() {
new_test_ext(1).execute_with(|| {
let n: u16 = 100;
let netuid_off: u16 = 1;
let netuid_on: u16 = 2;
let tempo: u16 = 1;
let netuids: Vec<u16> = vec![netuid_off, netuid_on];
let emissions: Vec<u64> = vec![1000000000, 1000000000];

// Add subnets with registration turned off and on
add_network(netuid_off, tempo, 0);
add_network(netuid_on, tempo, 0);
SubtensorModule::set_max_allowed_uids(netuid_off, n);
SubtensorModule::set_max_allowed_uids(netuid_on, n);
SubtensorModule::set_emission_values(&netuids, emissions).unwrap();
SubtensorModule::set_network_registration_allowed(netuid_off, false);
SubtensorModule::set_network_registration_allowed(netuid_on, true);

// Populate the subnets with neurons
for i in 0..n {
SubtensorModule::append_neuron(netuid_off, &U256::from(i), 0);
SubtensorModule::append_neuron(netuid_on, &U256::from(i), 0);
}

// Generate emission at block 0
let block: u64 = 0;
SubtensorModule::generate_emission(block);

// Verify that no emission tuples are loaded for the subnet with registration off
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_off).is_none());

// Verify that emission tuples are loaded for the subnet with registration on
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_on).is_some());
assert_eq!(
SubtensorModule::get_loaded_emission_tuples(netuid_on)
.unwrap()
.len(),
n as usize
);

// Step to the next epoch block
let epoch_block: u16 = tempo;
step_block(epoch_block);

// Verify that no emission tuples are loaded for the subnet with registration off
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_off).is_none());
log::info!(
"Emissions for netuid with registration off: {:?}",
SubtensorModule::get_loaded_emission_tuples(netuid_off)
);

// Verify that emission tuples are loaded for the subnet with registration on
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_on).is_some());
log::info!(
"Emissions for netuid with registration on: {:?}",
SubtensorModule::get_loaded_emission_tuples(netuid_on)
);
assert_eq!(
SubtensorModule::get_loaded_emission_tuples(netuid_on)
.unwrap()
.len(),
n as usize
);

// drain the emission tuples for the subnet with registration on
SubtensorModule::drain_emission(next_block as u64);
// Turn on registration for the subnet with registration off
SubtensorModule::set_network_registration_allowed(netuid_off, true);
SubtensorModule::set_network_registration_allowed(netuid_on, false);

// Generate emission at the next block
let next_block: u64 = block + 1;
SubtensorModule::generate_emission(next_block);

// Verify that emission tuples are now loaded for the subnet with registration turned on
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_off).is_some());
log::info!(
"Emissions for netuid with registration on: {:?}",
SubtensorModule::get_loaded_emission_tuples(netuid_on)
);
assert!(SubtensorModule::get_loaded_emission_tuples(netuid_on).is_none());
assert_eq!(
SubtensorModule::get_loaded_emission_tuples(netuid_off)
.unwrap()
.len(),
n as usize
);
});
}
Loading

0 comments on commit 4e319c5

Please sign in to comment.