From cc678c659ef3c31f4e806bc74d380bdfea8717d4 Mon Sep 17 00:00:00 2001 From: ordian Date: Wed, 16 Oct 2024 15:37:40 +0200 Subject: [PATCH] avoid double negatives --- .../service/src/client/call_executor.rs | 28 +++++++++---------- .../service/src/client/code_provider.rs | 6 ++-- .../client/service/test/src/client/mod.rs | 8 +++--- .../primitives/state-machine/src/backend.rs | 22 +++++++-------- .../benchmarking-cli/src/pallet/command.rs | 4 +-- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/substrate/client/service/src/client/call_executor.rs b/substrate/client/service/src/client/call_executor.rs index d3253a15dfa8..bcedcf92da72 100644 --- a/substrate/client/service/src/client/call_executor.rs +++ b/substrate/client/service/src/client/call_executor.rs @@ -27,9 +27,9 @@ use sp_externalities::Extensions; use sp_runtime::{ generic::BlockId, traits::{Block as BlockT, HashingFor}, -}; +; use sp_state_machine::{ - backend::{AsTrieBackend, IgnorePendingCode}, + backend::{AsTrieBackend, TryPendingCode}, OverlayedChanges, StateMachine, StorageProof, }; use std::{cell::RefCell, sync::Arc}; @@ -107,12 +107,12 @@ where let state = self.backend.state_at(at_hash)?; // TODO: is this correct? - let ignore_pending_code = match context { - CallContext::Onchain => IgnorePendingCode::No, - CallContext::Offchain => IgnorePendingCode::Yes, + let try_pending_code = match context { + CallContext::Onchain => TryPendingCode::Yes, + CallContext::Offchain => TryPendingCode::No, }; let state_runtime_code = - sp_state_machine::backend::BackendRuntimeCode::new(&state, ignore_pending_code); + sp_state_machine::backend::BackendRuntimeCode::new(&state, try_pending_code); let runtime_code = state_runtime_code.runtime_code().map_err(sp_blockchain::Error::RuntimeCode)?; @@ -150,15 +150,15 @@ where let changes = &mut *changes.borrow_mut(); // TODO: is this correct? - let ignore_pending_code = match call_context { - CallContext::Onchain => IgnorePendingCode::No, - CallContext::Offchain => IgnorePendingCode::Yes, + let try_pending_code = match call_context { + CallContext::Onchain => TryPendingCode::Yes, + CallContext::Offchain => TryPendingCode::No, }; // It is important to extract the runtime code here before we create the proof // recorder to not record it. We also need to fetch the runtime code from `state` to // make sure we use the caching layers. let state_runtime_code = - sp_state_machine::backend::BackendRuntimeCode::new(&state, ignore_pending_code); + sp_state_machine::backend::BackendRuntimeCode::new(&state, try_pending_code); let runtime_code = state_runtime_code.runtime_code().map_err(sp_blockchain::Error::RuntimeCode)?; @@ -207,9 +207,9 @@ where fn runtime_version(&self, at_hash: Block::Hash) -> sp_blockchain::Result { let state = self.backend.state_at(at_hash)?; // TODO: is this correct? - let ignore_pending_code = IgnorePendingCode::Yes; + let try_pending_code = TryPendingCode::No; let state_runtime_code = - sp_state_machine::backend::BackendRuntimeCode::new(&state, ignore_pending_code); + sp_state_machine::backend::BackendRuntimeCode::new(&state, try_pending_code); let runtime_code = state_runtime_code.runtime_code().map_err(sp_blockchain::Error::RuntimeCode)?; @@ -231,9 +231,9 @@ where let trie_backend = state.as_trie_backend(); // TODO: is this correct? - let ignore_pending_code = IgnorePendingCode::Yes; + let try_pending_code = TryPendingCode::No; let state_runtime_code = - sp_state_machine::backend::BackendRuntimeCode::new(trie_backend, ignore_pending_code); + sp_state_machine::backend::BackendRuntimeCode::new(trie_backend, try_pending_code); let runtime_code = state_runtime_code.runtime_code().map_err(sp_blockchain::Error::RuntimeCode)?; let runtime_code = self.code_provider.maybe_override_code(runtime_code, &state, at_hash)?.0; diff --git a/substrate/client/service/src/client/code_provider.rs b/substrate/client/service/src/client/code_provider.rs index f7304d0e3f05..d506219ce76e 100644 --- a/substrate/client/service/src/client/code_provider.rs +++ b/substrate/client/service/src/client/code_provider.rs @@ -21,7 +21,7 @@ use sc_client_api::backend; use sc_executor::{RuntimeVersion, RuntimeVersionOf}; use sp_core::traits::{FetchRuntimeCode, RuntimeCode}; use sp_runtime::traits::Block as BlockT; -use sp_state_machine::{backend::IgnorePendingCode, Ext, OverlayedChanges}; +use sp_state_machine::{backend::TryPendingCode, Ext, OverlayedChanges}; use std::sync::Arc; /// Provider for fetching `:code` of a block. @@ -82,9 +82,9 @@ where let state = self.backend.state_at(block)?; // TODO: make sure this is correct - let ignore_pending_code = IgnorePendingCode::No; + let try_pending_code = TryPendingCode::Yes; let state_runtime_code = - sp_state_machine::backend::BackendRuntimeCode::new(&state, ignore_pending_code); + sp_state_machine::backend::BackendRuntimeCode::new(&state, try_pending_code); let runtime_code = state_runtime_code.runtime_code().map_err(sp_blockchain::Error::RuntimeCode)?; diff --git a/substrate/client/service/test/src/client/mod.rs b/substrate/client/service/test/src/client/mod.rs index 31f0cd209153..2ad1a1beae1e 100644 --- a/substrate/client/service/test/src/client/mod.rs +++ b/substrate/client/service/test/src/client/mod.rs @@ -39,7 +39,7 @@ use sp_runtime::{ ConsensusEngineId, Justifications, StateVersion, }; use sp_state_machine::{ - backend::{Backend as _, IgnorePendingCode}, + backend::{Backend as _, TryPendingCode}, InMemoryBackend, OverlayedChanges, StateMachine, }; use sp_storage::{ChildInfo, StorageKey}; @@ -76,7 +76,7 @@ fn construct_block( }; let mut overlay = OverlayedChanges::default(); let backend_runtime_code = - sp_state_machine::backend::BackendRuntimeCode::new(backend, IgnorePendingCode::Yes); + sp_state_machine::backend::BackendRuntimeCode::new(backend, TryPendingCode::No); let runtime_code = backend_runtime_code.runtime_code().expect("Code is part of the backend"); StateMachine::new( @@ -171,7 +171,7 @@ fn construct_genesis_should_work_with_native() { let backend = InMemoryBackend::from((storage, StateVersion::default())); let b1data = block1(genesis_hash, &backend); let backend_runtime_code = - sp_state_machine::backend::BackendRuntimeCode::new(&backend, IgnorePendingCode::Yes); + sp_state_machine::backend::BackendRuntimeCode::new(&backend, TryPendingCode::No); let runtime_code = backend_runtime_code.runtime_code().expect("Code is part of the backend"); let mut overlay = OverlayedChanges::default(); @@ -203,7 +203,7 @@ fn construct_genesis_should_work_with_wasm() { let backend = InMemoryBackend::from((storage, StateVersion::default())); let b1data = block1(genesis_hash, &backend); let backend_runtime_code = - sp_state_machine::backend::BackendRuntimeCode::new(&backend, IgnorePendingCode::Yes); + sp_state_machine::backend::BackendRuntimeCode::new(&backend, TryPendingCode::No); let runtime_code = backend_runtime_code.runtime_code().expect("Code is part of the backend"); let mut overlay = OverlayedChanges::default(); diff --git a/substrate/primitives/state-machine/src/backend.rs b/substrate/primitives/state-machine/src/backend.rs index d0b2dbae1a0f..e0ac4ecb3c70 100644 --- a/substrate/primitives/state-machine/src/backend.rs +++ b/substrate/primitives/state-machine/src/backend.rs @@ -392,7 +392,7 @@ pub trait AsTrieBackend> { fn as_trie_backend(&self) -> &TrieBackend; } -/// Whether to ignore `:pending_code` storage value +/// Whether to to take `:pending_code` into account /// when fetching the runtime code. /// /// We want to use `:pending_code` in block production and import @@ -400,18 +400,18 @@ pub trait AsTrieBackend> { /// /// See for more details. #[cfg(feature = "std")] -pub enum IgnorePendingCode { +pub enum TryPendingCode { /// Used by runtime api calls. - Yes, - /// Used by block import and production. No, + /// Used by block import and production. + Yes, } /// Wrapper to create a [`RuntimeCode`] from a type that implements [`Backend`]. #[cfg(feature = "std")] pub struct BackendRuntimeCode<'a, B, H> { backend: &'a B, - ignore_pending_code: IgnorePendingCode, + try_pending_code: TryPendingCode, _marker: PhantomData, } @@ -420,7 +420,7 @@ impl<'a, B: Backend, H: Hasher> sp_core::traits::FetchRuntimeCode for BackendRuntimeCode<'a, B, H> { fn fetch_runtime_code(&self) -> Option> { - if matches!(self.ignore_pending_code, IgnorePendingCode::No) { + if matches!(self.try_pending_code, TryPendingCode::Yes) { let pending_code = self .backend .storage(sp_core::storage::well_known_keys::PENDING_CODE) @@ -446,16 +446,16 @@ where H::Out: Encode, { /// Create a new instance. - pub fn new(backend: &'a B, ignore_pending_code: IgnorePendingCode) -> Self { - Self { backend, ignore_pending_code, _marker: PhantomData } + pub fn new(backend: &'a B, try_pending_code: TryPendingCode) -> Self { + Self { backend, try_pending_code, _marker: PhantomData } } /// Return the [`RuntimeCode`] build from the wrapped `backend`. /// This method takes `:pending_code` into account. pub fn runtime_code(&self) -> Result { - let maybe_pending_code_hash = match self.ignore_pending_code { - IgnorePendingCode::Yes => None, - IgnorePendingCode::No => self + let maybe_pending_code_hash = match self.try_pending_code { + TryPendingCode::No => None, + TryPendingCode::Yes => self .backend .storage_hash(sp_core::storage::well_known_keys::PENDING_CODE) .ok() diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs index cf1db95914dd..0696e5a73e95 100644 --- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -42,7 +42,7 @@ use sp_core::{ use sp_externalities::Extensions; use sp_keystore::{testing::MemoryKeystore, KeystoreExt}; use sp_runtime::traits::Hash; -use sp_state_machine::{backend::IgnorePendingCode, StateMachine}; +use sp_state_machine::{backend::TryPendingCode, StateMachine}; use sp_storage::{well_known_keys::CODE, Storage}; use sp_trie::{proof_size_extension::ProofSizeExt, recorder::Recorder}; use sp_wasm_interface::HostFunctions; @@ -712,7 +712,7 @@ impl PalletCmd { } else { log::info!(target: LOG_TARGET, "Loading WASM from state"); let state = - sp_state_machine::backend::BackendRuntimeCode::new(state, IgnorePendingCode::Yes); + sp_state_machine::backend::BackendRuntimeCode::new(state, TryPendingCode::No); Ok(FetchedCode::FromGenesis { state }) }