Skip to content

Commit

Permalink
Merge pull request #866 from opentensor/cam/junius/feat-localnet-improve
Browse files Browse the repository at this point in the history
remove rest of SN3 localnet init behind condition
  • Loading branch information
open-junius authored Oct 18, 2024
2 parents b373a01 + 2e3b2a8 commit 93a3d19
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 60 deletions.
110 changes: 55 additions & 55 deletions pallets/subtensor/src/macros/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,66 +70,66 @@ mod genesis {
// Set initial total issuance from balances
TotalIssuance::<T>::put(self.balances_issuance);

let tempo = 99;

if self.initialize_network_3 {
init_network::<T>(3, tempo);
}

let netuid: u16 = 3;
let max_uids = 4096;

// Set max allowed uids
MaxAllowedUids::<T>::insert(netuid, max_uids);

let mut next_uid: u16 = 0;

for (coldkey, hotkeys) in self.stakes.iter() {
for (hotkey, stake_uid) in hotkeys.iter() {
let (stake, uid) = stake_uid;

// Expand Yuma Consensus with new position.
Rank::<T>::mutate(netuid, |v| v.push(0));
Trust::<T>::mutate(netuid, |v| v.push(0));
Active::<T>::mutate(netuid, |v| v.push(true));
Emission::<T>::mutate(netuid, |v| v.push(0));
Consensus::<T>::mutate(netuid, |v| v.push(0));
Incentive::<T>::mutate(netuid, |v| v.push(0));
Dividends::<T>::mutate(netuid, |v| v.push(0));
LastUpdate::<T>::mutate(netuid, |v| v.push(0));
PruningScores::<T>::mutate(netuid, |v| v.push(0));
ValidatorTrust::<T>::mutate(netuid, |v| v.push(0));
ValidatorPermit::<T>::mutate(netuid, |v| v.push(false));
let tempo = 99;

// Insert account information.
Keys::<T>::insert(netuid, uid, hotkey.clone()); // Make hotkey - uid association.
Uids::<T>::insert(netuid, hotkey.clone(), uid); // Make uid - hotkey association.
BlockAtRegistration::<T>::insert(netuid, uid, 0); // Fill block at registration.
IsNetworkMember::<T>::insert(hotkey.clone(), netuid, true); // Fill network is member.

// Fill stake information.
Owner::<T>::insert(hotkey.clone(), coldkey.clone());

TotalHotkeyStake::<T>::insert(hotkey.clone(), stake);
TotalColdkeyStake::<T>::insert(
coldkey.clone(),
TotalColdkeyStake::<T>::get(coldkey).saturating_add(*stake),
);

// Update total issuance value
TotalIssuance::<T>::put(TotalIssuance::<T>::get().saturating_add(*stake));

Stake::<T>::insert(hotkey.clone(), coldkey.clone(), stake);
init_network::<T>(3, tempo);

next_uid = next_uid.saturating_add(1);
let netuid: u16 = 3;
let max_uids = 4096;

// Set max allowed uids
MaxAllowedUids::<T>::insert(netuid, max_uids);

let mut next_uid: u16 = 0;

for (coldkey, hotkeys) in self.stakes.iter() {
for (hotkey, stake_uid) in hotkeys.iter() {
let (stake, uid) = stake_uid;

// Expand Yuma Consensus with new position.
Rank::<T>::mutate(netuid, |v| v.push(0));
Trust::<T>::mutate(netuid, |v| v.push(0));
Active::<T>::mutate(netuid, |v| v.push(true));
Emission::<T>::mutate(netuid, |v| v.push(0));
Consensus::<T>::mutate(netuid, |v| v.push(0));
Incentive::<T>::mutate(netuid, |v| v.push(0));
Dividends::<T>::mutate(netuid, |v| v.push(0));
LastUpdate::<T>::mutate(netuid, |v| v.push(0));
PruningScores::<T>::mutate(netuid, |v| v.push(0));
ValidatorTrust::<T>::mutate(netuid, |v| v.push(0));
ValidatorPermit::<T>::mutate(netuid, |v| v.push(false));

// Insert account information.
Keys::<T>::insert(netuid, uid, hotkey.clone()); // Make hotkey - uid association.
Uids::<T>::insert(netuid, hotkey.clone(), uid); // Make uid - hotkey association.
BlockAtRegistration::<T>::insert(netuid, uid, 0); // Fill block at registration.
IsNetworkMember::<T>::insert(hotkey.clone(), netuid, true); // Fill network is member.

// Fill stake information.
Owner::<T>::insert(hotkey.clone(), coldkey.clone());

TotalHotkeyStake::<T>::insert(hotkey.clone(), stake);
TotalColdkeyStake::<T>::insert(
coldkey.clone(),
TotalColdkeyStake::<T>::get(coldkey).saturating_add(*stake),
);

// Update total issuance value
TotalIssuance::<T>::put(TotalIssuance::<T>::get().saturating_add(*stake));

Stake::<T>::insert(hotkey.clone(), coldkey.clone(), stake);

next_uid = next_uid.saturating_add(1);
}
}
}

// Set correct length for Subnet neurons
SubnetworkN::<T>::insert(netuid, next_uid);
// Set correct length for Subnet neurons
SubnetworkN::<T>::insert(netuid, next_uid);

// --- Increase total network count.
TotalNetworks::<T>::mutate(|n| *n = n.saturating_add(1));
// --- Increase total network count.
TotalNetworks::<T>::mutate(|n| *n = n.saturating_add(1));
}

// Get the root network uid.
let root_netuid: u16 = 0;
Expand All @@ -140,7 +140,7 @@ mod genesis {
// Increment the number of total networks.
TotalNetworks::<T>::mutate(|n| *n = n.saturating_add(1));

// Set the number of validators to 1.
// Set the number of validators to 0.
SubnetworkN::<T>::insert(root_netuid, 0);

// Set the maximum number to the number of senate members.
Expand Down
19 changes: 14 additions & 5 deletions scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
# The base directory of the subtensor project
BASE_DIR="$SCRIPT_DIR/.."

LOG_DIR="$BASE_DIR/logs"
ALICE_LOG="$LOG_DIR/alice.log"
BOB_LOG="$LOG_DIR/bob.log"

# Create the log dir if it doesn't exist
mkdir -p "$LOG_DIR"

# get parameters
# Get the value of fast_blocks from the first argument
fast_blocks=${1:-"True"}
Expand Down Expand Up @@ -96,8 +103,10 @@ bob_start=(

trap 'pkill -P $$' EXIT SIGINT SIGTERM

(
("${alice_start[@]}" 2>&1) &
("${bob_start[@]}" 2>&1)
wait
)
# Redirect output to both alice.log and the terminal
("${alice_start[@]}" 2>&1 | tee -a "$ALICE_LOG") &

# Redirect output to both bob.log and the terminal
("${bob_start[@]}" 2>&1 | tee -a "$BOB_LOG") &

wait

0 comments on commit 93a3d19

Please sign in to comment.