Skip to content

Commit

Permalink
Fix how domain stateless runtime getting runtime version
Browse files Browse the repository at this point in the history
The previous way to get runtime version is wrong and will failed in test

Signed-off-by: linning <[email protected]>
  • Loading branch information
NingLin-P committed May 13, 2024
1 parent 0e03641 commit d4364c8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion domains/client/block-preprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ sp-domains = { version = "0.1.0", path = "../../../crates/sp-domains" }
sp-executive = { version = "0.1.0", path = "../../primitives/executive" }
sp-externalities = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "808269708cf5375526755797e8f9a9986016727d" }
sp-inherents = { git = "https://github.com/subspace/polkadot-sdk", rev = "808269708cf5375526755797e8f9a9986016727d" }
sp-io = { default-features = false, git = "https://github.com/subspace/polkadot-sdk", rev = "808269708cf5375526755797e8f9a9986016727d" }
sp-messenger = { version = "0.1.0", path = "../../primitives/messenger" }
sp-runtime = { git = "https://github.com/subspace/polkadot-sdk", rev = "808269708cf5375526755797e8f9a9986016727d" }
sp-state-machine = { git = "https://github.com/subspace/polkadot-sdk", rev = "808269708cf5375526755797e8f9a9986016727d" }
Expand Down
25 changes: 19 additions & 6 deletions domains/client/block-preprocessor/src/stateless_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sc_client_api::execution_extensions::ExtensionsFactory;
use sc_executor::RuntimeVersionOf;
use sp_api::{ApiError, Core, RuntimeApiInfo};
use sp_core::traits::{CallContext, CodeExecutor, FetchRuntimeCode, RuntimeCode};
use sp_core::{Decode, Hasher};
use sp_core::Hasher;
use sp_domains::core_api::DomainCoreApi;
use sp_domains::DomainAllowlistUpdates;
use sp_messenger::messages::MessageKey;
Expand Down Expand Up @@ -284,11 +284,24 @@ where
}

pub fn block_fees_storage_key(&self) -> Result<Vec<u8>, ApiError> {
let has_runtime_api = sp_io::misc::runtime_version(&self.runtime_code)
.and_then(|v| RuntimeVersion::decode(&mut &v[..]).ok())
.and_then(|runtime_version| {
runtime_version.api_version(&<dyn DomainCoreApi<Block>>::ID)
})
let runtime_version = {
let mut ext = BasicExternalities::new(self.storage.clone());
let ext_extensions = ext.extensions();
ext_extensions.merge(
self.extension_factory
.extensions_for(Default::default(), Default::default()),
);
let runtime_code = self.runtime_code();
self.executor
.runtime_version(&mut ext, &runtime_code)
.map_err(|err| {
ApiError::Application(Box::from(format!(
"failed to read domain runtime version: {err}"
)))
})?
};
let has_runtime_api = runtime_version
.api_version(&<dyn DomainCoreApi<Block>>::ID)
.map_or(false, |runtime_api_version| runtime_api_version >= 2);

if has_runtime_api {
Expand Down

0 comments on commit d4364c8

Please sign in to comment.