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

Prepare polkadot v0.9.30 for darwinia-2.0 #226

Merged
merged 15 commits into from
Nov 21, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Companion for paritytech/parity-bridges-common#1597 part.4 fix compile
jiguantong committed Nov 17, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
BridgeAR Ruben Bridgewater
commit ccbe15f97c2344ff9a30073a1788e965b9de7894
29 changes: 18 additions & 11 deletions modules/dispatch/src/lib.rs
Original file line number Diff line number Diff line change
@@ -38,11 +38,10 @@ use bp_runtime::{
};
// paritytech
use frame_support::{
dispatch::{DispatchInfo, DispatchResultWithPostInfo, Dispatchable, Weight},
dispatch::{DispatchInfo, DispatchResultWithPostInfo, Dispatchable, GetDispatchInfo, Weight},
ensure, log,
pallet_prelude::Pays,
traits::Get,
weights::GetDispatchInfo,
};
use frame_system::RawOrigin;
use sp_runtime::traits::{BadOrigin, Convert, IdentifyAccount, MaybeDisplay, Verify, Zero};
@@ -59,7 +58,8 @@ pub mod pallet {
#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config {
/// The overarching event type.
type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;
type RuntimeEvent: From<Event<Self, I>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Id of the message. Whenever message is passed to the dispatch module, it emits
/// event with this id + dispatch result. Could be e.g. (LaneId, MessageNonce) if
/// it comes from the messages module.
@@ -77,33 +77,40 @@ pub mod pallet {
/// owner of `TargetChainAccountPublic`.
type TargetChainSignature: Parameter + Verify<Signer = Self::TargetChainAccountPublic>;
/// The overarching dispatch call type.
type Call: Parameter
type RuntimeCall: Parameter
+ GetDispatchInfo
+ Dispatchable<
Origin = <Self as frame_system::Config>::Origin,
RuntimeOrigin = <Self as frame_system::Config>::RuntimeOrigin,
PostInfo = frame_support::dispatch::PostDispatchInfo,
>;
/// Pre-dispatch validation for incoming calls.
///
/// The pallet will validate all incoming calls right before they're dispatched. If this
/// validator rejects the call, special event (`Event::MessageCallRejected`) is emitted.
type CallValidator: CallValidate<Self::AccountId, Self::Origin, <Self as Config<I>>::Call>;
type CallValidator: CallValidate<
Self::AccountId,
Self::RuntimeOrigin,
<Self as Config<I>>::RuntimeCall,
>;
/// The type that is used to wrap the `Self::Call` when it is moved over bridge.
///
/// The idea behind this is to avoid `Call` conversion/decoding until we'll be sure
/// that all other stuff (like `spec_version`) is ok. If we would try to decode
/// `Call` which has been encoded using previous `spec_version`, then we might end
/// up with decoding error, instead of `MessageVersionSpecMismatch`.
type EncodedCall: Decode + Encode + Into<Result<<Self as Config<I>>::Call, ()>> + Clone;
type EncodedCall: Decode
+ Encode
+ Into<Result<<Self as Config<I>>::RuntimeCall, ()>>
+ Clone;
/// A type which can be turned into an AccountId from a 256-bit hash.
///
/// Used when deriving target chain AccountIds from source chain AccountIds.
type AccountIdConverter: sp_runtime::traits::Convert<sp_core::hash::H256, Self::AccountId>;
/// The type is used to customize the dispatch call origin.
type IntoDispatchOrigin: IntoDispatchOrigin<
Self::AccountId,
<Self as Config<I>>::Call,
Self::Origin,
<Self as Config<I>>::RuntimeCall,
Self::RuntimeOrigin,
>;
}

@@ -207,7 +214,7 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
Self::deposit_event(Event::MessageRejected(source_chain, id));
return MessageDispatchResult {
dispatch_result: false,
unspent_weight: 0,
unspent_weight: Weight::from_ref_time(0),
dispatch_fee_paid_during_dispatch: false,
};
},
@@ -319,7 +326,7 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
// because otherwise Calls may be dispatched at lower price)
let dispatch_info = call.get_dispatch_info();
let expected_weight = dispatch_info.weight;
if message.weight < expected_weight {
if message.weight.all_lt(expected_weight) {
log::trace!(
target: "runtime::bridge-dispatch",
"Message {:?}/{:?}: passed weight is too low. Expected at least {:?}, got {:?}",
3 changes: 2 additions & 1 deletion modules/fee-market/src/lib.rs
Original file line number Diff line number Diff line change
@@ -96,7 +96,8 @@ pub mod pallet {
type Slasher: Slasher<Self, I>;

type Currency: LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>;
type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;
type RuntimeEvent: From<Event<Self, I>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
type WeightInfo: WeightInfo;
}

6 changes: 2 additions & 4 deletions modules/fee-market/src/mock.rs
Original file line number Diff line number Diff line change
@@ -221,13 +221,11 @@ impl TargetHeaderChain<TestPayload, TestRelayer> for TestTargetHeaderChain {
/// Lane message verifier that is used in tests.
#[derive(Debug, Default)]
pub struct TestLaneMessageVerifier;
impl LaneMessageVerifier<Origin, AccountId, TestPayload, TestMessageFee>
for TestLaneMessageVerifier
{
impl LaneMessageVerifier<RuntimeOrigin, TestPayload, TestMessageFee> for TestLaneMessageVerifier {
type Error = &'static str;

fn verify_message(
_submitter: &Origin,
_submitter: &RuntimeOrigin,
delivery_and_dispatch_fee: &TestMessageFee,
_lane: &LaneId,
_lane_outbound_data: &OutboundLaneData,
7 changes: 4 additions & 3 deletions modules/fee-market/src/s2s/payment.rs
Original file line number Diff line number Diff line change
@@ -44,18 +44,19 @@ pub struct FeeMarketPayment<T, I, Currency> {
_phantom: sp_std::marker::PhantomData<(T, I, Currency)>,
}

impl<T, I, Currency> MessageDeliveryAndDispatchPayment<T::Origin, T::AccountId, BalanceOf<T, I>>
impl<T, I, Currency>
MessageDeliveryAndDispatchPayment<T::RuntimeOrigin, T::AccountId, BalanceOf<T, I>>
for FeeMarketPayment<T, I, Currency>
where
T: frame_system::Config + Config<I>,
I: 'static,
T::Origin: SenderOrigin<T::AccountId>,
T::RuntimeOrigin: SenderOrigin<T::AccountId>,
Currency: CurrencyT<T::AccountId>,
{
type Error = &'static str;

fn pay_delivery_and_dispatch_fee(
submitter: &T::Origin,
submitter: &T::RuntimeOrigin,
fee: &BalanceOf<T, I>,
relayer_fund_account: &T::AccountId,
) -> Result<(), Self::Error> {
5 changes: 3 additions & 2 deletions modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ use bp_messages::{
};
use bp_runtime::{BasicOperatingMode, ChainId, OwnedBridgeModule, Size};
// paritytech
use frame_support::{dispatch::PostDispatchInfo, ensure, fail, traits::Get};
use frame_support::{dispatch::PostDispatchInfo, ensure, fail, log, traits::Get};
use sp_core::H256;
use sp_runtime::traits::Convert;
use sp_std::{cell::RefCell, marker::PhantomData, prelude::*};
@@ -99,7 +99,8 @@ pub mod pallet {
// General types

/// The overarching event type.
type RuntimeEvent: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;
type RuntimeEvent: From<Event<Self, I>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Benchmarks results from runtime we're plugged into.
type WeightInfo: WeightInfoExt;

47 changes: 24 additions & 23 deletions modules/messages/src/weights_ext.rs
Original file line number Diff line number Diff line change
@@ -44,26 +44,26 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>(
db_weight: RuntimeDbWeight,
) {
// verify `send_message` weight components
assert_ne!(W::send_message_overhead(), 0);
assert_ne!(W::send_message_size_overhead(0), 0);
assert_ne!(W::send_message_overhead(), Weight::from_ref_time(0));
assert_ne!(W::send_message_size_overhead(0), Weight::from_ref_time(0));

// verify `receive_messages_proof` weight components
assert_ne!(W::receive_messages_proof_overhead(), 0);
assert_ne!(W::receive_messages_proof_messages_overhead(1), 0);
assert_ne!(W::receive_messages_proof_outbound_lane_state_overhead(), 0);
assert_ne!(W::storage_proof_size_overhead(1), 0);
assert_ne!(W::receive_messages_proof_overhead(), Weight::from_ref_time(0));
assert_ne!(W::receive_messages_proof_messages_overhead(1), Weight::from_ref_time(0));
assert_ne!(W::receive_messages_proof_outbound_lane_state_overhead(), Weight::from_ref_time(0));
assert_ne!(W::storage_proof_size_overhead(1), Weight::from_ref_time(0));

// verify that the hardcoded value covers `receive_messages_proof` weight
let actual_single_regular_message_delivery_tx_weight = W::receive_messages_proof_weight(
&PreComputedSize(
(EXPECTED_DEFAULT_MESSAGE_LENGTH + W::expected_extra_storage_proof_size()) as usize,
),
1,
0,
Weight::from_ref_time(0),
);
assert!(
actual_single_regular_message_delivery_tx_weight
<= expected_default_message_delivery_tx_weight,
actual_single_regular_message_delivery_tx_weight.ref_time()
<= expected_default_message_delivery_tx_weight.ref_time(),
"Default message delivery transaction weight {} is larger than expected weight {}",
actual_single_regular_message_delivery_tx_weight,
expected_default_message_delivery_tx_weight,
@@ -72,15 +72,16 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>(
// verify that hardcoded value covers additional byte length of `receive_messages_proof` weight
let actual_additional_byte_delivery_weight = W::storage_proof_size_overhead(1);
assert!(
actual_additional_byte_delivery_weight <= expected_additional_byte_delivery_weight,
actual_additional_byte_delivery_weight.ref_time()
<= expected_additional_byte_delivery_weight.ref_time(),
"Single additional byte delivery weight {} is larger than expected weight {}",
actual_additional_byte_delivery_weight,
expected_additional_byte_delivery_weight,
);

// verify `receive_messages_delivery_proof` weight components
assert_ne!(W::receive_messages_delivery_proof_overhead(), 0);
assert_ne!(W::storage_proof_size_overhead(1), 0);
assert_ne!(W::receive_messages_delivery_proof_overhead(), Weight::from_ref_time(0));
assert_ne!(W::storage_proof_size_overhead(1), Weight::from_ref_time(0));

// `receive_messages_delivery_proof_messages_overhead` and
// `receive_messages_delivery_proof_relayers_overhead` may return zero if rewards are not paid
@@ -97,8 +98,8 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>(
db_weight,
);
assert!(
actual_messages_delivery_confirmation_tx_weight
<= expected_messages_delivery_confirmation_tx_weight,
actual_messages_delivery_confirmation_tx_weight.ref_time()
<= expected_messages_delivery_confirmation_tx_weight.ref_time(),
"Messages delivery confirmation transaction weight {} is larger than expected weight {}",
actual_messages_delivery_confirmation_tx_weight,
expected_messages_delivery_confirmation_tx_weight,
@@ -107,7 +108,7 @@ pub fn ensure_weights_are_correct<W: WeightInfoExt>(
// verify pay-dispatch-fee overhead for inbound messages
let actual_pay_inbound_dispatch_fee_weight = W::pay_inbound_dispatch_fee_overhead();
assert!(
actual_pay_inbound_dispatch_fee_weight <= expected_pay_inbound_dispatch_fee_weight,
actual_pay_inbound_dispatch_fee_weight.ref_time() <= expected_pay_inbound_dispatch_fee_weight.ref_time(),
"Weight {} of pay-dispatch-fee overhead for inbound messages is larger than expected weight {}",
actual_pay_inbound_dispatch_fee_weight,
expected_pay_inbound_dispatch_fee_weight,
@@ -141,7 +142,7 @@ pub fn ensure_able_to_receive_message<W: WeightInfoExt>(
max_incoming_message_dispatch_weight,
);
assert!(
max_delivery_transaction_dispatch_weight <= max_extrinsic_weight,
max_delivery_transaction_dispatch_weight.ref_time() <= max_extrinsic_weight.ref_time(),
"Weight of maximal message delivery transaction + {} is larger than maximal possible transaction weight {}",
max_delivery_transaction_dispatch_weight,
max_extrinsic_weight,
@@ -180,7 +181,7 @@ pub fn ensure_able_to_receive_confirmation<W: WeightInfoExt>(
db_weight,
);
assert!(
max_confirmation_transaction_dispatch_weight <= max_extrinsic_weight,
max_confirmation_transaction_dispatch_weight.ref_time() <= max_extrinsic_weight.ref_time(),
"Weight of maximal confirmation transaction {} is larger than maximal possible transaction weight {}",
max_confirmation_transaction_dispatch_weight,
max_extrinsic_weight,
@@ -265,13 +266,13 @@ pub trait WeightInfoExt: WeightInfo {
// message
let callback_overhead = relayers_state
.total_messages
.saturating_mul(Self::single_message_callback_overhead(db_weight));
.saturating_mul(Self::single_message_callback_overhead(db_weight).ref_time());

transaction_overhead
.saturating_add(messages_overhead)
.saturating_add(relayers_overhead)
.saturating_add(proof_size_overhead)
.saturating_add(callback_overhead)
.saturating_add(Weight::from_ref_time(callback_overhead))
}

// Functions that are used by extrinsics weights formulas.
@@ -306,7 +307,7 @@ pub trait WeightInfoExt: WeightInfo {
let weight_of_single_message_and_single_tx_overhead = Self::receive_single_message_proof();
weight_of_two_messages_and_single_tx_overhead
.saturating_sub(weight_of_single_message_and_single_tx_overhead)
.saturating_mul(messages as u64)
.saturating_mul(messages as _)
}

/// Returns weight that needs to be accounted when message delivery transaction
@@ -337,7 +338,7 @@ pub trait WeightInfoExt: WeightInfo {
let weight_of_single_message = Self::receive_delivery_proof_for_single_message();
weight_of_two_messages
.saturating_sub(weight_of_single_message)
.saturating_mul(messages as u64)
.saturating_mul(messages as _)
}

/// Returns weight that needs to be accounted when receiving confirmations for given a number of
@@ -349,7 +350,7 @@ pub trait WeightInfoExt: WeightInfo {
Self::receive_delivery_proof_for_two_messages_by_single_relayer();
weight_of_two_messages_by_two_relayers
.saturating_sub(weight_of_two_messages_by_single_relayer)
.saturating_mul(relayers as u64)
.saturating_mul(relayers as _)
}

/// Returns weight that needs to be accounted when storage proof of given size is received
@@ -361,7 +362,7 @@ pub trait WeightInfoExt: WeightInfo {
/// relayer must pay when it relays proof of given size (even if cost based on other parameters
/// is less than that cost).
fn storage_proof_size_overhead(proof_size: u32) -> Weight {
let proof_size_in_bytes = proof_size as u64;
let proof_size_in_bytes = proof_size;
let byte_weight = (Self::receive_single_message_proof_16_kb()
- Self::receive_single_message_proof_1_kb())
/ (15 * 1024);
18 changes: 4 additions & 14 deletions modules/parachains/src/weights.rs
Original file line number Diff line number Diff line change
@@ -62,12 +62,8 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
Weight::from_ref_time(0 as u64)
.saturating_add(Weight::from_ref_time(18_706_000 as u64).saturating_mul(p as u64))
.saturating_add(T::DbWeight::get().reads(2 as u64))
.saturating_add(
T::DbWeight::get().reads(Weight::from_ref_time(2 as u64).saturating_mul(p as u64)),
)
.saturating_add(
T::DbWeight::get().writes(Weight::from_ref_time(3 as u64).saturating_mul(p as u64)),
)
.saturating_add(T::DbWeight::get().reads(2 as u64).saturating_mul(p as u64))
.saturating_add(T::DbWeight::get().writes(3 as u64).saturating_mul(p as u64))
}

fn submit_parachain_heads_with_1kb_proof() -> Weight {
@@ -89,14 +85,8 @@ impl WeightInfo for () {
Weight::from_ref_time(0 as u64)
.saturating_add(Weight::from_ref_time(18_706_000 as u64).saturating_mul(p as u64))
.saturating_add(RocksDbWeight::get().reads(2 as u64))
.saturating_add(
RocksDbWeight::get()
.reads(Weight::from_ref_time(2 as u64).saturating_mul(p as u64)),
)
.saturating_add(
RocksDbWeight::get()
.writes(Weight::from_ref_time(3 as u64).saturating_mul(p as u64)),
)
.saturating_add(RocksDbWeight::get().reads(2 as u64).saturating_mul(p as u64))
.saturating_add(RocksDbWeight::get().writes(3 as u64).saturating_mul(p as u64))
}

fn submit_parachain_heads_with_1kb_proof() -> Weight {
7 changes: 3 additions & 4 deletions modules/parachains/src/weights_ext.rs
Original file line number Diff line number Diff line change
@@ -63,8 +63,8 @@ pub trait WeightInfoExt: WeightInfo {
);

// potential pruning weight (refunded if hasn't happened)
let pruning_weight = (parachains_count as u64)
.saturating_mul(Self::parachain_head_pruning_weight(db_weight));
let pruning_weight =
Self::parachain_head_pruning_weight(db_weight).saturating_mul(parachains_count as u64);

base_weight.saturating_add(proof_size_overhead).saturating_add(pruning_weight)
}
@@ -88,11 +88,10 @@ pub trait WeightInfoExt: WeightInfo {

/// Returns weight that needs to be accounted when storage proof of given size is received.
fn storage_proof_size_overhead(extra_proof_bytes: u32) -> Weight {
let extra_proof_bytes_in_bytes = extra_proof_bytes as u64;
let extra_byte_weight = (Self::submit_parachain_heads_with_16kb_proof()
- Self::submit_parachain_heads_with_1kb_proof())
/ (15 * 1024);
extra_proof_bytes_in_bytes.saturating_mul(extra_byte_weight)
extra_byte_weight.saturating_mul(extra_proof_bytes as u64)
}
}

3 changes: 2 additions & 1 deletion primitives/darwinia-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -46,7 +46,8 @@ mod copy_paste_from_darwinia {

pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_perthousand(25);
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - remove `set_proof_size`
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2);

frame_support::parameter_types! {
pub RuntimeBlockLength: BlockLength =
2 changes: 1 addition & 1 deletion primitives/message-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ use sp_runtime::transaction_validity::TransactionValidityError;
use sp_std::prelude::*;

/// Message dispatch weight.
pub type Weight = u64;
pub type Weight = frame_support::weights::Weight;

/// Spec version type.
pub type SpecVersion = u32;
2 changes: 1 addition & 1 deletion primitives/polkadot-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ version = "0.1.0"
[dependencies]
# crates.io
codec = { package = "parity-scale-codec", version = "3.1", default-features = false, features = ["derive"] }
parity-util-mem = { version = "0.12", optional = true }
parity-util-mem = { version = "0.11", optional = true }
scale-info = { version = "2.1", default-features = false, features = ["derive"] }
serde = { version = "1.0", optional = true, features = ["derive"] }
# darwinia-network
2 changes: 1 addition & 1 deletion primitives/polkadot-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
///
/// This is a copy-paste from the Polkadot repo's `polkadot-runtime-common` crate.
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - remove `set_proof_size`
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.set_proof_size(1_000).saturating_mul(2);
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2);

/// All Polkadot-like chains assume that an on-initialize consumes 1 percent of the weight on
/// average, hence a single extrinsic will not be allowed to consume more than
Loading