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

Use generic hash for runtime wasm in resolve_state_version_from_wasm #3447

Merged
merged 4 commits into from
Feb 24, 2024

Conversation

tmpolaczyk
Copy link
Contributor

@tmpolaczyk tmpolaczyk commented Feb 22, 2024

Changes the runtime hash algorithm used in resolve_state_version_from_wasm from DefaultHasher to a caller-provided one (usually HashingFor<Block>), to match the one used elsewhere.

This fixes an issue where the runtime wasm is compiled 3 times when starting the tanssi-node with --dev. With this fix, the runtime wasm is only compiled 2 times. The other redundant compilation is caused by the GenesisConfigBuilderRuntimeCaller struct, which ignores the runtime cache.

@koute koute requested a review from a team February 23, 2024 12:41
wasm.hash(&mut state);
state.finish().to_le_bytes().to_vec()
},
hash: sp_core::blake2_256(wasm).to_vec(),
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct, you need to get the hasher used by the Block type. For most chains this is blake256, but not for all.

Copy link
Member

Choose a reason for hiding this comment

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

I mean "not correct" not being really the right term here, but if we want to fix this, we should fix it properly.

Copy link
Member

Choose a reason for hiding this comment

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

let hash = self
.backend
.storage_hash(sp_core::storage::well_known_keys::CODE)
.ok()
.flatten()
.ok_or("`:code` hash not found")?
.encode();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know how to do that, and there are many places where this hash is already hardcoded to be blake2_256. How about we merge this and create an issue to make the hasher depend on the Block?

Copy link
Member

Choose a reason for hiding this comment

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

Change the function to take H: Hash and then you can pass HashingOf<Block> on the calling side of this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, it was easier than I expected.

@tmpolaczyk tmpolaczyk changed the title Use blake2_256 hash for runtime wasm in resolve_state_version_from_wasm Use generic hash for runtime wasm in resolve_state_version_from_wasm Feb 23, 2024
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.

Ty!

substrate/client/chain-spec/src/genesis_block.rs Outdated Show resolved Hide resolved
@bkchr bkchr added the T0-node This PR/Issue is related to the topic “node”. label Feb 23, 2024
@bkchr
Copy link
Member

bkchr commented Feb 23, 2024

@tmpolaczyk could you add some prdoc? Then accept my changes and we can merge it.

tmpolaczyk and others added 2 commits February 23, 2024 16:58
Co-authored-by: Bastian Köcher <git@kchr.de>
@bkchr bkchr added this pull request to the merge queue Feb 24, 2024
Merged via the queue into paritytech:master with commit de6d025 Feb 24, 2024
129 of 130 checks passed
ordian added a commit that referenced this pull request Feb 28, 2024
…head-data

* origin/master: (51 commits)
  Runtime Upgrade ref docs and Single Block Migration example pallet  (#1554)
  Collator overseer builder unification (#3335)
  Introduce storage attr macro `#[disable_try_decode_storage]` and set it on `System::Events` and `ParachainSystem::HostConfiguration` (#3454)
  Add Polkadotters bootnoders per IBP application (#3423)
  Add documentation around FRAME Origin (#3362)
  Bridge zombienet tests: Check amount received at destination (#3490)
  Snowbridge benchmark tests fix (#3424)
  fix(zombienet): increase timeout in download artifacts (#3376)
  Cleanup String::from_utf8 (#3446)
  [prdoc] Validate crate names (#3467)
  Limit max execution time for `test-linux-stable` CI jobs (#3483)
  Introduce Notification block pinning limit (#2935)
  frame-support: Improve error reporting when having too many pallets (#3478)
  add Encointer as trusted teleporter for Westend (#3411)
  [pallet-xcm] Adjust benchmarks (teleport_assets/reserve_transfer_assets) not relying on ED (#3464)
  Add more debug logs to understand if statement-distribution misbehaving (#3419)
  Remove redundant parachains assigner pallet. (#3457)
  Use generic hash for runtime wasm in resolve_state_version_from_wasm (#3447)
  Runtime: allow backing multiple candidates of same parachain on different cores  (#3231)
  Bridge zombienet tests: move all "framework" files under one folder (#3462)
  ...
RomarQ pushed a commit to moonbeam-foundation/polkadot-sdk that referenced this pull request Mar 21, 2024
…aritytech#3447)

Changes the runtime hash algorithm used in
`resolve_state_version_from_wasm` from `DefaultHasher` to a
caller-provided one (usually `HashingFor<Block>`), to match the one used
elsewhere.

This fixes an issue where the runtime wasm is compiled 3 times when
starting the `tanssi-node` with `--dev`. With this fix, the runtime wasm
is only compiled 2 times. The other redundant compilation is caused by
the `GenesisConfigBuilderRuntimeCaller` struct, which ignores the
runtime cache.

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
…aritytech#3447)

Changes the runtime hash algorithm used in
`resolve_state_version_from_wasm` from `DefaultHasher` to a
caller-provided one (usually `HashingFor<Block>`), to match the one used
elsewhere.

This fixes an issue where the runtime wasm is compiled 3 times when
starting the `tanssi-node` with `--dev`. With this fix, the runtime wasm
is only compiled 2 times. The other redundant compilation is caused by
the `GenesisConfigBuilderRuntimeCaller` struct, which ignores the
runtime cache.

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T0-node This PR/Issue is related to the topic “node”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants