From e7aac451db98f5a29b70b7d0d457ec303211f322 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 16 Feb 2023 23:21:15 +0100 Subject: [PATCH] `BlockId` removal: `CallApiAt::state_at` (#13394) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * BlockId removal: CallApiAt::state_at It changes the arguments of: - `CallApiAt::state_at`, - `Client::code_at`, - `Client::state_at` from: `BlockId` to: `Block::Hash` * Apply suggestions from code review Co-authored-by: Bastian Köcher --------- Co-authored-by: Bastian Köcher Co-authored-by: parity-processbot <> --- client/service/src/client/client.rs | 8 +++----- primitives/api/src/lib.rs | 2 +- primitives/api/test/tests/runtime_calls.rs | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/client/service/src/client/client.rs b/client/service/src/client/client.rs index 6a75fad628681..4b28b39931756 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -481,8 +481,7 @@ where } /// Get the code at a given block. - pub fn code_at(&self, id: &BlockId) -> sp_blockchain::Result> { - let hash = self.backend.blockchain().expect_block_hash_from_id(id)?; + pub fn code_at(&self, hash: Block::Hash) -> sp_blockchain::Result> { Ok(StorageProvider::storage(self, hash, &StorageKey(well_known_keys::CODE.to_vec()))? .expect( "None is returned if there's no value stored for the given key;\ @@ -1746,9 +1745,8 @@ where CallExecutor::runtime_version(&self.executor, hash).map_err(Into::into) } - fn state_at(&self, at: &BlockId) -> Result { - let hash = self.backend.blockchain().expect_block_hash_from_id(at)?; - self.state_at(hash).map_err(Into::into) + fn state_at(&self, at: Block::Hash) -> Result { + self.state_at(at).map_err(Into::into) } } diff --git a/primitives/api/src/lib.rs b/primitives/api/src/lib.rs index 4ff4becb80f48..ad9a9b1811859 100644 --- a/primitives/api/src/lib.rs +++ b/primitives/api/src/lib.rs @@ -622,7 +622,7 @@ pub trait CallApiAt { fn runtime_version_at(&self, at: &BlockId) -> Result; /// Get the state `at` the given block. - fn state_at(&self, at: &BlockId) -> Result; + fn state_at(&self, at: Block::Hash) -> Result; } /// Auxiliary wrapper that holds an api instance and binds it to the given lifetime. diff --git a/primitives/api/test/tests/runtime_calls.rs b/primitives/api/test/tests/runtime_calls.rs index 2ac88c7e6c04f..3d355c4747736 100644 --- a/primitives/api/test/tests/runtime_calls.rs +++ b/primitives/api/test/tests/runtime_calls.rs @@ -147,13 +147,12 @@ fn record_proof_works() { .set_execution_strategy(ExecutionStrategy::Both) .build_with_longest_chain(); - let block_id = BlockId::Number(client.chain_info().best_number); let storage_root = *futures::executor::block_on(longest_chain.best_chain()).unwrap().state_root(); let runtime_code = sp_core::traits::RuntimeCode { code_fetcher: &sp_core::traits::WrappedRuntimeCode( - client.code_at(&block_id).unwrap().into(), + client.code_at(client.chain_info().best_hash).unwrap().into(), ), hash: vec![1], heap_pages: None, @@ -167,6 +166,7 @@ fn record_proof_works() { } .into_signed_tx(); + let block_id = BlockId::Hash(client.chain_info().best_hash); // Build the block and record proof let mut builder = client .new_block_at(&block_id, Default::default(), true)