Skip to content

Conversation

@serban300
Copy link
Contributor

@serban300 serban300 commented Jan 8, 2026

Resolves #8675

The PR introduces a global variable that limits the amount of heap memory available for decoding structures within nested contexts.

@serban300 serban300 self-assigned this Jan 8, 2026
@serban300 serban300 requested review from a team as code owners January 8, 2026 08:30
@serban300 serban300 added the T6-XCM This PR/Issue is related to XCM. label Jan 8, 2026
@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 8, 2026 08:30
@serban300 serban300 force-pushed the limit-memory-for-nested-extrinsics branch 2 times, most recently from 2bf2683 to 351c175 Compare January 8, 2026 09:20
@serban300 serban300 force-pushed the limit-memory-for-nested-extrinsics branch 2 times, most recently from b4ba120 to 59bccbe Compare January 19, 2026 07:02
@serban300 serban300 force-pushed the limit-memory-for-nested-extrinsics branch from 59bccbe to ea4fbeb Compare January 29, 2026 11:46
@serban300 serban300 changed the title [WIP] Track nested memory used by xcm::DoubleEncoded Track nested memory used by xcm::DoubleEncoded Jan 29, 2026
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

I find the current approach hard to follow and it also doesn't forward the left over limit from decoding the extrinsic.

E.g. when executing pallet_xcm::execute it should only leave the rest from the budget for Transact and not give it the full budget again. Also the budgeting right now maybe shares too much. E.g. when I want to load two XCM messages from the storage, they will both use the same limit. This is probably not wanted. We should provide some better "tools" around the bounded limit.

struct DecodeWithLimit {
       limit: usize,
       decoded: T,
}

impl Decode using DecodeWithLimitThingy {}

fn DecodeWithLimit {
     pub use(use: Impl(&mut T) -> R) -> R {
              mem::run_with(self.limit, || use(&mut self.decoded))
     }
}

Maybe something like this? Then we could use this to load XCM messages from storage?

//!
//! There are also cases where there can be multiple nested double-encoded layers.

use crate::generic::DEFAULT_CALL_SIZE_LIMIT;
Copy link
Member

Choose a reason for hiding this comment

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

If we want that to be generic, we should pass the limit as an input value and not use this constant.

"Dispatch failed"
);
Transact { origin_kind, call, .. } => {
sp_runtime::nested_mem::using_limiter_once(|| {
Copy link
Member

Choose a reason for hiding this comment

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

The problem here is that we will run here without knowing how much the outer extrinsic already used for decoding.

signature_check,
select,
);
nested_mem::using_limiter_once(|| {
Copy link
Member

Choose a reason for hiding this comment

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

The scope is way too broad here. We only need this for extrinsic applying.

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.

[DecodeWithMemTracking] Research keeping track of all the nested double encoded structs

2 participants