Skip to content
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] Make MQ pallet re-entrancy safe #2356

Merged
merged 26 commits into from
Dec 7, 2023
Merged

[FRAME] Make MQ pallet re-entrancy safe #2356

merged 26 commits into from
Dec 7, 2023

Conversation

ggwpez
Copy link
Member

@ggwpez ggwpez commented Nov 15, 2023

Closes #2319

Changes:

  • Ensure that only enqueue_message(s) is callable from within the message processor. This prevents messed up storage that can currently happen when the pallet is called into recursively.
  • Use H256 instead of [u8; 32] for clearer API.

Details

The re-entracy check is done with the environmental crate by adding a with_service_mutex(f) function that runs the closure exclusively. This works since the MQ pallet is not instantiable.

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
@ggwpez ggwpez added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Nov 15, 2023
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
@ggwpez ggwpez marked this pull request as ready for review November 16, 2023 19:12
@ggwpez ggwpez requested review from a team November 16, 2023 19:12
substrate/frame/message-queue/src/integration_test.rs Outdated Show resolved Hide resolved
substrate/frame/message-queue/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/message-queue/src/lib.rs Outdated Show resolved Hide resolved
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
@paritytech-review-bot paritytech-review-bot bot requested a review from a team November 17, 2023 21:43
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
@ggwpez ggwpez self-assigned this Dec 4, 2023
substrate/frame/message-queue/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/message-queue/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/message-queue/src/tests.rs Outdated Show resolved Hide resolved
@gavofyork gavofyork merged commit 7e7fe99 into master Dec 7, 2023
9 of 10 checks passed
@gavofyork gavofyork deleted the oty-fix-mq-pallet branch December 7, 2023 16:48
@xlc
Copy link
Contributor

xlc commented Dec 7, 2023

this is not the first time we had re-entrancy bug (e.g. paritytech/substrate#7605). I still don't know if we have an official best practice guide but if we do, it should have a section about re-entrancy and the pattern to workaround it. i.e. explain environmental and with_service_mutex

bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
Closes paritytech#2319

Changes:
- Ensure that only `enqueue_message(s)` is callable from within the
message processor. This prevents messed up storage that can currently
happen when the pallet is called into recursively.
- Use `H256` instead of `[u8; 32]` for clearer API.

## Details

The re-entracy check is done with the `environmental` crate by adding a
`with_service_mutex(f)` function that runs the closure exclusively. This
works since the MQ pallet is not instantiable.

---------

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Co-authored-by: Francisco Aguirre <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
Status: Audited
Development

Successfully merging this pull request may close these issues.

MessageQueue pallet does not process message
7 participants