Skip to content

Commit 657f640

Browse files
committed
pos wip
1 parent c1c9f47 commit 657f640

File tree

6 files changed

+69
-38
lines changed

6 files changed

+69
-38
lines changed

node/src/chain_spec/localnet.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ pub fn localnet_config() -> Result<ChainSpec, String> {
4242
// aura | grandpa
4343
vec![
4444
// Keys for debug
45-
authority_keys_from_seed("Alice"),
45+
// authority_keys_from_seed("Alice"),
4646
authority_keys_from_seed("Bob"),
47+
authority_keys_from_seed("Charlie"),
48+
authority_keys_from_seed("Dave"),
4749
],
4850
// Pre-funded accounts
4951
true,
@@ -83,9 +85,8 @@ fn localnet_genesis(
8385
),
8486
];
8587

86-
const STASH: u64 = 100 * UNITS;
8788
for a in initial_authorities.iter() {
88-
balances.push((a.0.clone(), STASH.into()));
89+
balances.push((a.0.clone(), 2000000000000u128));
8990
}
9091

9192
// Check if the environment variable is set
@@ -109,6 +110,7 @@ fn localnet_genesis(
109110
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
110111
];
111112

113+
const STAKE: u64 = 1000 * UNITS;
112114
serde_json::json!({
113115
"balances": { "balances": balances },
114116
"session": {
@@ -132,7 +134,7 @@ fn localnet_genesis(
132134
"validatorCount": initial_authorities.len() as u32,
133135
"stakers": initial_authorities
134136
.iter()
135-
.map(|x| (x.0.clone(), x.0.clone(), STASH, StakerStatus::<AccountId>::Validator))
137+
.map(|x| (x.0.clone(), x.0.clone(), STAKE, StakerStatus::<AccountId>::Validator))
136138
.collect::<Vec<_>>(),
137139
"invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::<Vec<_>>(),
138140
"forceEra": Forcing::NotForcing,

pallets/subtensor/src/coinbase/root.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -332,29 +332,41 @@ impl<T: Config> Pallet<T> {
332332
if blocks_until_next_epoch != 0 {
333333
// Not the block to update emission values.
334334
log::debug!("blocks_until_next_epoch: {:?}", blocks_until_next_epoch);
335-
return Err("");
335+
// return Err("");
336336
}
337337

338338
// --- 2. Retrieves the number of root validators on subnets.
339339
let n: u16 = Self::get_num_root_validators();
340340
log::debug!("n:\n{:?}\n", n);
341341
if n == 0 {
342342
// No validators.
343-
return Err("No validators to validate emission values.");
343+
// return Err("No validators to validate emission values.");
344344
}
345345

346346
// --- 3. Obtains the number of registered subnets.
347347
let k: u16 = Self::get_all_subnet_netuids().len() as u16;
348348
log::debug!("k:\n{:?}\n", k);
349349
if k == 0 {
350350
// No networks to validate.
351-
return Err("No networks to validate emission values.");
351+
// return Err("No networks to validate emission values.");
352352
}
353353

354-
// --- 4. Determines the total block emission across all the subnetworks. This is the
355-
// value which will be distributed based on the computation below.
356-
let block_emission: I64F64 = I64F64::from_num(Self::get_block_emission()?);
357-
log::debug!("block_emission:\n{:?}\n", block_emission);
354+
// --- 4. Determines the total block emission across all the subnetworks, node
355+
// validators and node validator nominators. This is the value which will be
356+
// distributed based on the computation below.
357+
//
358+
// The node validator emission is set aside in a seperate tracked storage for later
359+
// distribution.
360+
let total_block_emission: I64F64 = I64F64::from_num(Self::get_block_emission()?);
361+
let subnetwork_block_emission = total_block_emission.saturating_mul(I64F64::from_num(0.2));
362+
let node_validator_block_emission = total_block_emission.saturating_mul(I64F64::from_num(0.8));
363+
PendingNodeValidatorEmissions::<T>::mutate(|cur| {
364+
cur.saturating_accrue(node_validator_block_emission.to_num::<u64>());
365+
});
366+
367+
log::debug!("total_block_emission:\n{:?}\n", total_block_emission);
368+
log::debug!("node_validator_block_emission:\n{:?}\n", node_validator_block_emission);
369+
log::debug!("subnetwork_block_emission:\n{:?}\n", subnetwork_block_emission);
358370

359371
// --- 5. A collection of all registered hotkeys on the root network. Hotkeys
360372
// pairs with network UIDs and stake values.
@@ -449,7 +461,7 @@ impl<T: Config> Pallet<T> {
449461
// -- 11. Converts the normalized 64-bit fixed point rank values to u64 for the final emission calculation.
450462
let emission_as_tao: Vec<I64F64> = weighted_emission
451463
.iter()
452-
.map(|v: &I64F64| v.saturating_mul(block_emission))
464+
.map(|v: &I64F64| v.saturating_mul(subnetwork_block_emission))
453465
.collect();
454466

455467
// --- 12. Converts the normalized 64-bit fixed point rank values to u64 for the final emission calculation.

pallets/subtensor/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,9 @@ pub mod pallet {
885885
/// ITEM( nominator_min_required_stake )
886886
pub type NominatorMinRequiredStake<T> =
887887
StorageValue<_, u64, ValueQuery, DefaultNominatorMinRequiredStake<T>>;
888+
#[pallet::storage]
889+
/// ITEM ( pending_node_validator_emission )
890+
pub type PendingNodeValidatorEmissions<T> = StorageValue<_, u64, ValueQuery>;
888891

889892
/// ============================
890893
/// ==== Subnet Parameters =====

runtime/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ substrate-wasm-builder = { workspace = true, optional = true }
127127
[features]
128128
default = ["std"]
129129
pow-faucet = ["pallet-subtensor/pow-faucet"]
130-
fast-blocks = []
130+
fast-runtime = []
131131
std = [
132132
"frame-try-runtime?/std",
133133
"frame-system-benchmarking?/std",

runtime/src/lib.rs

+3-21
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use scale_info::TypeInfo;
4444
use smallvec::smallvec;
4545
use sp_api::impl_runtime_apis;
4646
use sp_core::{crypto::KeyTypeId, OpaqueMetadata, RuntimeDebug};
47-
use sp_runtime::curve::PiecewiseLinear;
4847
use sp_runtime::traits::OpaqueKeys;
4948
use sp_runtime::transaction_validity::TransactionPriority;
5049
use sp_runtime::Percent;
@@ -215,12 +214,7 @@ pub const BABE_GENESIS_EPOCH_CONFIG: babe_primitives::BabeEpochConfiguration =
215214
/// up by `pallet_aura` to implement `fn slot_duration()`.
216215
///
217216
/// Change this to adjust the block time.
218-
#[cfg(not(feature = "fast-blocks"))]
219-
pub const MILLISECS_PER_BLOCK: u64 = 12000;
220-
221-
/// Fast blocks for development
222-
#[cfg(feature = "fast-blocks")]
223-
pub const MILLISECS_PER_BLOCK: u64 = 250;
217+
pub const MILLISECS_PER_BLOCK: u64 = prod_or_fast!(12_000, 1000);
224218

225219
// NOTE: Currently it is not possible to change the slot duration after the chain has started.
226220
// Attempting to do so will brick block production.
@@ -1343,17 +1337,9 @@ impl pallet_commitments::Config for Runtime {
13431337
type RateLimit = CommitmentRateLimit;
13441338
}
13451339

1346-
#[cfg(not(feature = "fast-blocks"))]
1347-
pub const INITIAL_SUBNET_TEMPO: u16 = 99;
1348-
1349-
#[cfg(feature = "fast-blocks")]
1350-
pub const INITIAL_SUBNET_TEMPO: u16 = 10;
1351-
1352-
#[cfg(not(feature = "fast-blocks"))]
1353-
pub const INITIAL_CHILDKEY_TAKE_RATELIMIT: u64 = 216000; // 30 days at 12 seconds per block
1340+
pub const INITIAL_SUBNET_TEMPO: u16 = prod_or_fast!(99, 10);
13541341

1355-
#[cfg(feature = "fast-blocks")]
1356-
pub const INITIAL_CHILDKEY_TAKE_RATELIMIT: u64 = 5;
1342+
pub const INITIAL_CHILDKEY_TAKE_RATELIMIT: u64 = prod_or_fast!(216000, 5); // 30 days at 12 seconds per block
13571343

13581344
// Configure the pallet subtensor.
13591345
parameter_types! {
@@ -2006,9 +1992,6 @@ impl_runtime_apis! {
20061992
}
20071993
}
20081994

2009-
// #[cfg(test)]
2010-
// mod tests {
2011-
20121995
#[test]
20131996
fn check_whitelist() {
20141997
use crate::*;
@@ -2031,4 +2014,3 @@ fn check_whitelist() {
20312014
// System Events
20322015
assert!(whitelist.contains("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7"));
20332016
}
2034-
// }

scripts/localnet.sh

+36-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ else
3131
echo "fast_runtime is On"
3232
: "${CHAIN:=local}"
3333
: "${BUILD_BINARY:=1}"
34-
: "${FEATURES:="pow-faucet fast-blocks"}"
34+
: "${FEATURES:="pow-faucet fast-runtime"}"
3535
fi
3636

3737
SPEC_PATH="${SCRIPT_DIR}/specs/"
@@ -54,14 +54,16 @@ fi
5454

5555
echo "*** Building chainspec..."
5656
"$BASE_DIR/target/release/node-subtensor" build-spec --disable-default-bootnode --raw --chain $CHAIN >$FULL_PATH
57-
echo "*** Chainspec built and output to file"
57+
echo "*** Chainspec built and output to $FULL_PATH"
5858

5959
if [ $NO_PURGE -eq 1 ]; then
6060
echo "*** Purging previous state skipped..."
6161
else
6262
echo "*** Purging previous state..."
6363
"$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/bob --chain="$FULL_PATH" >/dev/null 2>&1
6464
"$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/alice --chain="$FULL_PATH" >/dev/null 2>&1
65+
"$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/charlie --chain="$FULL_PATH" >/dev/null 2>&1
66+
"$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/dave --chain="$FULL_PATH" >/dev/null 2>&1
6567
echo "*** Previous chainstate purged"
6668
fi
6769

@@ -94,10 +96,40 @@ bob_start=(
9496
--unsafe-force-node-key-generation
9597
)
9698

99+
charlie_start=(
100+
"$BASE_DIR"/target/release/node-subtensor
101+
--base-path /tmp/charlie
102+
--chain="$FULL_PATH"
103+
--charlie
104+
--port 30335
105+
--rpc-port 9944
106+
--validator
107+
--rpc-cors=all
108+
--allow-private-ipv4
109+
--discover-local
110+
--unsafe-force-node-key-generation
111+
)
112+
113+
dave_start=(
114+
"$BASE_DIR"/target/release/node-subtensor
115+
--base-path /tmp/dave
116+
--chain="$FULL_PATH"
117+
--dave
118+
--port 30335
119+
--rpc-port 9943
120+
--validator
121+
--rpc-cors=all
122+
--allow-private-ipv4
123+
--discover-local
124+
--unsafe-force-node-key-generation
125+
)
126+
97127
trap 'pkill -P $$' EXIT SIGINT SIGTERM
98128

99129
(
100-
("${alice_start[@]}" 2>&1) &
101-
("${bob_start[@]}" 2>&1)
130+
# ("${alice_start[@]}" 2>&1) &
131+
("${bob_start[@]}" 2>&1) &
132+
("${charlie_start[@]}" 2>&1) &
133+
("${dave_start[@]}" 2>&1)
102134
wait
103135
)

0 commit comments

Comments
 (0)