diff --git a/Cargo.lock b/Cargo.lock index 7e78684b1..4814175e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2435,6 +2435,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -3264,6 +3270,11 @@ name = "hashbrown" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] [[package]] name = "hashlink" @@ -3484,9 +3495,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" dependencies = [ "bytes", "futures-channel", @@ -3520,15 +3531,15 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" +checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" dependencies = [ "bytes", "futures-util", "http 1.1.0", "http-body 1.0.1", - "hyper 1.4.1", + "hyper 1.5.0", "pin-project-lite", "tokio", "tower-service", @@ -3852,9 +3863,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.24.5" +version = "0.24.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "126b48a5acc3c52fbd5381a77898cb60e145123179588a29e7ac48f9c06e401b" +checksum = "c5c71d8c1a731cc4227c2f698d377e7848ca12c8a48866fc5e6951c43a4db843" dependencies = [ "jsonrpsee-core", "jsonrpsee-proc-macros", @@ -3866,9 +3877,9 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.24.5" +version = "0.24.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0e503369a76e195b65af35058add0e6900b794a4e9a9316900ddd3a87a80477" +checksum = "f2882f6f8acb9fdaec7cefc4fd607119a9bd709831df7d7672a1d3b644628280" dependencies = [ "async-trait", "bytes", @@ -3889,9 +3900,9 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.24.5" +version = "0.24.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc660a9389e2748e794a40673a4155d501f32db667757cdb80edeff0306b489b" +checksum = "c06c01ae0007548e73412c08e2285ffe5d723195bf268bce67b1b77c3bb2a14d" dependencies = [ "heck 0.5.0", "proc-macro-crate 3.2.0", @@ -3902,15 +3913,15 @@ dependencies = [ [[package]] name = "jsonrpsee-server" -version = "0.24.5" +version = "0.24.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af6e6c9b6d975edcb443565d648b605f3e85a04ec63aa6941811a8894cc9cded" +checksum = "82ad8ddc14be1d4290cd68046e7d1d37acd408efed6d3ca08aefcc3ad6da069c" dependencies = [ "futures-util", "http 1.1.0", "http-body 1.0.1", "http-body-util", - "hyper 1.4.1", + "hyper 1.5.0", "hyper-util", "jsonrpsee-core", "jsonrpsee-types", @@ -3929,9 +3940,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.24.5" +version = "0.24.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8fb16314327cbc94fdf7965ef7e4422509cd5597f76d137bd104eb34aeede67" +checksum = "a178c60086f24cc35bb82f57c651d0d25d99c4742b4d335de04e97fa1f08a8a1" dependencies = [ "http 1.1.0", "serde", @@ -4110,7 +4121,7 @@ dependencies = [ "libp2p-identity", "log", "multiaddr 0.18.2", - "multihash 0.19.1", + "multihash 0.19.2", "multistream-select", "once_cell", "parking_lot 0.12.3", @@ -4155,7 +4166,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "log", - "lru 0.12.4", + "lru 0.12.5", "quick-protobuf", "quick-protobuf-codec", "smallvec", @@ -4172,7 +4183,7 @@ dependencies = [ "bs58 0.5.1", "ed25519-dalek", "hkdf", - "multihash 0.19.1", + "multihash 0.19.2", "quick-protobuf", "rand", "sha2 0.10.8", @@ -4261,7 +4272,7 @@ dependencies = [ "libp2p-identity", "log", "multiaddr 0.18.2", - "multihash 0.19.1", + "multihash 0.19.2", "once_cell", "quick-protobuf", "rand", @@ -4704,11 +4715,11 @@ dependencies = [ [[package]] name = "lru" -version = "0.12.4" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown 0.14.5", + "hashbrown 0.15.0", ] [[package]] @@ -5040,7 +5051,7 @@ dependencies = [ "data-encoding", "libp2p-identity", "multibase", - "multihash 0.19.1", + "multihash 0.19.2", "percent-encoding", "serde", "static_assertions", @@ -5095,12 +5106,12 @@ dependencies = [ [[package]] name = "multihash" -version = "0.19.1" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076d548d76a0e2a0d4ab471d0b1c36c577786dfc4471242035d97a12a735c492" +checksum = "cc41f430805af9d1cf4adae4ed2149c759b877b01d909a1f40256188d09345d2" dependencies = [ "core2", - "unsigned-varint 0.7.2", + "unsigned-varint 0.8.0", ] [[package]] @@ -5123,12 +5134,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "multimap" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" - [[package]] name = "multistream-select" version = "0.13.0" @@ -5687,9 +5692,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.66" +version = "0.10.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" dependencies = [ "bitflags 2.6.0", "cfg-if", @@ -5719,18 +5724,18 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "300.3.2+3.3.2" +version = "300.4.0+3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a211a18d945ef7e648cc6e0058f4c548ee46aab922ea203e0d30e966ea23647b" +checksum = "a709e02f2b4aca747929cca5ed248880847c650233cf8b8cdc48f40aaf4898a6" dependencies = [ "cc", ] [[package]] name = "openssl-sys" -version = "0.9.103" +version = "0.9.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" dependencies = [ "cc", "libc", @@ -6965,7 +6970,7 @@ dependencies = [ "itertools 0.10.5", "lazy_static", "log", - "multimap 0.8.3", + "multimap", "petgraph", "prettyplease 0.1.25", "prost 0.11.9", @@ -6986,7 +6991,7 @@ dependencies = [ "heck 0.5.0", "itertools 0.12.1", "log", - "multimap 0.10.0", + "multimap", "once_cell", "petgraph", "prettyplease 0.2.22", @@ -8439,7 +8444,7 @@ dependencies = [ "litep2p", "log", "multiaddr 0.18.2", - "multihash 0.19.1", + "multihash 0.19.2", "rand", "thiserror", "zeroize", @@ -8551,7 +8556,7 @@ dependencies = [ "governor", "http 1.1.0", "http-body-util", - "hyper 1.4.1", + "hyper 1.5.0", "ip_network", "jsonrpsee", "log", @@ -10398,7 +10403,7 @@ version = "0.17.0" source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409#87971b3e92721bdf10bf40b410eaae779d494ca0" dependencies = [ "http-body-util", - "hyper 1.4.1", + "hyper 1.5.0", "hyper-util", "log", "prometheus", diff --git a/node/src/service.rs b/node/src/service.rs index 91ffc3d45..84a3a1255 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -1,7 +1,7 @@ //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. use crate::cli::Sealing; -use crate::client::{FullBackend, FullClient, RuntimeApiCollection}; +use crate::client::{FullBackend, FullClient}; use crate::ethereum::{ db_config_dir, new_frontier_partial, spawn_frontier_tasks, BackendType, EthConfiguration, FrontierBackend, FrontierBlockImport, FrontierPartialComponents, StorageOverride, @@ -12,24 +12,20 @@ use sc_client_api::{Backend as BackendT, BlockBackend}; use sc_consensus::{BasicQueue, BoxBlockImport}; use sc_consensus_grandpa::BlockNumberOps; use sc_consensus_slots::BackoffAuthoringOnFinalizedHeadLagging; -use sc_executor::HostFunctions as HostFunctionsT; use sc_network_sync::strategy::warp::{WarpSyncConfig, WarpSyncProvider}; use sc_service::{error::Error as ServiceError, Configuration, PartialComponents, TaskManager}; use sc_telemetry::{log, Telemetry, TelemetryHandle, TelemetryWorker}; use sc_transaction_pool::FullPool; use sc_transaction_pool_api::OffchainTransactionPoolFactory; -use sp_api::ConstructRuntimeApi; -use sp_consensus_aura::sr25519::{AuthorityId as AuraId, AuthorityPair as AuraPair}; -use sp_core::{H256, U256}; +use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; +use sp_core::U256; use sp_runtime::traits::{Block as BlockT, NumberFor}; use std::{cell::RefCell, path::Path}; use std::{sync::Arc, time::Duration}; use substrate_prometheus_endpoint::Registry; // Runtime -use node_subtensor_runtime::{ - opaque::Block, AccountId, Balance, Nonce, RuntimeApi, TransactionConverter, -}; +use node_subtensor_runtime::{opaque::Block, RuntimeApi, TransactionConverter}; /// The minimum period of blocks on which justifications will be /// imported and generated. @@ -53,41 +49,41 @@ type GrandpaBlockImport = sc_consensus_grandpa::GrandpaBlockImport, B, C, FullSelectChain>; type GrandpaLinkHalf = sc_consensus_grandpa::LinkHalf>; -pub fn new_partial( +pub fn new_partial( config: &Configuration, eth_config: &EthConfiguration, build_import_queue: BIQ, ) -> Result< PartialComponents< - FullClient, - FullBackend, - FullSelectChain, - BasicQueue, - FullPool>, + Client, + FullBackend, + FullSelectChain, + BasicQueue, + FullPool, ( Option, - BoxBlockImport, - GrandpaLinkHalf>, - FrontierBackend>, - Arc>, + BoxBlockImport, + GrandpaLinkHalf, + FrontierBackend, + Arc>, ), >, ServiceError, > where - B: BlockT, - RA: ConstructRuntimeApi>, - RA: Send + Sync + 'static, - RA::RuntimeApi: RuntimeApiCollection, - HF: HostFunctionsT + 'static, + // B: BlockT, + // RA: ConstructRuntimeApi, + // RA: Send + Sync + 'static, + // RA::RuntimeApi: RuntimeApiCollection, + // HF: HostFunctionsT + 'static, BIQ: FnOnce( - Arc>, + Arc, &Configuration, &EthConfiguration, &TaskManager, Option, - GrandpaBlockImport>, - ) -> Result<(BasicQueue, BoxBlockImport), ServiceError>, + GrandpaBlockImport, + ) -> Result<(BasicQueue, BoxBlockImport), ServiceError>, { let telemetry = config .telemetry_endpoints @@ -101,12 +97,12 @@ where .transpose()?; let executor = sc_service::new_wasm_executor(&config.executor); - - let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( - config, - telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), - executor, - )?; + let (client, backend, keystore_container, task_manager) = + sc_service::new_full_parts::( + config, + telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), + executor, + )?; let client = Arc::new(client); let telemetry = telemetry.map(|(worker, telemetry)| { @@ -125,7 +121,7 @@ where telemetry.as_ref().map(|x| x.handle()), )?; - let storage_override = Arc::new(StorageOverrideHandler::::new(client.clone())); + let storage_override = Arc::new(StorageOverrideHandler::<_, _, _>::new(client.clone())); let frontier_backend = match eth_config.frontier_backend_type { BackendType::KeyValue => FrontierBackend::KeyValue(Arc::new(fc_db::kv::Backend::open( Arc::clone(&client), @@ -191,21 +187,21 @@ where } /// Build the import queue for the template runtime (aura + grandpa). -pub fn build_aura_grandpa_import_queue( - client: Arc>, +pub fn build_aura_grandpa_import_queue( + client: Arc, config: &Configuration, eth_config: &EthConfiguration, task_manager: &TaskManager, telemetry: Option, - grandpa_block_import: GrandpaBlockImport>, -) -> Result<(BasicQueue, BoxBlockImport), ServiceError> + grandpa_block_import: GrandpaBlockImport, +) -> Result<(BasicQueue, BoxBlockImport), ServiceError> where - B: BlockT, - NumberFor: BlockNumberOps, - RA: ConstructRuntimeApi>, - RA: Send + Sync + 'static, - RA::RuntimeApi: RuntimeApiCollection, - HF: HostFunctionsT + 'static, + // B: BlockT, + NumberFor: BlockNumberOps, + // RA: ConstructRuntimeApi>, + // RA: Send + Sync + 'static, + // RA::RuntimeApi: RuntimeApiCollection, + // HF: HostFunctionsT + 'static, { let frontier_block_import = FrontierBlockImport::new(grandpa_block_import.clone(), client.clone()); @@ -242,20 +238,20 @@ where } /// Build the import queue for the template runtime (manual seal). -pub fn build_manual_seal_import_queue( - client: Arc>, +pub fn build_manual_seal_import_queue( + client: Arc, config: &Configuration, _eth_config: &EthConfiguration, task_manager: &TaskManager, _telemetry: Option, - _grandpa_block_import: GrandpaBlockImport>, -) -> Result<(BasicQueue, BoxBlockImport), ServiceError> -where - B: BlockT, - RA: ConstructRuntimeApi>, - RA: Send + Sync + 'static, - RA::RuntimeApi: RuntimeApiCollection, - HF: HostFunctionsT + 'static, + _grandpa_block_import: GrandpaBlockImport, +) -> Result<(BasicQueue, BoxBlockImport), ServiceError> +// where + // B: BlockT, + // RA: ConstructRuntimeApi>, + // RA: Send + Sync + 'static, + // RA::RuntimeApi: RuntimeApiCollection, + // HF: HostFunctionsT + 'static, { let frontier_block_import = FrontierBlockImport::new(client.clone(), client); Ok(( @@ -269,25 +265,25 @@ where } /// Builds a new service for a full client. -pub async fn new_full( +pub async fn new_full( mut config: Configuration, eth_config: EthConfiguration, sealing: Option, ) -> Result where - B: BlockT, - NumberFor: BlockNumberOps, - ::Header: Unpin, - RA: ConstructRuntimeApi>, - RA: Send + Sync + 'static, - RA::RuntimeApi: RuntimeApiCollection, - HF: HostFunctionsT + 'static, - NB: sc_network::NetworkBackend::Hash>, + // B: BlockT, + NumberFor: BlockNumberOps, + // ::Header: Unpin, + // RA: ConstructRuntimeApi>, + // RA: Send + Sync + 'static, + // RA::RuntimeApi: RuntimeApiCollection, + // HF: HostFunctionsT + 'static, + NB: sc_network::NetworkBackend::Hash>, { let build_import_queue = if sealing.is_some() { - build_manual_seal_import_queue:: + build_manual_seal_import_queue } else { - build_aura_grandpa_import_queue:: + build_aura_grandpa_import_queue }; let PartialComponents { @@ -316,9 +312,7 @@ where let metrics = NB::register_notification_metrics(maybe_registry); let grandpa_protocol_name = sc_consensus_grandpa::protocol_standard_name( - &client - .block_hash(0u32.into())? - .expect("Genesis block exists; qed"), + &client.block_hash(0u32)?.expect("Genesis block exists; qed"), &config.chain_spec, ); @@ -333,7 +327,7 @@ where None } else { net_config.add_notification_protocol(grandpa_protocol_config); - let warp_sync: Arc> = + let warp_sync: Arc> = Arc::new(sc_consensus_grandpa::warp_proof::NetworkProvider::new( backend.clone(), grandpa_link.shared_authority_set().clone(), @@ -379,10 +373,11 @@ where let role = config.role; let force_authoring = config.force_authoring; - let backoff_authoring_blocks = Some(BackoffAuthoringOnFinalizedHeadLagging::> { - unfinalized_slack: 6u32.into(), - ..Default::default() - }); + let backoff_authoring_blocks = + Some(BackoffAuthoringOnFinalizedHeadLagging::> { + unfinalized_slack: 6u32, + ..Default::default() + }); let name = config.network.node_name.clone(); let frontier_backend = Arc::new(frontier_backend); let enable_grandpa = !config.disable_grandpa && sealing.is_none(); @@ -396,7 +391,7 @@ where // The MappingSyncWorker sends through the channel on block import and the subscription emits a notification to the subscriber on receiving a message through this channel. // This way we avoid race conditions when using native substrate block import notification stream. let pubsub_notification_sinks: fc_mapping_sync::EthereumBlockNotificationSinks< - fc_mapping_sync::EthereumBlockNotification, + fc_mapping_sync::EthereumBlockNotification, > = Default::default(); let pubsub_notification_sinks = Arc::new(pubsub_notification_sinks); @@ -448,7 +443,7 @@ where client: client.clone(), pool: pool.clone(), graph: pool.pool().clone(), - converter: Some(TransactionConverter::::default()), + converter: Some(TransactionConverter::::default()), is_authority, enable_dev_signer, network: network.clone(), @@ -641,16 +636,10 @@ pub async fn build_full( ) -> Result { match config.network.network_backend { sc_network::config::NetworkBackendType::Libp2p => { - new_full::>( - config, eth_config, sealing, - ) - .await + new_full::>(config, eth_config, sealing).await } sc_network::config::NetworkBackendType::Litep2p => { - new_full::( - config, eth_config, sealing, - ) - .await + new_full::>(config, eth_config, sealing).await } } } @@ -676,35 +665,31 @@ pub fn new_chain_ops( task_manager, other, .. - } = new_partial::( - config, - eth_config, - build_aura_grandpa_import_queue, - )?; + } = new_partial(config, eth_config, build_aura_grandpa_import_queue)?; Ok((client, backend, import_queue, task_manager, other.3)) } #[allow(clippy::too_many_arguments)] -fn run_manual_seal_authorship( +fn run_manual_seal_authorship( eth_config: &EthConfiguration, sealing: Sealing, - client: Arc>, - transaction_pool: Arc>>, - select_chain: FullSelectChain, - block_import: BoxBlockImport, + client: Arc, + transaction_pool: Arc>, + select_chain: FullSelectChain, + block_import: BoxBlockImport, task_manager: &TaskManager, prometheus_registry: Option<&Registry>, telemetry: Option<&Telemetry>, commands_stream: mpsc::Receiver< - sc_consensus_manual_seal::rpc::EngineCommand<::Hash>, + sc_consensus_manual_seal::rpc::EngineCommand<::Hash>, >, ) -> Result<(), ServiceError> -where - B: BlockT, - RA: ConstructRuntimeApi>, - RA: Send + Sync + 'static, - RA::RuntimeApi: RuntimeApiCollection, - HF: HostFunctionsT + 'static, +// where + // B: BlockT, + // RA: ConstructRuntimeApi>, + // RA: Send + Sync + 'static, + // RA::RuntimeApi: RuntimeApiCollection, + // HF: HostFunctionsT + 'static, { let proposer_factory = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), diff --git a/pallets/subtensor/tests/swap_hotkey.rs b/pallets/subtensor/tests/swap_hotkey.rs index 0901e7bda..59d114cf1 100644 --- a/pallets/subtensor/tests/swap_hotkey.rs +++ b/pallets/subtensor/tests/swap_hotkey.rs @@ -1150,6 +1150,94 @@ fn test_swap_complex_parent_child_structure() { }); } +// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_hotkey_swap_stake_delta --exact --nocapture +#[test] +fn test_hotkey_swap_stake_delta() { + new_test_ext(1).execute_with(|| { + let old_hotkey = U256::from(3); + let new_hotkey = U256::from(4); + let coldkey = U256::from(7); + + let coldkeys = [U256::from(1), U256::from(2), U256::from(5)]; + + let mut weight = Weight::zero(); + + // Set up initial state + // Add stake delta for each coldkey and the old_hotkey + for &coldkey in coldkeys.iter() { + StakeDeltaSinceLastEmissionDrain::::insert( + old_hotkey, + coldkey, + (123 + coldkey.saturated_into::()), + ); + + StakingHotkeys::::insert(coldkey, vec![old_hotkey]); + } + + // Add stake delta for one coldkey and the new_hotkey + StakeDeltaSinceLastEmissionDrain::::insert(new_hotkey, coldkeys[0], 456); + // Add corresponding StakingHotkeys + StakingHotkeys::::insert(coldkeys[0], vec![old_hotkey, new_hotkey]); + + // Perform the swap + SubtensorModule::perform_hotkey_swap(&old_hotkey, &new_hotkey, &coldkey, &mut weight); + + // Ensure the stake delta is correctly transferred for each coldkey + // -- coldkey[0] maintains its stake delta from the new_hotkey and the old_hotkey + assert_eq!( + StakeDeltaSinceLastEmissionDrain::::get(new_hotkey, coldkeys[0]), + 123 + coldkeys[0].saturated_into::() + 456 + ); + // -- coldkey[1..] maintains its stake delta from the old_hotkey + for &coldkey in coldkeys[1..].iter() { + assert_eq!( + StakeDeltaSinceLastEmissionDrain::::get(new_hotkey, coldkey), + 123 + coldkey.saturated_into::() + ); + assert!(!StakeDeltaSinceLastEmissionDrain::::contains_key( + old_hotkey, coldkey + )); + } + }); +} + +// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_hotkey_with_pending_emissions --exact --nocapture +#[test] +fn test_swap_hotkey_with_pending_emissions() { + new_test_ext(1).execute_with(|| { + let old_hotkey = U256::from(1); + let new_hotkey = U256::from(2); + let coldkey = U256::from(3); + let netuid = 0u16; + let mut weight = Weight::zero(); + + let pending_emission = 123_456_789u64; + + // Set up initial state + add_network(netuid, 0, 1); + + // Set up pending emissions + PendingdHotkeyEmission::::insert(old_hotkey, pending_emission); + // Verify the pending emissions are set + assert_eq!( + PendingdHotkeyEmission::::get(old_hotkey), + pending_emission + ); + // Verify the new hotkey does not have any pending emissions + assert!(!PendingdHotkeyEmission::::contains_key(new_hotkey)); + + // Perform the swap + SubtensorModule::perform_hotkey_swap(&old_hotkey, &new_hotkey, &coldkey, &mut weight); + + // Verify the pending emissions are transferred + assert_eq!( + PendingdHotkeyEmission::::get(new_hotkey), + pending_emission + ); + assert!(!PendingdHotkeyEmission::::contains_key(old_hotkey)); + }); +} + #[test] fn test_swap_parent_hotkey_childkey_maps() { new_test_ext(1).execute_with(|| { @@ -1246,91 +1334,3 @@ fn test_swap_child_hotkey_childkey_maps() { ); }) } - -// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_hotkey_swap_stake_delta --exact --nocapture -#[test] -fn test_hotkey_swap_stake_delta() { - new_test_ext(1).execute_with(|| { - let old_hotkey = U256::from(3); - let new_hotkey = U256::from(4); - let coldkey = U256::from(7); - - let coldkeys = [U256::from(1), U256::from(2), U256::from(5)]; - - let mut weight = Weight::zero(); - - // Set up initial state - // Add stake delta for each coldkey and the old_hotkey - for &coldkey in coldkeys.iter() { - StakeDeltaSinceLastEmissionDrain::::insert( - old_hotkey, - coldkey, - (123 + coldkey.saturated_into::()), - ); - - StakingHotkeys::::insert(coldkey, vec![old_hotkey]); - } - - // Add stake delta for one coldkey and the new_hotkey - StakeDeltaSinceLastEmissionDrain::::insert(new_hotkey, coldkeys[0], 456); - // Add corresponding StakingHotkeys - StakingHotkeys::::insert(coldkeys[0], vec![old_hotkey, new_hotkey]); - - // Perform the swap - SubtensorModule::perform_hotkey_swap(&old_hotkey, &new_hotkey, &coldkey, &mut weight); - - // Ensure the stake delta is correctly transferred for each coldkey - // -- coldkey[0] maintains its stake delta from the new_hotkey and the old_hotkey - assert_eq!( - StakeDeltaSinceLastEmissionDrain::::get(new_hotkey, coldkeys[0]), - 123 + coldkeys[0].saturated_into::() + 456 - ); - // -- coldkey[1..] maintains its stake delta from the old_hotkey - for &coldkey in coldkeys[1..].iter() { - assert_eq!( - StakeDeltaSinceLastEmissionDrain::::get(new_hotkey, coldkey), - 123 + coldkey.saturated_into::() - ); - assert!(!StakeDeltaSinceLastEmissionDrain::::contains_key( - old_hotkey, coldkey - )); - } - }); -} - -// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --test swap_hotkey -- test_swap_hotkey_with_pending_emissions --exact --nocapture -#[test] -fn test_swap_hotkey_with_pending_emissions() { - new_test_ext(1).execute_with(|| { - let old_hotkey = U256::from(1); - let new_hotkey = U256::from(2); - let coldkey = U256::from(3); - let netuid = 0u16; - let mut weight = Weight::zero(); - - let pending_emission = 123_456_789u64; - - // Set up initial state - add_network(netuid, 0, 1); - - // Set up pending emissions - PendingdHotkeyEmission::::insert(old_hotkey, pending_emission); - // Verify the pending emissions are set - assert_eq!( - PendingdHotkeyEmission::::get(old_hotkey), - pending_emission - ); - // Verify the new hotkey does not have any pending emissions - assert!(!PendingdHotkeyEmission::::contains_key(new_hotkey)); - - // Perform the swap - SubtensorModule::perform_hotkey_swap(&old_hotkey, &new_hotkey, &coldkey, &mut weight); - - // Verify the pending emissions are transferred - assert_eq!( - PendingdHotkeyEmission::::get(new_hotkey), - pending_emission - ); - assert!(!PendingdHotkeyEmission::::contains_key(old_hotkey)); - }); -} diff --git a/scripts/build_all_chainspecs.sh b/scripts/build_all_chainspecs.sh index 7750a358b..03727b728 100755 --- a/scripts/build_all_chainspecs.sh +++ b/scripts/build_all_chainspecs.sh @@ -3,7 +3,7 @@ set -e echo "*** Building node..." -cargo build +cargo build -p node-subtensor echo "*** Building new chainspecs..." diff --git a/support/procedural-fork/src/pallet/parse/storage.rs b/support/procedural-fork/src/pallet/parse/storage.rs index 811832427..64a5e685b 100644 --- a/support/procedural-fork/src/pallet/parse/storage.rs +++ b/support/procedural-fork/src/pallet/parse/storage.rs @@ -718,11 +718,11 @@ fn process_generics( "CountedStorageNMap" => StorageKind::CountedNMap, found => { let msg = format!( - "Invalid pallet::storage, expected ident: `StorageValue` or \ + "Invalid pallet::storage, expected ident: `StorageValue` or \ `StorageMap` or `CountedStorageMap` or `StorageDoubleMap` or `StorageNMap` or `CountedStorageNMap` \ in order to expand metadata, found `{}`.", - found, - ); + found, + ); return Err(syn::Error::new(segment.ident.span(), msg)); } }; diff --git a/support/procedural-fork/src/runtime/parse/mod.rs b/support/procedural-fork/src/runtime/parse/mod.rs index a6a49e814..494ab2c53 100644 --- a/support/procedural-fork/src/runtime/parse/mod.rs +++ b/support/procedural-fork/src/runtime/parse/mod.rs @@ -255,19 +255,19 @@ impl Def { }; let def = Def { - input, - runtime_struct: runtime_struct.ok_or_else(|| { - syn::Error::new(item_span, + input, + runtime_struct: runtime_struct.ok_or_else(|| { + syn::Error::new(item_span, "Missing Runtime. Please add a struct inside the module and annotate it with `#[runtime::runtime]`" ) - })?, - pallets, - runtime_types: runtime_types.ok_or_else(|| { - syn::Error::new(item_span, + })?, + pallets, + runtime_types: runtime_types.ok_or_else(|| { + syn::Error::new(item_span, "Missing Runtime Types. Please annotate the runtime struct with `#[runtime::derive]`" ) - })?, - }; + })?, + }; Ok(def) }