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

Check executor params coherence #1774

Merged
merged 9 commits into from
Oct 13, 2023
Merged

Conversation

eagr
Copy link
Contributor

@eagr eagr commented Oct 3, 2023

closes #1704

Really appreciate the help and patience from @s0me0ne-unkn0wn 🙏
I left some unsolved questions in the FIXME comments, would you take a look?

kusama address: FvpsvV1GQAAbwqX6oyRjemgdKV11QU5bXsMg9xsonD1FLGK

@cla-bot-2021
Copy link

cla-bot-2021 bot commented Oct 3, 2023

User @eagr, please sign the CLA here.

@eagr eagr marked this pull request as draft October 3, 2023 06:04
Copy link
Contributor

@s0me0ne-unkn0wn s0me0ne-unkn0wn left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, it's highly appreciated! Left some comments on how to improve it.

@eskimor @sandreim @slumber we need some brainstorming here. We want to limit values of backing and approval timeouts that could be set via ExecutorParams to some reasonable range, that is, to forbid setting a value that breaks things. Technically, for backing timeout, we could limit from 0 to block_time, and that's good enough to rule out obvious errors in configuration. Practically, I'd like to have more reasonable values, as setting the backing limit to 0, or, say, 0.01 sec, definitely breaks everything. My first guess is to limit it from 1/12 blocktime to 1/2 blocktime but I may not have a solid enough understanding of underlying logic, especially after async backing has landed. Do you have better ideas?

polkadot/primitives/src/v6/executor_params.rs Outdated Show resolved Hide resolved
polkadot/primitives/src/v6/executor_params.rs Outdated Show resolved Hide resolved
polkadot/primitives/src/v6/executor_params.rs Outdated Show resolved Hide resolved
polkadot/primitives/src/v6/executor_params.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@s0me0ne-unkn0wn s0me0ne-unkn0wn left a comment

Choose a reason for hiding this comment

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

Looks good! Now waiting for other teammates to come back and discuss the exact values of limits.

@s0me0ne-unkn0wn s0me0ne-unkn0wn marked this pull request as ready for review October 8, 2023 10:49
@eagr
Copy link
Contributor Author

eagr commented Oct 8, 2023

In the mean time, any good next issue I could work on?

@s0me0ne-unkn0wn
Copy link
Contributor

Hmm, maybe #677 (somewhat connected with this one), but we'd still need @mrcnski there.

Also, there's a test improvement puzzle #1597. It would be good to have it solved, but it's not urgent and nobody has time to even start thinking about it.

@mrcnski
Copy link
Contributor

mrcnski commented Oct 10, 2023

/tip small

@substrate-tip-bot
Copy link

@mrcnski A small (4 KSM) tip was successfully submitted for @eagr (FvpsvV1GQAAbwqX6oyRjemgdKV11QU5bXsMg9xsonD1FLGK on kusama).

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fkusama-rpc.polkadot.io#/referenda tip

@@ -130,6 +182,126 @@ impl ExecutorParams {
}
None
}

/// Check params coherence.
pub fn check_consistency(&self) -> Result<(), ExecutorParamError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have this logic right in configuration.rs? This file seems to be mainly defining a bunch of types with not much actual logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it would be nice to if we could put the checks in one place. But that may require opening up the internal of ExecutorParams, do you think it's worth it? @mrcnski

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what you mean exactly, but I think it's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I was thinking that we might need to make the internal state public in order to do the checks in another crate, like pub struct ExecutorParams(pub Vec<ExecutorParam>). Then it's possible that other crates may rely on the internal state which is not great.

I just realized that it comes with an iterator :)

But still, for the sake of separation of concerns, I think it wouldn't be a bad idea that the type does its own checks. Like, what if the checks are needed else where (other than configurations.rs)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. :)

sem.heap_alloc_strategy =
HeapAllocStrategy::Dynamic { maximum_pages: Some(*max_pages) },
sem.heap_alloc_strategy = HeapAllocStrategy::Dynamic {
maximum_pages: Some((*max_pages).saturating_add(DEFAULT_HEAP_PAGES_ESTIMATE)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! But can we just use the value from sem instead?

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 we discussed it here

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I misread this code, nevermind. Should it be this instead though?

Suggested change
maximum_pages: Some((*max_pages).saturating_add(DEFAULT_HEAP_PAGES_ESTIMATE)),
maximum_pages: Some((*max_pages).saturating_add(EXTRA_HEAP_PAGES)),

And are these values correct? I would have thought the extra pages were 32. @s0me0ne-unkn0wn

const DEFAULT_HEAP_PAGES_ESTIMATE: u32 = 32;
const EXTRA_HEAP_PAGES: u32 = 2048;

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I believe everything is okay with the current version.

EXTRA_HEAP_PAGES is the number of pages of linear memory the instance is allowed to allocate in addition to its initial memory size.

DEFAULT_HEAP_PAGES_ESTIMATE is the number of pages the instance will use for its own purposes, they are not part of linear memory.

So, the corresponding executor parameter defines the number of linear memory pages the instance is allowed to allocate, and here, we implicitly add those auxiliary pages to that limit (for example, we can set the limit to 0, and Wasm code not using any linear memory should still be functional, but it's not possible without having some space for shadow stack and other bits).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it clarify stuff if we name it SHADOW_STACK_HEAP_PAGES? Then current name may be a bit vague.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not just shadow stack, according to the comment 🤔 But I doubt if the reasoning behind the calculation provided is correct enough. I didn't dig deeper into this aspect of Wasmtime, but it seems obvious that data segment pages shouldn't be allocated implicitly. Wasm source must specify the initial memory size, and it should always be enough to accommodate the data segment at least. Considering that I'm not the author of the original constant naming, I'm not 100% sure what is better, but probably renaming DEFAULT_HEAP_PAGES_ESTIMATE to INITIAL_HEAP_PAGES_ESTIMATE would bring more clarity.

Copy link
Contributor

@mrcnski mrcnski left a comment

Choose a reason for hiding this comment

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

Great stuff, much appreciate your time!

sem.heap_alloc_strategy =
HeapAllocStrategy::Dynamic { maximum_pages: Some(*max_pages) },
sem.heap_alloc_strategy = HeapAllocStrategy::Dynamic {
maximum_pages: Some((*max_pages).saturating_add(DEFAULT_HEAP_PAGES_ESTIMATE)),
Copy link
Contributor

Choose a reason for hiding this comment

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

No, I believe everything is okay with the current version.

EXTRA_HEAP_PAGES is the number of pages of linear memory the instance is allowed to allocate in addition to its initial memory size.

DEFAULT_HEAP_PAGES_ESTIMATE is the number of pages the instance will use for its own purposes, they are not part of linear memory.

So, the corresponding executor parameter defines the number of linear memory pages the instance is allowed to allocate, and here, we implicitly add those auxiliary pages to that limit (for example, we can set the limit to 0, and Wasm code not using any linear memory should still be functional, but it's not possible without having some space for shadow stack and other bits).

Copy link
Contributor

@mrcnski mrcnski left a comment

Choose a reason for hiding this comment

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

Thanks! ⭐️

@eagr
Copy link
Contributor Author

eagr commented Oct 12, 2023

Thank you guys for spending the time to review! Is this good to go now?

@mrcnski
Copy link
Contributor

mrcnski commented Oct 12, 2023

@eagr Our CI was recently updated, so some checks here were failing. I merged in master, once CI succeeds we should be good!

@mrcnski mrcnski merged commit 681e7bb into paritytech:master Oct 13, 2023
8 of 10 checks passed
ordian added a commit that referenced this pull request Oct 16, 2023
* master: (54 commits)
  Publish `xcm-emulator` crate (#1881)
  Adding migrations to clean Rococo Gov 1 storage & reserved funds (#1849)
  Arkworks Elliptic Curve utils overhaul (#1870)
  Fix typos (#1878)
  fix: GoAhead signal only set when runtime upgrade is enacted from parachain side (#1176)
  Refactor staking ledger (#1484)
  Paired-key Crypto Scheme (#1705)
  Include polkadot version in artifact path (#1828)
  add link to rfc-0001 in broker README (#1862)
  Discard `Executor` (#1855)
  Macros to use path instead of ident (#1474)
  Remove clippy clone-double-ref lint noise (#1860)
  Refactor alliance benchmarks to v2 (#1868)
  Check executor params coherence (#1774)
  frame: use derive-impl for beefy and mmr pallets (#1867)
  sc-consensus-beefy: improve gossip logic (#1852)
  Adds instance support for composite enums (#1857)
  Fix links to implementers' guide (#1865)
  Disabled validators runtime API (#1257)
  Adding `try_state` hook for `Treasury` pallet (#1820)
  ...
ordian added a commit that referenced this pull request Oct 16, 2023
…ribution

* tsv-disabling-backing: (54 commits)
  Publish `xcm-emulator` crate (#1881)
  Adding migrations to clean Rococo Gov 1 storage & reserved funds (#1849)
  Arkworks Elliptic Curve utils overhaul (#1870)
  Fix typos (#1878)
  fix: GoAhead signal only set when runtime upgrade is enacted from parachain side (#1176)
  Refactor staking ledger (#1484)
  Paired-key Crypto Scheme (#1705)
  Include polkadot version in artifact path (#1828)
  add link to rfc-0001 in broker README (#1862)
  Discard `Executor` (#1855)
  Macros to use path instead of ident (#1474)
  Remove clippy clone-double-ref lint noise (#1860)
  Refactor alliance benchmarks to v2 (#1868)
  Check executor params coherence (#1774)
  frame: use derive-impl for beefy and mmr pallets (#1867)
  sc-consensus-beefy: improve gossip logic (#1852)
  Adds instance support for composite enums (#1857)
  Fix links to implementers' guide (#1865)
  Disabled validators runtime API (#1257)
  Adding `try_state` hook for `Treasury` pallet (#1820)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stricter checks for ExecutorParams soundness
4 participants