mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 10:17:57 +00:00
refund_pay_dispatch_fee removed (#1695)
This commit is contained in:
committed by
Bastian Köcher
parent
3a8cb23103
commit
9e92564c69
@@ -314,7 +314,6 @@ mod tests {
|
||||
dispatch_result,
|
||||
MessageDispatchResult {
|
||||
unspent_weight: frame_support::weights::Weight::from_ref_time(0),
|
||||
dispatch_fee_paid_during_dispatch: false,
|
||||
dispatch_level_result: (),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -892,7 +892,6 @@ mod tests {
|
||||
dispatch_result,
|
||||
MessageDispatchResult {
|
||||
unspent_weight: frame_support::weights::Weight::from_ref_time(0),
|
||||
dispatch_fee_paid_during_dispatch: false,
|
||||
dispatch_level_result: (),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -273,7 +273,6 @@ mod tests {
|
||||
dispatch_result,
|
||||
MessageDispatchResult {
|
||||
unspent_weight: frame_support::weights::Weight::from_ref_time(0),
|
||||
dispatch_fee_paid_during_dispatch: false,
|
||||
dispatch_level_result: (),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -542,11 +542,7 @@ pub mod target {
|
||||
},
|
||||
}
|
||||
|
||||
MessageDispatchResult {
|
||||
unspent_weight: Weight::zero(),
|
||||
dispatch_fee_paid_during_dispatch: false,
|
||||
dispatch_level_result: (),
|
||||
}
|
||||
MessageDispatchResult { unspent_weight: Weight::zero(), dispatch_level_result: () }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -256,39 +256,6 @@ benchmarks_instance_pallet! {
|
||||
assert!(T::is_message_dispatched(21));
|
||||
}
|
||||
|
||||
// Benchmark `receive_messages_proof` extrinsic with single minimal-weight message and following conditions:
|
||||
// * proof does not include outbound lane state proof;
|
||||
// * inbound lane already has state, so it needs to be read and decoded;
|
||||
// * message is successfully dispatched;
|
||||
// * message requires all heavy checks done by dispatcher;
|
||||
// * message dispatch fee is paid at source (bridged) chain.
|
||||
//
|
||||
// This benchmark is used to compute extra weight spent at target chain when fee is paid there. Then we use
|
||||
// this information in two places: (1) to reduce weight of delivery tx if sender pays fee at the source chain
|
||||
// and (2) to refund relayer with this weight if fee has been paid at the source chain.
|
||||
receive_single_prepaid_message_proof {
|
||||
let relayer_id_on_source = T::bridged_relayer_id();
|
||||
let relayer_id_on_target = account("relayer", 0, SEED);
|
||||
T::endow_account(&relayer_id_on_target);
|
||||
|
||||
// mark messages 1..=20 as delivered
|
||||
receive_messages::<T, I>(20);
|
||||
|
||||
let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams {
|
||||
lane: T::bench_lane_id(),
|
||||
message_nonces: 21..=21,
|
||||
outbound_lane_data: None,
|
||||
size: StorageProofSize::Minimal(EXPECTED_DEFAULT_MESSAGE_LENGTH),
|
||||
});
|
||||
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
|
||||
verify {
|
||||
assert_eq!(
|
||||
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(),
|
||||
21,
|
||||
);
|
||||
assert!(T::is_message_dispatched(21));
|
||||
}
|
||||
|
||||
// Benchmark `receive_messages_delivery_proof` extrinsic with following conditions:
|
||||
// * single relayer is rewarded for relaying single message;
|
||||
// * relayer account does not exist (in practice it needs to exist in production environment).
|
||||
|
||||
@@ -361,32 +361,20 @@ pub mod pallet {
|
||||
// losing funds for messages dispatch. But keep in mind that relayer pays base
|
||||
// delivery transaction cost anyway. And base cost covers everything except
|
||||
// dispatch, so we have a balance here.
|
||||
let (unspent_weight, refund_pay_dispatch_fee) = match &receival_result {
|
||||
let unspent_weight = match &receival_result {
|
||||
ReceivalResult::Dispatched(dispatch_result) => {
|
||||
valid_messages += 1;
|
||||
(
|
||||
dispatch_result.unspent_weight,
|
||||
!dispatch_result.dispatch_fee_paid_during_dispatch,
|
||||
)
|
||||
dispatch_result.unspent_weight
|
||||
},
|
||||
ReceivalResult::InvalidNonce |
|
||||
ReceivalResult::TooManyUnrewardedRelayers |
|
||||
ReceivalResult::TooManyUnconfirmedMessages => (message_dispatch_weight, true),
|
||||
ReceivalResult::TooManyUnconfirmedMessages => message_dispatch_weight,
|
||||
};
|
||||
lane_messages_received_status.push(message.key.nonce, receival_result);
|
||||
|
||||
let unspent_weight = unspent_weight.min(message_dispatch_weight);
|
||||
dispatch_weight_left -= message_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
|
||||
// this (target) chain. If the message is prepaid at the source
|
||||
// chain, let's refund relayer with this extra cost.
|
||||
if refund_pay_dispatch_fee {
|
||||
T::WeightInfo::pay_inbound_dispatch_fee_overhead()
|
||||
} else {
|
||||
Weight::zero()
|
||||
},
|
||||
);
|
||||
actual_weight = actual_weight.saturating_sub(unspent_weight);
|
||||
}
|
||||
|
||||
messages_received_status.push(lane_messages_received_status);
|
||||
@@ -1554,11 +1542,9 @@ mod tests {
|
||||
fn submit_with_unspent_weight(
|
||||
nonce: MessageNonce,
|
||||
unspent_weight: u64,
|
||||
is_prepaid: bool,
|
||||
) -> (Weight, Weight) {
|
||||
let mut payload = REGULAR_PAYLOAD;
|
||||
*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;
|
||||
let pre_dispatch_weight =
|
||||
@@ -1582,40 +1568,32 @@ mod tests {
|
||||
}
|
||||
|
||||
// when dispatch is returning `unspent_weight < declared_weight`
|
||||
let (pre, post) = submit_with_unspent_weight(1, 1, false);
|
||||
let (pre, post) = submit_with_unspent_weight(1, 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.ref_time(), false);
|
||||
submit_with_unspent_weight(2, REGULAR_PAYLOAD.declared_weight.ref_time());
|
||||
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.ref_time() + 1,
|
||||
false,
|
||||
);
|
||||
let (pre, post) =
|
||||
submit_with_unspent_weight(3, REGULAR_PAYLOAD.declared_weight.ref_time() + 1);
|
||||
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);
|
||||
let (pre, post) = submit_with_unspent_weight(4, 0);
|
||||
assert_eq!(post, pre);
|
||||
|
||||
// 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.ref_time(),
|
||||
pre.ref_time() -
|
||||
1 - <TestRuntime as Config>::WeightInfo::pay_inbound_dispatch_fee_overhead()
|
||||
.ref_time()
|
||||
);
|
||||
// when dispatch is returning `unspent_weight < declared_weight`
|
||||
let (pre, post) = submit_with_unspent_weight(5, 1);
|
||||
assert_eq!(post.ref_time(), pre.ref_time() - 1);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -395,7 +395,6 @@ pub const fn dispatch_result(
|
||||
) -> MessageDispatchResult<TestDispatchLevelResult> {
|
||||
MessageDispatchResult {
|
||||
unspent_weight: Weight::from_ref_time(unspent_weight),
|
||||
dispatch_fee_paid_during_dispatch: true,
|
||||
dispatch_level_result: (),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ pub trait WeightInfo {
|
||||
fn receive_single_message_proof_with_outbound_lane_state() -> Weight;
|
||||
fn receive_single_message_proof_1_kb() -> Weight;
|
||||
fn receive_single_message_proof_16_kb() -> Weight;
|
||||
fn receive_single_prepaid_message_proof() -> Weight;
|
||||
fn receive_delivery_proof_for_single_message() -> Weight;
|
||||
fn receive_delivery_proof_for_two_messages_by_single_relayer() -> Weight;
|
||||
fn receive_delivery_proof_for_two_messages_by_two_relayers() -> Weight;
|
||||
@@ -91,11 +90,6 @@ impl<T: frame_system::Config> WeightInfo for BridgeWeight<T> {
|
||||
.saturating_add(T::DbWeight::get().reads(3 as u64))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as u64))
|
||||
}
|
||||
fn receive_single_prepaid_message_proof() -> Weight {
|
||||
Weight::from_ref_time(49_646_000 as u64)
|
||||
.saturating_add(T::DbWeight::get().reads(4 as u64))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as u64))
|
||||
}
|
||||
fn receive_delivery_proof_for_single_message() -> Weight {
|
||||
Weight::from_ref_time(55_108_000 as u64)
|
||||
.saturating_add(T::DbWeight::get().reads(4 as u64))
|
||||
@@ -140,11 +134,6 @@ impl WeightInfo for () {
|
||||
.saturating_add(RocksDbWeight::get().reads(3 as u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as u64))
|
||||
}
|
||||
fn receive_single_prepaid_message_proof() -> Weight {
|
||||
Weight::from_ref_time(49_646_000 as u64)
|
||||
.saturating_add(RocksDbWeight::get().reads(4 as u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as u64))
|
||||
}
|
||||
fn receive_delivery_proof_for_single_message() -> Weight {
|
||||
Weight::from_ref_time(55_108_000 as u64)
|
||||
.saturating_add(RocksDbWeight::get().reads(4 as u64))
|
||||
|
||||
@@ -265,15 +265,6 @@ pub trait WeightInfoExt: WeightInfo {
|
||||
(15 * 1024);
|
||||
proof_size_in_bytes * byte_weight
|
||||
}
|
||||
|
||||
/// Returns weight of the pay-dispatch-fee operation for inbound messages.
|
||||
///
|
||||
/// This function may return zero if runtime doesn't support pay-dispatch-fee-at-target-chain
|
||||
/// option.
|
||||
fn pay_inbound_dispatch_fee_overhead() -> Weight {
|
||||
Self::receive_single_message_proof()
|
||||
.saturating_sub(Self::receive_single_prepaid_message_proof())
|
||||
}
|
||||
}
|
||||
|
||||
impl WeightInfoExt for () {
|
||||
|
||||
@@ -162,10 +162,6 @@ impl<AccountId> MessageDispatch<AccountId> for ForbidInboundMessages {
|
||||
_: &AccountId,
|
||||
_: DispatchMessage<Self::DispatchPayload>,
|
||||
) -> MessageDispatchResult<Self::DispatchLevelResult> {
|
||||
MessageDispatchResult {
|
||||
unspent_weight: Weight::zero(),
|
||||
dispatch_fee_paid_during_dispatch: false,
|
||||
dispatch_level_result: (),
|
||||
}
|
||||
MessageDispatchResult { unspent_weight: Weight::zero(), dispatch_level_result: () }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,6 @@ pub struct MessageDispatchResult<DispatchLevelResult> {
|
||||
/// the weight, declared by the message sender;
|
||||
/// 2) if message has not been dispatched at all.
|
||||
pub unspent_weight: Weight,
|
||||
/// Whether the message dispatch fee has been paid during dispatch. This will be true if your
|
||||
/// configuration supports pay-dispatch-fee-at-target-chain option and message sender has
|
||||
/// enabled this option.
|
||||
pub dispatch_fee_paid_during_dispatch: bool,
|
||||
/// Fine-grained result of single message dispatch (for better diagnostic purposes)
|
||||
pub dispatch_level_result: DispatchLevelResult,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user