diff --git a/bridges/bin/millau/runtime/src/lib.rs b/bridges/bin/millau/runtime/src/lib.rs index fcf443e937..8dc9fea628 100644 --- a/bridges/bin/millau/runtime/src/lib.rs +++ b/bridges/bin/millau/runtime/src/lib.rs @@ -313,8 +313,6 @@ parameter_types! { bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE; pub const MaxUnconfirmedMessagesAtInboundLane: bp_message_lane::MessageNonce = 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 { @@ -322,7 +320,6 @@ impl pallet_message_lane::Config for Runtime { type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce; type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane; type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane; - type MaxMessagesInDeliveryTransaction = MaxMessagesInDeliveryTransaction; type OutboundPayload = crate::rialto_messages::ToRialtoMessagePayload; type OutboundMessageFee = Balance; diff --git a/bridges/bin/millau/runtime/src/rialto_messages.rs b/bridges/bin/millau/runtime/src/rialto_messages.rs index a2fba5faf2..b5e1cc0fdb 100644 --- a/bridges/bin/millau/runtime/src/rialto_messages.rs +++ b/bridges/bin/millau/runtime/src/rialto_messages.rs @@ -192,8 +192,8 @@ impl SourceHeaderChain for Rialto { fn verify_messages_proof( proof: Self::MessagesProof, - max_messages: MessageNonce, + messages_count: MessageNonce, ) -> Result>, Self::Error> { - messages::target::verify_messages_proof::(proof, max_messages) + messages::target::verify_messages_proof::(proof, messages_count) } } diff --git a/bridges/bin/rialto/runtime/src/lib.rs b/bridges/bin/rialto/runtime/src/lib.rs index 89d84f2e72..52cd0896e9 100644 --- a/bridges/bin/rialto/runtime/src/lib.rs +++ b/bridges/bin/rialto/runtime/src/lib.rs @@ -420,8 +420,6 @@ parameter_types! { bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE; pub const MaxUnconfirmedMessagesAtInboundLane: bp_message_lane::MessageNonce = 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; @@ -430,7 +428,6 @@ impl pallet_message_lane::Config for Runtime { type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce; type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane; type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane; - type MaxMessagesInDeliveryTransaction = MaxMessagesInDeliveryTransaction; type OutboundPayload = crate::millau_messages::ToMillauMessagePayload; type OutboundMessageFee = Balance; diff --git a/bridges/bin/rialto/runtime/src/millau_messages.rs b/bridges/bin/rialto/runtime/src/millau_messages.rs index e1395d99b1..6fead2b451 100644 --- a/bridges/bin/rialto/runtime/src/millau_messages.rs +++ b/bridges/bin/rialto/runtime/src/millau_messages.rs @@ -192,8 +192,8 @@ impl SourceHeaderChain for Millau { fn verify_messages_proof( proof: Self::MessagesProof, - max_messages: MessageNonce, + messages_count: MessageNonce, ) -> Result>, Self::Error> { - messages::target::verify_messages_proof::(proof, max_messages) + messages::target::verify_messages_proof::(proof, messages_count) } } diff --git a/bridges/bin/runtime-common/src/messages.rs b/bridges/bin/runtime-common/src/messages.rs index 029707a017..6715295dd6 100644 --- a/bridges/bin/runtime-common/src/messages.rs +++ b/bridges/bin/runtime-common/src/messages.rs @@ -399,7 +399,7 @@ pub mod target { /// Verify proof of Bridged -> This chain messages. pub fn verify_messages_proof( proof: FromBridgedChainMessagesProof, - max_messages: MessageNonce, + messages_count: MessageNonce, ) -> Result>>>, &'static str> where ThisRuntime: pallet_substrate_bridge::Config, @@ -409,7 +409,7 @@ pub mod target { { verify_messages_proof_with_parser::( proof, - max_messages, + messages_count, |bridged_header_hash, bridged_storage_proof| { pallet_substrate_bridge::Module::::parse_finalized_storage_proof( bridged_header_hash.into(), @@ -429,7 +429,7 @@ pub mod target { #[derive(Debug, PartialEq)] pub(crate) enum MessageProofError { Empty, - TooManyMessages, + MessagesCountMismatch, MissingRequiredMessage, FailedToDecodeMessage, FailedToDecodeOutboundLaneState, @@ -440,7 +440,7 @@ pub mod target { fn from(err: MessageProofError) -> &'static str { match err { 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::FailedToDecodeMessage => "Failed to decode message from the proof", MessageProofError::FailedToDecodeOutboundLaneState => { @@ -488,7 +488,7 @@ pub mod target { /// Verify proof of Bridged -> This chain messages using given message proof parser. pub(crate) fn verify_messages_proof_with_parser( proof: FromBridgedChainMessagesProof, - max_messages: MessageNonce, + messages_count: MessageNonce, build_parser: BuildParser, ) -> Result>>>, MessageProofError> where @@ -500,8 +500,8 @@ pub mod target { // receiving proofs where end < begin is ok (if proof includes outbound lane state) // => hence 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 { - return Err(MessageProofError::TooManyMessages); + if messages_in_the_proof != messages_count { + return Err(MessageProofError::MessagesCountMismatch); } let parser = build_parser(bridged_header_hash, bridged_storage_proof)?; @@ -1009,14 +1009,26 @@ mod tests { } #[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!( target::verify_messages_proof_with_parser::( - (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 11), - 10, + (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 10), + 5, |_, _| 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::( + (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 10), + 15, + |_, _| unreachable!(), + ), + Err(target::MessageProofError::MessagesCountMismatch), ); } @@ -1069,7 +1081,7 @@ mod tests { assert_eq!( target::verify_messages_proof_with_parser::( (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 0), - 10, + 0, |_, _| Ok(TestMessageProofParser { failing: true, messages: no_messages_range(), @@ -1089,7 +1101,7 @@ mod tests { assert_eq!( target::verify_messages_proof_with_parser::( (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 0), - 10, + 0, |_, _| Ok(TestMessageProofParser { failing: false, messages: no_messages_range(), @@ -1105,7 +1117,7 @@ mod tests { assert_eq!( target::verify_messages_proof_with_parser::( (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 0), - 10, + 0, |_, _| Ok(TestMessageProofParser { failing: false, messages: no_messages_range(), @@ -1137,7 +1149,7 @@ mod tests { assert_eq!( target::verify_messages_proof_with_parser::( (Default::default(), StorageProof::new(vec![]), Default::default(), 1, 1), - 10, + 1, |_, _| Ok(TestMessageProofParser { failing: false, messages: 1..=1, diff --git a/bridges/modules/message-lane/src/benchmarking.rs b/bridges/modules/message-lane/src/benchmarking.rs index 67b69345ee..e0d20a6558 100644 --- a/bridges/modules/message-lane/src/benchmarking.rs +++ b/bridges/modules/message-lane/src/benchmarking.rs @@ -25,7 +25,7 @@ use frame_benchmarking::{account, benchmarks_instance}; use frame_support::{traits::Get, weights::Weight}; use frame_system::RawOrigin; 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. pub const WORST_MESSAGE_SIZE_FACTOR: u32 = 1000; @@ -127,7 +127,7 @@ benchmarks_instance! { message_nonces: 1..=1, 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 { assert_eq!( crate::Module::::inbound_latest_received_nonce(bench_lane_id()), @@ -154,7 +154,7 @@ benchmarks_instance! { message_nonces: 1..=2, 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 { assert_eq!( crate::Module::::inbound_latest_received_nonce(bench_lane_id()), @@ -188,7 +188,7 @@ benchmarks_instance! { 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 { assert_eq!( crate::Module::::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 // to verify that the other approximation is correct. receive_multiple_messages_proof { - let i in 1..T::MaxMessagesInDeliveryTransaction::get() - .try_into() - .expect("Value of MaxMessagesInDeliveryTransaction is too large"); + let i in 1..128; let relayer_id_on_source = T::bridged_relayer_id(); let relayer_id_on_target = account("relayer", 0, SEED); + let messages_count = i as _; let (proof, dispatch_weight) = T::prepare_message_proof(MessageProofParams { lane: bench_lane_id(), message_nonces: 1..=i as _, 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 { assert_eq!( crate::Module::::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)`. // So it may be used to verify that the other approximation is correct. receive_multiple_messages_proof_with_outbound_lane_state { - let i in 1..T::MaxMessagesInDeliveryTransaction::get() - .try_into() - .expect("Value of MaxMessagesInDeliveryTransaction is too large"); + let i in 1..128; let relayer_id_on_source = T::bridged_relayer_id(); let relayer_id_on_target = account("relayer", 0, SEED); + let messages_count = i as _; // mark messages 1..=20 as delivered receive_messages::(20); @@ -263,7 +267,13 @@ benchmarks_instance! { 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 { assert_eq!( crate::Module::::inbound_latest_received_nonce(bench_lane_id()), diff --git a/bridges/modules/message-lane/src/lib.rs b/bridges/modules/message-lane/src/lib.rs index 60cd2ce584..2b6dcb6bda 100644 --- a/bridges/modules/message-lane/src/lib.rs +++ b/bridges/modules/message-lane/src/lib.rs @@ -93,11 +93,6 @@ pub trait Config: frame_system::Config { /// This constant limits difference between last message from last entry of the /// `InboundLaneData::relayers` and first message at the first entry. type MaxUnconfirmedMessagesAtInboundLane: Get; - /// 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; /// Payload type of outbound messages. This payload is dispatched on the bridged chain. type OutboundPayload: Parameter; @@ -322,17 +317,16 @@ decl_module! { } /// Receive messages proof from bridged chain. - #[weight = DELIVERY_OVERHEAD_WEIGHT - .saturating_add( - T::MaxMessagesInDeliveryTransaction::get() - .saturating_mul(SINGLE_MESSAGE_DELIVERY_WEIGHT) - ) + #[weight = messages_count + .saturating_mul(SINGLE_MESSAGE_DELIVERY_WEIGHT) + .saturating_add(DELIVERY_OVERHEAD_WEIGHT) .saturating_add(*dispatch_weight) ] pub fn receive_messages_proof( origin, relayer_id: T::InboundRelayer, proof: MessagesProofOf, + messages_count: MessageNonce, dispatch_weight: Weight, ) -> DispatchResult { ensure_operational::()?; @@ -343,7 +337,7 @@ decl_module! { T::SourceHeaderChain, T::InboundMessageFee, T::InboundPayload, - >(proof, T::MaxMessagesInDeliveryTransaction::get()) + >(proof, messages_count) .map_err(|err| { frame_support::debug::trace!( "Rejecting invalid messages proof: {:?}", @@ -674,9 +668,9 @@ impl, I: Instance> OutboundLaneStorage for RuntimeOutboundLaneStora /// Verify messages proof and return proved messages with decoded payload. fn verify_and_decode_messages_proof, Fee, DispatchPayload: Decode>( proof: Chain::MessagesProof, - max_messages: MessageNonce, + messages_count: MessageNonce, ) -> Result>, 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 .into_iter() .map(|(lane, lane_data)| { @@ -846,6 +840,7 @@ mod tests { Origin::signed(1), TEST_RELAYER_A, Ok(vec![message(2, REGULAR_PAYLOAD)]).into(), + 1, REGULAR_PAYLOAD.1, ), Error::::Halted, @@ -924,6 +919,7 @@ mod tests { Origin::signed(1), TEST_RELAYER_A, Ok(vec![message(1, REGULAR_PAYLOAD)]).into(), + 1, REGULAR_PAYLOAD.1, )); @@ -964,6 +960,7 @@ mod tests { Origin::signed(1), TEST_RELAYER_A, message_proof, + 1, REGULAR_PAYLOAD.1, )); @@ -995,6 +992,7 @@ mod tests { Origin::signed(1), TEST_RELAYER_A, Ok(vec![message(1, REGULAR_PAYLOAD)]).into(), + 1, REGULAR_PAYLOAD.1 - 1, ), Error::::InvalidMessagesDispatchWeight, @@ -1010,6 +1008,7 @@ mod tests { Origin::signed(1), TEST_RELAYER_A, Err(()).into(), + 1, 0, ), Error::::InvalidMessagesProof, @@ -1112,6 +1111,7 @@ mod tests { Origin::signed(1), TEST_RELAYER_A, Ok(vec![invalid_message]).into(), + 1, 0, // weight may be zero in this case (all messages are improperly encoded) ),); @@ -1134,6 +1134,7 @@ mod tests { message(3, REGULAR_PAYLOAD), ]) .into(), + 3, REGULAR_PAYLOAD.1 + REGULAR_PAYLOAD.1, ),); diff --git a/bridges/modules/message-lane/src/mock.rs b/bridges/modules/message-lane/src/mock.rs index 2c3418b98f..8250b955be 100644 --- a/bridges/modules/message-lane/src/mock.rs +++ b/bridges/modules/message-lane/src/mock.rs @@ -97,7 +97,6 @@ parameter_types! { pub const MaxMessagesToPruneAtOnce: u64 = 10; pub const MaxUnrewardedRelayerEntriesAtInboundLane: u64 = 16; pub const MaxUnconfirmedMessagesAtInboundLane: u64 = 32; - pub const MaxMessagesInDeliveryTransaction: u64 = 128; } impl Config for TestRuntime { @@ -105,7 +104,6 @@ impl Config for TestRuntime { type MaxMessagesToPruneAtOnce = MaxMessagesToPruneAtOnce; type MaxUnrewardedRelayerEntriesAtInboundLane = MaxUnrewardedRelayerEntriesAtInboundLane; type MaxUnconfirmedMessagesAtInboundLane = MaxUnconfirmedMessagesAtInboundLane; - type MaxMessagesInDeliveryTransaction = MaxMessagesInDeliveryTransaction; type OutboundPayload = TestPayload; type OutboundMessageFee = TestMessageFee; @@ -279,7 +277,7 @@ impl SourceHeaderChain for TestSourceHeaderChain { fn verify_messages_proof( proof: Self::MessagesProof, - _max_messages: MessageNonce, + _messages_count: MessageNonce, ) -> Result>, Self::Error> { proof .result diff --git a/bridges/primitives/message-lane/src/target_chain.rs b/bridges/primitives/message-lane/src/target_chain.rs index 6e64c423d1..04eab55aff 100644 --- a/bridges/primitives/message-lane/src/target_chain.rs +++ b/bridges/primitives/message-lane/src/target_chain.rs @@ -68,13 +68,13 @@ pub trait SourceHeaderChain { /// Verify messages proof and return proved messages. /// /// 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 will be rejected. fn verify_messages_proof( proof: Self::MessagesProof, - max_messages: MessageNonce, + messages_count: MessageNonce, ) -> Result>, Self::Error>; } diff --git a/bridges/primitives/millau/src/lib.rs b/bridges/primitives/millau/src/lib.rs index 8642b04cf0..c9e90501ff 100644 --- a/bridges/primitives/millau/src/lib.rs +++ b/bridges/primitives/millau/src/lib.rs @@ -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. 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. pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 1024; diff --git a/bridges/primitives/rialto/src/lib.rs b/bridges/primitives/rialto/src/lib.rs index 71f0329afc..fffa556f72 100644 --- a/bridges/primitives/rialto/src/lib.rs +++ b/bridges/primitives/rialto/src/lib.rs @@ -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. 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. pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 128; diff --git a/bridges/relays/substrate/src/millau_messages_to_rialto.rs b/bridges/relays/substrate/src/millau_messages_to_rialto.rs index 268a20beb7..ebbb6a2bd5 100644 --- a/bridges/relays/substrate/src/millau_messages_to_rialto.rs +++ b/bridges/relays/substrate/src/millau_messages_to_rialto.rs @@ -73,11 +73,14 @@ impl SubstrateMessageLane for MillauMessagesToRialto { proof: ::MessagesProof, ) -> Result { 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 nonce = self.target_client.next_account_index(account_id).await?; let call = rialto_runtime::MessageLaneCall::receive_messages_proof( self.relayer_id_at_source.clone(), proof, + messages_count, dispatch_weight, ) .into(); @@ -119,6 +122,14 @@ pub fn run( 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::Params { lane: lane_id, @@ -129,10 +140,8 @@ pub fn run( delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams { 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_messages_in_single_batch: bp_rialto::MAX_MESSAGES_IN_DELIVERY_TRANSACTION, - // TODO: subtract base weight of delivery from this when it'll be known - // https://github.com/paritytech/parity-bridges-common/issues/78 - max_messages_weight_in_single_batch: bp_rialto::max_extrinsic_weight(), + max_messages_in_single_batch, + max_messages_weight_in_single_batch, // 2/3 is reserved for proofs and tx overhead max_messages_size_in_single_batch: bp_rialto::max_extrinsic_size() as usize / 3, }, diff --git a/bridges/relays/substrate/src/rialto_messages_to_millau.rs b/bridges/relays/substrate/src/rialto_messages_to_millau.rs index 0615810612..0e059f7cfd 100644 --- a/bridges/relays/substrate/src/rialto_messages_to_millau.rs +++ b/bridges/relays/substrate/src/rialto_messages_to_millau.rs @@ -73,11 +73,14 @@ impl SubstrateMessageLane for RialtoMessagesToMillau { proof: ::MessagesProof, ) -> Result { 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 nonce = self.target_client.next_account_index(account_id).await?; let call = millau_runtime::MessageLaneCall::receive_messages_proof( self.relayer_id_at_source.clone(), proof, + messages_count, dispatch_weight, ) .into(); @@ -119,6 +122,14 @@ pub fn run( 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::Params { lane: lane_id, @@ -129,10 +140,8 @@ pub fn run( delivery_params: messages_relay::message_lane_loop::MessageDeliveryParams { 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_messages_in_single_batch: bp_millau::MAX_MESSAGES_IN_DELIVERY_TRANSACTION, - // TODO: subtract base weight of delivery from this when it'll be known - // https://github.com/paritytech/parity-bridges-common/issues/78 - max_messages_weight_in_single_batch: bp_millau::max_extrinsic_weight(), + max_messages_in_single_batch, + max_messages_weight_in_single_batch, // 2/3 is reserved for proofs and tx overhead max_messages_size_in_single_batch: bp_millau::max_extrinsic_size() as usize / 3, },