-
Notifications
You must be signed in to change notification settings - Fork 803
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FRAME] MQ processor should be transactional #5198
Changes from 11 commits
fdaf250
f2bffb7
825c8e9
970253f
ca4ae3d
e846db5
74f82f7
cabe8d6
c692298
8b21cca
53a579e
d8201b1
851c534
f60ac77
c9e259e
8589b76
dee7b95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||||||||
title: "MQ processor should be transactional" | ||||||||||||
|
||||||||||||
doc: | ||||||||||||
- audience: Runtime User | ||||||||||||
description: | | ||||||||||||
Enforce transactional processing on pallet Message Queue Processor | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
crates: | ||||||||||||
- name: pallet-message-queue | ||||||||||||
bump: patch | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Its a logical breaking change, better safe than sorry for these things. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,7 +225,7 @@ use sp_arithmetic::traits::{BaseArithmetic, Unsigned}; | |
use sp_core::{defer, H256}; | ||
use sp_runtime::{ | ||
traits::{One, Zero}, | ||
SaturatedConversion, Saturating, | ||
SaturatedConversion, Saturating, TransactionOutcome, | ||
}; | ||
use sp_weights::WeightMeter; | ||
pub use weights::WeightInfo; | ||
|
@@ -1447,7 +1447,22 @@ impl<T: Config> Pallet<T> { | |
use ProcessMessageError::*; | ||
let prev_consumed = meter.consumed(); | ||
|
||
match T::MessageProcessor::process_message(message, origin.clone(), meter, &mut id) { | ||
let transaction = | ||
storage::with_transaction(|| -> TransactionOutcome<Result<_, DispatchError>> { | ||
let res = | ||
T::MessageProcessor::process_message(message, origin.clone(), meter, &mut id); | ||
match &res { | ||
Ok(_) => TransactionOutcome::Commit(Ok(res)), | ||
Err(_) => TransactionOutcome::Rollback(Ok(res)), | ||
} | ||
}); | ||
|
||
let transaction = match transaction { | ||
Ok(result) => result, | ||
_ => unreachable!(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With current I know, highly unlikely, but still I would prefer to:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea it should be defensive and then just return an error or so. Having panics in the runtime is never good. |
||
}; | ||
|
||
match transaction { | ||
Err(Overweight(w)) if w.any_gt(overweight_limit) => { | ||
// Permanently overweight. | ||
Self::deposit_event(Event::<T>::OverweightEnqueued { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,6 +164,7 @@ impl ProcessMessage for RecordingMessageProcessor { | |
meter: &mut WeightMeter, | ||
_id: &mut [u8; 32], | ||
) -> Result<bool, ProcessMessageError> { | ||
sp_io::storage::set(b"transactional_storage", &vec![1, 2, 3]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mocked process supports callbacks - no need to hard code it here. Check out the tests that use it: Callback::set(Box::new(|_, _| {
// whatever youwant
})); |
||
processing_message(message, &origin)?; | ||
|
||
let weight = if message.starts_with(&b"weight="[..]) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.