diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5986d89ef..bf65b8b3b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,8 +15,6 @@ jobs: matrix: package: - pallet-bridge-dispatch - - pallet-fee-market-rpc-runtime-api - - pallet-fee-market-rpc - pallet-fee-market - pallet-bridge-grandpa - pallet-bridge-messages diff --git a/Cargo.lock b/Cargo.lock index 2f91cec81..9b1e74b6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5617,32 +5617,6 @@ dependencies = [ "sp-std 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", ] -[[package]] -name = "pallet-fee-market-rpc" -version = "0.1.0" -dependencies = [ - "jsonrpc-core", - "jsonrpc-core-client", - "jsonrpc-derive", - "pallet-fee-market-rpc-runtime-api", - "parity-scale-codec", - "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-blockchain 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-runtime 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", -] - -[[package]] -name = "pallet-fee-market-rpc-runtime-api" -version = "0.1.0" -dependencies = [ - "bp-messages 0.1.0 (git+https://github.com/darwinia-network/darwinia-bridges-substrate?branch=darwinia-v0.12.2)", - "parity-scale-codec", - "serde", - "sp-api 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-runtime 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", - "sp-std 4.0.0-dev (git+https://github.com/darwinia-network/substrate?branch=darwinia-v0.12.2)", -] - [[package]] name = "pallet-grandpa" version = "4.0.0-dev" diff --git a/Cargo.toml b/Cargo.toml index 70215217a..d57157f3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,8 +3,6 @@ resolver = "2" members = [ "modules/*", - "modules/*/rpc", - "modules/*/rpc/runtime-api", "primitives/*", "relays/*", ] diff --git a/modules/fee-market/rpc/Cargo.toml b/modules/fee-market/rpc/Cargo.toml deleted file mode 100644 index c7e9df686..000000000 --- a/modules/fee-market/rpc/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -authors = ["Darwinia Network "] -description = "Node-specific RPC methods for interaction with fee-market" -edition = "2021" -homepage = "https://darwinia.network" -license = "GPL-3.0" -name = "pallet-fee-market-rpc" -readme = "README.md" -repository = "https://github.com/darwinia-network/darwinia-common" -version = "0.1.0" - -[dependencies] -# crates.io -codec = { package = "parity-scale-codec", version = "2.3" } -jsonrpc-core = { version = "18.0" } -jsonrpc-core-client = { version = "18.0" } -jsonrpc-derive = { version = "18.0" } -# darwinia-network -pallet-fee-market-rpc-runtime-api = { path = "./runtime-api" } -# paritytech -sp-api = { git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" } -sp-blockchain = { git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" } -sp-runtime = { git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" } diff --git a/modules/fee-market/rpc/runtime-api/Cargo.toml b/modules/fee-market/rpc/runtime-api/Cargo.toml deleted file mode 100644 index 74f7dc9d5..000000000 --- a/modules/fee-market/rpc/runtime-api/Cargo.toml +++ /dev/null @@ -1,34 +0,0 @@ -[package] -authors = ["Darwinia Network "] -description = "Runtime API definition required by fee-market RPC extensions." -edition = "2021" -homepage = "https://darwinia.network" -license = "GPL-3.0" -name = "pallet-fee-market-rpc-runtime-api" -readme = "README.md" -repository = "https://github.com/darwinia-network/darwinia-common" -version = "0.1.0" - -[dependencies] -# crates.io -codec = { package = "parity-scale-codec", version = "2.3", default-features = false } -serde = { version = "1.0", optional = true, features = ["derive"] } -# paritytech -bp-messages = { default-features = false, git = "https://github.com/darwinia-network/darwinia-bridges-substrate", branch = "darwinia-v0.12.2" } -sp-api = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" } -sp-runtime = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" } -sp-std = { default-features = false, git = "https://github.com/darwinia-network/substrate", branch = "darwinia-v0.12.2" } - -[features] -default = ["std"] - -std = [ - # crates.io - "codec/std", - "serde", - # paritytech - "bp-messages/std", - "sp-api/std", - "sp-std/std", - "sp-runtime/std", -] diff --git a/modules/fee-market/rpc/runtime-api/src/lib.rs b/modules/fee-market/rpc/runtime-api/src/lib.rs deleted file mode 100644 index b3068e74f..000000000 --- a/modules/fee-market/rpc/runtime-api/src/lib.rs +++ /dev/null @@ -1,80 +0,0 @@ -// This file is part of Darwinia. -// -// Copyright (C) 2018-2022 Darwinia Network -// SPDX-License-Identifier: GPL-3.0 -// -// Darwinia is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Darwinia is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Darwinia. If not, see . - -//! Runtime API definition required by header-mmr RPC extensions. -//! -//! This API should be imported and implemented by the runtime, -//! of a node that wants to use the custom RPC extension -//! adding header-mmr access methods. - -#![cfg_attr(not(feature = "std"), no_std)] - -// --- crates.io --- -use codec::{Codec, Decode, Encode}; -#[cfg(feature = "std")] -use serde::{Deserialize, Deserializer, Serialize, Serializer}; -// --- paritytech --- -use bp_messages::{LaneId, MessageNonce}; -use sp_api::decl_runtime_apis; -use sp_runtime::traits::{MaybeDisplay, MaybeFromStr}; -use sp_std::vec::Vec; - -#[derive(Eq, PartialEq, Encode, Decode, Default)] -#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] -#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] -pub struct Fee { - #[cfg_attr(feature = "std", serde(bound(serialize = "Balance: std::fmt::Display")))] - #[cfg_attr(feature = "std", serde(serialize_with = "serialize_as_string"))] - #[cfg_attr(feature = "std", serde(bound(deserialize = "Balance: std::str::FromStr")))] - #[cfg_attr(feature = "std", serde(deserialize_with = "deserialize_from_string"))] - pub amount: Balance, -} - -#[cfg(feature = "std")] -fn serialize_as_string( - t: &T, - serializer: S, -) -> Result { - serializer.serialize_str(&t.to_string()) -} - -#[cfg(feature = "std")] -fn deserialize_from_string<'de, D: Deserializer<'de>, T: std::str::FromStr>( - deserializer: D, -) -> Result { - let s = String::deserialize(deserializer)?; - s.parse::().map_err(|_| serde::de::Error::custom("Parse from string failed")) -} - -#[derive(Eq, PartialEq, Encode, Decode, Default)] -#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] -#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] -pub struct InProcessOrders { - pub orders: Vec<(LaneId, MessageNonce)>, -} - -decl_runtime_apis! { - pub trait FeeMarketApi - where - Balance: Codec + MaybeDisplay + MaybeFromStr, - { - fn market_fee(instance: u8) -> Option>; - - fn in_process_orders(instance: u8) -> InProcessOrders; - } -} diff --git a/modules/fee-market/rpc/src/lib.rs b/modules/fee-market/rpc/src/lib.rs deleted file mode 100644 index d0f86cc12..000000000 --- a/modules/fee-market/rpc/src/lib.rs +++ /dev/null @@ -1,91 +0,0 @@ -// This file is part of Darwinia. -// -// Copyright (C) 2018-2022 Darwinia Network -// SPDX-License-Identifier: GPL-3.0 -// -// Darwinia is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Darwinia is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Darwinia. If not, see . - -//! Node-specific RPC methods for interaction with fee-market. - -// --- darwinia-network --- -pub use pallet_fee_market_rpc_runtime_api::{ - Fee, FeeMarketApi as FeeMarketRuntimeApi, InProcessOrders, -}; - -// --- std --- -use std::sync::Arc; -// --- crates.io --- -use codec::Codec; -use jsonrpc_core::{Error, ErrorCode, Result}; -use jsonrpc_derive::rpc; -// --- paritytech --- -use sp_api::ProvideRuntimeApi; -use sp_blockchain::HeaderBackend; -use sp_runtime::{ - generic::BlockId, - traits::{Block as BlockT, MaybeDisplay, MaybeFromStr}, -}; - -const RUNTIME_ERROR: i64 = -1; - -#[rpc] -pub trait FeeMarketApi { - #[rpc(name = "fee_marketFee")] - fn market_fee(&self, instance: u8) -> Result>; - #[rpc(name = "fee_inProcessOrders")] - fn in_process_orders(&self, instance: u8) -> Result; -} - -pub struct FeeMarket { - client: Arc, - _marker: std::marker::PhantomData<(Block, Balance)>, -} - -impl FeeMarket { - pub fn new(client: Arc) -> Self { - Self { client, _marker: Default::default() } - } -} - -impl FeeMarketApi> for FeeMarket -where - Client: 'static + Send + Sync + ProvideRuntimeApi + HeaderBackend, - Client::Api: FeeMarketRuntimeApi, - Block: BlockT, - Balance: 'static + Sync + Send + Codec + MaybeDisplay + MaybeFromStr, -{ - fn market_fee(&self, instance: u8) -> Result>> { - let api = self.client.runtime_api(); - let best = self.client.info().best_hash; - let at = BlockId::hash(best); - - api.market_fee(&at, instance).map_err(|e| Error { - code: ErrorCode::ServerError(RUNTIME_ERROR), - message: "Unable to query market fee.".into(), - data: Some(format!("{:?}", e).into()), - }) - } - - fn in_process_orders(&self, instance: u8) -> Result { - let api = self.client.runtime_api(); - let best = self.client.info().best_hash; - let at = BlockId::hash(best); - - api.in_process_orders(&at, instance).map_err(|e| Error { - code: ErrorCode::ServerError(RUNTIME_ERROR), - message: "Unable to query in process orders.".into(), - data: Some(format!("{:?}", e).into()), - }) - } -} diff --git a/modules/fee-market/src/benchmarking.rs b/modules/fee-market/src/benchmarking.rs index 57bb91284..ec425cfc0 100644 --- a/modules/fee-market/src/benchmarking.rs +++ b/modules/fee-market/src/benchmarking.rs @@ -34,10 +34,10 @@ fn fee_market_ready() { let caller2: T::AccountId = account("source", 2, SEED); let caller3: T::AccountId = account("source", 3, SEED); let collateral = T::CollateralPerOrder::get(); - T::RingCurrency::make_free_balance_be(&caller0, collateral.saturating_mul(10u32.into())); - T::RingCurrency::make_free_balance_be(&caller1, collateral.saturating_mul(10u32.into())); - T::RingCurrency::make_free_balance_be(&caller2, collateral.saturating_mul(10u32.into())); - T::RingCurrency::make_free_balance_be(&caller3, collateral.saturating_mul(10u32.into())); + T::Currency::make_free_balance_be(&caller0, collateral.saturating_mul(10u32.into())); + T::Currency::make_free_balance_be(&caller1, collateral.saturating_mul(10u32.into())); + T::Currency::make_free_balance_be(&caller2, collateral.saturating_mul(10u32.into())); + T::Currency::make_free_balance_be(&caller3, collateral.saturating_mul(10u32.into())); assert_ne!(caller0, caller1); assert_ne!(caller1, caller2); @@ -69,7 +69,7 @@ benchmarks! { enroll_and_lock_collateral { fee_market_ready::(); let relayer: T::AccountId = account("source", 100, SEED); - T::RingCurrency::make_free_balance_be(&relayer, T::CollateralPerOrder::get().saturating_mul(10u32.into())); + T::Currency::make_free_balance_be(&relayer, T::CollateralPerOrder::get().saturating_mul(10u32.into())); let lock_collateral = T::CollateralPerOrder::get().saturating_mul(5u32.into()); }: enroll_and_lock_collateral(RawOrigin::Signed(relayer.clone()), lock_collateral, None) verify { diff --git a/modules/fee-market/src/lib.rs b/modules/fee-market/src/lib.rs index 62ce0baa4..8391410ef 100644 --- a/modules/fee-market/src/lib.rs +++ b/modules/fee-market/src/lib.rs @@ -50,7 +50,7 @@ use sp_std::vec::Vec; use types::{Order, Relayer, SlashReport}; pub type AccountId = ::AccountId; -pub type RingBalance = <>::RingCurrency as Currency>>::Balance; +pub type BalanceOf = <>::Currency as Currency>>::Balance; #[frame_support::pallet] pub mod pallet { @@ -68,10 +68,10 @@ pub mod pallet { /// The minimum fee for relaying. #[pallet::constant] - type MinimumRelayFee: Get>; + type MinimumRelayFee: Get>; /// The collateral relayer need to lock for each order. #[pallet::constant] - type CollateralPerOrder: Get>; + type CollateralPerOrder: Get>; /// The slot times set #[pallet::constant] type Slot: Get; @@ -86,7 +86,7 @@ pub mod pallet { /// The slash rule type Slasher: Slasher; - type RingCurrency: LockableCurrency; + type Currency: LockableCurrency; type Event: From> + IsType<::Event>; type WeightInfo: WeightInfo; @@ -96,19 +96,19 @@ pub mod pallet { #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event, I: 'static = ()> { /// Relayer enrollment. \[account_id, locked_collateral, relay_fee\] - Enroll(T::AccountId, RingBalance, RingBalance), + Enroll(T::AccountId, BalanceOf, BalanceOf), /// Update relayer locked collateral. \[account_id, new_collateral\] - UpdateLockedCollateral(T::AccountId, RingBalance), + UpdateLockedCollateral(T::AccountId, BalanceOf), /// Update relayer fee. \[account_id, new_fee\] - UpdateRelayFee(T::AccountId, RingBalance), + UpdateRelayFee(T::AccountId, BalanceOf), /// Relayer cancel enrollment. \[account_id\] CancelEnrollment(T::AccountId), /// Update collateral slash protect value. \[slash_protect_value\] - UpdateCollateralSlashProtect(RingBalance), + UpdateCollateralSlashProtect(BalanceOf), /// Update market assigned relayers numbers. \[new_assigned_relayers_number\] UpdateAssignedRelayersNumber(u32), /// Slash report - FeeMarketSlash(SlashReport>), + FeeMarketSlash(SlashReport>), } #[pallet::error] @@ -134,7 +134,7 @@ pub mod pallet { _, Blake2_128Concat, T::AccountId, - Relayer>, + Relayer>, ValueQuery, >; #[pallet::storage] @@ -146,7 +146,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn assigned_relayers)] pub type AssignedRelayers, I: 'static = ()> = - StorageValue<_, Vec>>, OptionQuery>; + StorageValue<_, Vec>>, OptionQuery>; // Order storage #[pallet::storage] @@ -155,14 +155,14 @@ pub mod pallet { _, Blake2_128Concat, (LaneId, MessageNonce), - Order>, + Order>, OptionQuery, >; #[pallet::storage] #[pallet::getter(fn collateral_slash_protect)] pub type CollateralSlashProtect, I: 'static = ()> = - StorageValue<_, RingBalance, OptionQuery>; + StorageValue<_, BalanceOf, OptionQuery>; #[pallet::storage] #[pallet::getter(fn assigned_relayers_number)] @@ -198,14 +198,14 @@ pub mod pallet { #[transactional] pub fn enroll_and_lock_collateral( origin: OriginFor, - lock_collateral: RingBalance, - relay_fee: Option>, + lock_collateral: BalanceOf, + relay_fee: Option>, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; ensure!(!Self::is_enrolled(&who), >::AlreadyEnrolled); ensure!( - T::RingCurrency::free_balance(&who) >= lock_collateral, + T::Currency::free_balance(&who) >= lock_collateral, >::InsufficientBalance ); if let Some(fee) = relay_fee { @@ -213,12 +213,7 @@ pub mod pallet { } let fee = relay_fee.unwrap_or_else(T::MinimumRelayFee::get); - T::RingCurrency::set_lock( - T::LockId::get(), - &who, - lock_collateral, - WithdrawReasons::all(), - ); + T::Currency::set_lock(T::LockId::get(), &who, lock_collateral, WithdrawReasons::all()); // Store enrollment detail information. >::insert(&who, Relayer::new(who.clone(), lock_collateral, fee)); >::append(&who); @@ -234,18 +229,18 @@ pub mod pallet { #[transactional] pub fn update_locked_collateral( origin: OriginFor, - new_collateral: RingBalance, + new_collateral: BalanceOf, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; ensure!(Self::is_enrolled(&who), >::NotEnrolled); ensure!( - T::RingCurrency::free_balance(&who) >= new_collateral, + T::Currency::free_balance(&who) >= new_collateral, >::InsufficientBalance ); // Increase the locked collateral if new_collateral >= Self::relayer(&who).collateral { - T::RingCurrency::set_lock( + T::Currency::set_lock( T::LockId::get(), &who, new_collateral, @@ -259,8 +254,8 @@ pub mod pallet { >::StillHasOrdersNotConfirmed ); - T::RingCurrency::remove_lock(T::LockId::get(), &who); - T::RingCurrency::set_lock( + T::Currency::remove_lock(T::LockId::get(), &who); + T::Currency::set_lock( T::LockId::get(), &who, new_collateral, @@ -282,7 +277,7 @@ pub mod pallet { #[transactional] pub fn update_relay_fee( origin: OriginFor, - new_fee: RingBalance, + new_fee: BalanceOf, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; ensure!(Self::is_enrolled(&who), >::NotEnrolled); @@ -314,7 +309,7 @@ pub mod pallet { #[transactional] pub fn set_slash_protect( origin: OriginFor, - slash_protect: RingBalance, + slash_protect: BalanceOf, ) -> DispatchResultWithPostInfo { ensure_root(origin)?; CollateralSlashProtect::::put(slash_protect); @@ -349,7 +344,7 @@ impl, I: 'static> Pallet { /// - The order didn't confirm in-time, slash occurred. pub(crate) fn update_market() { // Sort all enrolled relayers who are able to accept orders. - let mut relayers: Vec>> = >::get() + let mut relayers: Vec>> = >::get() .iter() .map(RelayersMap::::get) .filter(|r| Self::usable_order_capacity(&r.id) >= 1) @@ -373,10 +368,10 @@ impl, I: 'static> Pallet { /// needed) pub(crate) fn update_relayer_after_slash( who: &T::AccountId, - new_collateral: RingBalance, - report: SlashReport>, + new_collateral: BalanceOf, + report: SlashReport>, ) { - T::RingCurrency::set_lock(T::LockId::get(), &who, new_collateral, WithdrawReasons::all()); + T::Currency::set_lock(T::LockId::get(), &who, new_collateral, WithdrawReasons::all()); >::mutate(who.clone(), |relayer| { relayer.collateral = new_collateral; }); @@ -387,7 +382,7 @@ impl, I: 'static> Pallet { /// Remove enrolled relayer, then update market fee. (Update market needed) pub(crate) fn remove_enrolled_relayer(who: &T::AccountId) { - T::RingCurrency::remove_lock(T::LockId::get(), who); + T::Currency::remove_lock(T::LockId::get(), who); >::remove(who.clone()); >::mutate(|relayers| relayers.retain(|x| x != who)); @@ -406,7 +401,7 @@ impl, I: 'static> Pallet { /// Get market fee, If there is not enough relayers have order capacity to accept new order, /// return None. - pub fn market_fee() -> Option> { + pub fn market_fee() -> Option> { Self::assigned_relayers().and_then(|relayers| relayers.last().map(|r| r.fee)) } @@ -418,9 +413,9 @@ impl, I: 'static> Pallet { /// Whether the enrolled relayer is occupied(Responsible for order relaying) /// Whether the enrolled relayer is occupied, If occupied, return the number of orders and /// orders locked collateral, otherwise, return None. - pub(crate) fn occupied(who: &T::AccountId) -> Option<(u32, RingBalance)> { + pub(crate) fn occupied(who: &T::AccountId) -> Option<(u32, BalanceOf)> { let mut count = 0u32; - let mut orders_locked_collateral = RingBalance::::zero(); + let mut orders_locked_collateral = BalanceOf::::zero(); for (_, order) in >::iter() { if order.relayers_slice().iter().any(|r| r.id == *who) && !order.is_confirmed() { count += 1; @@ -446,11 +441,11 @@ impl, I: 'static> Pallet { Self::collateral_to_order_capacity(Self::relayer(who).collateral) } - fn collateral_to_order_capacity(collateral: RingBalance) -> u32 { + fn collateral_to_order_capacity(collateral: BalanceOf) -> u32 { (collateral / T::CollateralPerOrder::get()).saturated_into::() } } pub trait Slasher, I: 'static> { - fn slash(locked_collateral: RingBalance, timeout: T::BlockNumber) -> RingBalance; + fn slash(locked_collateral: BalanceOf, timeout: T::BlockNumber) -> BalanceOf; } diff --git a/modules/fee-market/src/s2s/payment.rs b/modules/fee-market/src/s2s/payment.rs index 4b65d604e..47e2697b7 100644 --- a/modules/fee-market/src/s2s/payment.rs +++ b/modules/fee-market/src/s2s/payment.rs @@ -37,7 +37,7 @@ pub struct FeeMarketPayment { _phantom: sp_std::marker::PhantomData<(T, I, Currency, RootAccount)>, } -impl MessageDeliveryAndDispatchPayment> +impl MessageDeliveryAndDispatchPayment> for FeeMarketPayment where T: frame_system::Config + Config, @@ -49,7 +49,7 @@ where fn pay_delivery_and_dispatch_fee( submitter: &Sender, - fee: &RingBalance, + fee: &BalanceOf, relayer_fund_account: &T::AccountId, ) -> Result<(), Self::Error> { let root_account = RootAccount::get(); @@ -60,7 +60,7 @@ where .ok_or("Sending messages using Root or None origin is disallowed.")?, }; - >::RingCurrency::transfer( + >::Currency::transfer( account, relayer_fund_account, *fee, @@ -115,15 +115,15 @@ pub fn slash_and_calculate_rewards( messages_relayers: VecDeque>, received_range: &RangeInclusive, relayer_fund_account: &T::AccountId, -) -> RewardsBook> +) -> RewardsBook> where T: frame_system::Config + Config, I: 'static, { - let mut confirmation_rewards = RingBalance::::zero(); - let mut messages_rewards = BTreeMap::>::new(); - let mut assigned_relayers_rewards = BTreeMap::>::new(); - let mut treasury_total_rewards = RingBalance::::zero(); + let mut confirmation_rewards = BalanceOf::::zero(); + let mut messages_rewards = BTreeMap::>::new(); + let mut assigned_relayers_rewards = BTreeMap::>::new(); + let mut treasury_total_rewards = BalanceOf::::zero(); for entry in messages_relayers { let nonce_begin = sp_std::cmp::max(entry.messages.begin, *received_range.start()); @@ -168,7 +168,7 @@ where let mut total_slash = message_fee; // calculate slash amount - let mut amount: RingBalance = T::Slasher::slash( + let mut amount: BalanceOf = T::Slasher::slash( order.locked_collateral, order.delivery_delay().unwrap_or_default(), ); @@ -177,7 +177,7 @@ where } // Slash order's assigned relayers - let mut assigned_relayers_slash = RingBalance::::zero(); + let mut assigned_relayers_slash = BalanceOf::::zero(); for assigned_relayer in order.relayers_slice() { let report = SlashReport::new(&order, assigned_relayer.id.clone(), amount); let slashed = do_slash::( @@ -219,17 +219,17 @@ where pub(crate) fn do_slash, I: 'static>( who: &T::AccountId, fund_account: &T::AccountId, - amount: RingBalance, - report: SlashReport>, -) -> RingBalance { + amount: BalanceOf, + report: SlashReport>, +) -> BalanceOf { let locked_collateral = Pallet::::relayer(&who).collateral; - T::RingCurrency::remove_lock(T::LockId::get(), &who); + T::Currency::remove_lock(T::LockId::get(), &who); debug_assert!( locked_collateral >= amount, "The locked collateral must alway greater than slash max" ); - let pay_result = >::RingCurrency::transfer( + let pay_result = >::Currency::transfer( who, fund_account, amount, @@ -251,20 +251,20 @@ pub(crate) fn do_slash, I: 'static>( }, } - RingBalance::::zero() + BalanceOf::::zero() } /// Do reward pub(crate) fn do_reward, I: 'static>( from: &T::AccountId, to: &T::AccountId, - reward: RingBalance, + reward: BalanceOf, ) { if reward.is_zero() { return } - let pay_result = >::RingCurrency::transfer( + let pay_result = >::Currency::transfer( from, to, reward, diff --git a/modules/fee-market/src/tests.rs b/modules/fee-market/src/tests.rs index 8f9488f5e..f9806a30b 100644 --- a/modules/fee-market/src/tests.rs +++ b/modules/fee-market/src/tests.rs @@ -56,10 +56,10 @@ use crate::{ *, }; -pub type Block = MockBlock; -pub type UncheckedExtrinsic = MockUncheckedExtrinsic; -pub type Balance = u64; -pub type AccountId = u64; +type Block = MockBlock; +type UncheckedExtrinsic = MockUncheckedExtrinsic; +type Balance = u64; +type AccountId = u64; frame_support::parameter_types! { pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 1, write: 2 }; @@ -417,7 +417,7 @@ frame_support::parameter_types! { pub struct TestSlasher; impl, I: 'static> Slasher for TestSlasher { - fn slash(locked_collateral: RingBalance, timeout: T::BlockNumber) -> RingBalance { + fn slash(locked_collateral: BalanceOf, timeout: T::BlockNumber) -> BalanceOf { let slash_each_block = 2; let slash_value = UniqueSaturatedInto::::unique_saturated_into(timeout) .saturating_mul(UniqueSaturatedInto::::unique_saturated_into(slash_each_block)) @@ -439,7 +439,7 @@ impl Config for Test { type ConfirmRelayersRewardRatio = ConfirmRelayersRewardRatio; type Slasher = TestSlasher; - type RingCurrency = Ring; + type Currency = Balances; type Event = Event; type WeightInfo = (); } @@ -452,7 +452,7 @@ frame_support::construct_runtime! { { System: frame_system::{Pallet, Call, Config, Storage, Event}, Timestamp: pallet_timestamp::{Pallet, Call, Storage}, - Ring: pallet_balances::{Pallet, Call, Storage, Config, Event}, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, FeeMarket: darwinia_fee_market::{Pallet, Call, Storage, Event}, Messages: pallet_bridge_messages::{Pallet, Call, Event}, } @@ -514,7 +514,7 @@ pub fn unrewarded_relayer( #[test] fn test_call_relayer_enroll_works() { new_test_ext().execute_with(|| { - assert_eq!(Ring::free_balance(1), 150); + assert_eq!(Balances::free_balance(1), 150); assert_err!( FeeMarket::enroll_and_lock_collateral(Origin::signed(1), 200, None), >::InsufficientBalance @@ -523,8 +523,8 @@ fn test_call_relayer_enroll_works() { assert_ok!(FeeMarket::enroll_and_lock_collateral(Origin::signed(1), 100, None)); assert!(FeeMarket::is_enrolled(&1)); assert_eq!(FeeMarket::relayers().len(), 1); - assert_eq!(Ring::free_balance(1), 150); - assert_eq!(Ring::usable_balance(&1), 50); + assert_eq!(Balances::free_balance(1), 150); + assert_eq!(Balances::usable_balance(&1), 50); assert_eq!(FeeMarket::relayer(&1).collateral, 100); assert_eq!(FeeMarket::market_fee(), None); assert_err!( diff --git a/modules/fee-market/src/types.rs b/modules/fee-market/src/types.rs index 5390b70d2..9fa9a0d37 100644 --- a/modules/fee-market/src/types.rs +++ b/modules/fee-market/src/types.rs @@ -1,19 +1,20 @@ -// This file is part of Frontier. +// This file is part of Darwinia. // -// Copyright (C) 2017-2020 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2018-2022 Darwinia Network +// SPDX-License-Identifier: GPL-3.0 // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// Darwinia is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // -// http://www.apache.org/licenses/LICENSE-2.0 +// Darwinia is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// You should have received a copy of the GNU General Public License +// along with Darwinia. If not, see . // --- core --- use core::{cmp::Ordering, ops::Range}; diff --git a/modules/grandpa/src/lib.rs b/modules/grandpa/src/lib.rs index d53ae2c40..e3074d41a 100644 --- a/modules/grandpa/src/lib.rs +++ b/modules/grandpa/src/lib.rs @@ -620,7 +620,9 @@ pub fn initialize_for_benchmarks, I: 'static>(header: BridgedHeader #[cfg(test)] mod tests { use super::*; - use crate::mock::{run_test, test_header, Origin, TestHash, TestHeader, TestNumber, TestRuntime}; + use crate::mock::{ + run_test, test_header, Origin, TestHash, TestHeader, TestNumber, TestRuntime, + }; use bp_test_utils::{ authority_list, make_default_justification, make_justification_for_header, JustificationGeneratorParams, ALICE, BOB, @@ -677,7 +679,9 @@ mod tests { delay, }); - Digest:: { logs: vec![DigestItem::Consensus(GRANDPA_ENGINE_ID, consensus_log.encode())] } + Digest:: { + logs: vec![DigestItem::Consensus(GRANDPA_ENGINE_ID, consensus_log.encode())], + } } fn forced_change_log(delay: u64) -> Digest { @@ -689,7 +693,9 @@ mod tests { }, ); - Digest:: { logs: vec![DigestItem::Consensus(GRANDPA_ENGINE_ID, consensus_log.encode())] } + Digest:: { + logs: vec![DigestItem::Consensus(GRANDPA_ENGINE_ID, consensus_log.encode())], + } } #[test]