Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Fix compile
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Lau <xavier@inv.cafe>
  • Loading branch information
AurevoirXavier committed Oct 24, 2023
1 parent aa56364 commit 5fa597f
Show file tree
Hide file tree
Showing 14 changed files with 729 additions and 698 deletions.
1,293 changes: 667 additions & 626 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ finality-grandpa = { version = "0.16", default-features = false }
hash-db = { version = "0.16", default-features = false }
num-traits = { version = "0.2", default-features = false }
scale-info = { version = "2.9", default-features = false, features = ["derive"] }
serde = { version = "1.0" }
serde = { version = "1.0", default-features = false }
trie-db = { version = "0.27", default-features = false }

# darwinia
Expand All @@ -32,7 +32,7 @@ pallet-bridge-parachains = { path = "modules/parachains", default-features = fal
pallet-fee-market = { path = "modules/fee-market", default-features = false }

# frontier
fp-account = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.0.0", default-features = false }
fp-account = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.0.0", default-features = false, features = ["serde"] }

# substrate
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false }
Expand Down
30 changes: 11 additions & 19 deletions modules/fee-market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ use s2s::RewardItem;
use types::{Order, Relayer, SlashReport};
// paritytech
use bp_messages::{LaneId, MessageNonce};
#[cfg(feature = "std")]
use frame_support::traits::GenesisBuild;
use frame_support::{
ensure,
pallet_prelude::*,
traits::{Currency, Get, LockIdentifier, LockableCurrency, WithdrawReasons},
PalletId,
DefaultNoBound, PalletId,
};
use frame_system::{ensure_signed, pallet_prelude::*, RawOrigin};
use sp_runtime::{
Expand Down Expand Up @@ -80,7 +78,7 @@ pub mod pallet {
type CollateralPerOrder: Get<BalanceOf<Self, I>>;
/// The slot times set
#[pallet::constant]
type Slot: Get<Self::BlockNumber>;
type Slot: Get<BlockNumberFor<Self>>;

/// Reward parameters
#[pallet::constant]
Expand All @@ -95,7 +93,7 @@ pub mod pallet {
type AssignedRelayerSlashRatio: Get<Permill>;
type Slasher: Slasher<Self, I>;

type Currency: LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>;
type Currency: LockableCurrency<Self::AccountId, Moment = BlockNumberFor<Self>>;
type RuntimeEvent: From<Event<Self, I>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
type WeightInfo: WeightInfo;
Expand All @@ -117,15 +115,15 @@ pub mod pallet {
/// Update market assigned relayers numbers. \[new_assigned_relayers_number\]
UpdateAssignedRelayersNumber(u32),
/// Slash report
FeeMarketSlash(SlashReport<T::AccountId, T::BlockNumber, BalanceOf<T, I>>),
FeeMarketSlash(SlashReport<T::AccountId, BlockNumberFor<T>, BalanceOf<T, I>>),
/// Create new order. \[lane_id, message_nonce, order_fee, assigned_relayers,
/// out_of_slots_time\]
OrderCreated(
LaneId,
MessageNonce,
BalanceOf<T, I>,
Vec<T::AccountId>,
Option<T::BlockNumber>,
Option<BlockNumberFor<T>>,
),
/// Reward distribute of the order. \[lane_id, message_nonce, rewards\]
OrderReward(LaneId, MessageNonce, RewardItem<T::AccountId, BalanceOf<T, I>>),
Expand Down Expand Up @@ -181,7 +179,7 @@ pub mod pallet {
_,
Blake2_128Concat,
(LaneId, MessageNonce),
Order<T::AccountId, T::BlockNumber, BalanceOf<T, I>>,
Order<T::AccountId, BlockNumberFor<T>, BalanceOf<T, I>>,
OptionQuery,
>;

Expand All @@ -199,21 +197,15 @@ pub mod pallet {
3
}

#[derive(DefaultNoBound)]
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
// Initialization relayers data.[AccoundId, Collateral, Quota]
pub relayers: Vec<(T::AccountId, BalanceOf<T, I>, Option<BalanceOf<T, I>>)>,
}

#[cfg(feature = "std")]
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self { relayers: vec![] }
}
}

#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
impl<T: Config<I>, I: 'static> BuildGenesisConfig for GenesisConfig<T, I> {
fn build(&self) {
self.relayers.iter().cloned().for_each(|(id, collateral, quota)| {
let _ = Pallet::<T, I>::enroll_and_lock_collateral(
Expand Down Expand Up @@ -504,7 +496,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
pub(crate) fn update_relayer_after_slash(
who: &T::AccountId,
new_collateral: BalanceOf<T, I>,
report: SlashReport<T::AccountId, T::BlockNumber, BalanceOf<T, I>>,
report: SlashReport<T::AccountId, BlockNumberFor<T>, BalanceOf<T, I>>,
) {
let _ = Self::update_market(
|| {
Expand Down Expand Up @@ -591,13 +583,13 @@ pub trait Slasher<T: Config<I>, I: 'static> {
/// Calculate the concrete slash amount
fn calc_amount(
collateral_per_order: BalanceOf<T, I>,
timeout: T::BlockNumber,
timeout: BlockNumberFor<T>,
) -> BalanceOf<T, I>;
}

/// No penalties, more for testing purposes.
impl<T: Config<I>, I: 'static> Slasher<T, I> for () {
fn calc_amount(_: BalanceOf<T, I>, _: T::BlockNumber) -> BalanceOf<T, I> {
fn calc_amount(_: BalanceOf<T, I>, _: BlockNumberFor<T>) -> BalanceOf<T, I> {
BalanceOf::<T, I>::zero()
}
}
2 changes: 1 addition & 1 deletion modules/fee-market/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ pub struct TestSlasher;
impl<T: Config<I>, I: 'static> Slasher<T, I> for TestSlasher {
fn calc_amount(
collateral_per_order: BalanceOf<T, I>,
timeout: T::BlockNumber,
timeout: BlockNumberFor<T>,
) -> BalanceOf<T, I> {
let slash_each_block = 2;
let slash_value = UniqueSaturatedInto::<u128>::unique_saturated_into(timeout)
Expand Down
2 changes: 1 addition & 1 deletion modules/fee-market/src/s2s/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ where
/// order. The slash part will be transferred to fund_account first, and then distributed to various
/// relayers.
pub(crate) fn slash_assigned_relayer<T: Config<I>, I: 'static>(
order: &Order<T::AccountId, T::BlockNumber, BalanceOf<T, I>>,
order: &Order<T::AccountId, BlockNumberFor<T>, BalanceOf<T, I>>,
who: &T::AccountId,
fund_account: &T::AccountId,
amount: BalanceOf<T, I>,
Expand Down
14 changes: 4 additions & 10 deletions modules/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use bp_runtime::{
};
use storage_types::StoredAuthoritySet;
// substrate
use frame_support::{ensure, fail, log};
use frame_support::{ensure, fail, log, DefaultNoBound};
use frame_system::ensure_signed;
use sp_consensus_grandpa::{ConsensusLog, GRANDPA_ENGINE_ID};
use sp_runtime::traits::{Header as HeaderT, Zero};
Expand Down Expand Up @@ -134,7 +134,7 @@ pub mod pallet {

#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
fn on_initialize(_n: T::BlockNumber) -> frame_support::weights::Weight {
fn on_initialize(_n: BlockNumberFor<T>) -> frame_support::weights::Weight {
<RequestCount<T, I>>::mutate(|count| *count = count.saturating_sub(1));

T::DbWeight::get().reads_writes(1, 1)
Expand Down Expand Up @@ -347,6 +347,7 @@ pub mod pallet {
pub type PalletOperatingMode<T: Config<I>, I: 'static = ()> =
StorageValue<_, BasicOperatingMode, ValueQuery>;

#[derive(DefaultNoBound)]
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
/// Optional module owner account.
Expand All @@ -355,15 +356,8 @@ pub mod pallet {
pub init_data: Option<super::InitializationData<BridgedHeader<T, I>>>,
}

#[cfg(feature = "std")]
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self { owner: None, init_data: None }
}
}

#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
impl<T: Config<I>, I: 'static> BuildGenesisConfig for GenesisConfig<T, I> {
fn build(&self) {
if let Some(ref owner) = self.owner {
<PalletOwner<T, I>>::put(owner);
Expand Down
18 changes: 4 additions & 14 deletions modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ use bp_messages::{
};
use bp_runtime::{BasicOperatingMode, ChainId, OwnedBridgeModule, Size};
// substrate
use frame_support::{dispatch::PostDispatchInfo, ensure, fail, log, traits::Get};
use frame_support::{dispatch::PostDispatchInfo, ensure, fail, log, traits::Get, DefaultNoBound};
use sp_core::H256;
use sp_runtime::traits::Convert;
use sp_std::{cell::RefCell, marker::PhantomData, prelude::*};
Expand Down Expand Up @@ -681,7 +681,8 @@ pub mod pallet {
pub type OutboundMessages<T: Config<I>, I: 'static = ()> =
StorageMap<_, Blake2_128Concat, MessageKey, StoredMessageData<T, I>>;

#[pallet::genesis_config]
#[derive(DefaultNoBound)]
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
/// Initial pallet operating mode.
pub operating_mode: MessagesOperatingMode,
Expand All @@ -691,19 +692,8 @@ pub mod pallet {
pub phantom: sp_std::marker::PhantomData<I>,
}

#[cfg(feature = "std")]
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self {
operating_mode: Default::default(),
owner: Default::default(),
phantom: Default::default(),
}
}
}

#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
impl<T: Config<I>, I: 'static> BuildGenesisConfig for GenesisConfig<T, I> {
fn build(&self) {
PalletOperatingMode::<T, I>::put(self.operating_mode);
if let Some(ref owner) = self.owner {
Expand Down
16 changes: 3 additions & 13 deletions modules/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use bp_parachains::{parachain_head_storage_key_at_source, ParaInfo};
use bp_polkadot_core::parachains::{ParaHash, ParaHasher, ParaHead, ParaHeadsProof, ParaId};
use bp_runtime::StorageProofError;
// substrate
use frame_support::{dispatch::PostDispatchInfo, traits::Contains};
use frame_support::{dispatch::PostDispatchInfo, traits::Contains, DefaultNoBound};
use sp_runtime::traits::Header as HeaderT;
use sp_std::prelude::*;

Expand Down Expand Up @@ -590,6 +590,7 @@ pub mod pallet {
}
}

#[derive(DefaultNoBound)]
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
/// Initial pallet operating mode.
Expand All @@ -600,19 +601,8 @@ pub mod pallet {
pub phantom: sp_std::marker::PhantomData<I>,
}

#[cfg(feature = "std")]
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
Self {
operating_mode: Default::default(),
owner: Default::default(),
phantom: Default::default(),
}
}
}

#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
impl<T: Config<I>, I: 'static> BuildGenesisConfig for GenesisConfig<T, I> {
fn build(&self) {
PalletOperatingMode::<T, I>::put(self.operating_mode);
if let Some(ref owner) = self.owner {
Expand Down
6 changes: 3 additions & 3 deletions primitives/header-chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use core::fmt::Debug;
// crates.io
use codec::{Codec, Decode, Encode, EncodeLike};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
// darwinia-network
use bp_runtime::BasicOperatingMode;
Expand Down Expand Up @@ -67,8 +66,9 @@ impl AuthoritySet {
/// Data required for initializing the bridge pallet.
///
/// The bridge needs to know where to start its sync from, and this provides that initial context.
#[derive(Clone, Default, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(
Clone, Default, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, RuntimeDebug, TypeInfo,
)]
pub struct InitializationData<H: HeaderT> {
/// The header from which we should start syncing.
pub header: Box<H>,
Expand Down
4 changes: 2 additions & 2 deletions primitives/messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bitvec = { workspace = true }
codec = { package = "parity-scale-codec", workspace = true, features = ["bit-vec"] }
impl-trait-for-tuples = { version = "0.2" }
scale-info = { workspace = true, features = ["bit-vec"] }
serde = { workspace = true, optional = true }
serde = { workspace = true }

# darwinia-messages-substrate
bp-runtime = { workspace = true }
Expand All @@ -34,7 +34,7 @@ std = [
"bitvec/std",
"codec/std",
"scale-info/std",
"serde",
"serde/std",

# darwinia-messages-substrate
"bp-runtime/std",
Expand Down
16 changes: 14 additions & 2 deletions primitives/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod target_chain;
use bitvec::prelude::*;
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
// darwinia-network
use bp_runtime::{BasicOperatingMode, OperatingMode};
// substrate
Expand Down Expand Up @@ -63,8 +64,19 @@ impl Parameter for () {
}

/// Messages pallet operating mode.
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
Encode,
Decode,
RuntimeDebug,
MaxEncodedLen,
TypeInfo,
)]
pub enum MessagesOperatingMode {
/// Basic operating mode (Normal/Halted)
Basic(BasicOperatingMode),
Expand Down
4 changes: 2 additions & 2 deletions primitives/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ codec = { package = "parity-scale-codec", workspace = true }
hash-db = { workspace = true }
num-traits = { workspace = true }
scale-info = { workspace = true }
serde = { workspace = true, optional = true }
serde = { workspace = true }
trie-db = { workspace = true }

# substrate
Expand All @@ -37,7 +37,7 @@ std = [
"hash-db/std",
"num-traits/std",
"scale-info/std",
"serde",
"serde/std",

# substrate
"frame-support/std",
Expand Down
16 changes: 14 additions & 2 deletions primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub use sp_runtime::paste;
use codec::{Decode, Encode, FullCodec, MaxEncodedLen};
use num_traits::{CheckedSub, One};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
// substrate
use frame_support::{
log, pallet_prelude::DispatchResult, PalletError, RuntimeDebug, StorageHasher, StorageValue,
Expand Down Expand Up @@ -351,8 +352,19 @@ pub enum OwnedBridgeModuleError {
}

/// Basic operating modes for a bridges module (Normal/Halted).
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, RuntimeDebug, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Clone,
Copy,
PartialEq,
Eq,
Serialize,
Deserialize,
Encode,
Decode,
RuntimeDebug,
MaxEncodedLen,
TypeInfo,
)]
pub enum BasicOperatingMode {
/// Normal mode, when all operations are allowed.
Normal,
Expand Down
2 changes: 1 addition & 1 deletion runtime-common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ pub mod target {
impl<DecodedCall> FromBridgedChainEncodedMessageCall<DecodedCall> {
/// Create encoded call.
pub fn new(encoded_call: Vec<u8>) -> Self {
FromBridgedChainEncodedMessageCall { encoded_call, _marker: PhantomData::default() }
FromBridgedChainEncodedMessageCall { encoded_call, _marker: PhantomData }
}
}

Expand Down

0 comments on commit 5fa597f

Please sign in to comment.