mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
Relay basic single-bit message dispatch results back to the source chain (#935)
* relay dispatch result flags back to the source chain * OnMessagesDelivered callback * add lane id to OnDeliveredMessages callback * fix benchmarks && upate weights * clippy * clippy * clipy another try * OnMessagesDelivered -> OnDeliveryConfirmed * Update primitives/messages/src/source_chain.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
committed by
Bastian Köcher
parent
87c48f649b
commit
ee43a560f8
@@ -154,6 +154,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::AccountId, T::MessageId> for
|
||||
);
|
||||
Self::deposit_event(RawEvent::MessageRejected(source_chain, id));
|
||||
return MessageDispatchResult {
|
||||
dispatch_result: false,
|
||||
unspent_weight: 0,
|
||||
dispatch_fee_paid_during_dispatch: false,
|
||||
};
|
||||
@@ -163,6 +164,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::AccountId, T::MessageId> for
|
||||
// verify spec version
|
||||
// (we want it to be the same, because otherwise we may decode Call improperly)
|
||||
let mut dispatch_result = MessageDispatchResult {
|
||||
dispatch_result: false,
|
||||
unspent_weight: message.weight,
|
||||
dispatch_fee_paid_during_dispatch: false,
|
||||
};
|
||||
@@ -303,6 +305,7 @@ impl<T: Config<I>, I: Instance> MessageDispatch<T::AccountId, T::MessageId> for
|
||||
log::trace!(target: "runtime::bridge-dispatch", "Message being dispatched is: {:.4096?}", &call);
|
||||
let result = call.dispatch(origin);
|
||||
let actual_call_weight = extract_actual_weight(&result, &dispatch_info);
|
||||
dispatch_result.dispatch_result = result.is_ok();
|
||||
dispatch_result.unspent_weight = message.weight.saturating_sub(actual_call_weight);
|
||||
|
||||
log::trace!(
|
||||
@@ -573,6 +576,7 @@ mod tests {
|
||||
System::set_block_number(1);
|
||||
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| unreachable!());
|
||||
assert_eq!(result.unspent_weight, weight);
|
||||
assert!(!result.dispatch_result);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -601,6 +605,7 @@ mod tests {
|
||||
System::set_block_number(1);
|
||||
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| unreachable!());
|
||||
assert_eq!(result.unspent_weight, 7);
|
||||
assert!(!result.dispatch_result);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -633,6 +638,7 @@ mod tests {
|
||||
System::set_block_number(1);
|
||||
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| unreachable!());
|
||||
assert_eq!(result.unspent_weight, weight);
|
||||
assert!(!result.dispatch_result);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -683,6 +689,7 @@ mod tests {
|
||||
System::set_block_number(1);
|
||||
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| unreachable!());
|
||||
assert_eq!(result.unspent_weight, weight);
|
||||
assert!(!result.dispatch_result);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -711,6 +718,7 @@ mod tests {
|
||||
System::set_block_number(1);
|
||||
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| unreachable!());
|
||||
assert_eq!(result.unspent_weight, weight);
|
||||
assert!(!result.dispatch_result);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -739,12 +747,13 @@ mod tests {
|
||||
System::set_block_number(1);
|
||||
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| Err(()));
|
||||
assert_eq!(result.unspent_weight, weight);
|
||||
assert!(!result.dispatch_result);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
vec![EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::call_dispatch(call_dispatch::Event::<TestRuntime>::MessageDispatchPaymentFailed(
|
||||
event: Event::Dispatch(call_dispatch::Event::<TestRuntime>::MessageDispatchPaymentFailed(
|
||||
SOURCE_CHAIN_ID,
|
||||
id,
|
||||
AccountIdConverter::convert(derive_account_id::<AccountId>(
|
||||
@@ -771,12 +780,13 @@ mod tests {
|
||||
System::set_block_number(1);
|
||||
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| Ok(()));
|
||||
assert!(result.dispatch_fee_paid_during_dispatch);
|
||||
assert!(result.dispatch_result);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
vec![EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::call_dispatch(call_dispatch::Event::<TestRuntime>::MessageDispatched(
|
||||
event: Event::Dispatch(call_dispatch::Event::<TestRuntime>::MessageDispatched(
|
||||
SOURCE_CHAIN_ID,
|
||||
id,
|
||||
Ok(())
|
||||
@@ -787,6 +797,34 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_return_dispatch_failed_flag_if_dispatch_happened_but_failed() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let id = [0; 4];
|
||||
|
||||
let call = Call::System(<frame_system::Call<TestRuntime>>::set_heap_pages(1));
|
||||
let message = prepare_target_message(call);
|
||||
|
||||
System::set_block_number(1);
|
||||
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| unreachable!());
|
||||
assert!(!result.dispatch_fee_paid_during_dispatch);
|
||||
assert!(!result.dispatch_result);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
vec![EventRecord {
|
||||
phase: Phase::Initialization,
|
||||
event: Event::Dispatch(call_dispatch::Event::<TestRuntime>::MessageDispatched(
|
||||
SOURCE_CHAIN_ID,
|
||||
id,
|
||||
Err(sp_runtime::DispatchError::BadOrigin)
|
||||
)),
|
||||
topics: vec![],
|
||||
}],
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_dispatch_bridge_message_from_root_origin() {
|
||||
new_test_ext().execute_with(|| {
|
||||
@@ -796,6 +834,7 @@ mod tests {
|
||||
System::set_block_number(1);
|
||||
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| unreachable!());
|
||||
assert!(!result.dispatch_fee_paid_during_dispatch);
|
||||
assert!(result.dispatch_result);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -823,6 +862,7 @@ mod tests {
|
||||
System::set_block_number(1);
|
||||
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| unreachable!());
|
||||
assert!(!result.dispatch_fee_paid_during_dispatch);
|
||||
assert!(result.dispatch_result);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
@@ -850,6 +890,7 @@ mod tests {
|
||||
System::set_block_number(1);
|
||||
let result = Dispatch::dispatch(SOURCE_CHAIN_ID, TARGET_CHAIN_ID, id, Ok(message), |_, _| unreachable!());
|
||||
assert!(!result.dispatch_fee_paid_during_dispatch);
|
||||
assert!(result.dispatch_result);
|
||||
|
||||
assert_eq!(
|
||||
System::events(),
|
||||
|
||||
Reference in New Issue
Block a user