From 9e92564c69da4234ac5a6cdf2ba7fe45e698043f Mon Sep 17 00:00:00 2001
From: Svyatoslav Nikolsky <svyatonik@gmail.com>
Date: Fri, 2 Dec 2022 12:57:41 +0300
Subject: [PATCH] refund_pay_dispatch_fee removed (#1695)

---
 bridges/bin/millau/runtime/src/xcm_config.rs  |  1 -
 .../bin/rialto-parachain/runtime/src/lib.rs   |  1 -
 bridges/bin/rialto/runtime/src/xcm_config.rs  |  1 -
 bridges/bin/runtime-common/src/messages.rs    |  6 +--
 bridges/modules/messages/src/benchmarking.rs  | 33 -------------
 bridges/modules/messages/src/lib.rs           | 46 +++++--------------
 bridges/modules/messages/src/mock.rs          |  1 -
 bridges/modules/messages/src/weights.rs       | 11 -----
 bridges/modules/messages/src/weights_ext.rs   |  9 ----
 .../primitives/messages/src/target_chain.rs   |  6 +--
 bridges/primitives/runtime/src/messages.rs    |  4 --
 11 files changed, 14 insertions(+), 105 deletions(-)

diff --git a/bridges/bin/millau/runtime/src/xcm_config.rs b/bridges/bin/millau/runtime/src/xcm_config.rs
index a3a59e626e5..b5e238d28b3 100644
--- a/bridges/bin/millau/runtime/src/xcm_config.rs
+++ b/bridges/bin/millau/runtime/src/xcm_config.rs
@@ -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: (),
 				}
 			);
diff --git a/bridges/bin/rialto-parachain/runtime/src/lib.rs b/bridges/bin/rialto-parachain/runtime/src/lib.rs
index 2d0be49a07f..0fe03883e0f 100644
--- a/bridges/bin/rialto-parachain/runtime/src/lib.rs
+++ b/bridges/bin/rialto-parachain/runtime/src/lib.rs
@@ -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: (),
 				}
 			);
diff --git a/bridges/bin/rialto/runtime/src/xcm_config.rs b/bridges/bin/rialto/runtime/src/xcm_config.rs
index 419a5548930..feab0f35c79 100644
--- a/bridges/bin/rialto/runtime/src/xcm_config.rs
+++ b/bridges/bin/rialto/runtime/src/xcm_config.rs
@@ -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: (),
 				}
 			);
diff --git a/bridges/bin/runtime-common/src/messages.rs b/bridges/bin/runtime-common/src/messages.rs
index 23c79b1c583..3530e683140 100644
--- a/bridges/bin/runtime-common/src/messages.rs
+++ b/bridges/bin/runtime-common/src/messages.rs
@@ -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: () }
 		}
 	}
 
diff --git a/bridges/modules/messages/src/benchmarking.rs b/bridges/modules/messages/src/benchmarking.rs
index b8360facacb..36018474a8f 100644
--- a/bridges/modules/messages/src/benchmarking.rs
+++ b/bridges/modules/messages/src/benchmarking.rs
@@ -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).
diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs
index 0df6c686cc6..d19b17e0ddf 100644
--- a/bridges/modules/messages/src/lib.rs
+++ b/bridges/modules/messages/src/lib.rs
@@ -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);
 		});
 	}
 
diff --git a/bridges/modules/messages/src/mock.rs b/bridges/modules/messages/src/mock.rs
index da2d1c6a4da..59f72602c84 100644
--- a/bridges/modules/messages/src/mock.rs
+++ b/bridges/modules/messages/src/mock.rs
@@ -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: (),
 	}
 }
diff --git a/bridges/modules/messages/src/weights.rs b/bridges/modules/messages/src/weights.rs
index 2ae60c17faf..834e0d1f3d6 100644
--- a/bridges/modules/messages/src/weights.rs
+++ b/bridges/modules/messages/src/weights.rs
@@ -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))
diff --git a/bridges/modules/messages/src/weights_ext.rs b/bridges/modules/messages/src/weights_ext.rs
index 1604832c079..e597ed84cdd 100644
--- a/bridges/modules/messages/src/weights_ext.rs
+++ b/bridges/modules/messages/src/weights_ext.rs
@@ -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 () {
diff --git a/bridges/primitives/messages/src/target_chain.rs b/bridges/primitives/messages/src/target_chain.rs
index 9c6b60e1e15..1a3daad4043 100644
--- a/bridges/primitives/messages/src/target_chain.rs
+++ b/bridges/primitives/messages/src/target_chain.rs
@@ -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: () }
 	}
 }
diff --git a/bridges/primitives/runtime/src/messages.rs b/bridges/primitives/runtime/src/messages.rs
index 0bb09090df9..9f7c8ab5ca4 100644
--- a/bridges/primitives/runtime/src/messages.rs
+++ b/bridges/primitives/runtime/src/messages.rs
@@ -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,
 }
-- 
GitLab