Skip to content

Commit 925dd85

Browse files
committed
Merge branch 'devnet-ready' into serve-axon-promethoeus
2 parents 77f343f + fc49aca commit 925dd85

File tree

8 files changed

+593
-102
lines changed

8 files changed

+593
-102
lines changed

pallets/admin-utils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub mod pallet {
158158
netuid: u16,
159159
min_difficulty: u64,
160160
) -> DispatchResult {
161-
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;
161+
ensure_root(origin)?;
162162

163163
ensure!(
164164
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),

pallets/subtensor/src/coinbase/run_coinbase.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<T: Config> Pallet<T> {
8787
let alpha_out_i = alpha_emission_i;
8888
// Only emit TAO if the subnetwork allows registration.
8989
if !Self::get_network_registration_allowed(*netuid_i)
90-
&& Self::get_network_pow_registration_allowed(*netuid_i)
90+
&& !Self::get_network_pow_registration_allowed(*netuid_i)
9191
{
9292
tao_in_i = asfloat!(0.0);
9393
}
@@ -249,11 +249,6 @@ impl<T: Config> Pallet<T> {
249249
BlocksSinceLastStep::<T>::mutate(netuid, |total| *total = total.saturating_add(1));
250250
}
251251
}
252-
253-
// --- 8. Apply pending childkeys of this subnet for the next epoch
254-
for netuid in subnets.iter() {
255-
Self::do_set_pending_children(*netuid);
256-
}
257252
}
258253

259254
pub fn drain_pending_emission(

pallets/subtensor/src/lib.rs

Lines changed: 183 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,18 @@ pub mod pallet {
15501550
pub type RevealPeriodEpochs<T: Config> =
15511551
StorageMap<_, Twox64Concat, u16, u64, ValueQuery, DefaultRevealPeriodEpochs<T>>;
15521552

1553+
#[pallet::storage]
1554+
/// --- Map (coldkey, hotkey) --> u64 the last block at which stake was added/removed.
1555+
pub type LastColdkeyHotkeyStakeBlock<T: Config> = StorageDoubleMap<
1556+
_,
1557+
Twox64Concat,
1558+
T::AccountId,
1559+
Twox64Concat,
1560+
T::AccountId,
1561+
u64,
1562+
OptionQuery,
1563+
>;
1564+
15531565
/// ==================
15541566
/// ==== Genesis =====
15551567
/// ==================
@@ -1588,6 +1600,19 @@ pub mod pallet {
15881600
0
15891601
}
15901602

1603+
/// Returns the transaction priority for stake operations.
1604+
pub fn get_priority_staking(coldkey: &T::AccountId, hotkey: &T::AccountId) -> u64 {
1605+
match LastColdkeyHotkeyStakeBlock::<T>::get(coldkey, hotkey) {
1606+
Some(last_stake_block) => {
1607+
let current_block_number = Self::get_current_block_as_u64();
1608+
let default_priority = current_block_number.saturating_sub(last_stake_block);
1609+
1610+
default_priority.saturating_add(u32::MAX as u64)
1611+
}
1612+
None => 0,
1613+
}
1614+
}
1615+
15911616
/// Is the caller allowed to set weights
15921617
pub fn check_weights_min_stake(hotkey: &T::AccountId, netuid: u16) -> bool {
15931618
// Blacklist weights transactions for low stake peers.
@@ -1705,11 +1730,15 @@ where
17051730
Pallet::<T>::get_priority_set_weights(who, netuid)
17061731
}
17071732

1733+
pub fn get_priority_staking(coldkey: &T::AccountId, hotkey: &T::AccountId) -> u64 {
1734+
Pallet::<T>::get_priority_staking(coldkey, hotkey)
1735+
}
1736+
17081737
pub fn check_weights_min_stake(who: &T::AccountId, netuid: u16) -> bool {
17091738
Pallet::<T>::check_weights_min_stake(who, netuid)
17101739
}
17111740

1712-
pub fn result_to_validity(result: Result<(), Error<T>>) -> TransactionValidity {
1741+
pub fn result_to_validity(result: Result<(), Error<T>>, priority: u64) -> TransactionValidity {
17131742
if let Err(err) = result {
17141743
match err {
17151744
Error::<T>::AmountTooLow => Err(InvalidTransaction::Custom(
@@ -1750,7 +1779,7 @@ where
17501779
}
17511780
} else {
17521781
Ok(ValidTransaction {
1753-
priority: Self::get_priority_vanilla(),
1782+
priority,
17541783
..Default::default()
17551784
})
17561785
}
@@ -1885,15 +1914,24 @@ where
18851914
netuid,
18861915
amount_staked,
18871916
}) => {
1917+
if ColdkeySwapScheduled::<T>::contains_key(who) {
1918+
return InvalidTransaction::Custom(
1919+
CustomTransactionError::ColdkeyInSwapSchedule.into(),
1920+
)
1921+
.into();
1922+
}
18881923
// Fully validate the user input
1889-
Self::result_to_validity(Pallet::<T>::validate_add_stake(
1890-
who,
1891-
hotkey,
1892-
*netuid,
1893-
*amount_staked,
1894-
*amount_staked,
1895-
false,
1896-
))
1924+
Self::result_to_validity(
1925+
Pallet::<T>::validate_add_stake(
1926+
who,
1927+
hotkey,
1928+
*netuid,
1929+
*amount_staked,
1930+
*amount_staked,
1931+
false,
1932+
),
1933+
Self::get_priority_staking(who, hotkey),
1934+
)
18971935
}
18981936
Some(Call::add_stake_limit {
18991937
hotkey,
@@ -1902,33 +1940,46 @@ where
19021940
limit_price,
19031941
allow_partial,
19041942
}) => {
1943+
if ColdkeySwapScheduled::<T>::contains_key(who) {
1944+
return InvalidTransaction::Custom(
1945+
CustomTransactionError::ColdkeyInSwapSchedule.into(),
1946+
)
1947+
.into();
1948+
}
1949+
19051950
// Calcaulate the maximum amount that can be executed with price limit
19061951
let max_amount = Pallet::<T>::get_max_amount_add(*netuid, *limit_price);
19071952

19081953
// Fully validate the user input
1909-
Self::result_to_validity(Pallet::<T>::validate_add_stake(
1910-
who,
1911-
hotkey,
1912-
*netuid,
1913-
*amount_staked,
1914-
max_amount,
1915-
*allow_partial,
1916-
))
1954+
Self::result_to_validity(
1955+
Pallet::<T>::validate_add_stake(
1956+
who,
1957+
hotkey,
1958+
*netuid,
1959+
*amount_staked,
1960+
max_amount,
1961+
*allow_partial,
1962+
),
1963+
Self::get_priority_staking(who, hotkey),
1964+
)
19171965
}
19181966
Some(Call::remove_stake {
19191967
hotkey,
19201968
netuid,
19211969
amount_unstaked,
19221970
}) => {
19231971
// Fully validate the user input
1924-
Self::result_to_validity(Pallet::<T>::validate_remove_stake(
1925-
who,
1926-
hotkey,
1927-
*netuid,
1928-
*amount_unstaked,
1929-
*amount_unstaked,
1930-
false,
1931-
))
1972+
Self::result_to_validity(
1973+
Pallet::<T>::validate_remove_stake(
1974+
who,
1975+
hotkey,
1976+
*netuid,
1977+
*amount_unstaked,
1978+
*amount_unstaked,
1979+
false,
1980+
),
1981+
Self::get_priority_staking(who, hotkey),
1982+
)
19321983
}
19331984
Some(Call::remove_stake_limit {
19341985
hotkey,
@@ -1941,14 +1992,17 @@ where
19411992
let max_amount = Pallet::<T>::get_max_amount_remove(*netuid, *limit_price);
19421993

19431994
// Fully validate the user input
1944-
Self::result_to_validity(Pallet::<T>::validate_remove_stake(
1945-
who,
1946-
hotkey,
1947-
*netuid,
1948-
*amount_unstaked,
1949-
max_amount,
1950-
*allow_partial,
1951-
))
1995+
Self::result_to_validity(
1996+
Pallet::<T>::validate_remove_stake(
1997+
who,
1998+
hotkey,
1999+
*netuid,
2000+
*amount_unstaked,
2001+
max_amount,
2002+
*allow_partial,
2003+
),
2004+
Self::get_priority_staking(who, hotkey),
2005+
)
19522006
}
19532007
Some(Call::move_stake {
19542008
origin_hotkey,
@@ -1957,19 +2011,29 @@ where
19572011
destination_netuid,
19582012
alpha_amount,
19592013
}) => {
2014+
if ColdkeySwapScheduled::<T>::contains_key(who) {
2015+
return InvalidTransaction::Custom(
2016+
CustomTransactionError::ColdkeyInSwapSchedule.into(),
2017+
)
2018+
.into();
2019+
}
2020+
19602021
// Fully validate the user input
1961-
Self::result_to_validity(Pallet::<T>::validate_stake_transition(
1962-
who,
1963-
who,
1964-
origin_hotkey,
1965-
destination_hotkey,
1966-
*origin_netuid,
1967-
*destination_netuid,
1968-
*alpha_amount,
1969-
*alpha_amount,
1970-
None,
1971-
false,
1972-
))
2022+
Self::result_to_validity(
2023+
Pallet::<T>::validate_stake_transition(
2024+
who,
2025+
who,
2026+
origin_hotkey,
2027+
destination_hotkey,
2028+
*origin_netuid,
2029+
*destination_netuid,
2030+
*alpha_amount,
2031+
*alpha_amount,
2032+
None,
2033+
false,
2034+
),
2035+
Self::get_priority_staking(who, origin_hotkey),
2036+
)
19732037
}
19742038
Some(Call::transfer_stake {
19752039
destination_coldkey,
@@ -1978,39 +2042,59 @@ where
19782042
destination_netuid,
19792043
alpha_amount,
19802044
}) => {
2045+
if ColdkeySwapScheduled::<T>::contains_key(who) {
2046+
return InvalidTransaction::Custom(
2047+
CustomTransactionError::ColdkeyInSwapSchedule.into(),
2048+
)
2049+
.into();
2050+
}
2051+
19812052
// Fully validate the user input
1982-
Self::result_to_validity(Pallet::<T>::validate_stake_transition(
1983-
who,
1984-
destination_coldkey,
1985-
hotkey,
1986-
hotkey,
1987-
*origin_netuid,
1988-
*destination_netuid,
1989-
*alpha_amount,
1990-
*alpha_amount,
1991-
None,
1992-
true,
1993-
))
2053+
Self::result_to_validity(
2054+
Pallet::<T>::validate_stake_transition(
2055+
who,
2056+
destination_coldkey,
2057+
hotkey,
2058+
hotkey,
2059+
*origin_netuid,
2060+
*destination_netuid,
2061+
*alpha_amount,
2062+
*alpha_amount,
2063+
None,
2064+
true,
2065+
),
2066+
Self::get_priority_staking(who, hotkey),
2067+
)
19942068
}
19952069
Some(Call::swap_stake {
19962070
hotkey,
19972071
origin_netuid,
19982072
destination_netuid,
19992073
alpha_amount,
20002074
}) => {
2075+
if ColdkeySwapScheduled::<T>::contains_key(who) {
2076+
return InvalidTransaction::Custom(
2077+
CustomTransactionError::ColdkeyInSwapSchedule.into(),
2078+
)
2079+
.into();
2080+
}
2081+
20012082
// Fully validate the user input
2002-
Self::result_to_validity(Pallet::<T>::validate_stake_transition(
2003-
who,
2004-
who,
2005-
hotkey,
2006-
hotkey,
2007-
*origin_netuid,
2008-
*destination_netuid,
2009-
*alpha_amount,
2010-
*alpha_amount,
2011-
None,
2012-
false,
2013-
))
2083+
Self::result_to_validity(
2084+
Pallet::<T>::validate_stake_transition(
2085+
who,
2086+
who,
2087+
hotkey,
2088+
hotkey,
2089+
*origin_netuid,
2090+
*destination_netuid,
2091+
*alpha_amount,
2092+
*alpha_amount,
2093+
None,
2094+
false,
2095+
),
2096+
Self::get_priority_staking(who, hotkey),
2097+
)
20142098
}
20152099
Some(Call::swap_stake_limit {
20162100
hotkey,
@@ -2020,6 +2104,13 @@ where
20202104
limit_price,
20212105
allow_partial,
20222106
}) => {
2107+
if ColdkeySwapScheduled::<T>::contains_key(who) {
2108+
return InvalidTransaction::Custom(
2109+
CustomTransactionError::ColdkeyInSwapSchedule.into(),
2110+
)
2111+
.into();
2112+
}
2113+
20232114
// Get the max amount possible to exchange
20242115
let max_amount = Pallet::<T>::get_max_amount_move(
20252116
*origin_netuid,
@@ -2028,20 +2119,30 @@ where
20282119
);
20292120

20302121
// Fully validate the user input
2031-
Self::result_to_validity(Pallet::<T>::validate_stake_transition(
2032-
who,
2033-
who,
2034-
hotkey,
2035-
hotkey,
2036-
*origin_netuid,
2037-
*destination_netuid,
2038-
*alpha_amount,
2039-
max_amount,
2040-
Some(*allow_partial),
2041-
false,
2042-
))
2122+
Self::result_to_validity(
2123+
Pallet::<T>::validate_stake_transition(
2124+
who,
2125+
who,
2126+
hotkey,
2127+
hotkey,
2128+
*origin_netuid,
2129+
*destination_netuid,
2130+
*alpha_amount,
2131+
max_amount,
2132+
Some(*allow_partial),
2133+
false,
2134+
),
2135+
Self::get_priority_staking(who, hotkey),
2136+
)
20432137
}
20442138
Some(Call::register { netuid, .. } | Call::burned_register { netuid, .. }) => {
2139+
if ColdkeySwapScheduled::<T>::contains_key(who) {
2140+
return InvalidTransaction::Custom(
2141+
CustomTransactionError::ColdkeyInSwapSchedule.into(),
2142+
)
2143+
.into();
2144+
}
2145+
20452146
let registrations_this_interval =
20462147
Pallet::<T>::get_registrations_this_interval(*netuid);
20472148
let max_registrations_per_interval =

0 commit comments

Comments
 (0)