Skip to content

Commit 2456428

Browse files
committed
merge with target branch
2 parents fcc482a + f0ceef7 commit 2456428

File tree

23 files changed

+1618
-193
lines changed

23 files changed

+1618
-193
lines changed

Cargo.lock

Lines changed: 5 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ substrate-prometheus-endpoint = { workspace = true }
9595
fc-storage = { workspace = true }
9696
fc-db = { workspace = true }
9797
fc-consensus = { workspace = true }
98-
fp-dynamic-fee = { workspace = true }
9998
fc-api = { workspace = true }
10099
fc-rpc = { workspace = true }
101100
fc-rpc-core = { workspace = true }

node/src/ethereum.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ pub struct EthConfiguration {
5656
#[arg(long)]
5757
pub enable_dev_signer: bool,
5858

59-
/// The dynamic-fee pallet target gas price set by block author
60-
#[arg(long, default_value = "1")]
61-
pub target_gas_price: u64,
62-
6359
/// Maximum allowed gas limit will be `block.gas_limit * execute_gas_limit_multiplier`
6460
/// when using eth_call/eth_estimateGas.
6561
#[arg(long, default_value = "10")]

node/src/service.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use sp_api::ProvideRuntimeApi;
1919
use sp_block_builder::BlockBuilder as BlockBuilderApi;
2020
use sp_consensus::Error as ConsensusError;
2121
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
22-
use sp_core::U256;
2322
use sp_runtime::traits::{Block as BlockT, Header, NumberFor};
2423
use std::{cell::RefCell, path::Path};
2524
use std::{marker::PhantomData, sync::Arc, time::Duration};
@@ -279,7 +278,7 @@ where
279278
pub fn build_aura_grandpa_import_queue(
280279
client: Arc<FullClient>,
281280
config: &Configuration,
282-
eth_config: &EthConfiguration,
281+
_eth_config: &EthConfiguration,
283282
task_manager: &TaskManager,
284283
telemetry: Option<TelemetryHandle>,
285284
grandpa_block_import: GrandpaBlockImport,
@@ -294,16 +293,14 @@ where
294293
);
295294

296295
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
297-
let target_gas_price = eth_config.target_gas_price;
298296
let create_inherent_data_providers = move |_, ()| async move {
299297
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
300298
let slot =
301299
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
302300
*timestamp,
303301
slot_duration,
304302
);
305-
let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price));
306-
Ok((slot, timestamp, dynamic_fee))
303+
Ok((slot, timestamp))
307304
};
308305

309306
let import_queue = sc_consensus_aura::import_queue::<AuraPair, _, _, _, _, _>(
@@ -521,7 +518,6 @@ where
521518
));
522519

523520
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
524-
let target_gas_price = eth_config.target_gas_price;
525521
let pending_create_inherent_data_providers = move |_, ()| async move {
526522
let current = sp_timestamp::InherentDataProvider::from_system_time();
527523
let next_slot = current
@@ -533,8 +529,7 @@ where
533529
*timestamp,
534530
slot_duration,
535531
);
536-
let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price));
537-
Ok((slot, timestamp, dynamic_fee))
532+
Ok((slot, timestamp))
538533
};
539534

540535
Box::new(move |subscription_task_executor| {
@@ -613,7 +608,6 @@ where
613608
// manual-seal authorship
614609
if let Some(sealing) = sealing {
615610
run_manual_seal_authorship(
616-
&eth_config,
617611
sealing,
618612
client,
619613
transaction_pool,
@@ -639,15 +633,13 @@ where
639633
);
640634

641635
let slot_duration = sc_consensus_aura::slot_duration(&*client)?;
642-
let target_gas_price = eth_config.target_gas_price;
643636
let create_inherent_data_providers = move |_, ()| async move {
644637
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
645638
let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
646639
*timestamp,
647640
slot_duration,
648641
);
649-
let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price));
650-
Ok((slot, timestamp, dynamic_fee))
642+
Ok((slot, timestamp))
651643
};
652644

653645
let aura = sc_consensus_aura::start_aura::<AuraPair, _, _, _, _, _, _, _, _, _, _>(
@@ -770,7 +762,6 @@ pub fn new_chain_ops(
770762

771763
#[allow(clippy::too_many_arguments)]
772764
fn run_manual_seal_authorship(
773-
eth_config: &EthConfiguration,
774765
sealing: Sealing,
775766
client: Arc<FullClient>,
776767
transaction_pool: Arc<FullPool<Block, FullClient>>,
@@ -820,12 +811,8 @@ fn run_manual_seal_authorship(
820811
}
821812
}
822813

823-
let target_gas_price = eth_config.target_gas_price;
824-
let create_inherent_data_providers = move |_, ()| async move {
825-
let timestamp = MockTimestampInherentDataProvider;
826-
let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price));
827-
Ok((timestamp, dynamic_fee))
828-
};
814+
let create_inherent_data_providers =
815+
move |_, ()| async move { Ok(MockTimestampInherentDataProvider) };
829816

830817
let manual_seal = match sealing {
831818
Sealing::Manual => future::Either::Left(sc_consensus_manual_seal::run_manual_seal(

pallets/subtensor/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,8 @@ where
18871887
*origin_netuid,
18881888
*destination_netuid,
18891889
*alpha_amount,
1890+
*alpha_amount,
1891+
None,
18901892
))
18911893
}
18921894
Some(Call::transfer_stake {
@@ -1905,6 +1907,8 @@ where
19051907
*origin_netuid,
19061908
*destination_netuid,
19071909
*alpha_amount,
1910+
*alpha_amount,
1911+
None,
19081912
))
19091913
}
19101914
Some(Call::swap_stake {
@@ -1922,6 +1926,36 @@ where
19221926
*origin_netuid,
19231927
*destination_netuid,
19241928
*alpha_amount,
1929+
*alpha_amount,
1930+
None,
1931+
))
1932+
}
1933+
Some(Call::swap_stake_limit {
1934+
hotkey,
1935+
origin_netuid,
1936+
destination_netuid,
1937+
alpha_amount,
1938+
limit_price,
1939+
allow_partial,
1940+
}) => {
1941+
// Get the max amount possible to exchange
1942+
let max_amount = Pallet::<T>::get_max_amount_move(
1943+
*origin_netuid,
1944+
*destination_netuid,
1945+
*limit_price,
1946+
);
1947+
1948+
// Fully validate the user input
1949+
Self::result_to_validity(Pallet::<T>::validate_stake_transition(
1950+
who,
1951+
who,
1952+
hotkey,
1953+
hotkey,
1954+
*origin_netuid,
1955+
*destination_netuid,
1956+
*alpha_amount,
1957+
max_amount,
1958+
Some(*allow_partial),
19251959
))
19261960
}
19271961
Some(Call::register { netuid, .. } | Call::burned_register { netuid, .. }) => {

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,10 +1769,10 @@ mod dispatches {
17691769
/// - The amount of stake to be added to the hotkey staking account.
17701770
///
17711771
/// * 'limit_price' (u64):
1772-
/// - The limit price expressed in units of RAO per one Alpha.
1772+
/// - The limit price expressed in units of RAO per one Alpha.
17731773
///
17741774
/// * 'allow_partial' (bool):
1775-
/// - Allows partial execution of the amount. If set to false, this becomes
1775+
/// - Allows partial execution of the amount. If set to false, this becomes
17761776
/// fill or kill type or order.
17771777
///
17781778
/// # Event:
@@ -1811,5 +1811,52 @@ mod dispatches {
18111811
allow_partial,
18121812
)
18131813
}
1814+
1815+
/// Swaps a specified amount of stake from one subnet to another, while keeping the same coldkey and hotkey.
1816+
///
1817+
/// # Arguments
1818+
/// * `origin` - The origin of the transaction, which must be signed by the coldkey that owns the `hotkey`.
1819+
/// * `hotkey` - The hotkey whose stake is being swapped.
1820+
/// * `origin_netuid` - The network/subnet ID from which stake is removed.
1821+
/// * `destination_netuid` - The network/subnet ID to which stake is added.
1822+
/// * `alpha_amount` - The amount of stake to swap.
1823+
/// * `limit_price` - The limit price expressed in units of RAO per one Alpha.
1824+
/// * `allow_partial` - Allows partial execution of the amount. If set to false, this becomes fill or kill type or order.
1825+
///
1826+
/// # Errors
1827+
/// Returns an error if:
1828+
/// * The transaction is not signed by the correct coldkey (i.e., `coldkey_owns_hotkey` fails).
1829+
/// * Either `origin_netuid` or `destination_netuid` does not exist.
1830+
/// * The hotkey does not exist.
1831+
/// * There is insufficient stake on `(coldkey, hotkey, origin_netuid)`.
1832+
/// * The swap amount is below the minimum stake requirement.
1833+
///
1834+
/// # Events
1835+
/// May emit a `StakeSwapped` event on success.
1836+
#[pallet::call_index(90)]
1837+
#[pallet::weight((
1838+
Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().writes(1)),
1839+
DispatchClass::Operational,
1840+
Pays::No
1841+
))]
1842+
pub fn swap_stake_limit(
1843+
origin: T::RuntimeOrigin,
1844+
hotkey: T::AccountId,
1845+
origin_netuid: u16,
1846+
destination_netuid: u16,
1847+
alpha_amount: u64,
1848+
limit_price: u64,
1849+
allow_partial: bool,
1850+
) -> DispatchResult {
1851+
Self::do_swap_stake_limit(
1852+
origin,
1853+
hotkey,
1854+
origin_netuid,
1855+
destination_netuid,
1856+
alpha_amount,
1857+
limit_price,
1858+
allow_partial,
1859+
)
1860+
}
18141861
}
18151862
}

pallets/subtensor/src/macros/hooks.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ mod hooks {
7676
// Migrate to RAO
7777
.saturating_add(migrations::migrate_rao::migrate_rao::<T>())
7878
// Fix the IsNetworkMember map to be consistent with other storage maps
79-
.saturating_add(migrations::migrate_fix_is_network_member::migrate_fix_is_network_member::<T>());
79+
.saturating_add(migrations::migrate_fix_is_network_member::migrate_fix_is_network_member::<T>())
80+
.saturating_add(migrations::migrate_subnet_volume::migrate_subnet_volume::<T>());
8081
weight
8182
}
8283

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use super::*;
2+
use alloc::string::String;
3+
use frame_support::{traits::Get, weights::Weight};
4+
5+
pub fn migrate_subnet_volume<T: Config>() -> Weight {
6+
let migration_name = b"migrate_subnet_volume".to_vec();
7+
8+
// Initialize the weight with one read operation.
9+
let weight = T::DbWeight::get().reads(1);
10+
11+
// Check if the migration has already run
12+
if HasMigrationRun::<T>::get(&migration_name) {
13+
log::info!(
14+
"Migration '{:?}' has already run. Skipping.",
15+
migration_name
16+
);
17+
return weight;
18+
}
19+
log::info!(
20+
"Running migration '{}'",
21+
String::from_utf8_lossy(&migration_name)
22+
);
23+
24+
let mut migrated = 0u64;
25+
26+
SubnetVolume::<T>::translate::<u64, _>(|_key, old_value| {
27+
migrated = migrated.saturating_add(1);
28+
Some(old_value as u128) // Convert and store as u128
29+
});
30+
31+
log::info!("Migrated {} entries in SubnetVolume", migrated);
32+
weight.saturating_add(T::DbWeight::get().reads_writes(migrated, migrated))
33+
}

pallets/subtensor/src/migrations/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod migrate_populate_owned_hotkeys;
1111
pub mod migrate_populate_staking_hotkeys;
1212
pub mod migrate_rao;
1313
pub mod migrate_stake_threshold;
14+
pub mod migrate_subnet_volume;
1415
pub mod migrate_to_v1_separate_emission;
1516
pub mod migrate_to_v2_fixed_total_stake;
1617
pub mod migrate_total_issuance;

0 commit comments

Comments
 (0)