From 1f1c0f32c469d0e1f0833d13a2ef975aa516c498 Mon Sep 17 00:00:00 2001 From: Andrei Eres Date: Sun, 2 Mar 2025 22:34:15 +0100 Subject: [PATCH] Fix unspecified Hash in NodeBlock (#7756) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description Working with https://github.com/paritytech/polkadot-sdk/pull/7556 I encountered an internal compiler error on polkadot-omni-node-lib: see bellow or [in CI](https://github.com/paritytech/polkadot-sdk/actions/runs/13521547633/job/37781894640). ``` error: internal compiler error: compiler/rustc_traits/src/codegen.rs:45:13: Encountered error `SignatureMismatch(SignatureMismatchData { found_trait_ref: <{closure@sp_state_machine::trie_backend_essence::TrieBackendEssence::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>>, <<::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing, sp_trie::cache::LocalTrieCache<<<::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>, sp_trie::recorder::Recorder<<<::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>>::storage::{closure#1}} as std::ops::FnOnce<(std::option::Option<&mut dyn trie_db::TrieRecorder>, std::option::Option<&mut dyn trie_db::TrieCache::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>>>)>>, expected_trait_ref: <{closure@sp_state_machine::trie_backend_essence::TrieBackendEssence::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>>, <<::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing, sp_trie::cache::LocalTrieCache<<<::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>, sp_trie::recorder::Recorder<<<::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>>::storage::{closure#1}} as std::ops::FnOnce<(std::option::Option<&mut dyn trie_db::TrieRecorder<<<::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hash>>, std::option::Option<&mut dyn trie_db::TrieCache::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>>>)>>, terr: Sorts(ExpectedFound { expected: Alias(Projection, AliasTy { args: [Alias(Projection, AliasTy { args: [Alias(Projection, AliasTy { args: [NodeSpec/#0], def_id: DefId(0:410 ~ polkadot_omni_node_lib[7cce]::common::spec::BaseNodeSpec::Block), .. })], def_id: DefId(0:507 ~ polkadot_omni_node_lib[7cce]::common::NodeBlock::BoundedHeader), .. })], def_id: DefId(229:1706 ~ sp_runtime[5da1]::traits::Header::Hash), .. }), found: sp_core::H256 }) })` selecting `<{closure@sp_state_machine::trie_backend_essence::TrieBackendEssence::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>>, <<::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing, sp_trie::cache::LocalTrieCache<<<::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>, sp_trie::recorder::Recorder<<<::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>>::storage::{closure#1}} as std::ops::FnOnce<(std::option::Option<&mut dyn trie_db::TrieRecorder<<<::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hash>>, std::option::Option<&mut dyn trie_db::TrieCache::Block as common::NodeBlock>::BoundedHeader as sp_runtime::traits::Header>::Hashing>>>)>>` during codegen ``` Trying to parse the error I found that TrieRecorder was not supposed to work with H256: - Expected: `&mut dyn TrieRecorder<<<::Block as common::NodeBlock>::BoundedHeader as Header>::Hash>>` - Found: `&mut dyn TrieRecorder>` The error happened because I added to `new_full_parts_with_genesis_builder` interaction with Trie Cache which eventually uses `TrieRecorder`. Here is the path: - In polkadot-omni-node-lib trait BaseNodeSpec defined with Block as `NodeBlock: BlockT`, where DbHash is H256. - BaseNodeSpec calls [new_full_parts_record_import::](https://github.com/paritytech/polkadot-sdk/blob/75726c65d40d3631c441b946a26b2f0b30d40c26/cumulus/polkadot-omni-node/lib/src/common/spec.rs#L184-L189) and eventually it goes to [new_full_parts_with_genesis_builder](https://github.com/paritytech/polkadot-sdk/blob/08b302464a6ccaacf391516ff7b058fe07b5cca3/substrate/client/service/src/builder.rs#L195). - In `new_full_parts_with_genesis_builder` we accessed storage, initiating TrieRecorder with H256 what never happened before. I believe the compiler found a mismatch checking types for TrieRecorder: NodeBlock inherits from the trait `Block`, but it uses BoundedHeader, which inherits from the trait Header with the default Hash. --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- cumulus/polkadot-omni-node/lib/src/common/mod.rs | 2 +- prdoc/pr_7756.prdoc | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 prdoc/pr_7756.prdoc diff --git a/cumulus/polkadot-omni-node/lib/src/common/mod.rs b/cumulus/polkadot-omni-node/lib/src/common/mod.rs index af003b87e3d24..7a11d9fb4a962 100644 --- a/cumulus/polkadot-omni-node/lib/src/common/mod.rs +++ b/cumulus/polkadot-omni-node/lib/src/common/mod.rs @@ -45,7 +45,7 @@ pub trait NodeBlock: { type BoundedFromStrErr: Debug; type BoundedNumber: FromStr + BlockNumber; - type BoundedHeader: HeaderT + Unpin; + type BoundedHeader: HeaderT + Unpin; } impl NodeBlock for T diff --git a/prdoc/pr_7756.prdoc b/prdoc/pr_7756.prdoc new file mode 100644 index 0000000000000..908374ae46a68 --- /dev/null +++ b/prdoc/pr_7756.prdoc @@ -0,0 +1,7 @@ +title: Fix unspecified Hash in NodeBlock +doc: +- audience: Node Dev + description: "Specified Hash type for BoundedHeader in NodeBlock, fixing possible internal compiler error" +crates: +- name: polkadot-omni-node-lib + bump: patch