fix(xcm): use Outcome::Incomplete for barrier rejection and improve weight accounting#11302
fix(xcm): use Outcome::Incomplete for barrier rejection and improve weight accounting#11302Kanasjnr wants to merge 8 commits intoparitytech:masterfrom
Conversation
|
/cmd label T6-XCM D2-substantial I5-enhancement |
|
/cmd prdoc --audience runtime_dev --bump patch |
|
@bkontur @franciscoaguirre @raymondkfcheung |
|
Do you check the original PR #9808? |
No I didn't it was closed so I didn't bother to check and moreover it was not referenced in the issue description |
franciscoaguirre
left a comment
There was a problem hiding this comment.
I would definitely test this out on one of the westend runtimes
| @@ -26,19 +26,58 @@ use polkadot_parachain_primitives::primitives::IsSystem; | |||
| use xcm::prelude::*; | |||
| use xcm_executor::traits::{CheckSuspension, DenyExecution, OnResponse, Properties, ShouldExecute}; | |||
|
|
|||
| /// Benchmark weights for this pallet. | |||
| @@ -26,19 +26,58 @@ use polkadot_parachain_primitives::primitives::IsSystem; | |||
| use xcm::prelude::*; | |||
| use xcm_executor::traits::{CheckSuspension, DenyExecution, OnResponse, Properties, ShouldExecute}; | |||
|
|
|||
| /// Benchmark weights for this pallet. | |||
| pub trait WeightInfo { | |||
There was a problem hiding this comment.
We shouldn't require runtimes to implement this for each one of these barriers when they might not even use all of them or they might use their own custom one.
It might be better to have a trait with just one function weight() -> Weight.
|
@franciscoaguirre updated!! kindly review |
franciscoaguirre
left a comment
There was a problem hiding this comment.
Please benchmark these for the westend runtimes to see how it would look like. Right now this change is just floating there
|
|
||
| pub use chain::{ | ||
| AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, Chain, EncodedOrDecodedCall, HashOf, | ||
| __private, AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, Chain, EncodedOrDecodedCall, HashOf, |
There was a problem hiding this comment.
This doesn't look right...
There was a problem hiding this comment.
i was trying to fix fmt ci earlier i reverted it already tho will push the fix soon as soon as i'm done addressing the feedbacks
| #[cfg(feature = "runtime-benchmarks")] | ||
| assert_eq!(r, Outcome::Complete { used: weight }); | ||
|
|
||
| #[cfg(feature = "runtime-benchmarks")] | ||
| mock::clear_sent_xcm(); |
There was a problem hiding this comment.
Seems pretty fragile to do conditional compilation on a line-by-line basis here. Is there something you could do to avoid that?
There was a problem hiding this comment.
Hmm.. true .i will refector this by introducing a helper function assert_teleport_outcome that encapsulates the conditional logic. This will keep the test cases clean and uniform across different configurations.
| if origin == &(Location { parents: 1, interior: Here }) { | ||
| return Ok(()); | ||
| } |
There was a problem hiding this comment.
This change seems unrelated to the rest of the PR. What is it for?
This barrier is not even needed anymore, we now do this check directly on the xcm-executor
|
@franciscoaguirre I've addressed the feedback from the previous review and verified the changes with benchmarks and full test runs |
franciscoaguirre
left a comment
There was a problem hiding this comment.
The approach in #9808 was to have each runtime benchmark only once for their Barrier tuple in the worst case that the barrier does a lot of work before failing.
The approach taken in this PR is to benchmark each barrier individually. While this is more accurate, it requires every runtime to benchmark each of these barriers. We might be able to provide static weights for some barriers but it's still a lot of complexity for runtime developers.
I would go for something like #9808. What do you think?
I've looked at the #9808 approach, but I'm worried it's a bit too blunt for long-term XCM weight accounting. A single "worst-case" fee for the entire barrier tuple feels like it’ll either over charge for simple rejections or under charge if the worst case scenario isn't perfectly caught across all runtimes. Benchmarking barriers individually is more precise and fits naturally with how the executor actually processes instructions step-by-step. It also keeps everything transparent if a particular barrier is heavy, it shows up in the weights rather than being buried in an aggregate. Maybe a better compromise would be to provide static or default weights for the really common or trivial barriers? That would keep the integration simple for most developers without losing the accuracy for more complex setups. What do you think about that trade off? I can pivot if you still prefer the #9808, but I believe the granular approach is more robust for the long run. |
|
@franciscoaguirre Still awaiting your feedback |
|
@franciscoaguirre i'm still awaiting feedback on this thanks |
Description
This PR improves XCM weight accounting by ensuring the executor reports precise used weight when a message is rejected by a barrier. Previously, the executor could overestimate weight (e.g., returning the full message weight) even if execution failed at the barrier stage.
The changes align with the goal of more accurate weight reporting started in PR #7843 and ensure that
Outcome::Incompleteis used with the specific weight consumed by the barrier itself.Closes #7965
Integration
Downstream projects using
staging-xcm-builderbarriers may need to update their configurations if they wish to provide precise benchmarked weights for barrier checks:xcm-builder.XcmConfigdefinitions will continue to compile without changes.ShouldExecutetrait signature was updated to returnResult<Weight, (Weight, ProcessMessageError)>to allow returning consumed weight on error.Review Notes
Implementation Details
xcm-builder::barriers.XcmExecutor::executeto handle Err((weight, error)) from the barrier, returningOutcome::Incomplete { used: weight, error: InstructionError { index: 0, error: XcmError::Barrier } }.Location { parents: 1, interior: Here }), which allows the Relay Chain to transfer reserve assets to itself as expected by the tests.xcm-builderand 40 unit tests inxcm-executorpass.Checklist
Trequired)Bot Commands
You can use the following bot commands in comments to help manage your PR:
Labeling (Self-service for contributors):
/cmd label T1-FRAME- Add a single label/cmd label T1-FRAME R0-no-crate-publish-required- Add multiple labels/cmd label T6-XCM D2-substantial I5-enhancement- Add multiple labels at onceOther useful commands:
/cmd fmt- Format code (cargo +nightly fmt and taplo)/cmd prdoc- Generate PR documentation/cmd bench- Run benchmarks/cmd update-ui- Update UI tests/cmd --help- Show help for all available commands