Add messages count parameter to delivery transaction (#581)

* add messages count parameter to delivery transaction

* fix benchmarks compilation
This commit is contained in:
Svyatoslav Nikolsky
2020-12-17 12:47:45 +03:00
committed by Bastian Köcher
parent 6317a31e25
commit 63e2655c8b
13 changed files with 96 additions and 71 deletions
-3
View File
@@ -313,8 +313,6 @@ parameter_types! {
bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE; bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE;
pub const MaxUnconfirmedMessagesAtInboundLane: bp_message_lane::MessageNonce = pub const MaxUnconfirmedMessagesAtInboundLane: bp_message_lane::MessageNonce =
bp_millau::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE; bp_millau::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE;
pub const MaxMessagesInDeliveryTransaction: bp_message_lane::MessageNonce =
bp_millau::MAX_MESSAGES_IN_DELIVERY_TRANSACTION;
} }
impl pallet_message_lane::Config for Runtime { impl pallet_message_lane::Config for Runtime {
@@ -322,7 +320,6 @@ impl pallet_message_lane::Config for Runtime {
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce; type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane; type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane; type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;
type MaxMessagesInDeliveryTransaction = MaxMessagesInDeliveryTransaction;
type OutboundPayload = crate::rialto_messages::ToRialtoMessagePayload; type OutboundPayload = crate::rialto_messages::ToRialtoMessagePayload;
type OutboundMessageFee = Balance; type OutboundMessageFee = Balance;
@@ -192,8 +192,8 @@ impl SourceHeaderChain<bp_rialto::Balance> for Rialto {
fn verify_messages_proof( fn verify_messages_proof(
proof: Self::MessagesProof, proof: Self::MessagesProof,
max_messages: MessageNonce, messages_count: MessageNonce,
) -> Result<ProvedMessages<Message<bp_rialto::Balance>>, Self::Error> { ) -> Result<ProvedMessages<Message<bp_rialto::Balance>>, Self::Error> {
messages::target::verify_messages_proof::<WithRialtoMessageBridge, Runtime>(proof, max_messages) messages::target::verify_messages_proof::<WithRialtoMessageBridge, Runtime>(proof, messages_count)
} }
} }
-3
View File
@@ -420,8 +420,6 @@ parameter_types! {
bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE; bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE;
pub const MaxUnconfirmedMessagesAtInboundLane: bp_message_lane::MessageNonce = pub const MaxUnconfirmedMessagesAtInboundLane: bp_message_lane::MessageNonce =
bp_rialto::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE; bp_rialto::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE;
pub const MaxMessagesInDeliveryTransaction: bp_message_lane::MessageNonce =
bp_rialto::MAX_MESSAGES_IN_DELIVERY_TRANSACTION;
} }
pub(crate) type WithMillauMessageLaneInstance = pallet_message_lane::DefaultInstance; pub(crate) type WithMillauMessageLaneInstance = pallet_message_lane::DefaultInstance;
@@ -430,7 +428,6 @@ impl pallet_message_lane::Config for Runtime {
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce; type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane; type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane; type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;
type MaxMessagesInDeliveryTransaction = MaxMessagesInDeliveryTransaction;
type OutboundPayload = crate::millau_messages::ToMillauMessagePayload; type OutboundPayload = crate::millau_messages::ToMillauMessagePayload;
type OutboundMessageFee = Balance; type OutboundMessageFee = Balance;
@@ -192,8 +192,8 @@ impl SourceHeaderChain<bp_millau::Balance> for Millau {
fn verify_messages_proof( fn verify_messages_proof(
proof: Self::MessagesProof, proof: Self::MessagesProof,
max_messages: MessageNonce, messages_count: MessageNonce,
) -> Result<ProvedMessages<Message<bp_millau::Balance>>, Self::Error> { ) -> Result<ProvedMessages<Message<bp_millau::Balance>>, Self::Error> {
messages::target::verify_messages_proof::<WithMillauMessageBridge, Runtime>(proof, max_messages) messages::target::verify_messages_proof::<WithMillauMessageBridge, Runtime>(proof, messages_count)
} }
} }
+27 -15
View File
@@ -399,7 +399,7 @@ pub mod target {
/// Verify proof of Bridged -> This chain messages. /// Verify proof of Bridged -> This chain messages.
pub fn verify_messages_proof<B: MessageBridge, ThisRuntime>( pub fn verify_messages_proof<B: MessageBridge, ThisRuntime>(
proof: FromBridgedChainMessagesProof<B>, proof: FromBridgedChainMessagesProof<B>,
max_messages: MessageNonce, messages_count: MessageNonce,
) -> Result<ProvedMessages<Message<BalanceOf<BridgedChain<B>>>>, &'static str> ) -> Result<ProvedMessages<Message<BalanceOf<BridgedChain<B>>>>, &'static str>
where where
ThisRuntime: pallet_substrate_bridge::Config, ThisRuntime: pallet_substrate_bridge::Config,
@@ -409,7 +409,7 @@ pub mod target {
{ {
verify_messages_proof_with_parser::<B, _, _>( verify_messages_proof_with_parser::<B, _, _>(
proof, proof,
max_messages, messages_count,
|bridged_header_hash, bridged_storage_proof| { |bridged_header_hash, bridged_storage_proof| {
pallet_substrate_bridge::Module::<ThisRuntime>::parse_finalized_storage_proof( pallet_substrate_bridge::Module::<ThisRuntime>::parse_finalized_storage_proof(
bridged_header_hash.into(), bridged_header_hash.into(),
@@ -429,7 +429,7 @@ pub mod target {
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub(crate) enum MessageProofError { pub(crate) enum MessageProofError {
Empty, Empty,
TooManyMessages, MessagesCountMismatch,
MissingRequiredMessage, MissingRequiredMessage,
FailedToDecodeMessage, FailedToDecodeMessage,
FailedToDecodeOutboundLaneState, FailedToDecodeOutboundLaneState,
@@ -440,7 +440,7 @@ pub mod target {
fn from(err: MessageProofError) -> &'static str { fn from(err: MessageProofError) -> &'static str {
match err { match err {
MessageProofError::Empty => "Messages proof is empty", MessageProofError::Empty => "Messages proof is empty",
MessageProofError::TooManyMessages => "Too many messages in the proof", MessageProofError::MessagesCountMismatch => "Declared messages count doesn't match actual value",
MessageProofError::MissingRequiredMessage => "Message is missing from the proof", MessageProofError::MissingRequiredMessage => "Message is missing from the proof",
MessageProofError::FailedToDecodeMessage => "Failed to decode message from the proof", MessageProofError::FailedToDecodeMessage => "Failed to decode message from the proof",
MessageProofError::FailedToDecodeOutboundLaneState => { MessageProofError::FailedToDecodeOutboundLaneState => {
@@ -488,7 +488,7 @@ pub mod target {
/// Verify proof of Bridged -> This chain messages using given message proof parser. /// Verify proof of Bridged -> This chain messages using given message proof parser.
pub(crate) fn verify_messages_proof_with_parser<B: MessageBridge, BuildParser, Parser>( pub(crate) fn verify_messages_proof_with_parser<B: MessageBridge, BuildParser, Parser>(
proof: FromBridgedChainMessagesProof<B>, proof: FromBridgedChainMessagesProof<B>,
max_messages: MessageNonce, messages_count: MessageNonce,
build_parser: BuildParser, build_parser: BuildParser,
) -> Result<ProvedMessages<Message<BalanceOf<BridgedChain<B>>>>, MessageProofError> ) -> Result<ProvedMessages<Message<BalanceOf<BridgedChain<B>>>>, MessageProofError>
where where
@@ -500,8 +500,8 @@ pub mod target {
// receiving proofs where end < begin is ok (if proof includes outbound lane state) // receiving proofs where end < begin is ok (if proof includes outbound lane state)
// => hence unwrap_or(0) // => hence unwrap_or(0)
let messages_in_the_proof = end.checked_sub(begin).and_then(|diff| diff.checked_add(1)).unwrap_or(0); let messages_in_the_proof = end.checked_sub(begin).and_then(|diff| diff.checked_add(1)).unwrap_or(0);
if messages_in_the_proof > max_messages { if messages_in_the_proof != messages_count {
return Err(MessageProofError::TooManyMessages); return Err(MessageProofError::MessagesCountMismatch);
} }
let parser = build_parser(bridged_header_hash, bridged_storage_proof)?; let parser = build_parser(bridged_header_hash, bridged_storage_proof)?;
@@ -1009,14 +1009,26 @@ mod tests {
} }
#[test] #[test]
fn messages_proof_is_rejected_if_there_are_too_many_messages() { fn messages_proof_is_rejected_if_declared_less_than_actual_number_of_messages() {
assert_eq!( assert_eq!(
target::verify_messages_proof_with_parser::<OnThisChainBridge, _, TestMessageProofParser>( target::verify_messages_proof_with_parser::<OnThisChainBridge, _, TestMessageProofParser>(
(Default::default(), StorageProof::new(vec![]), Default::default(), 1, 11), (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 10),
10, 5,
|_, _| unreachable!(), |_, _| unreachable!(),
), ),
Err(target::MessageProofError::TooManyMessages), Err(target::MessageProofError::MessagesCountMismatch),
);
}
#[test]
fn messages_proof_is_rejected_if_declared_more_than_actual_number_of_messages() {
assert_eq!(
target::verify_messages_proof_with_parser::<OnThisChainBridge, _, TestMessageProofParser>(
(Default::default(), StorageProof::new(vec![]), Default::default(), 1, 10),
15,
|_, _| unreachable!(),
),
Err(target::MessageProofError::MessagesCountMismatch),
); );
} }
@@ -1069,7 +1081,7 @@ mod tests {
assert_eq!( assert_eq!(
target::verify_messages_proof_with_parser::<OnThisChainBridge, _, _>( target::verify_messages_proof_with_parser::<OnThisChainBridge, _, _>(
(Default::default(), StorageProof::new(vec![]), Default::default(), 1, 0), (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 0),
10, 0,
|_, _| Ok(TestMessageProofParser { |_, _| Ok(TestMessageProofParser {
failing: true, failing: true,
messages: no_messages_range(), messages: no_messages_range(),
@@ -1089,7 +1101,7 @@ mod tests {
assert_eq!( assert_eq!(
target::verify_messages_proof_with_parser::<OnThisChainBridge, _, _>( target::verify_messages_proof_with_parser::<OnThisChainBridge, _, _>(
(Default::default(), StorageProof::new(vec![]), Default::default(), 1, 0), (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 0),
10, 0,
|_, _| Ok(TestMessageProofParser { |_, _| Ok(TestMessageProofParser {
failing: false, failing: false,
messages: no_messages_range(), messages: no_messages_range(),
@@ -1105,7 +1117,7 @@ mod tests {
assert_eq!( assert_eq!(
target::verify_messages_proof_with_parser::<OnThisChainBridge, _, _>( target::verify_messages_proof_with_parser::<OnThisChainBridge, _, _>(
(Default::default(), StorageProof::new(vec![]), Default::default(), 1, 0), (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 0),
10, 0,
|_, _| Ok(TestMessageProofParser { |_, _| Ok(TestMessageProofParser {
failing: false, failing: false,
messages: no_messages_range(), messages: no_messages_range(),
@@ -1137,7 +1149,7 @@ mod tests {
assert_eq!( assert_eq!(
target::verify_messages_proof_with_parser::<OnThisChainBridge, _, _>( target::verify_messages_proof_with_parser::<OnThisChainBridge, _, _>(
(Default::default(), StorageProof::new(vec![]), Default::default(), 1, 1), (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 1),
10, 1,
|_, _| Ok(TestMessageProofParser { |_, _| Ok(TestMessageProofParser {
failing: false, failing: false,
messages: 1..=1, messages: 1..=1,
@@ -25,7 +25,7 @@ use frame_benchmarking::{account, benchmarks_instance};
use frame_support::{traits::Get, weights::Weight}; use frame_support::{traits::Get, weights::Weight};
use frame_system::RawOrigin; use frame_system::RawOrigin;
use num_traits::Zero; use num_traits::Zero;
use sp_std::{convert::TryInto, ops::RangeInclusive, prelude::*}; use sp_std::{ops::RangeInclusive, prelude::*};
/// Message crafted with this size factor should be the largest possible message. /// Message crafted with this size factor should be the largest possible message.
pub const WORST_MESSAGE_SIZE_FACTOR: u32 = 1000; pub const WORST_MESSAGE_SIZE_FACTOR: u32 = 1000;
@@ -127,7 +127,7 @@ benchmarks_instance! {
message_nonces: 1..=1, message_nonces: 1..=1,
outbound_lane_data: None, outbound_lane_data: None,
}); });
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, dispatch_weight) }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify { verify {
assert_eq!( assert_eq!(
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()), crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
@@ -154,7 +154,7 @@ benchmarks_instance! {
message_nonces: 1..=2, message_nonces: 1..=2,
outbound_lane_data: None, outbound_lane_data: None,
}); });
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, dispatch_weight) }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 2, dispatch_weight)
verify { verify {
assert_eq!( assert_eq!(
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()), crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
@@ -188,7 +188,7 @@ benchmarks_instance! {
latest_generated_nonce: 21, latest_generated_nonce: 21,
}), }),
}); });
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, dispatch_weight) }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify { verify {
assert_eq!( assert_eq!(
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()), crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
@@ -214,19 +214,24 @@ benchmarks_instance! {
// `weight(receive_two_messages_proof) - weight(receive_single_message_proof)`. So it may be used // `weight(receive_two_messages_proof) - weight(receive_single_message_proof)`. So it may be used
// to verify that the other approximation is correct. // to verify that the other approximation is correct.
receive_multiple_messages_proof { receive_multiple_messages_proof {
let i in 1..T::MaxMessagesInDeliveryTransaction::get() let i in 1..128;
.try_into()
.expect("Value of MaxMessagesInDeliveryTransaction is too large");
let relayer_id_on_source = T::bridged_relayer_id(); let relayer_id_on_source = T::bridged_relayer_id();
let relayer_id_on_target = account("relayer", 0, SEED); let relayer_id_on_target = account("relayer", 0, SEED);
let messages_count = i as _;
let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams { let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams {
lane: bench_lane_id(), lane: bench_lane_id(),
message_nonces: 1..=i as _, message_nonces: 1..=i as _,
outbound_lane_data: None, outbound_lane_data: None,
}); });
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, dispatch_weight) }: receive_messages_proof(
RawOrigin::Signed(relayer_id_on_target),
relayer_id_on_source,
proof,
messages_count,
dispatch_weight
)
verify { verify {
assert_eq!( assert_eq!(
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()), crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
@@ -244,12 +249,11 @@ benchmarks_instance! {
// `weight(receive_single_message_proof_with_outbound_lane_state) - weight(receive_single_message_proof)`. // `weight(receive_single_message_proof_with_outbound_lane_state) - weight(receive_single_message_proof)`.
// So it may be used to verify that the other approximation is correct. // So it may be used to verify that the other approximation is correct.
receive_multiple_messages_proof_with_outbound_lane_state { receive_multiple_messages_proof_with_outbound_lane_state {
let i in 1..T::MaxMessagesInDeliveryTransaction::get() let i in 1..128;
.try_into()
.expect("Value of MaxMessagesInDeliveryTransaction is too large");
let relayer_id_on_source = T::bridged_relayer_id(); let relayer_id_on_source = T::bridged_relayer_id();
let relayer_id_on_target = account("relayer", 0, SEED); let relayer_id_on_target = account("relayer", 0, SEED);
let messages_count = i as _;
// mark messages 1..=20 as delivered // mark messages 1..=20 as delivered
receive_messages::<T, I>(20); receive_messages::<T, I>(20);
@@ -263,7 +267,13 @@ benchmarks_instance! {
latest_generated_nonce: 21, latest_generated_nonce: 21,
}), }),
}); });
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, dispatch_weight) }: receive_messages_proof(
RawOrigin::Signed(relayer_id_on_target),
relayer_id_on_source,
proof,
messages_count,
dispatch_weight
)
verify { verify {
assert_eq!( assert_eq!(
crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()), crate::Module::<T, I>::inbound_latest_received_nonce(bench_lane_id()),
+14 -13
View File
@@ -93,11 +93,6 @@ pub trait Config<I = DefaultInstance>: frame_system::Config {
/// This constant limits difference between last message from last entry of the /// This constant limits difference between last message from last entry of the
/// `InboundLaneData::relayers` and first message at the first entry. /// `InboundLaneData::relayers` and first message at the first entry.
type MaxUnconfirmedMessagesAtInboundLane: Get<MessageNonce>; type MaxUnconfirmedMessagesAtInboundLane: Get<MessageNonce>;
/// Maximal number of messages in single delivery transaction. This directly affects the base
/// weight of the delivery transaction.
///
/// All transactions that deliver more messages than this number, are rejected.
type MaxMessagesInDeliveryTransaction: Get<MessageNonce>;
/// Payload type of outbound messages. This payload is dispatched on the bridged chain. /// Payload type of outbound messages. This payload is dispatched on the bridged chain.
type OutboundPayload: Parameter; type OutboundPayload: Parameter;
@@ -322,17 +317,16 @@ decl_module! {
} }
/// Receive messages proof from bridged chain. /// Receive messages proof from bridged chain.
#[weight = DELIVERY_OVERHEAD_WEIGHT #[weight = messages_count
.saturating_add( .saturating_mul(SINGLE_MESSAGE_DELIVERY_WEIGHT)
T::MaxMessagesInDeliveryTransaction::get() .saturating_add(DELIVERY_OVERHEAD_WEIGHT)
.saturating_mul(SINGLE_MESSAGE_DELIVERY_WEIGHT)
)
.saturating_add(*dispatch_weight) .saturating_add(*dispatch_weight)
] ]
pub fn receive_messages_proof( pub fn receive_messages_proof(
origin, origin,
relayer_id: T::InboundRelayer, relayer_id: T::InboundRelayer,
proof: MessagesProofOf<T, I>, proof: MessagesProofOf<T, I>,
messages_count: MessageNonce,
dispatch_weight: Weight, dispatch_weight: Weight,
) -> DispatchResult { ) -> DispatchResult {
ensure_operational::<T, I>()?; ensure_operational::<T, I>()?;
@@ -343,7 +337,7 @@ decl_module! {
T::SourceHeaderChain, T::SourceHeaderChain,
T::InboundMessageFee, T::InboundMessageFee,
T::InboundPayload, T::InboundPayload,
>(proof, T::MaxMessagesInDeliveryTransaction::get()) >(proof, messages_count)
.map_err(|err| { .map_err(|err| {
frame_support::debug::trace!( frame_support::debug::trace!(
"Rejecting invalid messages proof: {:?}", "Rejecting invalid messages proof: {:?}",
@@ -674,9 +668,9 @@ impl<T: Config<I>, I: Instance> OutboundLaneStorage for RuntimeOutboundLaneStora
/// Verify messages proof and return proved messages with decoded payload. /// Verify messages proof and return proved messages with decoded payload.
fn verify_and_decode_messages_proof<Chain: SourceHeaderChain<Fee>, Fee, DispatchPayload: Decode>( fn verify_and_decode_messages_proof<Chain: SourceHeaderChain<Fee>, Fee, DispatchPayload: Decode>(
proof: Chain::MessagesProof, proof: Chain::MessagesProof,
max_messages: MessageNonce, messages_count: MessageNonce,
) -> Result<ProvedMessages<DispatchMessage<DispatchPayload, Fee>>, Chain::Error> { ) -> Result<ProvedMessages<DispatchMessage<DispatchPayload, Fee>>, Chain::Error> {
Chain::verify_messages_proof(proof, max_messages).map(|messages_by_lane| { Chain::verify_messages_proof(proof, messages_count).map(|messages_by_lane| {
messages_by_lane messages_by_lane
.into_iter() .into_iter()
.map(|(lane, lane_data)| { .map(|(lane, lane_data)| {
@@ -846,6 +840,7 @@ mod tests {
Origin::signed(1), Origin::signed(1),
TEST_RELAYER_A, TEST_RELAYER_A,
Ok(vec![message(2, REGULAR_PAYLOAD)]).into(), Ok(vec![message(2, REGULAR_PAYLOAD)]).into(),
1,
REGULAR_PAYLOAD.1, REGULAR_PAYLOAD.1,
), ),
Error::<TestRuntime, DefaultInstance>::Halted, Error::<TestRuntime, DefaultInstance>::Halted,
@@ -924,6 +919,7 @@ mod tests {
Origin::signed(1), Origin::signed(1),
TEST_RELAYER_A, TEST_RELAYER_A,
Ok(vec![message(1, REGULAR_PAYLOAD)]).into(), Ok(vec![message(1, REGULAR_PAYLOAD)]).into(),
1,
REGULAR_PAYLOAD.1, REGULAR_PAYLOAD.1,
)); ));
@@ -964,6 +960,7 @@ mod tests {
Origin::signed(1), Origin::signed(1),
TEST_RELAYER_A, TEST_RELAYER_A,
message_proof, message_proof,
1,
REGULAR_PAYLOAD.1, REGULAR_PAYLOAD.1,
)); ));
@@ -995,6 +992,7 @@ mod tests {
Origin::signed(1), Origin::signed(1),
TEST_RELAYER_A, TEST_RELAYER_A,
Ok(vec![message(1, REGULAR_PAYLOAD)]).into(), Ok(vec![message(1, REGULAR_PAYLOAD)]).into(),
1,
REGULAR_PAYLOAD.1 - 1, REGULAR_PAYLOAD.1 - 1,
), ),
Error::<TestRuntime, DefaultInstance>::InvalidMessagesDispatchWeight, Error::<TestRuntime, DefaultInstance>::InvalidMessagesDispatchWeight,
@@ -1010,6 +1008,7 @@ mod tests {
Origin::signed(1), Origin::signed(1),
TEST_RELAYER_A, TEST_RELAYER_A,
Err(()).into(), Err(()).into(),
1,
0, 0,
), ),
Error::<TestRuntime, DefaultInstance>::InvalidMessagesProof, Error::<TestRuntime, DefaultInstance>::InvalidMessagesProof,
@@ -1112,6 +1111,7 @@ mod tests {
Origin::signed(1), Origin::signed(1),
TEST_RELAYER_A, TEST_RELAYER_A,
Ok(vec![invalid_message]).into(), Ok(vec![invalid_message]).into(),
1,
0, // weight may be zero in this case (all messages are improperly encoded) 0, // weight may be zero in this case (all messages are improperly encoded)
),); ),);
@@ -1134,6 +1134,7 @@ mod tests {
message(3, REGULAR_PAYLOAD), message(3, REGULAR_PAYLOAD),
]) ])
.into(), .into(),
3,
REGULAR_PAYLOAD.1 + REGULAR_PAYLOAD.1, REGULAR_PAYLOAD.1 + REGULAR_PAYLOAD.1,
),); ),);
+1 -3
View File
@@ -97,7 +97,6 @@ parameter_types! {
pub const MaxMessagesToPruneAtOnce: u64 = 10; pub const MaxMessagesToPruneAtOnce: u64 = 10;
pub const MaxUnrewardedRelayerEntriesAtInboundLane: u64 = 16; pub const MaxUnrewardedRelayerEntriesAtInboundLane: u64 = 16;
pub const MaxUnconfirmedMessagesAtInboundLane: u64 = 32; pub const MaxUnconfirmedMessagesAtInboundLane: u64 = 32;
pub const MaxMessagesInDeliveryTransaction: u64 = 128;
} }
impl Config for TestRuntime { impl Config for TestRuntime {
@@ -105,7 +104,6 @@ impl Config for TestRuntime {
type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce; type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce;
type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane; type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane;
type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane; type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane;
type MaxMessagesInDeliveryTransaction = MaxMessagesInDeliveryTransaction;
type OutboundPayload = TestPayload; type OutboundPayload = TestPayload;
type OutboundMessageFee = TestMessageFee; type OutboundMessageFee = TestMessageFee;
@@ -279,7 +277,7 @@ impl SourceHeaderChain<TestMessageFee> for TestSourceHeaderChain {
fn verify_messages_proof( fn verify_messages_proof(
proof: Self::MessagesProof, proof: Self::MessagesProof,
_max_messages: MessageNonce, _messages_count: MessageNonce,
) -> Result<ProvedMessages<Message<TestMessageFee>>, Self::Error> { ) -> Result<ProvedMessages<Message<TestMessageFee>>, Self::Error> {
proof proof
.result .result
@@ -68,13 +68,13 @@ pub trait SourceHeaderChain<Fee> {
/// Verify messages proof and return proved messages. /// Verify messages proof and return proved messages.
/// ///
/// Returns error if either proof is incorrect, or the number of messages in the proof /// Returns error if either proof is incorrect, or the number of messages in the proof
/// is larger than `max_messages`. /// is not matching the `messages_count`.
/// ///
/// Messages vector is required to be sorted by nonce within each lane. Out-of-order /// Messages vector is required to be sorted by nonce within each lane. Out-of-order
/// messages will be rejected. /// messages will be rejected.
fn verify_messages_proof( fn verify_messages_proof(
proof: Self::MessagesProof, proof: Self::MessagesProof,
max_messages: MessageNonce, messages_count: MessageNonce,
) -> Result<ProvedMessages<Message<Fee>>, Self::Error>; ) -> Result<ProvedMessages<Message<Fee>>, Self::Error>;
} }
-4
View File
@@ -84,10 +84,6 @@ pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// Represents the portion of a block that will be used by Normal extrinsics. /// Represents the portion of a block that will be used by Normal extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
// TODO: may need to be updated after https://github.com/paritytech/parity-bridges-common/issues/78
/// Maximal number of messages in single delivery transaction.
pub const MAX_MESSAGES_IN_DELIVERY_TRANSACTION: MessageNonce = 1024;
/// Maximal number of unrewarded relayer entries at inbound lane. /// Maximal number of unrewarded relayer entries at inbound lane.
pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 1024; pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 1024;
-4
View File
@@ -45,10 +45,6 @@ pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// Represents the portion of a block that will be used by Normal extrinsics. /// Represents the portion of a block that will be used by Normal extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
// TODO: may need to be updated after https://github.com/paritytech/parity-bridges-common/issues/78
/// Maximal number of messages in single delivery transaction.
pub const MAX_MESSAGES_IN_DELIVERY_TRANSACTION: MessageNonce = 128;
/// Maximal number of unrewarded relayer entries at inbound lane. /// Maximal number of unrewarded relayer entries at inbound lane.
pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 128; pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 128;
@@ -73,11 +73,14 @@ impl SubstrateMessageLane for MillauMessagesToRialto {
proof: <Self as MessageLane>::MessagesProof, proof: <Self as MessageLane>::MessagesProof,
) -> Result<Self::TargetSignedTransaction, SubstrateError> { ) -> Result<Self::TargetSignedTransaction, SubstrateError> {
let (dispatch_weight, proof) = proof; let (dispatch_weight, proof) = proof;
let (_, _, _, ref nonces_begin, ref nonces_end) = proof;
let messages_count = nonces_end - nonces_begin + 1;
let account_id = self.target_sign.signer.public().as_array_ref().clone().into(); let account_id = self.target_sign.signer.public().as_array_ref().clone().into();
let nonce = self.target_client.next_account_index(account_id).await?; let nonce = self.target_client.next_account_index(account_id).await?;
let call = rialto_runtime::MessageLaneCall::receive_messages_proof( let call = rialto_runtime::MessageLaneCall::receive_messages_proof(
self.relayer_id_at_source.clone(), self.relayer_id_at_source.clone(),
proof, proof,
messages_count,
dispatch_weight, dispatch_weight,
) )
.into(); .into();
@@ -119,6 +122,14 @@ pub fn run(
lane.relayer_id_at_source, lane.relayer_id_at_source,
); );
// TODO: these two parameters need to be updated after https://github.com/paritytech/parity-bridges-common/issues/78
// the rough idea is to reserve some portion (1/3?) of max extrinsic weight for delivery tx overhead + messages
// overhead
// this must be tuned mostly with `max_messages_in_single_batch`, but `max_messages_weight_in_single_batch` also
// needs to be updated (subtract tx overhead)
let max_messages_in_single_batch = 1024;
let max_messages_weight_in_single_batch = bp_rialto::max_extrinsic_weight();
messages_relay::message_lane_loop::run( messages_relay::message_lane_loop::run(
messages_relay::message_lane_loop::Params { messages_relay::message_lane_loop::Params {
lane: lane_id, lane: lane_id,
@@ -129,10 +140,8 @@ pub fn run(
delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams { delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams {
max_unrewarded_relayer_entries_at_target: bp_rialto::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE, max_unrewarded_relayer_entries_at_target: bp_rialto::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
max_unconfirmed_nonces_at_target: bp_rialto::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE, max_unconfirmed_nonces_at_target: bp_rialto::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
max_messages_in_single_batch: bp_rialto::MAX_MESSAGES_IN_DELIVERY_TRANSACTION, max_messages_in_single_batch,
// TODO: subtract base weight of delivery from this when it'll be known max_messages_weight_in_single_batch,
// https://github.com/paritytech/parity-bridges-common/issues/78
max_messages_weight_in_single_batch: bp_rialto::max_extrinsic_weight(),
// 2/3 is reserved for proofs and tx overhead // 2/3 is reserved for proofs and tx overhead
max_messages_size_in_single_batch: bp_rialto::max_extrinsic_size() as usize / 3, max_messages_size_in_single_batch: bp_rialto::max_extrinsic_size() as usize / 3,
}, },
@@ -73,11 +73,14 @@ impl SubstrateMessageLane for RialtoMessagesToMillau {
proof: <Self as MessageLane>::MessagesProof, proof: <Self as MessageLane>::MessagesProof,
) -> Result<Self::TargetSignedTransaction, SubstrateError> { ) -> Result<Self::TargetSignedTransaction, SubstrateError> {
let (dispatch_weight, proof) = proof; let (dispatch_weight, proof) = proof;
let (_, _, _, ref nonces_begin, ref nonces_end) = proof;
let messages_count = nonces_end - nonces_begin + 1;
let account_id = self.target_sign.signer.public().as_array_ref().clone().into(); let account_id = self.target_sign.signer.public().as_array_ref().clone().into();
let nonce = self.target_client.next_account_index(account_id).await?; let nonce = self.target_client.next_account_index(account_id).await?;
let call = millau_runtime::MessageLaneCall::receive_messages_proof( let call = millau_runtime::MessageLaneCall::receive_messages_proof(
self.relayer_id_at_source.clone(), self.relayer_id_at_source.clone(),
proof, proof,
messages_count,
dispatch_weight, dispatch_weight,
) )
.into(); .into();
@@ -119,6 +122,14 @@ pub fn run(
lane.relayer_id_at_source, lane.relayer_id_at_source,
); );
// TODO: these two parameters need to be updated after https://github.com/paritytech/parity-bridges-common/issues/78
// the rough idea is to reserve some portion (1/3?) of max extrinsic weight for delivery tx overhead + messages
// overhead
// this must be tuned mostly with `max_messages_in_single_batch`, but `max_messages_weight_in_single_batch` also
// needs to be updated (subtract tx overhead)
let max_messages_in_single_batch = 1024;
let max_messages_weight_in_single_batch = bp_rialto::max_extrinsic_weight();
messages_relay::message_lane_loop::run( messages_relay::message_lane_loop::run(
messages_relay::message_lane_loop::Params { messages_relay::message_lane_loop::Params {
lane: lane_id, lane: lane_id,
@@ -129,10 +140,8 @@ pub fn run(
delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams { delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams {
max_unrewarded_relayer_entries_at_target: bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE, max_unrewarded_relayer_entries_at_target: bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
max_unconfirmed_nonces_at_target: bp_millau::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE, max_unconfirmed_nonces_at_target: bp_millau::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
max_messages_in_single_batch: bp_millau::MAX_MESSAGES_IN_DELIVERY_TRANSACTION, max_messages_in_single_batch,
// TODO: subtract base weight of delivery from this when it'll be known max_messages_weight_in_single_batch,
// https://github.com/paritytech/parity-bridges-common/issues/78
max_messages_weight_in_single_batch: bp_millau::max_extrinsic_weight(),
// 2/3 is reserved for proofs and tx overhead // 2/3 is reserved for proofs and tx overhead
max_messages_size_in_single_batch: bp_millau::max_extrinsic_size() as usize / 3, max_messages_size_in_single_batch: bp_millau::max_extrinsic_size() as usize / 3,
}, },