Skip to content

Commit

Permalink
Merge branch 'main' into sudo_decentralization
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayden Brewer committed Jun 27, 2023
2 parents d3f398f + 4412494 commit 23b6338
Show file tree
Hide file tree
Showing 35 changed files with 2,637 additions and 486 deletions.
2 changes: 1 addition & 1 deletion .cargo-husky/hooks/post-commit
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ __hey_listen__() {
fi
}

while read -rd '' _path; do
while read -r _path; do
if rustup run nightly -- rustfmt --check --quiet -- "${_path}" 1>/dev/null 2>&1; then
__hey_listen__ "Skipping -> ${_path}"
continue 1
Expand Down
2 changes: 2 additions & 0 deletions .cargo-husky/hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# ```
##

export PATH="$HOME/.cargo/bin:$PATH"

set -EeT

__hey_listen__() {
Expand Down
18 changes: 18 additions & 0 deletions .cargo-husky/hooks/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
#
# git prepare-commit-msg hook for automatically prepending an issue key
# from the start of the current branch name to commit messages.

# check if commit is merge commit or a commit ammend
if [ $2 = "merge" ] || [ $2 = "commit" ]; then
exit
fi
ISSUE_KEY=`git branch | grep -o "\* \(.*/\)*[A-Z]\{2,\}-[0-9]\+" | grep -o "[A-Z]\{2,\}-[0-9]\+"`
if [ $? -ne 0 ]; then
# no issue key in branch, use the default message
exit
fi
# issue key matched from branch prefix, prepend to commit message
TEMP=`mktemp /tmp/commitmsg-XXXXX`
(echo "$ISSUE_KEY: $(cat $1)") > $TEMP
cat $TEMP > $1
19 changes: 18 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ SKIP_WASM_BUILD=1 \

Running code coverage
```bash
SKIP_WASM_BUILD=1 RUST_LOG=runtime=debug cargo tarpaulin --skip-clean
bash scripts/code-coverage.sh
```
> Note; above requires `cargo-tarpaulin` is installed to the host, eg. `cargo install cargo-tarpaulin`

Expand Down
12 changes: 6 additions & 6 deletions hyperparameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ TxRateLimit: u64 = 1; // [1 @ 64,888]
```rust
Rho: u16 = 10;
Kappa: u16 = 32_767; // 0.5 = 65535/2
MaxAllowedUids: u16 = 128;
MaxAllowedUids: u16 = 1024;
Issuance: u64 = 0;
MinAllowedWeights: u16 = 8;
EmissionValue: u64 = 50_000_000;
EmissionValue: u64 = 142_223_000;
MaxWeightsLimit: u16 = 32768; // 50% of u16
ValidatorBatchSize: u16 = 1;
ValidatorSequenceLen: u16 = 2048; // 2048
Expand All @@ -22,17 +22,17 @@ ValidatorPruneLen: u64 = 1;
ValidatorLogitsDivergence: u16 = 1310; // 2% of u16
ScalingLawPower: u16 = 50; // 0.5
SynergyScalingLawPower: u16 = 50; // 0.5
MaxAllowedValidators: u16 = 8;
MaxAllowedValidators: u16 = 128;
Tempo: u16 = 99;
Difficulty: u64 = 10_000_000;
AdjustmentInterval: u16 = 225;
TargetRegistrationsPerInterval: u16 = 1;
TargetRegistrationsPerInterval: u16 = 2;
ImmunityPeriod: u16 = 7200;
ActivityCutoff: u16 = 5000;
MaxRegistrationsPerBlock: u16 = 1;
PruningScore : u16 = u16::MAX;
BondsMovingAverage: u64 = 900_000;
WeightsVersionKey: u64 = 370;
WeightsVersionKey: u64 = 1000;
MinDifficulty: u64 = 10_000_000;
MaxDifficulty: u64 = u64::MAX / 4;
ServingRateLimit: u64 = 10;
Expand All @@ -49,7 +49,7 @@ Kappa: u16 = 32_767; // 0.5 = 65535/2
MaxAllowedUids: u16 = 4096;
Issuance: u64 = 0;
MinAllowedWeights: u16 = 50;
EmissionValue: u64 = 950_000_000;
EmissionValue: u64 = 857_777_000;
MaxWeightsLimit: u16 = 655; // 655/2^16 = 0.01 [655 @ 7,160]
ValidatorBatchSize: u16 = 32; // 32
ValidatorSequenceLen: u16 = 256; // 256
Expand Down
124 changes: 123 additions & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
Some("bittensor"),
None,
// Properties
None,
Some(properties),
// Extensions
None,
))
Expand Down Expand Up @@ -541,3 +541,125 @@ fn finney_genesis(
}
}
}

pub fn localnet_config() -> Result<ChainSpec, String> {
let path: PathBuf = std::path::PathBuf::from("./snapshot.json");
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

// We mmap the file into memory first, as this is *a lot* faster than using
// `serde_json::from_reader`. See https://github.com/serde-rs/json/issues/160
let file = File::open(&path)
.map_err(|e| format!("Error opening genesis file `{}`: {}", path.display(), e))?;

// SAFETY: `mmap` is fundamentally unsafe since technically the file can change
// underneath us while it is mapped; in practice it's unlikely to be a problem
let bytes = unsafe {
memmap2::Mmap::map(&file)
.map_err(|e| format!("Error mmaping genesis file `{}`: {}", path.display(), e))?
};

let old_state: ColdkeyHotkeys =
json::from_slice(&bytes).map_err(|e| format!("Error parsing genesis file: {}", e))?;

let mut processed_stakes: Vec<(sp_runtime::AccountId32, Vec<(sp_runtime::AccountId32, (u64, u16))>)> = Vec::new();
for (coldkey_str, hotkeys) in old_state.stakes.iter() {
let coldkey = <sr25519::Public as Ss58Codec>::from_ss58check(&coldkey_str).unwrap();
let coldkey_account = sp_runtime::AccountId32::from(coldkey);

let mut processed_hotkeys: Vec<(sp_runtime::AccountId32, (u64, u16))> = Vec::new();

for (hotkey_str, amount_uid) in hotkeys.iter() {
let (amount, uid) = amount_uid;
let hotkey = <sr25519::Public as Ss58Codec>::from_ss58check(&hotkey_str).unwrap();
let hotkey_account = sp_runtime::AccountId32::from(hotkey);

processed_hotkeys.push((hotkey_account, (*amount, *uid)));
}

processed_stakes.push((coldkey_account, processed_hotkeys));
}

let mut balances_issuance: u64 = 0;
let mut processed_balances: Vec<(sp_runtime::AccountId32, u64)> = Vec::new();
for (key_str, amount) in old_state.balances.iter() {
let key = <sr25519::Public as Ss58Codec>::from_ss58check(&key_str).unwrap();
let key_account = sp_runtime::AccountId32::from(key);

processed_balances.push((key_account, *amount));
balances_issuance += *amount;
}

// Give front-ends necessary data to present to users
let mut properties = sc_service::Properties::new();
properties.insert("tokenSymbol".into(), "TAO".into());
properties.insert("tokenDecimals".into(), 9.into());
properties.insert("ss58Format".into(), 13116.into());

Ok(ChainSpec::from_genesis(
// Name
"Bittensor",
// ID
"bittensor",
ChainType::Development,
move || {
localnet_genesis(
wasm_binary,
// Initial PoA authorities (Validators)
// aura | grandpa
vec![
// Keys for debug
authority_keys_from_seed("Alice"),
authority_keys_from_seed("Bob"),
],
// Pre-funded accounts
true,
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
Some("bittensor"),
None,
// Properties
Some(properties),
// Extensions
None,
))
}

fn localnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
_enable_println: bool,
) -> GenesisConfig {
GenesisConfig {
system: SystemConfig {
// Add Wasm runtime to storage.
code: wasm_binary.to_vec(),
},
balances: BalancesConfig {
// Configure sudo balance
balances: vec![
(get_account_id_from_seed::<sr25519::Public>("Alice"), 1000000000000),
(get_account_id_from_seed::<sr25519::Public>("Bob"), 1000000000000),
(get_account_id_from_seed::<sr25519::Public>("Charlie"), 1000000000000),
(get_account_id_from_seed::<sr25519::Public>("Dave"), 2000000000),
(get_account_id_from_seed::<sr25519::Public>("Eve"), 2000000000),
(get_account_id_from_seed::<sr25519::Public>("Ferdie"), 2000000000),
]
},
aura: AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
},
grandpa: GrandpaConfig {
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
},
sudo: SudoConfig {
key: Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
},
transaction_payment: Default::default(),
subtensor_module: Default::default(),
}
}
3 changes: 2 additions & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use sc_service::PartialComponents;

impl SubstrateCli for Cli {
fn impl_name() -> String {
"Substrate Node".into()
"Subtensor Node".into()
}

fn impl_version() -> String {
Expand All @@ -44,6 +44,7 @@ impl SubstrateCli for Cli {

fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"local" => Box::new(chain_spec::localnet_config()?),
"finney" => Box::new(chain_spec::finney_mainnet_config()?),
"" |"test_finney" => Box::new(chain_spec::finney_testnet_config()?),
"local" => Box::new(chain_spec::localnet_config()?),
Expand Down
Loading

0 comments on commit 23b6338

Please sign in to comment.