mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 02:37:58 +00:00
Add weight of refund extension post_dispatch to the weights of messages pallet (#2089)
* add weight of refund extension post_dispatch to the weights of messages pallet * fixed tests and removed TODO * verify runtime overhead weight in integrity tests * add integrity tests to rialto-parachain runtime * refactor weights a bit * refund ext is disabled for Rialto <> Millau bridge * Update bin/runtime-common/src/integrity.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * Update bin/runtime-common/src/integrity.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * Update modules/relayers/src/weights_ext.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> --------- Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
committed by
Bastian Köcher
parent
b03c584e31
commit
49d11e9ce5
@@ -24,8 +24,9 @@ use crate::{messages, messages::MessageBridge};
|
||||
use bp_messages::{InboundLaneData, MessageNonce};
|
||||
use bp_runtime::{Chain, ChainId};
|
||||
use codec::Encode;
|
||||
use frame_support::{storage::generator::StorageValue, traits::Get};
|
||||
use frame_support::{storage::generator::StorageValue, traits::Get, weights::Weight};
|
||||
use frame_system::limits;
|
||||
use pallet_bridge_messages::WeightInfoExt as _;
|
||||
use sp_runtime::traits::SignedExtension;
|
||||
|
||||
/// Macro that ensures that the runtime configuration and chain primitives crate are sharing
|
||||
@@ -289,15 +290,25 @@ where
|
||||
}
|
||||
|
||||
/// Check that the message lane weights are correct.
|
||||
pub fn check_message_lane_weights<C: Chain, T: frame_system::Config>(
|
||||
pub fn check_message_lane_weights<
|
||||
C: Chain,
|
||||
T: frame_system::Config + pallet_bridge_messages::Config,
|
||||
>(
|
||||
bridged_chain_extra_storage_proof_size: u32,
|
||||
this_chain_max_unrewarded_relayers: MessageNonce,
|
||||
this_chain_max_unconfirmed_messages: MessageNonce,
|
||||
// whether `RefundBridgedParachainMessages` extension is deployed at runtime and is used for
|
||||
// refunding this bridge transactions?
|
||||
//
|
||||
// in other words: pass true for all known production chains
|
||||
runtime_includes_refund_extension: bool,
|
||||
) {
|
||||
type Weights<T> = pallet_bridge_messages::weights::BridgeWeight<T>;
|
||||
type Weights<T> = <T as pallet_bridge_messages::Config>::WeightInfo;
|
||||
|
||||
// check basic weight assumptions
|
||||
pallet_bridge_messages::ensure_weights_are_correct::<Weights<T>>();
|
||||
|
||||
// check that weights allow us to receive messages
|
||||
let max_incoming_message_proof_size = bridged_chain_extra_storage_proof_size
|
||||
.saturating_add(messages::target::maximal_incoming_message_size(C::max_extrinsic_size()));
|
||||
pallet_bridge_messages::ensure_able_to_receive_message::<Weights<T>>(
|
||||
@@ -307,6 +318,7 @@ pub fn check_message_lane_weights<C: Chain, T: frame_system::Config>(
|
||||
messages::target::maximal_incoming_message_dispatch_weight(C::max_extrinsic_weight()),
|
||||
);
|
||||
|
||||
// check that weights allow us to receive delivery confirmations
|
||||
let max_incoming_inbound_lane_data_proof_size =
|
||||
InboundLaneData::<()>::encoded_size_hint_u32(this_chain_max_unrewarded_relayers as _);
|
||||
pallet_bridge_messages::ensure_able_to_receive_confirmation::<Weights<T>>(
|
||||
@@ -316,6 +328,20 @@ pub fn check_message_lane_weights<C: Chain, T: frame_system::Config>(
|
||||
this_chain_max_unrewarded_relayers,
|
||||
this_chain_max_unconfirmed_messages,
|
||||
);
|
||||
|
||||
// check that extra weights of delivery/confirmation transactions include the weight
|
||||
// of `RefundBridgedParachainMessages` operations. This signed extension assumes the worst case
|
||||
// (i.e. slashing if delivery transaction was invalid) and refunds some weight if
|
||||
// assumption was wrong (i.e. if we did refund instead of slashing). This check
|
||||
// ensures the extension will not refund weight when it doesn't need to (i.e. if pallet
|
||||
// weights do not account weights of refund extension).
|
||||
if runtime_includes_refund_extension {
|
||||
assert_ne!(Weights::<T>::receive_messages_proof_overhead_from_runtime(), Weight::zero());
|
||||
assert_ne!(
|
||||
Weights::<T>::receive_messages_delivery_proof_overhead_from_runtime(),
|
||||
Weight::zero()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Check that the `AdditionalSigned` type of a wrapped runtime is the same as the one of the
|
||||
|
||||
@@ -40,7 +40,9 @@ use pallet_bridge_parachains::{
|
||||
BoundedBridgeGrandpaConfig, CallSubType as ParachainsCallSubType, Config as ParachainsConfig,
|
||||
RelayBlockNumber, SubmitParachainHeadsHelper, SubmitParachainHeadsInfo,
|
||||
};
|
||||
use pallet_bridge_relayers::{Config as RelayersConfig, Pallet as RelayersPallet};
|
||||
use pallet_bridge_relayers::{
|
||||
Config as RelayersConfig, Pallet as RelayersPallet, WeightInfoExt as _,
|
||||
};
|
||||
use pallet_transaction_payment::{Config as TransactionPaymentConfig, OnChargeTransaction};
|
||||
use pallet_utility::{Call as UtilityCall, Config as UtilityConfig, Pallet as UtilityPallet};
|
||||
use scale_info::TypeInfo;
|
||||
@@ -445,11 +447,19 @@ where
|
||||
|
||||
// decrease post-dispatch weight/size using extra weight/size that we know now
|
||||
let post_info_len = len.saturating_sub(extra_size as usize);
|
||||
let mut post_info = *post_info;
|
||||
post_info.actual_weight =
|
||||
Some(post_info.actual_weight.unwrap_or(info.weight).saturating_sub(extra_weight));
|
||||
let mut post_info_weight =
|
||||
post_info.actual_weight.unwrap_or(info.weight).saturating_sub(extra_weight);
|
||||
|
||||
// let's also replace the weight of slashing relayer with the weight of rewarding relayer
|
||||
if call_info.is_receive_messages_proof_call() {
|
||||
post_info_weight = post_info_weight.saturating_sub(
|
||||
<Runtime as RelayersConfig>::WeightInfo::extra_weight_of_successful_receive_messages_proof_call(),
|
||||
);
|
||||
}
|
||||
|
||||
// compute the relayer refund
|
||||
let mut post_info = *post_info;
|
||||
post_info.actual_weight = Some(post_info_weight);
|
||||
let refund = Refund::compute_refund(info, &post_info, post_info_len, tip);
|
||||
|
||||
// we can finally reward relayer
|
||||
@@ -1052,7 +1062,20 @@ mod tests {
|
||||
assert_eq!(post_dispatch_result, Ok(()));
|
||||
}
|
||||
|
||||
fn expected_reward() -> ThisChainBalance {
|
||||
fn expected_delivery_reward() -> ThisChainBalance {
|
||||
let mut post_dispatch_info = post_dispatch_info();
|
||||
let extra_weight = <TestRuntime as RelayersConfig>::WeightInfo::extra_weight_of_successful_receive_messages_proof_call();
|
||||
post_dispatch_info.actual_weight =
|
||||
Some(dispatch_info().weight.saturating_sub(extra_weight));
|
||||
pallet_transaction_payment::Pallet::<TestRuntime>::compute_actual_fee(
|
||||
1024,
|
||||
&dispatch_info(),
|
||||
&post_dispatch_info,
|
||||
Zero::zero(),
|
||||
)
|
||||
}
|
||||
|
||||
fn expected_confirmation_reward() -> ThisChainBalance {
|
||||
pallet_transaction_payment::Pallet::<TestRuntime>::compute_actual_fee(
|
||||
1024,
|
||||
&dispatch_info(),
|
||||
@@ -1449,7 +1472,7 @@ mod tests {
|
||||
|
||||
// without any size/weight refund: we expect regular reward
|
||||
let pre_dispatch_data = all_finality_pre_dispatch_data();
|
||||
let regular_reward = expected_reward();
|
||||
let regular_reward = expected_delivery_reward();
|
||||
run_post_dispatch(Some(pre_dispatch_data), Ok(()));
|
||||
assert_eq!(
|
||||
RelayersPallet::<TestRuntime>::relayer_reward(
|
||||
@@ -1496,7 +1519,7 @@ mod tests {
|
||||
relayer_account_at_this_chain(),
|
||||
MsgProofsRewardsAccount::get()
|
||||
),
|
||||
Some(expected_reward()),
|
||||
Some(expected_delivery_reward()),
|
||||
);
|
||||
|
||||
run_post_dispatch(Some(all_finality_confirmation_pre_dispatch_data()), Ok(()));
|
||||
@@ -1505,7 +1528,7 @@ mod tests {
|
||||
relayer_account_at_this_chain(),
|
||||
MsgDeliveryProofsRewardsAccount::get()
|
||||
),
|
||||
Some(expected_reward()),
|
||||
Some(expected_confirmation_reward()),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -1521,7 +1544,7 @@ mod tests {
|
||||
relayer_account_at_this_chain(),
|
||||
MsgProofsRewardsAccount::get()
|
||||
),
|
||||
Some(expected_reward()),
|
||||
Some(expected_delivery_reward()),
|
||||
);
|
||||
|
||||
run_post_dispatch(Some(parachain_finality_confirmation_pre_dispatch_data()), Ok(()));
|
||||
@@ -1530,7 +1553,7 @@ mod tests {
|
||||
relayer_account_at_this_chain(),
|
||||
MsgDeliveryProofsRewardsAccount::get()
|
||||
),
|
||||
Some(expected_reward()),
|
||||
Some(expected_confirmation_reward()),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -1546,7 +1569,7 @@ mod tests {
|
||||
relayer_account_at_this_chain(),
|
||||
MsgProofsRewardsAccount::get()
|
||||
),
|
||||
Some(expected_reward()),
|
||||
Some(expected_delivery_reward()),
|
||||
);
|
||||
|
||||
run_post_dispatch(Some(confirmation_pre_dispatch_data()), Ok(()));
|
||||
@@ -1555,7 +1578,7 @@ mod tests {
|
||||
relayer_account_at_this_chain(),
|
||||
MsgDeliveryProofsRewardsAccount::get()
|
||||
),
|
||||
Some(expected_reward()),
|
||||
Some(expected_confirmation_reward()),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user