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

xcm: fix for DenyThenTry Barrier #7169

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

yrong
Copy link
Contributor

@yrong yrong commented Jan 15, 2025

Resolves: #7148

This PR changes the behavior of DenyThenTry from the pattern DenyIfAllMatch to DenyIfAnyMatch for the tuple.

I would expect the latter is the right behavior so make the fix in place, but we can also add a dedicated Impl with the legacy one untouched if necessary.

@yrong yrong requested a review from a team as a code owner January 15, 2025 02:43
@yrong yrong changed the title Fix for DenyThenTry xcm: fix for DenyThenTry Barrier Jan 15, 2025
@yrong yrong marked this pull request as draft January 15, 2025 03:36
@@ -504,3 +506,36 @@ impl ShouldExecute for DenyReserveTransferToRelayChain {
Ok(())
}
}

// See https://github.com/paritytech/polkadot-sdk/pull/6838
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, add here the real description

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -504,3 +506,36 @@ impl ShouldExecute for DenyReserveTransferToRelayChain {
Ok(())
}
}

// See https://github.com/paritytech/polkadot-sdk/pull/6838
pub struct DenyFirstExportMessageFrom<FromOrigin, ToGlobalConsensus>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty specific barrier for BridgeHubs, so I would move it with tests to the bridge-hub-common

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_max_weight: Weight,
_properties: &mut Properties,
) -> Result<(), ProcessMessageError> {
message.matcher().match_next_inst_while(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that match_next_inst_while with ControlFlow::Continue checks all the instructions, so the name DenyFirstExportMessageFrom is not correct, so let's better use DenyExportMessage.

I am just thinking, that my initial advice DenyFirst was wrong, if there are multiple ExportMessage instructions, we should check them all for sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// Can be amalgamated into a tuple to have multiple trials. If any of the tuple elements returns
/// `Err(())`, the execution stops. Else, `Ok(_)` is returned if all elements accept the message.
pub trait ShouldNotExecute {
/// Returns `Ok(())` if the given `message` may be executed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this description is copied from ShouldExecute. Please revise it to something like: "Ok(()) means there is no reason not to execute, while Err(e) indicates there is a reason not to execute."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 143 to 148
fn should_not_execute<RuntimeCall>(
origin: &Location,
instructions: &mut [Instruction<RuntimeCall>],
max_weight: Weight,
properties: &mut Properties,
) -> Result<(), ProcessMessageError>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe fn should_not_execute<RuntimeCall>(..) -> Option<ProcessMessageError> would be a bit more readable. In this case, Option could represent: Some(reason) if there is a reason why it should not be executed, and None if there is no reason to deny execution.

Currently, when we ask Barrier::should_not_execute(message) and the answer is Ok(()), it’s unclear what Ok(()) means. Does it imply it’s okay not to execute, or that it’s okay to execute?

What about renaming trait ShouldNotExecute { fn should_not_execute() -> Result } to something like trait DenyExecution { fn deny_execution() -> Option<ProcessMessageError> }? This would make the intent more explicit?

Maybe it’s fine as it is now, but perhaps it’s just my language barrier or the challenge of double negations... I’d definitely appreciate other suggestions here! :D

Please, do not change anything, let's keep this renaming as a last open point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, I found similar comment in the very old PR: paritytech/cumulus#1169 (comment)

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed the naming and what is returned might be confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkontur
Copy link
Contributor

bkontur commented Jan 15, 2025

@yrong overall looks good so far, I was also thinking about another trait for that like this

@bkontur bkontur requested a review from x3c41a January 15, 2025 09:46
@yrong yrong marked this pull request as ready for review January 15, 2025 12:38
@franciscoaguirre franciscoaguirre added the T6-XCM This PR/Issue is related to XCM. label Jan 15, 2025
Comment on lines 143 to 148
fn should_not_execute<RuntimeCall>(
origin: &Location,
instructions: &mut [Instruction<RuntimeCall>],
max_weight: Weight,
properties: &mut Properties,
) -> Result<(), ProcessMessageError>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed the naming and what is returned might be confusing

prdoc/pr_7169.prdoc Outdated Show resolved Hide resolved
@yrong yrong requested a review from bkontur January 15, 2025 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T6-XCM This PR/Issue is related to XCM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[XCM] Investigate better support for filtering XCM programs with Barrier
3 participants