Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/lock tests #739

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 114 additions & 22 deletions node/src/chain_spec/raonet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

use super::*;

/// Generates the configuration for the Raonet chain.
///
/// # Returns
///
/// * `Result<ChainSpec, String>` - The chain specification or an error message.
///
pub fn raonet_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

Expand Down Expand Up @@ -44,95 +50,181 @@ pub fn raonet_config() -> Result<ChainSpec, String> {
.build())
}

/// Generates the genesis configuration for the Raonet chain.
///
/// # Arguments
///
/// * `initial_authorities` - A vector of initial authorities (AuraId, GrandpaId).
/// * `_enable_println` - A boolean flag to enable println (currently unused).
///
/// # Returns
///
/// * `serde_json::Value` - The genesis configuration as a JSON value.
fn raonet_genesis(
initial_authorities: Vec<(AuraId, GrandpaId)>,
_enable_println: bool,
) -> serde_json::Value {
let mut balances = vec![
// Add Alice, Bob, and Charlie with 10 trillion tokens each
(
<AccountId32 as Ss58Codec>::from_ss58check("5FRo4vab84LM3aiK4DijnVawGDKagLGLzfn95j9tjDaHja8Z").unwrap(),
get_account_id_from_seed::<sr25519::Public>("Alice"),
10_000_000_000_000u128,
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
10_000_000_000_000u128,
),
(
get_account_id_from_seed::<sr25519::Public>("Charlie"),
10_000_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check(
"5FRo4vab84LM3aiK4DijnVawGDKagLGLzfn95j9tjDaHja8Z",
)
.unwrap(),
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5H3qhPGzKMNV9fTPuizxzp8azyFRMd4BnheSuwN9Qxb5Cz3u").unwrap(), // Greg
<AccountId32 as Ss58Codec>::from_ss58check(
"5H3qhPGzKMNV9fTPuizxzp8azyFRMd4BnheSuwN9Qxb5Cz3u",
)
.unwrap(), // Greg
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5H8zkg8K9hkM5PSeumivNXGuK8J8cUjtwEL9PfyqmgWELPka").unwrap(), // William
<AccountId32 as Ss58Codec>::from_ss58check(
"5H8zkg8K9hkM5PSeumivNXGuK8J8cUjtwEL9PfyqmgWELPka",
)
.unwrap(), // William
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5Ckg2z5NdrfbXpsPtZuVYXxRWh283QWw1gbXfN8CJC3tmxnY").unwrap(), // Dick
<AccountId32 as Ss58Codec>::from_ss58check(
"5Ckg2z5NdrfbXpsPtZuVYXxRWh283QWw1gbXfN8CJC3tmxnY",
)
.unwrap(), // Dick
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5CiUxGA5dTh1cPdgH67Kt62x4w5aKubnmWZMYSrZzoB4hpQi").unwrap(), // Michal
<AccountId32 as Ss58Codec>::from_ss58check(
"5CiUxGA5dTh1cPdgH67Kt62x4w5aKubnmWZMYSrZzoB4hpQi",
)
.unwrap(), // Michal
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5FLHD4eZkPStKUG7p9B1VPjD4w93Fxncf6JG5EK2uRcELmJy").unwrap(), // Carlos
<AccountId32 as Ss58Codec>::from_ss58check(
"5FLHD4eZkPStKUG7p9B1VPjD4w93Fxncf6JG5EK2uRcELmJy",
)
.unwrap(), // Carlos
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5G4FseBtaQd8sqeC98ZEL7xgtF2GSdueMXwUs8vsBENs4Ysn").unwrap(), // Sai
<AccountId32 as Ss58Codec>::from_ss58check(
"5G4FseBtaQd8sqeC98ZEL7xgtF2GSdueMXwUs8vsBENs4Ysn",
)
.unwrap(), // Sai
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5DiJqQoQdpgKaLz97Fk8ZkChAxMqf2mF2pVa6xDKYH8Cf9Sx").unwrap(), // Xavier
<AccountId32 as Ss58Codec>::from_ss58check(
"5DiJqQoQdpgKaLz97Fk8ZkChAxMqf2mF2pVa6xDKYH8Cf9Sx",
)
.unwrap(), // Xavier
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5EUJyRh3x9QftnUw7taFk3Xen6fCQgdc9ko8ort51RnR6LCn").unwrap(), // Elo
<AccountId32 as Ss58Codec>::from_ss58check(
"5EUJyRh3x9QftnUw7taFk3Xen6fCQgdc9ko8ort51RnR6LCn",
)
.unwrap(), // Elo
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5FREUpwG4wJYr1Usyp1i5XmxM3ycGTfvtjJtrSZETPgvh4Hx").unwrap(), // Roman
<AccountId32 as Ss58Codec>::from_ss58check(
"5FREUpwG4wJYr1Usyp1i5XmxM3ycGTfvtjJtrSZETPgvh4Hx",
)
.unwrap(), // Roman
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5GxREgL1Kvuv1kixbY2oJe36Q2HnWqTcfakBZqTPKWiPpVxf").unwrap(), // Abe
<AccountId32 as Ss58Codec>::from_ss58check(
"5GxREgL1Kvuv1kixbY2oJe36Q2HnWqTcfakBZqTPKWiPpVxf",
)
.unwrap(), // Abe
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5GsSxM8p1TYrpXfCx7Un5cTp1fr1RwHJczYDUUn8Xjnqj9Sk").unwrap(), // Nico
<AccountId32 as Ss58Codec>::from_ss58check(
"5GsSxM8p1TYrpXfCx7Un5cTp1fr1RwHJczYDUUn8Xjnqj9Sk",
)
.unwrap(), // Nico
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5HjEUemUaXSkxPcxGYiLykHmi5VfXBh5NCeNXYMbj9akYHbn").unwrap(), // Jip
<AccountId32 as Ss58Codec>::from_ss58check(
"5HjEUemUaXSkxPcxGYiLykHmi5VfXBh5NCeNXYMbj9akYHbn",
)
.unwrap(), // Jip
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5DUFdkP4rJrkXq9pfrWMHQS8zgiwXBZRgw2MMEAnBot59Taz").unwrap(), // Bob
<AccountId32 as Ss58Codec>::from_ss58check(
"5DUFdkP4rJrkXq9pfrWMHQS8zgiwXBZRgw2MMEAnBot59Taz",
)
.unwrap(), // Bob
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5CoSC9nRDT4CbnEGLCHcC8PxgpJsWpSdF3RLnTx2aBvX3qPu").unwrap(), // Faybian
<AccountId32 as Ss58Codec>::from_ss58check(
"5CoSC9nRDT4CbnEGLCHcC8PxgpJsWpSdF3RLnTx2aBvX3qPu",
)
.unwrap(), // Faybian
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5CXgmrp6Ts5igz9uxSdQQy9ERUVaJFtswzaSBUXhb3Ci7drK").unwrap(), // Special K
<AccountId32 as Ss58Codec>::from_ss58check(
"5CXgmrp6Ts5igz9uxSdQQy9ERUVaJFtswzaSBUXhb3Ci7drK",
)
.unwrap(), // Special K
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5HDpGZLNYSxHGWVhsPgKRDKVM6oob7MMnwxdpU8dBP7N51dX").unwrap(), // Michal
<AccountId32 as Ss58Codec>::from_ss58check(
"5HDpGZLNYSxHGWVhsPgKRDKVM6oob7MMnwxdpU8dBP7N51dX",
)
.unwrap(), // Michal
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5GH3haJWuJjcZWuC7iFGtaVajJNEpNg2Guaqyf71y9uDfFrt").unwrap(), // Isa
<AccountId32 as Ss58Codec>::from_ss58check(
"5GH3haJWuJjcZWuC7iFGtaVajJNEpNg2Guaqyf71y9uDfFrt",
)
.unwrap(), // Isa
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5HTukLb2y59rrL5tM9RMw3baziCFZUeSZATWMWHgSrNknc9A").unwrap(), // Gus
<AccountId32 as Ss58Codec>::from_ss58check(
"5HTukLb2y59rrL5tM9RMw3baziCFZUeSZATWMWHgSrNknc9A",
)
.unwrap(), // Gus
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5CkV7PPFWh8EihTK5uLm7VNF4C9hiKJ9UeJJwQuByn3bx82L").unwrap(), // Carrot
<AccountId32 as Ss58Codec>::from_ss58check(
"5CkV7PPFWh8EihTK5uLm7VNF4C9hiKJ9UeJJwQuByn3bx82L",
)
.unwrap(), // Carrot
100_000_000_000u128,
),
(
<AccountId32 as Ss58Codec>::from_ss58check("5DV8tTjq8EXE6KmoCbJ3xaN54HTXsfev5ZyKJEQPyTcm4MmE").unwrap(), // Paul
<AccountId32 as Ss58Codec>::from_ss58check(
"5DV8tTjq8EXE6KmoCbJ3xaN54HTXsfev5ZyKJEQPyTcm4MmE",
)
.unwrap(), // Paul
100_000_000_000u128,
)
),
];

// Check if the environment variable is set
Expand Down
1 change: 0 additions & 1 deletion pallets/subtensor/src/staking/add_stake.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::*;
// use substrate_fixed::types::I96F32;

impl<T: Config> Pallet<T> {
/// ---- The implementation for the extrinsic add_stake: Adds stake to a hotkey account.
Expand Down
17 changes: 11 additions & 6 deletions pallets/subtensor/src/staking/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<T: Config> Pallet<T> {
netuid: u16,
) -> u64 {
let (locked, _, end) = Locks::<T>::get((netuid, hotkey.clone(), coldkey.clone()));

Self::calculate_conviction(locked, end, Self::get_current_block_as_u64())
}

Expand Down Expand Up @@ -318,8 +318,8 @@ impl<T: Config> Pallet<T> {

// Set the total subnet Conviction.
let largest_conviction = convictions.iter().max().cloned().unwrap_or(1);
SubnetLocked::<T>::insert( netuid, total_conviction ) ;
LargestLocked::<T>::insert( netuid, largest_conviction );
SubnetLocked::<T>::insert(netuid, total_conviction);
LargestLocked::<T>::insert(netuid, largest_conviction);

// Calculate shares using the lion's share distribution
let shares: Vec<I96F32> = Self::calculate_lions_share(convictions, 20);
Expand Down Expand Up @@ -463,19 +463,25 @@ impl<T: Config> Pallet<T> {
// Handle the case where no locks exist for the subnet
if hotkey_convictions.is_empty() {
log::warn!("No locks found for subnet {}", netuid);
SubnetOwner::<T>::remove(netuid);
SubnetLocked::<T>::remove(netuid);
return;
}

// Implement a minimum conviction threshold for becoming a subnet owner
let min_conviction_threshold = I96F32::from_num(1000); // Example threshold, adjust as needed
if max_total_conviction < min_conviction_threshold {
SubnetOwner::<T>::remove(netuid);
SubnetLocked::<T>::remove(netuid);
return;
}

// Set the subnet owner to the coldkey of the hotkey with highest conviction
if let Some(hotkey) = max_conviction_hotkey {
let owning_coldkey = Self::get_owning_coldkey_for_hotkey(&hotkey);
SubnetOwner::<T>::insert(netuid, owning_coldkey.clone());
// Set the SubnetLocked value to the maximum conviction
SubnetLocked::<T>::insert(netuid, max_total_conviction.to_num::<u64>());
}

// Implement a tie-breaking mechanism for equal conviction scores
Expand All @@ -486,8 +492,7 @@ impl<T: Config> Pallet<T> {

if tied_hotkeys.len() > 1 {
// Use a deterministic method to break ties, e.g., lowest hotkey value
if let Some((winning_hotkey, _)) =
tied_hotkeys.iter().min_by_key(|(hotkey, _)| hotkey)
if let Some((winning_hotkey, _)) = tied_hotkeys.iter().min_by_key(|(hotkey, _)| hotkey)
{
let owning_coldkey = Self::get_owning_coldkey_for_hotkey(winning_hotkey);
SubnetOwner::<T>::insert(netuid, owning_coldkey.clone());
Expand Down Expand Up @@ -536,7 +541,7 @@ impl<T: Config> Pallet<T> {
-I96F32::from_num(lock_duration).saturating_div(I96F32::from_num(lock_interval_blocks));
let exp_term = I96F32::from_num(1) - exp_safe_f96(I96F32::from_num(time_factor));
let conviction_score = I96F32::from_num(lock_amount).saturating_mul(exp_term);

conviction_score.to_num::<u64>()
}

Expand Down
Loading
Loading