mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 05:11:02 +00:00
Bump Substrate/Polkadot/Cumulus refs (aka Weights v1.5) (#1597)
* update Substrate + Polkadot + Cumulus refs * Origin -> RuntimeOrigin * weights v1.5 * update refs once again + `cargo test -p pallet-bridge-grandpa` works * started work on `cargo test -p pallet-bridge-messages` * cargo test -p pallet-bridge-relayers * cargo test -p pallet-bridge-parachains * cargo test -p millau-runtime * cargo test -p bridge-runtime-common * cargo test -p rialto-runtime * cargo test -p rialto-parachain-runtime * cargo test -p millau-bridge-node * cargo test -p rialto-bridge-node * cargo test -p rialto-parachain-collator * cargo test -p messages-relay * cargo test -p parachains-relay * cargo test -p substrate-relay * cargo test --all * cargo check -p millau-runtime --locked --features runtime-benchmarks * fix remaining test * fmt * try to allow clippy failure temporarily * Revert "try to allow clippy failure temporarily" This reverts commit d1b6593580f07e0dbeecb7ab0aa92cee98888ed3. * use min_by * Revert "use min_by" This reverts commit 33042f49ed37e8dd0505370289e17f03bf1a56ee. * Revert "Revert "use min_by"" This reverts commit 1d2204f0b14dc81e5650bb574dedb5fa78c7097d. * trigger CI * Revert "trigger CI" This reverts commit 259d91b5606743bba9d043c69f07eac6c8700ef5. * new day, new clippy warning * more clippy issues
This commit is contained in:
committed by
Bastian Köcher
parent
9e1847d12a
commit
a3dc2d2748
+137
-105
@@ -65,11 +65,7 @@ use bp_messages::{
|
||||
};
|
||||
use bp_runtime::{BasicOperatingMode, ChainId, OwnedBridgeModule, Size};
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use frame_support::{
|
||||
ensure, fail,
|
||||
traits::Get,
|
||||
weights::{Pays, PostDispatchInfo},
|
||||
};
|
||||
use frame_support::{dispatch::PostDispatchInfo, ensure, fail, traits::Get};
|
||||
use num_traits::{SaturatingAdd, Zero};
|
||||
use sp_std::{
|
||||
cell::RefCell, cmp::PartialOrd, collections::vec_deque::VecDeque, marker::PhantomData,
|
||||
@@ -104,7 +100,8 @@ pub mod pallet {
|
||||
// General types
|
||||
|
||||
/// 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>;
|
||||
/// Benchmarks results from runtime we're plugged into.
|
||||
type WeightInfo: WeightInfoExt;
|
||||
|
||||
@@ -174,13 +171,13 @@ pub mod pallet {
|
||||
type TargetHeaderChain: TargetHeaderChain<Self::OutboundPayload, Self::AccountId>;
|
||||
/// Message payload verifier.
|
||||
type LaneMessageVerifier: LaneMessageVerifier<
|
||||
Self::Origin,
|
||||
Self::RuntimeOrigin,
|
||||
Self::OutboundPayload,
|
||||
Self::OutboundMessageFee,
|
||||
>;
|
||||
/// Message delivery payment.
|
||||
type MessageDeliveryAndDispatchPayment: MessageDeliveryAndDispatchPayment<
|
||||
Self::Origin,
|
||||
Self::RuntimeOrigin,
|
||||
Self::AccountId,
|
||||
Self::OutboundMessageFee,
|
||||
>;
|
||||
@@ -333,9 +330,10 @@ pub mod pallet {
|
||||
});
|
||||
|
||||
// compute actual dispatch weight that depends on the stored message size
|
||||
let actual_weight = sp_std::cmp::min(
|
||||
let actual_weight = sp_std::cmp::min_by(
|
||||
T::WeightInfo::maximal_increase_message_fee(),
|
||||
T::WeightInfo::increase_message_fee(message_size as _),
|
||||
|w1, w2| w1.ref_time().cmp(&w2.ref_time()),
|
||||
);
|
||||
|
||||
Ok(PostDispatchInfo { actual_weight: Some(actual_weight), pays_fee: Pays::Yes })
|
||||
@@ -418,7 +416,7 @@ pub mod pallet {
|
||||
// on this lane. We can't dispatch lane messages out-of-order, so if declared
|
||||
// weight is not enough, let's move to next lane
|
||||
let dispatch_weight = T::MessageDispatch::dispatch_weight(&mut message);
|
||||
if dispatch_weight > dispatch_weight_left {
|
||||
if dispatch_weight.ref_time() > dispatch_weight_left.ref_time() {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
"Cannot dispatch any more messages on lane {:?}. Weight: declared={}, left={}",
|
||||
@@ -456,7 +454,10 @@ pub mod pallet {
|
||||
ReceivalResult::TooManyUnconfirmedMessages => (dispatch_weight, true),
|
||||
};
|
||||
|
||||
let unspent_weight = sp_std::cmp::min(unspent_weight, dispatch_weight);
|
||||
let unspent_weight =
|
||||
sp_std::cmp::min_by(unspent_weight, dispatch_weight, |w1, w2| {
|
||||
w1.ref_time().cmp(&w2.ref_time())
|
||||
});
|
||||
dispatch_weight_left -= dispatch_weight - unspent_weight;
|
||||
actual_weight = actual_weight.saturating_sub(unspent_weight).saturating_sub(
|
||||
// delivery call weight formula assumes that the fee is paid at
|
||||
@@ -465,7 +466,7 @@ pub mod pallet {
|
||||
if refund_pay_dispatch_fee {
|
||||
T::WeightInfo::pay_inbound_dispatch_fee_overhead()
|
||||
} else {
|
||||
0
|
||||
Weight::from_ref_time(0)
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -580,11 +581,11 @@ pub mod pallet {
|
||||
if let Some(confirmed_messages) = confirmed_messages {
|
||||
// handle messages delivery confirmation
|
||||
let preliminary_callback_overhead =
|
||||
relayers_state.total_messages.saturating_mul(single_message_callback_overhead);
|
||||
single_message_callback_overhead.saturating_mul(relayers_state.total_messages);
|
||||
let actual_callback_weight =
|
||||
T::OnDeliveryConfirmed::on_messages_delivered(&lane_id, &confirmed_messages);
|
||||
match preliminary_callback_overhead.checked_sub(actual_callback_weight) {
|
||||
Some(difference) if difference == 0 => (),
|
||||
match preliminary_callback_overhead.checked_sub(&actual_callback_weight) {
|
||||
Some(difference) if difference.ref_time() == 0 => (),
|
||||
Some(difference) => {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
@@ -775,8 +776,11 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
impl<T, I>
|
||||
bp_messages::source_chain::MessagesBridge<T::Origin, T::OutboundMessageFee, T::OutboundPayload>
|
||||
for Pallet<T, I>
|
||||
bp_messages::source_chain::MessagesBridge<
|
||||
T::RuntimeOrigin,
|
||||
T::OutboundMessageFee,
|
||||
T::OutboundPayload,
|
||||
> for Pallet<T, I>
|
||||
where
|
||||
T: Config<I>,
|
||||
I: 'static,
|
||||
@@ -784,7 +788,7 @@ where
|
||||
type Error = sp_runtime::DispatchErrorWithPostInfo<PostDispatchInfo>;
|
||||
|
||||
fn send_message(
|
||||
sender: T::Origin,
|
||||
sender: T::RuntimeOrigin,
|
||||
lane: LaneId,
|
||||
message: T::OutboundPayload,
|
||||
delivery_and_dispatch_fee: T::OutboundMessageFee,
|
||||
@@ -795,7 +799,7 @@ where
|
||||
|
||||
/// Function that actually sends message.
|
||||
fn send_message<T: Config<I>, I: 'static>(
|
||||
submitter: T::Origin,
|
||||
submitter: T::RuntimeOrigin,
|
||||
lane_id: LaneId,
|
||||
payload: T::OutboundPayload,
|
||||
delivery_and_dispatch_fee: T::OutboundMessageFee,
|
||||
@@ -875,8 +879,8 @@ fn send_message<T: Config<I>, I: 'static>(
|
||||
let single_message_callback_overhead =
|
||||
T::WeightInfo::single_message_callback_overhead(T::DbWeight::get());
|
||||
let actual_callback_weight = T::OnMessageAccepted::on_messages_accepted(&lane_id, &nonce);
|
||||
match single_message_callback_overhead.checked_sub(actual_callback_weight) {
|
||||
Some(difference) if difference == 0 => (),
|
||||
match single_message_callback_overhead.checked_sub(&actual_callback_weight) {
|
||||
Some(difference) if difference.ref_time() == 0 => (),
|
||||
Some(difference) => {
|
||||
log::trace!(
|
||||
target: LOG_TARGET,
|
||||
@@ -1104,8 +1108,8 @@ fn verify_and_decode_messages_proof<Chain: SourceHeaderChain<Fee>, Fee, Dispatch
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::mock::{
|
||||
message, message_payload, run_test, unrewarded_relayer, Balance, Event as TestEvent,
|
||||
Origin, TestMessageDeliveryAndDispatchPayment, TestMessagesDeliveryProof,
|
||||
message, message_payload, run_test, unrewarded_relayer, Balance, RuntimeEvent as TestEvent,
|
||||
RuntimeOrigin, TestMessageDeliveryAndDispatchPayment, TestMessagesDeliveryProof,
|
||||
TestMessagesParameter, TestMessagesProof, TestOnDeliveryConfirmed1,
|
||||
TestOnDeliveryConfirmed2, TestOnMessageAccepted, TestRuntime, TokenConversionRate,
|
||||
MAX_OUTBOUND_PAYLOAD_SIZE, PAYLOAD_REJECTED_BY_TARGET_CHAIN, REGULAR_PAYLOAD, TEST_LANE_ID,
|
||||
@@ -1149,10 +1153,10 @@ mod tests {
|
||||
let message_nonce =
|
||||
outbound_lane::<TestRuntime, ()>(TEST_LANE_ID).data().latest_generated_nonce + 1;
|
||||
let weight = Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
REGULAR_PAYLOAD.declared_weight,
|
||||
REGULAR_PAYLOAD.declared_weight.ref_time(),
|
||||
)
|
||||
.expect("send_message has failed")
|
||||
.actual_weight
|
||||
@@ -1174,7 +1178,7 @@ mod tests {
|
||||
// check that fee has been withdrawn from submitter
|
||||
assert!(TestMessageDeliveryAndDispatchPayment::is_fee_paid(
|
||||
1,
|
||||
REGULAR_PAYLOAD.declared_weight
|
||||
REGULAR_PAYLOAD.declared_weight.ref_time()
|
||||
));
|
||||
|
||||
weight
|
||||
@@ -1185,7 +1189,7 @@ mod tests {
|
||||
System::<TestRuntime>::reset_events();
|
||||
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
InboundLaneData {
|
||||
@@ -1226,7 +1230,7 @@ mod tests {
|
||||
|
||||
let parameter = TestMessagesParameter::TokenConversionRate(10.into());
|
||||
assert_ok!(Pallet::<TestRuntime>::update_pallet_parameter(
|
||||
Origin::root(),
|
||||
RuntimeOrigin::root(),
|
||||
parameter.clone(),
|
||||
));
|
||||
|
||||
@@ -1250,7 +1254,7 @@ mod tests {
|
||||
|
||||
let parameter = TestMessagesParameter::TokenConversionRate(10.into());
|
||||
assert_ok!(Pallet::<TestRuntime>::update_pallet_parameter(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
parameter.clone(),
|
||||
));
|
||||
|
||||
@@ -1271,7 +1275,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::update_pallet_parameter(
|
||||
Origin::signed(2),
|
||||
RuntimeOrigin::signed(2),
|
||||
TestMessagesParameter::TokenConversionRate(10.into()),
|
||||
),
|
||||
DispatchError::BadOrigin,
|
||||
@@ -1281,7 +1285,7 @@ mod tests {
|
||||
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::update_pallet_parameter(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesParameter::TokenConversionRate(10.into()),
|
||||
),
|
||||
DispatchError::BadOrigin,
|
||||
@@ -1327,22 +1331,27 @@ mod tests {
|
||||
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
REGULAR_PAYLOAD.declared_weight,
|
||||
REGULAR_PAYLOAD.declared_weight.ref_time(),
|
||||
),
|
||||
Error::<TestRuntime, ()>::NotOperatingNormally,
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::increase_message_fee(Origin::signed(1), TEST_LANE_ID, 1, 1,),
|
||||
Pallet::<TestRuntime>::increase_message_fee(
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
1,
|
||||
1,
|
||||
),
|
||||
Error::<TestRuntime, ()>::BridgeModule(bp_runtime::OwnedBridgeModuleError::Halted),
|
||||
);
|
||||
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![message(2, REGULAR_PAYLOAD)]).into(),
|
||||
1,
|
||||
@@ -1353,7 +1362,7 @@ mod tests {
|
||||
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
InboundLaneData {
|
||||
@@ -1387,23 +1396,23 @@ mod tests {
|
||||
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
REGULAR_PAYLOAD.declared_weight,
|
||||
REGULAR_PAYLOAD.declared_weight.ref_time(),
|
||||
),
|
||||
Error::<TestRuntime, ()>::NotOperatingNormally,
|
||||
);
|
||||
|
||||
assert_ok!(Pallet::<TestRuntime>::increase_message_fee(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
1,
|
||||
1,
|
||||
));
|
||||
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![message(1, REGULAR_PAYLOAD)]).into(),
|
||||
1,
|
||||
@@ -1411,7 +1420,7 @@ mod tests {
|
||||
),);
|
||||
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
InboundLaneData {
|
||||
@@ -1449,7 +1458,7 @@ mod tests {
|
||||
.extend_from_slice(&[0u8; MAX_OUTBOUND_PAYLOAD_SIZE as usize]);
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
message_payload.clone(),
|
||||
Balance::MAX,
|
||||
@@ -1463,7 +1472,7 @@ mod tests {
|
||||
}
|
||||
assert_eq!(message_payload.size(), MAX_OUTBOUND_PAYLOAD_SIZE);
|
||||
assert_ok!(Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
message_payload,
|
||||
Balance::MAX,
|
||||
@@ -1477,10 +1486,10 @@ mod tests {
|
||||
// messages with this payload are rejected by target chain verifier
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
PAYLOAD_REJECTED_BY_TARGET_CHAIN,
|
||||
PAYLOAD_REJECTED_BY_TARGET_CHAIN.declared_weight
|
||||
PAYLOAD_REJECTED_BY_TARGET_CHAIN.declared_weight.ref_time(),
|
||||
),
|
||||
Error::<TestRuntime, ()>::MessageRejectedByChainVerifier,
|
||||
);
|
||||
@@ -1493,7 +1502,7 @@ mod tests {
|
||||
// messages with zero fee are rejected by lane verifier
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
0
|
||||
@@ -1509,10 +1518,10 @@ mod tests {
|
||||
TestMessageDeliveryAndDispatchPayment::reject_payments();
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
REGULAR_PAYLOAD.declared_weight
|
||||
REGULAR_PAYLOAD.declared_weight.ref_time(),
|
||||
),
|
||||
Error::<TestRuntime, ()>::FailedToWithdrawMessageFee,
|
||||
);
|
||||
@@ -1523,7 +1532,7 @@ mod tests {
|
||||
fn receive_messages_proof_works() {
|
||||
run_test(|| {
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![message(1, REGULAR_PAYLOAD)]).into(),
|
||||
1,
|
||||
@@ -1567,7 +1576,7 @@ mod tests {
|
||||
Some(OutboundLaneData { latest_received_nonce: 9, ..Default::default() });
|
||||
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
message_proof,
|
||||
1,
|
||||
@@ -1601,12 +1610,14 @@ mod tests {
|
||||
#[test]
|
||||
fn receive_messages_proof_does_not_accept_message_if_dispatch_weight_is_not_enough() {
|
||||
run_test(|| {
|
||||
let mut declared_weight = REGULAR_PAYLOAD.declared_weight;
|
||||
*declared_weight.ref_time_mut() -= 1;
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![message(1, REGULAR_PAYLOAD)]).into(),
|
||||
1,
|
||||
REGULAR_PAYLOAD.declared_weight - 1,
|
||||
declared_weight,
|
||||
));
|
||||
assert_eq!(InboundLanes::<TestRuntime>::get(TEST_LANE_ID).last_delivered_nonce(), 0);
|
||||
});
|
||||
@@ -1617,11 +1628,11 @@ mod tests {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime, ()>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Err(()).into(),
|
||||
1,
|
||||
0,
|
||||
Weight::from_ref_time(0),
|
||||
),
|
||||
Error::<TestRuntime, ()>::InvalidMessagesProof,
|
||||
);
|
||||
@@ -1633,11 +1644,11 @@ mod tests {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime, ()>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![message(1, REGULAR_PAYLOAD)]).into(),
|
||||
u32::MAX,
|
||||
0,
|
||||
Weight::from_ref_time(0),
|
||||
),
|
||||
Error::<TestRuntime, ()>::TooManyMessagesInTheProof,
|
||||
);
|
||||
@@ -1661,13 +1672,13 @@ mod tests {
|
||||
fn receive_messages_delivery_proof_rewards_relayers() {
|
||||
run_test(|| {
|
||||
assert_ok!(Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
1000,
|
||||
));
|
||||
assert_ok!(Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
REGULAR_PAYLOAD,
|
||||
2000,
|
||||
@@ -1675,7 +1686,7 @@ mod tests {
|
||||
|
||||
// this reports delivery of message 1 => reward is paid to TEST_RELAYER_A
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
InboundLaneData {
|
||||
@@ -1698,7 +1709,7 @@ mod tests {
|
||||
// this reports delivery of both message 1 and message 2 => reward is paid only to
|
||||
// TEST_RELAYER_B
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
InboundLaneData {
|
||||
@@ -1728,7 +1739,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(Err(())),
|
||||
Default::default(),
|
||||
),
|
||||
@@ -1743,7 +1754,7 @@ mod tests {
|
||||
// when number of relayers entries is invalid
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
InboundLaneData {
|
||||
@@ -1769,7 +1780,7 @@ mod tests {
|
||||
// when number of messages is invalid
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
InboundLaneData {
|
||||
@@ -1795,7 +1806,7 @@ mod tests {
|
||||
// when last delivered nonce is invalid
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
InboundLaneData {
|
||||
@@ -1827,11 +1838,12 @@ mod tests {
|
||||
invalid_message.data.payload = Vec::new();
|
||||
|
||||
assert_ok!(Pallet::<TestRuntime, ()>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(vec![invalid_message]).into(),
|
||||
1,
|
||||
0, // weight may be zero in this case (all messages are improperly encoded)
|
||||
Weight::from_ref_time(0), /* weight may be zero in this case (all messages are
|
||||
* improperly encoded) */
|
||||
),);
|
||||
|
||||
assert_eq!(InboundLanes::<TestRuntime>::get(TEST_LANE_ID).last_delivered_nonce(), 1,);
|
||||
@@ -1845,7 +1857,7 @@ mod tests {
|
||||
invalid_message.data.payload = Vec::new();
|
||||
|
||||
assert_ok!(Pallet::<TestRuntime, ()>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
Ok(
|
||||
vec![message(1, REGULAR_PAYLOAD), invalid_message, message(3, REGULAR_PAYLOAD),]
|
||||
@@ -1862,12 +1874,12 @@ mod tests {
|
||||
#[test]
|
||||
fn actual_dispatch_weight_does_not_overlow() {
|
||||
run_test(|| {
|
||||
let message1 = message(1, message_payload(0, Weight::MAX / 2));
|
||||
let message2 = message(2, message_payload(0, Weight::MAX / 2));
|
||||
let message3 = message(3, message_payload(0, Weight::MAX / 2));
|
||||
let message1 = message(1, message_payload(0, u64::MAX / 2));
|
||||
let message2 = message(2, message_payload(0, u64::MAX / 2));
|
||||
let message3 = message(3, message_payload(0, u64::MAX / 2));
|
||||
|
||||
assert_ok!(Pallet::<TestRuntime, ()>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
// this may cause overflow if source chain storage is invalid
|
||||
Ok(vec![message1, message2, message3]).into(),
|
||||
@@ -1886,7 +1898,7 @@ mod tests {
|
||||
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime, ()>::increase_message_fee(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
1,
|
||||
100,
|
||||
@@ -1901,7 +1913,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime, ()>::increase_message_fee(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
1,
|
||||
100,
|
||||
@@ -1920,7 +1932,7 @@ mod tests {
|
||||
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime, ()>::increase_message_fee(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
1,
|
||||
100,
|
||||
@@ -1936,7 +1948,7 @@ mod tests {
|
||||
send_regular_message();
|
||||
|
||||
assert_ok!(Pallet::<TestRuntime, ()>::increase_message_fee(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
1,
|
||||
100,
|
||||
@@ -1950,11 +1962,11 @@ mod tests {
|
||||
run_test(|| {
|
||||
fn submit_with_unspent_weight(
|
||||
nonce: MessageNonce,
|
||||
unspent_weight: Weight,
|
||||
unspent_weight: u64,
|
||||
is_prepaid: bool,
|
||||
) -> (Weight, Weight) {
|
||||
let mut payload = REGULAR_PAYLOAD;
|
||||
payload.dispatch_result.unspent_weight = unspent_weight;
|
||||
*payload.dispatch_result.unspent_weight.ref_time_mut() = unspent_weight;
|
||||
payload.dispatch_result.dispatch_fee_paid_during_dispatch = !is_prepaid;
|
||||
let proof = Ok(vec![message(nonce, payload)]).into();
|
||||
let messages_count = 1;
|
||||
@@ -1965,7 +1977,7 @@ mod tests {
|
||||
REGULAR_PAYLOAD.declared_weight,
|
||||
);
|
||||
let post_dispatch_weight = Pallet::<TestRuntime>::receive_messages_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_RELAYER_A,
|
||||
proof,
|
||||
messages_count,
|
||||
@@ -1980,16 +1992,26 @@ mod tests {
|
||||
|
||||
// when dispatch is returning `unspent_weight < declared_weight`
|
||||
let (pre, post) = submit_with_unspent_weight(1, 1, false);
|
||||
assert_eq!(post, pre - 1);
|
||||
assert_eq!(post.ref_time(), pre.ref_time() - 1);
|
||||
|
||||
// when dispatch is returning `unspent_weight = declared_weight`
|
||||
let (pre, post) = submit_with_unspent_weight(2, REGULAR_PAYLOAD.declared_weight, false);
|
||||
assert_eq!(post, pre - REGULAR_PAYLOAD.declared_weight);
|
||||
let (pre, post) =
|
||||
submit_with_unspent_weight(2, REGULAR_PAYLOAD.declared_weight.ref_time(), false);
|
||||
assert_eq!(
|
||||
post.ref_time(),
|
||||
pre.ref_time() - REGULAR_PAYLOAD.declared_weight.ref_time()
|
||||
);
|
||||
|
||||
// when dispatch is returning `unspent_weight > declared_weight`
|
||||
let (pre, post) =
|
||||
submit_with_unspent_weight(3, REGULAR_PAYLOAD.declared_weight + 1, false);
|
||||
assert_eq!(post, pre - REGULAR_PAYLOAD.declared_weight);
|
||||
let (pre, post) = submit_with_unspent_weight(
|
||||
3,
|
||||
REGULAR_PAYLOAD.declared_weight.ref_time() + 1,
|
||||
false,
|
||||
);
|
||||
assert_eq!(
|
||||
post.ref_time(),
|
||||
pre.ref_time() - REGULAR_PAYLOAD.declared_weight.ref_time()
|
||||
);
|
||||
|
||||
// when there's no unspent weight
|
||||
let (pre, post) = submit_with_unspent_weight(4, 0, false);
|
||||
@@ -1998,8 +2020,10 @@ mod tests {
|
||||
// when dispatch is returning `unspent_weight < declared_weight` AND message is prepaid
|
||||
let (pre, post) = submit_with_unspent_weight(5, 1, true);
|
||||
assert_eq!(
|
||||
post,
|
||||
pre - 1 - <TestRuntime as Config>::WeightInfo::pay_inbound_dispatch_fee_overhead()
|
||||
post.ref_time(),
|
||||
pre.ref_time() -
|
||||
1 - <TestRuntime as Config>::WeightInfo::pay_inbound_dispatch_fee_overhead()
|
||||
.ref_time()
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -2043,7 +2067,7 @@ mod tests {
|
||||
|
||||
// first tx with messages 1+2
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(messages_1_and_2_proof),
|
||||
UnrewardedRelayersState {
|
||||
unrewarded_relayer_entries: 1,
|
||||
@@ -2054,7 +2078,7 @@ mod tests {
|
||||
));
|
||||
// second tx with message 3
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(messages_3_proof),
|
||||
UnrewardedRelayersState {
|
||||
unrewarded_relayer_entries: 1,
|
||||
@@ -2097,7 +2121,7 @@ mod tests {
|
||||
crate::mock::DbWeight::get(),
|
||||
);
|
||||
let post_dispatch_weight = Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
proof,
|
||||
relayers_state,
|
||||
)
|
||||
@@ -2157,7 +2181,7 @@ mod tests {
|
||||
// numer of actually confirmed messages is `1`.
|
||||
assert_noop!(
|
||||
Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
InboundLaneData { last_confirmed_nonce: 1, relayers: Default::default() },
|
||||
@@ -2178,32 +2202,40 @@ mod tests {
|
||||
large_payload.extra = vec![2; MAX_OUTBOUND_PAYLOAD_SIZE as usize / 5];
|
||||
|
||||
assert_ok!(Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
small_payload,
|
||||
100,
|
||||
));
|
||||
assert_ok!(Pallet::<TestRuntime>::send_message(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
large_payload,
|
||||
100,
|
||||
));
|
||||
|
||||
let small_weight =
|
||||
Pallet::<TestRuntime>::increase_message_fee(Origin::signed(1), TEST_LANE_ID, 1, 1)
|
||||
.expect("increase_message_fee has failed")
|
||||
.actual_weight
|
||||
.expect("increase_message_fee always returns Some");
|
||||
let small_weight = Pallet::<TestRuntime>::increase_message_fee(
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
1,
|
||||
1,
|
||||
)
|
||||
.expect("increase_message_fee has failed")
|
||||
.actual_weight
|
||||
.expect("increase_message_fee always returns Some");
|
||||
|
||||
let large_weight =
|
||||
Pallet::<TestRuntime>::increase_message_fee(Origin::signed(1), TEST_LANE_ID, 2, 1)
|
||||
.expect("increase_message_fee has failed")
|
||||
.actual_weight
|
||||
.expect("increase_message_fee always returns Some");
|
||||
let large_weight = Pallet::<TestRuntime>::increase_message_fee(
|
||||
RuntimeOrigin::signed(1),
|
||||
TEST_LANE_ID,
|
||||
2,
|
||||
1,
|
||||
)
|
||||
.expect("increase_message_fee has failed")
|
||||
.actual_weight
|
||||
.expect("increase_message_fee always returns Some");
|
||||
|
||||
assert!(
|
||||
large_weight > small_weight,
|
||||
large_weight.ref_time() > small_weight.ref_time(),
|
||||
"Actual post-dispatch weigth for larger message {} must be larger than {} for small message",
|
||||
large_weight,
|
||||
small_weight,
|
||||
@@ -2225,7 +2257,7 @@ mod tests {
|
||||
|
||||
// confirm delivery of all sent messages
|
||||
assert_ok!(Pallet::<TestRuntime>::receive_messages_delivery_proof(
|
||||
Origin::signed(1),
|
||||
RuntimeOrigin::signed(1),
|
||||
TestMessagesDeliveryProof(Ok((
|
||||
TEST_LANE_ID,
|
||||
InboundLaneData {
|
||||
@@ -2332,7 +2364,7 @@ mod tests {
|
||||
REGULAR_PAYLOAD.encode(),
|
||||
OutboundMessageDetails {
|
||||
nonce: 0,
|
||||
dispatch_weight: 0,
|
||||
dispatch_weight: Weight::from_ref_time(0),
|
||||
size: 0,
|
||||
delivery_and_dispatch_fee: 0,
|
||||
dispatch_fee_payment:
|
||||
|
||||
Reference in New Issue
Block a user