Skip to content

Commit

Permalink
Merge branch 'devnet-ready' into feat/runtime-apis-return-types
Browse files Browse the repository at this point in the history
  • Loading branch information
camfairchild committed Nov 13, 2024
2 parents 49e0479 + 4b45cd3 commit 6c9c832
Show file tree
Hide file tree
Showing 30 changed files with 2,790 additions and 77 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/hotfixes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Handle Hotfix PRs

on:
pull_request:
types: [opened]

permissions:
pull-requests: write
contents: write

jobs:
handle-hotfix-pr:
runs-on: ubuntu-latest
steps:
- name: Check if PR is a hotfix into `main`
if: >
github.event.pull_request.base.ref == 'main' &&
github.event.pull_request.head.ref != 'testnet'
run: |
echo "Hotfix PR detected. Proceeding to label and comment."
- name: Add `hotfix` label
if: >
github.event.pull_request.base.ref == 'main' &&
github.event.pull_request.head.ref != 'testnet'
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
-d '{"labels":["hotfix"]}'
- name: Add hotfix bot comment
if: >
github.event.pull_request.base.ref == 'main' &&
github.event.pull_request.head.ref != 'testnet'
run: |
COMMENT_BODY=$(cat <<EOF
## 🚨🚨🚨 HOTFIX DETECTED 🚨🚨🚨
It looks like you are trying to merge a hotfix PR into `main`. If this isn't what you wanted to do, and you just wanted to make a regular PR, please close this PR, base your changes off the `devnet-ready` branch and open a new PR into `devnet ready`.
If you _are_ trying to merge a hotfix PR, please complete the following essential steps:
1. [ ] go ahead and get this PR into `main` merged, so we can get the change in as quickly as possible!
2. [ ] merge `main` into `testnet`, bumping `spec_version`
3. [ ] deploy `testnet`
4. [ ] merge `testnet` into `devnet`, bumping `spec_version`
5. [ ] deploy `devnet`
6. [ ] merge `devnet` into `devnet-ready`
If you do not complete these steps, your hotfix may be inadvertently removed in the future when branches are promoted to \`main\`, so it is essential that you do so.
EOF
)
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
-d "$(jq -n --arg body "$COMMENT_BODY" '{body: $body}')"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97 changes: 97 additions & 0 deletions node/src/chain_spec/devnet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Allowed since it's actually better to panic during chain setup when there is an error
#![allow(clippy::unwrap_used)]

use super::*;

pub fn devnet_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

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

Ok(ChainSpec::builder(
wasm_binary,
Extensions {
bad_blocks: Some(HashSet::new()),
..Default::default()
},
)
.with_name("Bittensor")
.with_protocol_id("bittensor")
.with_id("bittensor")
.with_chain_type(ChainType::Development)
.with_genesis_config_patch(devnet_genesis(
// Initial PoA authorities (Validators)
// aura | grandpa
vec![
// Keys for debug
authority_keys_from_ss58(
"5D5ABUyMsdmJdH7xrsz9vREq5eGXr5pXhHxix2dENQR62dEo",
"5H3qMjQjoeZxZ98jzDmoCwbz2sugd5fDN1wrr8Phf49zemKL",
),
authority_keys_from_ss58(
"5GbRc5sNDdhcPAU9suV2g9P5zyK1hjAQ9JHeeadY1mb8kXoM",
"5GbkysfaCjK3cprKPhi3CUwaB5xWpBwcfrkzs6FmqHxej8HZ",
),
authority_keys_from_ss58(
"5CoVWwBwXz2ndEChGcS46VfSTb3RMUZzZzAYdBKo263zDhEz",
"5HTLp4BvPp99iXtd8YTBZA1sMfzo8pd4mZzBJf7HYdCn2boU",
),
authority_keys_from_ss58(
"5EekcbqupwbgWqF8hWGY4Pczsxp9sbarjDehqk7bdyLhDCwC",
"5GAemcU4Pzyfe8DwLwDFx3aWzyg3FuqYUCCw2h4sdDZhyFvE",
),
authority_keys_from_ss58(
"5GgdEQyS5DZzUwKuyucEPEZLxFKGmasUFm1mqM3sx1MRC5RV",
"5EibpMomXmgekxcfs25SzFBpGWUsG9Lc8ALNjXN3TYH5Tube",
),
authority_keys_from_ss58(
"5Ek5JLCGk2PuoT1fS23GXiWYUT98HVUBERFQBu5g57sNf44x",
"5Gyrc6b2mx1Af6zWJYHdx3gwgtXgZvD9YkcG9uTUPYry4V2a",
),
],
// Sudo account
Ss58Codec::from_ss58check("5GpzQgpiAKHMWNSH3RN4GLf96GVTDct9QxYEFAY7LWcVzTbx").unwrap(),
// Pre-funded accounts
vec![],
true,
vec![],
vec![],
0,
))
.with_properties(properties)
.build())
}

// Configure initial storage state for FRAME modules.
#[allow(clippy::too_many_arguments)]
fn devnet_genesis(
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
_endowed_accounts: Vec<AccountId>,
_enable_println: bool,
_stakes: Vec<(AccountId, Vec<(AccountId, (u64, u16))>)>,
_balances: Vec<(AccountId, u64)>,
_balances_issuance: u64,
) -> serde_json::Value {
serde_json::json!({
"balances": {
"balances": vec![(root_key.clone(), 1_000_000_000_000u128)],
},
"aura": {
"authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(),
},
"grandpa": {
"authorities": initial_authorities
.iter()
.map(|x| (x.1.clone(), 1))
.collect::<Vec<_>>(),
},
"sudo": {
"key": Some(root_key),
},
})
}
1 change: 1 addition & 0 deletions node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Allowed since it's actually better to panic during chain setup when there is an error
#![allow(clippy::unwrap_used)]

pub mod devnet;
pub mod finney;
pub mod localnet;
pub mod testnet;
Expand Down
42 changes: 6 additions & 36 deletions node/src/chain_spec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,6 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
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)
.map_err(|e| e.to_string())?;
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)
.map_err(|e| e.to_string())?;
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() {
Expand All @@ -60,7 +37,7 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {

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

Expand Down Expand Up @@ -116,8 +93,8 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
// Pre-funded accounts
vec![],
true,
processed_stakes.clone(),
processed_balances.clone(),
vec![],
processed_balances,
balances_issuance,
))
.with_properties(properties)
Expand All @@ -128,7 +105,7 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
#[allow(clippy::too_many_arguments)]
fn testnet_genesis(
initial_authorities: Vec<(AuraId, GrandpaId)>,
_root_key: AccountId,
root_key: AccountId,
_endowed_accounts: Vec<AccountId>,
_enable_println: bool,
_stakes: Vec<(AccountId, Vec<(AccountId, (u64, u16))>)>,
Expand All @@ -138,11 +115,7 @@ fn testnet_genesis(
serde_json::json!({
"balances": {
// Configure sudo balance
"balances": vec![(
<AccountId32 as Ss58Codec>::from_ss58check("5GpzQgpiAKHMWNSH3RN4GLf96GVTDct9QxYEFAY7LWcVzTbx")
.unwrap(),
1000000000000u128,
)],
"balances": vec![(root_key.clone(), 1_000_000_000_000u128)],
},
"aura": {
"authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(),
Expand All @@ -154,10 +127,7 @@ fn testnet_genesis(
.collect::<Vec<_>>(),
},
"sudo": {
"key": Some(
<AccountId32 as Ss58Codec>::from_ss58check("5GpzQgpiAKHMWNSH3RN4GLf96GVTDct9QxYEFAY7LWcVzTbx")
.unwrap(),
),
"key": Some(root_key),
},
})
}
1 change: 1 addition & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl SubstrateCli for Cli {
Ok(match id {
"local" => Box::new(chain_spec::localnet::localnet_config()?),
"finney" => Box::new(chain_spec::finney::finney_mainnet_config()?),
"devnet" => Box::new(chain_spec::devnet::devnet_config()?),
"" | "test_finney" => Box::new(chain_spec::testnet::finney_testnet_config()?),
path => Box::new(chain_spec::ChainSpec::from_json_file(
std::path::PathBuf::from(path),
Expand Down
10 changes: 5 additions & 5 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ use node_subtensor_runtime::{
/// imported and generated.
const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512;

/// Only enable the benchmarking host functions when we actually want to benchmark.
#[cfg(feature = "runtime-benchmarks")]
/// Always enable runtime benchmark host functions, the genesis state
/// was built with them so we're stuck with them forever.
///
/// They're just a noop, never actually get used if the runtime was not compiled with
/// `runtime-benchmarks`.
pub type HostFunctions = (
sp_io::SubstrateHostFunctions,
frame_benchmarking::benchmarking::HostFunctions,
);
/// Otherwise we use empty host functions for ext host functions.
#[cfg(not(feature = "runtime-benchmarks"))]
pub type HostFunctions = sp_io::SubstrateHostFunctions;

pub type Backend = FullBackend<Block>;
pub type Client = FullClient<Block, RuntimeApi, HostFunctions>;
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ try-runtime = [
"pallet-collective/try-runtime"
]
pow-faucet = []
fast-blocks = []
17 changes: 14 additions & 3 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ impl<T: Config> Pallet<T> {
// --- 3. Drain the subnet block emission and accumulate it as subnet emission, which increases until the tempo is reached in #4.
// subnet_blockwise_emission -> subnet_pending_emission
for netuid in subnets.clone().iter() {
if *netuid == 0 {
continue;
}
// --- 3.1 Get the network's block-wise emission amount.
// This value is newly minted TAO which has not reached staking accounts yet.
let subnet_blockwise_emission: u64 = EmissionValues::<T>::get(*netuid);
Expand Down Expand Up @@ -87,6 +90,11 @@ impl<T: Config> Pallet<T> {
Self::set_blocks_since_last_step(*netuid, 0);
Self::set_last_mechanism_step_block(*netuid, current_block);

if *netuid == 0 {
// Skip netuid 0 payouts
continue;
}

// --- 4.4 Distribute owner take.
if SubnetOwner::<T>::contains_key(netuid) {
// Does the subnet have an owner?
Expand Down Expand Up @@ -295,8 +303,8 @@ impl<T: Config> Pallet<T> {
// --- 8 Iterate over each nominator.
if total_viable_nominator_stake != 0 {
for (nominator, nominator_stake) in Stake::<T>::iter_prefix(hotkey) {
// --- 9 Check if the stake was manually increased by the user since the last emission drain for this hotkey.
// If it was, skip this nominator as they will not receive their proportion of the emission.
// --- 9 Skip emission for any stake the was added by the nominator since the last emission drain.
// This means the nominator will get emission on existing stake, but not on new stake, until the next emission drain.
let viable_nominator_stake =
nominator_stake.saturating_sub(Self::get_nonviable_stake(hotkey, &nominator));

Expand All @@ -323,7 +331,10 @@ impl<T: Config> Pallet<T> {
let hotkey_new_tao: u64 = hotkey_take.saturating_add(remainder);
Self::increase_stake_on_hotkey_account(hotkey, hotkey_new_tao);

// --- 14 Record new tao creation event and return the amount created.
// --- 14 Reset the stake delta for the hotkey.
let _ = StakeDeltaSinceLastEmissionDrain::<T>::clear_prefix(hotkey, u32::MAX, None);

// --- 15 Record new tao creation event and return the amount created.
total_new_tao = total_new_tao.saturating_add(hotkey_new_tao);
total_new_tao
}
Expand Down
Loading

0 comments on commit 6c9c832

Please sign in to comment.