mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 04:01:02 +00:00
lower limit for message weight (#536)
* lower limit for message weight * fmt * do not include tx overhead in weights returned by weight_limits_of_message_on_bridged_chain * Use correct chain in comment Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
This commit is contained in:
committed by
Bastian Köcher
parent
951aa36c2b
commit
a872ee6ff1
@@ -30,6 +30,7 @@ use frame_support::{
|
|||||||
RuntimeDebug,
|
RuntimeDebug,
|
||||||
};
|
};
|
||||||
use sp_core::storage::StorageKey;
|
use sp_core::storage::StorageKey;
|
||||||
|
use sp_std::{convert::TryFrom, ops::RangeInclusive};
|
||||||
|
|
||||||
/// Storage key of the Millau -> Rialto message in the runtime storage.
|
/// Storage key of the Millau -> Rialto message in the runtime storage.
|
||||||
pub fn message_key(lane: &LaneId, nonce: MessageNonce) -> StorageKey {
|
pub fn message_key(lane: &LaneId, nonce: MessageNonce) -> StorageKey {
|
||||||
@@ -87,9 +88,15 @@ impl MessageBridge for WithRialtoMessageBridge {
|
|||||||
type ThisChain = Millau;
|
type ThisChain = Millau;
|
||||||
type BridgedChain = Rialto;
|
type BridgedChain = Rialto;
|
||||||
|
|
||||||
fn maximal_dispatch_weight_of_message_on_bridged_chain() -> Weight {
|
fn weight_limits_of_message_on_bridged_chain(message_payload: &[u8]) -> RangeInclusive<Weight> {
|
||||||
// we don't want to relay too large messages + keep reserve for future upgrades
|
// we don't want to relay too large messages + keep reserve for future upgrades
|
||||||
bp_rialto::MAXIMUM_EXTRINSIC_WEIGHT / 2
|
let upper_limit = bp_rialto::MAXIMUM_EXTRINSIC_WEIGHT / 2;
|
||||||
|
|
||||||
|
// given Rialto chain parameters (`TransactionByteFee`, `WeightToFee`, `FeeMultiplierUpdate`),
|
||||||
|
// the minimal weight of the message may be computed as message.length()
|
||||||
|
let lower_limit = Weight::try_from(message_payload.len()).unwrap_or(Weight::MAX);
|
||||||
|
|
||||||
|
lower_limit..=upper_limit
|
||||||
}
|
}
|
||||||
|
|
||||||
fn weight_of_delivery_transaction() -> Weight {
|
fn weight_of_delivery_transaction() -> Weight {
|
||||||
@@ -160,8 +167,9 @@ impl TargetHeaderChain<ToRialtoMessagePayload, bp_rialto::AccountId> for Rialto
|
|||||||
type MessagesDeliveryProof = ToRialtoMessagesDeliveryProof;
|
type MessagesDeliveryProof = ToRialtoMessagesDeliveryProof;
|
||||||
|
|
||||||
fn verify_message(payload: &ToRialtoMessagePayload) -> Result<(), Self::Error> {
|
fn verify_message(payload: &ToRialtoMessagePayload) -> Result<(), Self::Error> {
|
||||||
if payload.weight > WithRialtoMessageBridge::maximal_dispatch_weight_of_message_on_bridged_chain() {
|
let weight_limits = WithRialtoMessageBridge::weight_limits_of_message_on_bridged_chain(&payload.call);
|
||||||
return Err("Too large weight declared");
|
if !weight_limits.contains(&payload.weight) {
|
||||||
|
return Err("Incorrect message weight declared");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ use frame_support::{
|
|||||||
RuntimeDebug,
|
RuntimeDebug,
|
||||||
};
|
};
|
||||||
use sp_core::storage::StorageKey;
|
use sp_core::storage::StorageKey;
|
||||||
|
use sp_std::{convert::TryFrom, ops::RangeInclusive};
|
||||||
|
|
||||||
/// Storage key of the Rialto -> Millau message in the runtime storage.
|
/// Storage key of the Rialto -> Millau message in the runtime storage.
|
||||||
pub fn message_key(lane: &LaneId, nonce: MessageNonce) -> StorageKey {
|
pub fn message_key(lane: &LaneId, nonce: MessageNonce) -> StorageKey {
|
||||||
@@ -87,9 +88,15 @@ impl MessageBridge for WithMillauMessageBridge {
|
|||||||
type ThisChain = Rialto;
|
type ThisChain = Rialto;
|
||||||
type BridgedChain = Millau;
|
type BridgedChain = Millau;
|
||||||
|
|
||||||
fn maximal_dispatch_weight_of_message_on_bridged_chain() -> Weight {
|
fn weight_limits_of_message_on_bridged_chain(message_payload: &[u8]) -> RangeInclusive<Weight> {
|
||||||
// we don't want to relay too large messages + keep reserve for future upgrades
|
// we don't want to relay too large messages + keep reserve for future upgrades
|
||||||
bp_millau::MAXIMUM_EXTRINSIC_WEIGHT / 2
|
let upper_limit = bp_millau::MAXIMUM_EXTRINSIC_WEIGHT / 2;
|
||||||
|
|
||||||
|
// given Millau chain parameters (`TransactionByteFee`, `WeightToFee`, `FeeMultiplierUpdate`),
|
||||||
|
// the minimal weight of the message may be computed as message.length()
|
||||||
|
let lower_limit = Weight::try_from(message_payload.len()).unwrap_or(Weight::MAX);
|
||||||
|
|
||||||
|
lower_limit..=upper_limit
|
||||||
}
|
}
|
||||||
|
|
||||||
fn weight_of_delivery_transaction() -> Weight {
|
fn weight_of_delivery_transaction() -> Weight {
|
||||||
@@ -160,8 +167,9 @@ impl TargetHeaderChain<ToMillauMessagePayload, bp_millau::AccountId> for Millau
|
|||||||
type MessagesDeliveryProof = ToMillauMessagesDeliveryProof;
|
type MessagesDeliveryProof = ToMillauMessagesDeliveryProof;
|
||||||
|
|
||||||
fn verify_message(payload: &ToMillauMessagePayload) -> Result<(), Self::Error> {
|
fn verify_message(payload: &ToMillauMessagePayload) -> Result<(), Self::Error> {
|
||||||
if payload.weight > WithMillauMessageBridge::maximal_dispatch_weight_of_message_on_bridged_chain() {
|
let weight_limits = WithMillauMessageBridge::weight_limits_of_message_on_bridged_chain(&payload.call);
|
||||||
return Err("Payload has weight larger than maximum allowed weight");
|
if !weight_limits.contains(&payload.weight) {
|
||||||
|
return Err("Incorrect message weight declared");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use bp_runtime::InstanceId;
|
|||||||
use codec::{Compact, Decode, Input};
|
use codec::{Compact, Decode, Input};
|
||||||
use frame_support::{traits::Instance, RuntimeDebug};
|
use frame_support::{traits::Instance, RuntimeDebug};
|
||||||
use sp_runtime::traits::{CheckedAdd, CheckedDiv, CheckedMul};
|
use sp_runtime::traits::{CheckedAdd, CheckedDiv, CheckedMul};
|
||||||
use sp_std::{cmp::PartialOrd, marker::PhantomData, vec::Vec};
|
use sp_std::{cmp::PartialOrd, marker::PhantomData, ops::RangeInclusive, vec::Vec};
|
||||||
use sp_trie::StorageProof;
|
use sp_trie::StorageProof;
|
||||||
|
|
||||||
/// Bidirectional message bridge.
|
/// Bidirectional message bridge.
|
||||||
@@ -46,8 +46,18 @@ pub trait MessageBridge {
|
|||||||
/// Bridged chain in context of message bridge.
|
/// Bridged chain in context of message bridge.
|
||||||
type BridgedChain: ChainWithMessageLanes;
|
type BridgedChain: ChainWithMessageLanes;
|
||||||
|
|
||||||
/// Maximal (dispatch) weight of the message that we are able to send to Bridged chain.
|
/// Returns feasible weights range for given message payload on the target chain.
|
||||||
fn maximal_dispatch_weight_of_message_on_bridged_chain() -> WeightOf<BridgedChain<Self>>;
|
///
|
||||||
|
/// If message is being sent with the weight that is out of this range, then it
|
||||||
|
/// should be rejected.
|
||||||
|
///
|
||||||
|
/// Weights returned from this function shall not include transaction overhead
|
||||||
|
/// (like weight of signature and signed extensions verification), because they're
|
||||||
|
/// already accounted by the `weight_of_delivery_transaction`. So this function should
|
||||||
|
/// return pure call dispatch weights range.
|
||||||
|
fn weight_limits_of_message_on_bridged_chain(
|
||||||
|
message_payload: &[u8],
|
||||||
|
) -> RangeInclusive<WeightOf<BridgedChain<Self>>>;
|
||||||
|
|
||||||
/// Maximal weight of single message delivery transaction on Bridged chain.
|
/// Maximal weight of single message delivery transaction on Bridged chain.
|
||||||
fn weight_of_delivery_transaction() -> WeightOf<BridgedChain<Self>>;
|
fn weight_of_delivery_transaction() -> WeightOf<BridgedChain<Self>>;
|
||||||
@@ -425,7 +435,7 @@ mod tests {
|
|||||||
type ThisChain = ThisChain;
|
type ThisChain = ThisChain;
|
||||||
type BridgedChain = BridgedChain;
|
type BridgedChain = BridgedChain;
|
||||||
|
|
||||||
fn maximal_dispatch_weight_of_message_on_bridged_chain() -> Weight {
|
fn weight_limits_of_message_on_bridged_chain(_message_payload: &[u8]) -> RangeInclusive<Weight> {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,7 +474,7 @@ mod tests {
|
|||||||
type ThisChain = BridgedChain;
|
type ThisChain = BridgedChain;
|
||||||
type BridgedChain = ThisChain;
|
type BridgedChain = ThisChain;
|
||||||
|
|
||||||
fn maximal_dispatch_weight_of_message_on_bridged_chain() -> Weight {
|
fn weight_limits_of_message_on_bridged_chain(_message_payload: &[u8]) -> RangeInclusive<Weight> {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user