From c5e73ec4659bdc6a4e674412c0cccc70a14034a2 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 17 Jun 2024 18:14:52 +0200 Subject: [PATCH 01/10] fix: unit tests for polkadot-1.9 --- pallets/collator-selection/src/mock.rs | 7 ++++++- pallets/identity/src/tests.rs | 7 ++++++- pallets/inflation/src/tests.rs | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pallets/collator-selection/src/mock.rs b/pallets/collator-selection/src/mock.rs index 9488abdf38..f5e42e4e4e 100644 --- a/pallets/collator-selection/src/mock.rs +++ b/pallets/collator-selection/src/mock.rs @@ -91,6 +91,12 @@ impl system::Config for Test { type SS58Prefix = SS58Prefix; type OnSetCode = (); type MaxConsumers = ConstU32<16>; + type RuntimeTask = (); + type PreInherents = (); + type PostInherents = (); + type PostTransactions = (); + type SingleBlockMigrations = (); + type MultiBlockMigrator = (); } parameter_types! { @@ -111,7 +117,6 @@ impl pallet_balances::Config for Test { type MaxReserves = MaxReserves; type ReserveIdentifier = [u8; 8]; type FreezeIdentifier = [u8; 16]; - type MaxHolds = MaxHolds; type MaxFreezes = MaxFreezes; type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; diff --git a/pallets/identity/src/tests.rs b/pallets/identity/src/tests.rs index c80e55233a..8372ee1c06 100644 --- a/pallets/identity/src/tests.rs +++ b/pallets/identity/src/tests.rs @@ -88,6 +88,12 @@ impl frame_system::Config for Test { type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = ConstU32<16>; + type RuntimeTask = (); + type PreInherents = (); + type PostInherents = (); + type PostTransactions = (); + type SingleBlockMigrations = (); + type MultiBlockMigrator = (); } impl pallet_balances::Config for Test { @@ -103,7 +109,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = (); type MaxFreezes = (); } diff --git a/pallets/inflation/src/tests.rs b/pallets/inflation/src/tests.rs index 74958be22c..fbd0d45c0a 100644 --- a/pallets/inflation/src/tests.rs +++ b/pallets/inflation/src/tests.rs @@ -58,7 +58,6 @@ impl pallet_balances::Config for Test { type MaxReserves = (); type ReserveIdentifier = (); type FreezeIdentifier = (); - type MaxHolds = (); type MaxFreezes = (); type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; @@ -103,6 +102,12 @@ impl frame_system::Config for Test { type SS58Prefix = SS58Prefix; type OnSetCode = (); type MaxConsumers = ConstU32<16>; + type RuntimeTask = (); + type PreInherents = (); + type PostInherents = (); + type PostTransactions = (); + type SingleBlockMigrations = (); + type MultiBlockMigrator = (); } parameter_types! { From 72b9f19daa1536180b50c7c15d846697486ce490 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Tue, 18 Jun 2024 14:58:14 +0200 Subject: [PATCH 02/10] fix: frontier wants timestamp inherent now --- node/cli/src/service.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/node/cli/src/service.rs b/node/cli/src/service.rs index ad80828914..50444aee91 100644 --- a/node/cli/src/service.rs +++ b/node/cli/src/service.rs @@ -238,7 +238,7 @@ ez_bounds!( pub trait LookaheadApiDep: cumulus_primitives_aura::AuraUnincludedSegmentApi {} ); -fn ethereum_parachain_inherent() -> ParachainInherentData { +fn ethereum_parachain_inherent() -> (sp_timestamp::InherentDataProvider, ParachainInherentData) { let (relay_parent_storage_root, relay_chain_state) = RelayStateSproofBuilder::default().into_state_root_and_proof(); let vfp = PersistedValidationData { @@ -249,12 +249,15 @@ fn ethereum_parachain_inherent() -> ParachainInherentData { ..Default::default() }; - ParachainInherentData { - validation_data: vfp, - relay_chain_state, - downward_messages: Default::default(), - horizontal_messages: Default::default(), - } + ( + sp_timestamp::InherentDataProvider::from_system_time(), + ParachainInherentData { + validation_data: vfp, + relay_chain_state, + downward_messages: Default::default(), + horizontal_messages: Default::default(), + }, + ) } /// Starts a `ServiceBuilder` for a full service. @@ -557,7 +560,7 @@ where overrides, sync: sync_service.clone(), pending_create_inherent_data_providers: |_, ()| async move { - Ok((ethereum_parachain_inherent(),)) + Ok(ethereum_parachain_inherent()) }, }; @@ -1147,7 +1150,7 @@ where sync: sync_service.clone(), // We don't have any inherents except parachain built-ins, which we can't even extract from inside `run_aura`. pending_create_inherent_data_providers: |_, ()| async move { - Ok((ethereum_parachain_inherent(),)) + Ok(ethereum_parachain_inherent()) }, }; From e6ed5f4e38dbe0b7c88d445d6fc7bc7cef810b99 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 19 Jun 2024 16:59:06 +0200 Subject: [PATCH 03/10] refactor: use build_network from cumulus_client_service --- node/cli/src/rpc.rs | 14 +++--------- node/cli/src/service.rs | 48 +++++++++++------------------------------ 2 files changed, 16 insertions(+), 46 deletions(-) diff --git a/node/cli/src/rpc.rs b/node/cli/src/rpc.rs index 5d4b0d16cf..9be511c6de 100644 --- a/node/cli/src/rpc.rs +++ b/node/cli/src/rpc.rs @@ -43,18 +43,13 @@ use crate::service::RuntimeApiDep; type FullBackend = sc_service::TFullBackend; /// Full client dependencies. -pub struct FullDeps { +pub struct FullDeps { /// The client instance to use. pub client: Arc, /// Transaction pool instance. pub pool: Arc

, - /// The SelectChain Strategy - pub select_chain: SC, /// Whether to deny unsafe calls pub deny_unsafe: DenyUnsafe, - - /// Runtime identification (read from the chain spec) - pub runtime_id: RuntimeId, /// Executor params for PoV estimating #[cfg(feature = "pov-estimate")] pub exec_params: uc_rpc::pov_estimate::ExecutorParams, @@ -64,9 +59,9 @@ pub struct FullDeps { } /// Instantiate all Full RPC extensions. -pub fn create_full( +pub fn create_full( io: &mut RpcModule<()>, - deps: FullDeps, + deps: FullDeps, ) -> Result<(), Box> where C: ProvideRuntimeApi + StorageProvider + AuxStore, @@ -93,11 +88,8 @@ where let FullDeps { client, pool, - select_chain: _, deny_unsafe, - runtime_id: _, - #[cfg(feature = "pov-estimate")] exec_params, diff --git a/node/cli/src/service.rs b/node/cli/src/service.rs index 50444aee91..3e729fa67b 100644 --- a/node/cli/src/service.rs +++ b/node/cli/src/service.rs @@ -36,8 +36,8 @@ use cumulus_client_consensus_aura::collators::lookahead::{ use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport; use cumulus_client_consensus_proposer::Proposer; use cumulus_client_service::{ - build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, DARecoveryProfile, - StartRelayChainTasksParams, + build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, + CollatorSybilResistance, DARecoveryProfile, StartRelayChainTasksParams, }; use cumulus_primitives_core::ParaId; use cumulus_primitives_parachain_inherent::ParachainInherentData; @@ -85,10 +85,7 @@ pub type ParachainHostFunctions = ( use cumulus_primitives_core::PersistedValidationData; use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; -use crate::{ - chain_spec::RuntimeIdentification, - rpc::{create_eth, create_full, EthDeps, FullDeps}, -}; +use crate::rpc::{create_eth, create_full, EthDeps, FullDeps}; /// Unique native executor instance. #[cfg(feature = "unique-runtime")] @@ -429,33 +426,25 @@ where .await .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?; - // Aura is sybil-resistant, collator-selection is generally too. - let block_announce_validator = - cumulus_client_network::AssumeSybilResistance::allow_seconded_messages(); - let validator = parachain_config.role.is_authority(); let prometheus_registry = parachain_config.prometheus_registry().cloned(); let transaction_pool = params.transaction_pool.clone(); let import_queue_service = params.import_queue.service(); let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = - sc_service::build_network(sc_service::BuildNetworkParams { - config: ¶chain_config, + cumulus_client_service::build_network(cumulus_client_service::BuildNetworkParams { + parachain_config: ¶chain_config, net_config, client: client.clone(), transaction_pool: transaction_pool.clone(), + para_id, spawn_handle: task_manager.spawn_handle(), + relay_chain_interface: relay_chain_interface.clone(), import_queue: params.import_queue, - block_announce_validator_builder: Some(Box::new(|_| { - Box::new(block_announce_validator) - })), - warp_sync_params: None, - block_relay: None, - })?; - - let select_chain = params.select_chain.clone(); - - let runtime_id = parachain_config.chain_spec.runtime_id(); + // Aura is sybil-resistant, collator-selection is generally too. + sybil_resistance_level: CollatorSybilResistance::Resistant, + }) + .await?; // Frontier let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new())); @@ -508,9 +497,7 @@ where fee_history_cache, eth_block_data_cache, network, - runtime_id, transaction_pool, - select_chain, overrides, ); @@ -521,7 +508,6 @@ where let full_deps = FullDeps { client: client.clone(), - runtime_id, #[cfg(feature = "pov-estimate")] exec_params: uc_rpc::pov_estimate::ExecutorParams { @@ -536,10 +522,9 @@ where deny_unsafe, pool: transaction_pool.clone(), - select_chain, }; - create_full::<_, _, _, Runtime, _>(&mut rpc_handle, full_deps)?; + create_full::<_, _, Runtime, _>(&mut rpc_handle, full_deps)?; let eth_deps = EthDeps { client, @@ -1044,8 +1029,6 @@ where #[cfg(feature = "pov-estimate")] let rpc_backend = backend.clone(); - let runtime_id = config.chain_spec.runtime_id(); - // Frontier let fee_history_cache: FeeHistoryCache = Arc::new(Mutex::new(BTreeMap::new())); let fee_history_limit = 2048; @@ -1097,9 +1080,7 @@ where fee_history_cache, eth_block_data_cache, network, - runtime_id, transaction_pool, - select_chain, overrides, ); @@ -1109,8 +1090,6 @@ where let mut rpc_module = RpcModule::new(()); let full_deps = FullDeps { - runtime_id, - #[cfg(feature = "pov-estimate")] exec_params: uc_rpc::pov_estimate::ExecutorParams { wasm_method: config.wasm_method, @@ -1125,10 +1104,9 @@ where deny_unsafe, client: client.clone(), pool: transaction_pool.clone(), - select_chain, }; - create_full::<_, _, _, Runtime, _>(&mut rpc_module, full_deps)?; + create_full::<_, _, Runtime, _>(&mut rpc_module, full_deps)?; let eth_deps = EthDeps { client, From e8c8f78361e7210f0478874dfbf58990a9323a3a Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 19 Jun 2024 16:59:32 +0200 Subject: [PATCH 04/10] refactor: use derive_impl for frame_system::Config --- runtime/common/config/substrate.rs | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/runtime/common/config/substrate.rs b/runtime/common/config/substrate.rs index fd49403f9a..16e7f62248 100644 --- a/runtime/common/config/substrate.rs +++ b/runtime/common/config/substrate.rs @@ -25,7 +25,7 @@ use frame_support::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}, ConstantMultiplier, }, - PalletId, + PalletId, derive_impl, }; use frame_system::{ limits::{BlockLength, BlockWeights}, @@ -43,7 +43,7 @@ use up_common::{constants::*, types::*}; use crate::{ runtime_common::DealWithFees, Balances, Block, OriginCaller, PalletInfo, Runtime, RuntimeCall, RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, SS58Prefix, System, - Treasury, Version, + Treasury, Version, RuntimeTask, }; parameter_types! { @@ -72,13 +72,12 @@ parameter_types! { .build_or_panic(); } +#[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { /// The data to be stored in an account. type AccountData = pallet_balances::AccountData; /// The identifier used to distinguish between accounts. type AccountId = AccountId; - /// The basic call filter to use in dispatchable. - type BaseCallFilter = Everything; /// Maximum number of block number to block hash mappings to keep (oldest pruned first). type BlockHashCount = BlockHashCount; /// The block type. @@ -87,12 +86,8 @@ impl frame_system::Config for Runtime { type BlockLength = RuntimeBlockLength; /// The weight of the overhead invoked on the block import process, independent of the extrinsics included in that block. type BlockWeights = RuntimeBlockWeights; - /// The aggregated dispatch type that is available for extrinsics. - type RuntimeCall = RuntimeCall; /// The weight of database operations that the runtime can invoke. type DbWeight = RocksDbWeight; - /// The ubiquitous event type. - type RuntimeEvent = RuntimeEvent; /// The type for hashing blocks and tries. type Hash = Hash; /// The hashing algorithm used. @@ -101,10 +96,6 @@ impl frame_system::Config for Runtime { type Nonce = Nonce; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; - /// What to do if an account is fully reaped from the system. - type OnKilledAccount = (); - /// What to do if a new account is created. - type OnNewAccount = (); type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; /// The ubiquitous origin type. type RuntimeOrigin = RuntimeOrigin; @@ -117,14 +108,6 @@ impl frame_system::Config for Runtime { /// Version of the runtime. type Version = Version; type MaxConsumers = ConstU32<16>; - - type RuntimeTask = (); - - type SingleBlockMigrations = (); - type MultiBlockMigrator = (); - type PreInherents = (); - type PostInherents = (); - type PostTransactions = (); } parameter_types! { From 02607563eb3d28f438d31f064ef9df24bfbf9c8c Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 19 Jun 2024 16:59:58 +0200 Subject: [PATCH 05/10] build: update lockfile --- Cargo.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c4680d4fc4..355f3f7327 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6304,7 +6304,7 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opal-runtime" -version = "1.3.0" +version = "1.9.0" dependencies = [ "app-promotion-rpc", "cumulus-pallet-aura-ext", @@ -10188,7 +10188,7 @@ dependencies = [ [[package]] name = "quartz-runtime" -version = "1.3.0" +version = "1.9.0" dependencies = [ "app-promotion-rpc", "cumulus-pallet-aura-ext", @@ -14976,7 +14976,7 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "unique-node" -version = "1.3.0" +version = "1.9.0" dependencies = [ "app-promotion-rpc", "clap", @@ -15063,7 +15063,7 @@ dependencies = [ [[package]] name = "unique-runtime" -version = "1.3.0" +version = "1.9.0" dependencies = [ "app-promotion-rpc", "cumulus-pallet-aura-ext", @@ -15210,7 +15210,7 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "up-common" -version = "1.3.0" +version = "1.9.0" dependencies = [ "cumulus-primitives-core", "fp-rpc", From 90c8f967eff657a4dc326198ec3f75d77e0c9ae4 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 24 Jun 2024 06:12:53 +0200 Subject: [PATCH 06/10] fix: do not confuse baedeker with Session in genesis config json --- node/cli/src/chain_spec.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index 500d76b220..98725e62ad 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -185,20 +185,24 @@ fn genesis_patch() -> serde_json::Value { .collect::>(), }, - "session": { - "keys": invulnerables.into_iter() - .map(|name| { - let account = get_account_id_from_seed::(name); - let aura = get_from_seed::(name); - - ( - /* account id: */ account.clone(), - /* validator id: */ account, - /* session keys: */ SessionKeys { aura }, - ) - }) - .collect::>() - }, + // We don't have Session pallet in production anywhere, + // Adding this config makes baedeker think we have pallet-session, and it tries to + // reconfigure chain using it, which makes no sense, because then aura knows no + // authority, as baedeker expects them to be configured by session pallet. + // "session": { + // "keys": invulnerables.into_iter() + // .map(|name| { + // let account = get_account_id_from_seed::(name); + // let aura = get_from_seed::(name); + // + // ( + // /* account id: */ account.clone(), + // /* validator id: */ account, + // /* session keys: */ SessionKeys { aura }, + // ) + // }) + // .collect::>() + // }, "sudo": { "key": get_account_id_from_seed::("Alice"), From 5a77207814cdc2c88e97108c047cb6067cfa5d3b Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 24 Jun 2024 06:14:13 +0200 Subject: [PATCH 07/10] style: fix formatting --- runtime/common/config/substrate.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runtime/common/config/substrate.rs b/runtime/common/config/substrate.rs index 16e7f62248..5f54b46556 100644 --- a/runtime/common/config/substrate.rs +++ b/runtime/common/config/substrate.rs @@ -15,6 +15,7 @@ // along with Unique Network. If not, see . use frame_support::{ + derive_impl, dispatch::DispatchClass, ord_parameter_types, parameter_types, traits::{ @@ -25,7 +26,7 @@ use frame_support::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}, ConstantMultiplier, }, - PalletId, derive_impl, + PalletId, }; use frame_system::{ limits::{BlockLength, BlockWeights}, @@ -42,8 +43,8 @@ use up_common::{constants::*, types::*}; use crate::{ runtime_common::DealWithFees, Balances, Block, OriginCaller, PalletInfo, Runtime, RuntimeCall, - RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, SS58Prefix, System, - Treasury, Version, RuntimeTask, + RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask, SS58Prefix, + System, Treasury, Version, }; parameter_types! { From 1e1dae4deafd50a9c6ce1d1c126a7f239db229e2 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 24 Jun 2024 11:29:49 +0200 Subject: [PATCH 08/10] fix: update Cargo.lock unique-frontier 1.9 --- Cargo.lock | 47 +++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 355f3f7327..58aea4f4ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3108,7 +3108,7 @@ dependencies = [ [[package]] name = "fc-api" version = "1.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "async-trait", "fp-storage", @@ -3120,7 +3120,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "async-trait", "fp-consensus", @@ -3136,7 +3136,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "async-trait", "fc-api", @@ -3157,7 +3157,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "fc-db", "fc-storage", @@ -3178,7 +3178,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "ethereum", "ethereum-types", @@ -3233,7 +3233,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "ethereum", "ethereum-types", @@ -3248,7 +3248,7 @@ dependencies = [ [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "ethereum", "ethereum-types", @@ -3392,7 +3392,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "hex", "impl-serde", @@ -3411,7 +3411,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "ethereum", "parity-scale-codec", @@ -3423,7 +3423,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "ethereum", "ethereum-types", @@ -3436,7 +3436,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "evm", "frame-support", @@ -3452,7 +3452,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "ethereum", "ethereum-types", @@ -3469,7 +3469,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "frame-support", "parity-scale-codec", @@ -3481,7 +3481,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "parity-scale-codec", "serde", @@ -4663,15 +4663,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.11" @@ -6804,7 +6795,7 @@ dependencies = [ [[package]] name = "pallet-base-fee" version = "1.0.0" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "fp-evm", "frame-support", @@ -7127,7 +7118,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "ethereum", "ethereum-types", @@ -7150,7 +7141,7 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "environmental", "evm", @@ -7232,7 +7223,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#0b08553e48ce2e9a237478ccd1aebef9d935a5ab" +source = "git+https://github.com/uniquenetwork/unique-frontier?branch=unique-polkadot-v1.9.0#edc28caf745f80d0616dcb26a43401596971a5f8" dependencies = [ "fp-evm", "ripemd", @@ -10147,7 +10138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools 0.12.1", + "itertools 0.11.0", "proc-macro2", "quote", "syn 2.0.66", From 347f218123fd95df30a599fd01f9f3c60746ac39 Mon Sep 17 00:00:00 2001 From: Pavel Orlov <45266194+PraetorP@users.noreply.github.com> Date: Mon, 24 Jun 2024 22:27:26 +0700 Subject: [PATCH 09/10] fix: evm fees burn & test (#1079) * fix evm fees burn & test * fix tips handling --- .../tests/creditFeesToTreasury.seqtest.ts | 34 +++++++++++++++++++ pallets/evm-transaction-payment/src/lib.rs | 5 ++- runtime/common/mod.rs | 16 +-------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/js-packages/tests/creditFeesToTreasury.seqtest.ts b/js-packages/tests/creditFeesToTreasury.seqtest.ts index e4e4856f96..581a8d67a9 100644 --- a/js-packages/tests/creditFeesToTreasury.seqtest.ts +++ b/js-packages/tests/creditFeesToTreasury.seqtest.ts @@ -18,6 +18,8 @@ import type {IKeyringPair} from '@polkadot/types/types'; import {ApiPromise} from '@polkadot/api'; import {usingPlaygrounds, expect, itSub} from '@unique/test-utils/util.js'; import type {u32} from '@polkadot/types-codec'; +import { itEth } from '@unique/test-utils/eth/util.js'; +import { ITransactionResult } from '@unique-nft/playgrounds/types'; const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z'; const saneMinimumFee = 0.05; @@ -163,4 +165,36 @@ describe('integration test: Fees must be credited to Treasury:', () => { expect(Math.abs(fee - expectedTransferFee)).to.be.lessThan(tolerance); }); + + itEth('Evm Transactions send fees to Treasury', async ({helper}) => { + const value = helper.balance.getOneTokenNominal(); + const gasPrice = await helper.getWeb3().eth.getGasPrice(); + let result = null; + + const lambda = async () => { + result = await helper.executeExtrinsic(alice, 'api.tx.evm.call', [ + helper.address.substrateToEth(alice.address), + helper.address.substrateToEth(bob.address), + '0x', + value, + 25_000, + gasPrice, + null, + null, + [], + ]); + }; + + const totalPaid = await helper.arrange.calculcateFee({ Substrate: alice.address }, lambda); + const evmFees = totalPaid - value; + + const treasuryDepoosited = (result as unknown as ITransactionResult).result.events + .filter(({ event: { method, section } }) => section == 'treasury' && method == 'Deposit') + .map(({ event: { data } }) => data[0].toJSON()); + + const deposit = BigInt(treasuryDepoosited[0]); + + expect(deposit).to.be.equal(evmFees); + }); + }); diff --git a/pallets/evm-transaction-payment/src/lib.rs b/pallets/evm-transaction-payment/src/lib.rs index 4056840c19..7ff5267def 100644 --- a/pallets/evm-transaction-payment/src/lib.rs +++ b/pallets/evm-transaction-payment/src/lib.rs @@ -287,8 +287,7 @@ where } fn pay_priority_fee(tip: Self::LiquidityInfo) { - as OnChargeEVMTransaction>::pay_priority_fee( - tip.0, - ) + let Some(imbalance) = tip.0 else { return }; + OU::on_unbalanced(imbalance) } } diff --git a/runtime/common/mod.rs b/runtime/common/mod.rs index 2c9793dd9a..10e5d1c461 100644 --- a/runtime/common/mod.rs +++ b/runtime/common/mod.rs @@ -107,21 +107,7 @@ pub type Executive = frame_executive::Executive< type NegativeImbalance = >::NegativeImbalance; -pub struct DealWithFees; -impl OnUnbalanced for DealWithFees { - fn on_unbalanceds(mut fees_then_tips: impl Iterator) { - if let Some(fees) = fees_then_tips.next() { - // for fees, 100% to treasury - let mut split = fees.ration(100, 0); - if let Some(tips) = fees_then_tips.next() { - // for tips, if any, 100% to treasury - tips.ration_merge_into(100, 0, &mut split); - } - Treasury::on_unbalanced(split.0); - // Author::on_unbalanced(split.1); - } - } -} +pub(crate) type DealWithFees = Treasury; pub struct RelayChainBlockNumberProvider(sp_std::marker::PhantomData); From 0ceea0af66a9aa476fc5a7f413261f77838d81ec Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Tue, 25 Jun 2024 23:49:33 +0300 Subject: [PATCH 10/10] fix: account token ownership limit when transfer (#1080) * fix: account token ownership limit when mint * fix: limit tests * fix: account token ownership limit rft mint * Revert "fix: account token ownership limit rft mint" This reverts commit 054110e015fd237fed77be1ef21bba6cea13fbea. * Revert "fix: limit tests" This reverts commit 75699574656bb0a34caddf3c9abdbffef79ba85d. * Revert "fix: account token ownership limit when mint" This reverts commit b89a3c86d3bf0888a636bc7da1949affa12d867d. * fix: account token ownership limit when transfer * test: account token ownership transfer tests --------- Co-authored-by: Max Andreev --- js-packages/tests/limits.test.ts | 50 ++++++++++++++++++++++++++++++-- pallets/nonfungible/src/lib.rs | 2 +- pallets/refungible/src/lib.rs | 2 +- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/js-packages/tests/limits.test.ts b/js-packages/tests/limits.test.ts index f0dcb3553e..7d6126f271 100644 --- a/js-packages/tests/limits.test.ts +++ b/js-packages/tests/limits.test.ts @@ -19,11 +19,12 @@ import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from '@u describe('Number of tokens per address (NFT)', () => { let alice: IKeyringPair; + let bob: IKeyringPair; before(async () => { await usingPlaygrounds(async (helper, privateKey) => { const donor = await privateKey({url: import.meta.url}); - [alice] = await helper.arrange.createAccounts([10n], donor); + [alice, bob] = await helper.arrange.createAccounts([10n, 0n], donor); }); }); @@ -51,17 +52,40 @@ describe('Number of tokens per address (NFT)', () => { await collection.burnToken(alice, 1); await expect(collection.burn(alice)).to.be.not.rejected; }); + + itSub('Can transfer tokens to address equal to accountTokenOwnershipLimit', async ({helper}) => { + const collection = await helper.nft.mintCollection(alice, {}); + await collection.setLimits(alice, {accountTokenOwnershipLimit: 1}); + + // Limit 1 - can transfer #1 token + const tkn1 = await collection.mintToken(alice); + await collection.transferToken(alice, tkn1.tokenId, {Substrate: bob.address}); + + // Limit 1 - cannot transfer #2 token + const tkn2 = await collection.mintToken(alice); + await expect(collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/); + + // Increase limit to 2 + // Now can transfer token #2 + await collection.setLimits(alice, {accountTokenOwnershipLimit: 2}); + await collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address}); + + // But cannot transfer token #3 + const tkn3 = await collection.mintToken(alice); + await expect(collection.transferToken(alice, tkn3.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/); + }); }); describe('Number of tokens per address (ReFungible)', () => { let alice: IKeyringPair; + let bob: IKeyringPair; before(async function() { await usingPlaygrounds(async (helper, privateKey) => { requirePalletsOrSkip(this, helper, [Pallets.ReFungible]); const donor = await privateKey({url: import.meta.url}); - [alice] = await helper.arrange.createAccounts([10n], donor); + [alice, bob] = await helper.arrange.createAccounts([10n, 0n], donor); }); }); @@ -89,6 +113,28 @@ describe('Number of tokens per address (ReFungible)', () => { await collection.burnToken(alice, 1); await expect(collection.burn(alice)).to.be.not.rejected; }); + + itSub('Can transfer tokens to address equal to accountTokenOwnershipLimit', async ({helper}) => { + const collection = await helper.rft.mintCollection(alice, {}); + await collection.setLimits(alice, {accountTokenOwnershipLimit: 1}); + + // Limit 1 - can transfer #1 token + const tkn1 = await collection.mintToken(alice); + await collection.transferToken(alice, tkn1.tokenId, {Substrate: bob.address}); + + // Limit 1 - cannot transfer #2 token + const tkn2 = await collection.mintToken(alice); + await expect(collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/); + + // Increase limit to 2 + // Now can transfer token #2 + await collection.setLimits(alice, {accountTokenOwnershipLimit: 2}); + await collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address}); + + // But cannot transfer token #3 + const tkn3 = await collection.mintToken(alice); + await expect(collection.transferToken(alice, tkn3.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/); + }); }); // todo:playgrounds skipped ~ postponed diff --git a/pallets/nonfungible/src/lib.rs b/pallets/nonfungible/src/lib.rs index 0ea6459446..8db862a582 100644 --- a/pallets/nonfungible/src/lib.rs +++ b/pallets/nonfungible/src/lib.rs @@ -746,7 +746,7 @@ impl Pallet { .ok_or(ArithmeticError::Overflow)?; ensure!( - balance_to < collection.limits.account_token_ownership_limit(), + balance_to <= collection.limits.account_token_ownership_limit(), >::AccountTokenLimitExceeded, ); diff --git a/pallets/refungible/src/lib.rs b/pallets/refungible/src/lib.rs index 47966766a6..bb89ba0d2d 100644 --- a/pallets/refungible/src/lib.rs +++ b/pallets/refungible/src/lib.rs @@ -679,7 +679,7 @@ impl Pallet { .checked_add(1) .ok_or(ArithmeticError::Overflow)?; ensure!( - account_balance_to < collection.limits.account_token_ownership_limit(), + account_balance_to <= collection.limits.account_token_ownership_limit(), >::AccountTokenLimitExceeded, );