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

Commit

Permalink
merge #72
Browse files Browse the repository at this point in the history
  • Loading branch information
jiguantong committed May 18, 2022
1 parent 1ff7292 commit f5fccff
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 57 deletions.
3 changes: 1 addition & 2 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ where
+ sp_blockchain::HeaderMetadata<Block, Error = BlockChainError>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ sp_block_builder::BlockBuilder<Block>

+ sp_block_builder::BlockBuilder<Block>,
P: 'static + Send + Sync + sc_transaction_pool_api::TransactionPool,
{
// --- paritytech ---
Expand Down
15 changes: 8 additions & 7 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,19 @@ where
/// dispatch origin;
/// - check that the sender has paid enough funds for both message delivery and dispatch.
#[derive(RuntimeDebug)]
pub struct FromThisChainMessageVerifier<B, R>(PhantomData<(B, R)>);
impl<B, R>
pub struct FromThisChainMessageVerifier<B, R, I>(PhantomData<(B, R, I)>);
impl<B, R, I>
LaneMessageVerifier<
AccountIdOf<ThisChain<B>>,
FromThisChainMessagePayload<B>,
BalanceOf<ThisChain<B>>,
> for FromThisChainMessageVerifier<B, R>
> for FromThisChainMessageVerifier<B, R, I>
where
B: MessageBridge,
R: pallet_fee_market::Config,
R: pallet_fee_market::Config<I>,
I: 'static,
AccountIdOf<ThisChain<B>>: Clone + PartialEq,
pallet_fee_market::RingBalance<R>: From<BalanceOf<ThisChain<B>>>,
pallet_fee_market::BalanceOf<R, I>: From<BalanceOf<ThisChain<B>>>,
{
type Error = &'static str;

Expand Down Expand Up @@ -173,8 +174,8 @@ where

// Do the delivery_and_dispatch_fee. We assume that the delivery and dispatch fee always
// greater than the fee market provided fee.
if let Some(market_fee) = pallet_fee_market::Pallet::<R>::market_fee() {
let message_fee: pallet_fee_market::RingBalance<R> =
if let Some(market_fee) = pallet_fee_market::Pallet::<R, I>::market_fee() {
let message_fee: pallet_fee_market::BalanceOf<R, I> =
(*delivery_and_dispatch_fee).into();

// compare with actual fee paid
Expand Down
6 changes: 5 additions & 1 deletion runtime/crab-parachain/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// --- paritytech ---
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};
#[allow(unused)]
use frame_support::{migration, traits::OnRuntimeUpgrade, weights::Weight};
// --- darwinia-network ---
#[allow(unused)]
use crate::*;

pub struct CustomOnRuntimeUpgrade;
impl OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
Expand Down
4 changes: 2 additions & 2 deletions runtime/pangolin-parachain/src/bridges_message/pangolin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub type ToPangolinMessagePayload = FromThisChainMessagePayload<WithPangolinMess
pub type FromPangolinMessagePayload = FromBridgedChainMessagePayload<WithPangolinMessageBridge>;

/// Message verifier for PangolinParachain -> Pangolin messages.
pub type ToPangolinMessageVerifier<R> = FromThisChainMessageVerifier<WithPangolinMessageBridge, R>;

pub type ToPangolinMessageVerifier<R> =
FromThisChainMessageVerifier<WithPangolinMessageBridge, R, WithPangolinFeeMarket>;
/// Encoded Pangolin Call as it comes from Pangolin.
pub type FromPangolinEncodedCall = FromBridgedChainEncodedMessageCall<Call>;

Expand Down
6 changes: 5 additions & 1 deletion runtime/pangolin-parachain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub mod wasm {
}
pub use wasm::*;

mod migrations;
use migrations::*;

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;
Expand Down Expand Up @@ -108,6 +111,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
CustomOnRuntimeUpgrade,
>;

type Ring = Balances;
Expand Down Expand Up @@ -181,7 +185,7 @@ frame_support::construct_runtime! {
BridgePangolinMessages: pallet_bridge_messages::<Instance1>::{Pallet, Call, Storage, Event<T>} = 21,
BridgePangolinDispatch: pallet_bridge_dispatch::<Instance1>::{Pallet, Event<T>} = 22,

FeeMarket: pallet_fee_market::{Pallet, Call, Storage, Event<T>} = 23,
PangolinFeeMarket: pallet_fee_market::<Instance1>::{Pallet, Call, Storage, Event<T>} = 23,
}
}

Expand Down
43 changes: 16 additions & 27 deletions runtime/pangolin-parachain/src/pallets/bridge_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,25 @@ frame_support::parameter_types! {
}

impl Config<WithPangolinMessages> for Runtime {
type AccountIdConverter = bp_pangolin_parachain::AccountIdConverter;
type BridgedChainId = BridgedChainId;
type Event = Event;
type WeightInfo = WeightInfo<Runtime>;
type Parameter = bm_pangolin::PangolinParachainToPangolinParameter;
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;

type OutboundPayload = bm_pangolin::ToPangolinMessagePayload;
type OutboundMessageFee = Balance;

type InboundPayload = bm_pangolin::FromPangolinMessagePayload;
type InboundMessageFee = bp_pangolin::Balance;
type InboundPayload = bm_pangolin::FromPangolinMessagePayload;
type InboundRelayer = bp_pangolin::AccountId;

type AccountIdConverter = bp_pangolin_parachain::AccountIdConverter;

type TargetHeaderChain = bm_pangolin::Pangolin;
type LaneMessageVerifier = bm_pangolin::ToPangolinMessageVerifier<Self>;
type MessageDeliveryAndDispatchPayment = FeeMarketPayment<
Runtime,
WithPangolinMessages,
Ring,
GetDeliveryConfirmationTransactionFee,
RootAccountForPayments,
>;

type OnMessageAccepted = FeeMarketMessageAcceptedHandler<Self>;
type OnDeliveryConfirmed = (FeeMarketMessageConfirmedHandler<Self>,);

type SourceHeaderChain = bm_pangolin::Pangolin;
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
type MessageDeliveryAndDispatchPayment =
FeeMarketPayment<Self, WithPangolinFeeMarket, Ring, RootAccountForPayments>;
type MessageDispatch = bm_pangolin::FromPangolinMessageDispatch;
type BridgedChainId = BridgedChainId;
type OnDeliveryConfirmed = (FeeMarketMessageConfirmedHandler<Self, WithPangolinFeeMarket>,);
type OnMessageAccepted = FeeMarketMessageAcceptedHandler<Self, WithPangolinFeeMarket>;
type OutboundMessageFee = bp_pangolin_parachain::Balance;
type OutboundPayload = bm_pangolin::ToPangolinMessagePayload;
type Parameter = bm_pangolin::PangolinParachainToPangolinParameter;
type SourceHeaderChain = bm_pangolin::Pangolin;
type TargetHeaderChain = bm_pangolin::Pangolin;
type WeightInfo = WeightInfo<Runtime>;
}
35 changes: 18 additions & 17 deletions runtime/pangolin-parachain/src/pallets/fee_market.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
pub use pallet_fee_market::Instance1 as WithPangolinFeeMarket;

// --- core ---
use core::cmp;
// --- substrate ---
use frame_support::{traits::LockIdentifier, PalletId};
use sp_runtime::{traits::UniqueSaturatedInto, Permill};
// --- darwinia ---
use crate::{weights::pallet_fee_market::WeightInfo, *};
use pallet_fee_market::{Config, RingBalance, Slasher};
use pallet_fee_market::{BalanceOf, Config, Slasher};

pub struct FeeMarketSlasher;
impl<T: Config> Slasher<T> for FeeMarketSlasher {
fn slash(locked_collateral: RingBalance<T>, timeout: T::BlockNumber) -> RingBalance<T> {
impl<T, I> Slasher<T, I> for FeeMarketSlasher
where
T: Config<I>,
I: 'static,
{
fn slash(locked_collateral: BalanceOf<T, I>, timeout: T::BlockNumber) -> BalanceOf<T, I> {
let slash_each_block = 2 * COIN;
let slash_value = UniqueSaturatedInto::<Balance>::unique_saturated_into(timeout)
.saturating_mul(UniqueSaturatedInto::<Balance>::unique_saturated_into(
Expand All @@ -22,7 +28,6 @@ impl<T: Config> Slasher<T> for FeeMarketSlasher {
}

frame_support::parameter_types! {
pub const FeeMarketPalletId: PalletId = PalletId(*b"da/feemk");
pub const TreasuryPalletId: PalletId = PalletId(*b"da/trsry");
pub const FeeMarketLockId: LockIdentifier = *b"da/feelf";

Expand All @@ -35,21 +40,17 @@ frame_support::parameter_types! {
pub const ConfirmRelayersRewardRatio: Permill = Permill::from_percent(20);
}

impl Config for Runtime {
type PalletId = FeeMarketPalletId;
type TreasuryPalletId = TreasuryPalletId;
type LockId = FeeMarketLockId;

type MinimumRelayFee = MinimumRelayFee;
type CollateralPerOrder = CollateralPerOrder;
type Slot = Slot;

impl Config<WithPangolinFeeMarket> for Runtime {
type AssignedRelayersRewardRatio = AssignedRelayersRewardRatio;
type MessageRelayersRewardRatio = MessageRelayersRewardRatio;
type CollateralPerOrder = CollateralPerOrder;
type ConfirmRelayersRewardRatio = ConfirmRelayersRewardRatio;

type Slasher = FeeMarketSlasher;
type RingCurrency = Ring;
type Currency = Ring;
type Event = Event;
type LockId = FeeMarketLockId;
type MessageRelayersRewardRatio = MessageRelayersRewardRatio;
type MinimumRelayFee = MinimumRelayFee;
type Slasher = FeeMarketSlasher;
type Slot = Slot;
type TreasuryPalletId = TreasuryPalletId;
type WeightInfo = WeightInfo<Runtime>;
}

0 comments on commit f5fccff

Please sign in to comment.