Skip to content

Commit

Permalink
sp-api: Move macro related re-exports to __private (paritytech#2446)
Browse files Browse the repository at this point in the history
This moves the macro related re-exports to `__private` to make it more
obvious for downstream users that they are using an internal api.

---------

Co-authored-by: command-bot <>
  • Loading branch information
bkchr authored Nov 23, 2023
1 parent a910d12 commit 138b387
Show file tree
Hide file tree
Showing 25 changed files with 113 additions and 93 deletions.
4 changes: 2 additions & 2 deletions substrate/client/api/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
use sc_executor::{RuntimeVersion, RuntimeVersionOf};
use sp_core::traits::CallContext;
use sp_externalities::Extensions;
use sp_runtime::traits::Block as BlockT;
use sp_runtime::traits::{Block as BlockT, HashingFor};
use sp_state_machine::{OverlayedChanges, StorageProof};
use std::cell::RefCell;

use crate::execution_extensions::ExecutionExtensions;
use sp_api::{HashingFor, ProofRecorder};
use sp_api::ProofRecorder;

/// Executor Provider
pub trait ExecutorProvider<Block: BlockT> {
Expand Down
3 changes: 1 addition & 2 deletions substrate/client/api/src/in_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,8 @@ pub fn check_genesis_storage(storage: &Storage) -> sp_blockchain::Result<()> {
#[cfg(test)]
mod tests {
use crate::{in_mem::Blockchain, NewBlockState};
use sp_api::HeaderT;
use sp_blockchain::Backend;
use sp_runtime::{ConsensusEngineId, Justifications};
use sp_runtime::{traits::Header as HeaderT, ConsensusEngineId, Justifications};
use substrate_test_runtime::{Block, Header, H256};

pub const ID1: ConsensusEngineId = *b"TST1";
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/consensus/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use sc_client_api::{Backend, BlockBackend, BlockchainEvents, FinalityNotificatio
use sc_consensus::BlockImport;
use sc_network::{NetworkRequest, ProtocolName};
use sc_network_gossip::{GossipEngine, Network as GossipNetwork, Syncing as GossipSyncing};
use sp_api::{HeaderT, NumberFor, ProvideRuntimeApi};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::{
Backend as BlockchainBackend, Error as ClientError, HeaderBackend, Result as ClientResult,
};
Expand All @@ -51,7 +51,7 @@ use sp_consensus_beefy::{
};
use sp_keystore::KeystorePtr;
use sp_mmr_primitives::MmrApi;
use sp_runtime::traits::{Block, Zero};
use sp_runtime::traits::{Block, Header as HeaderT, NumberFor, Zero};
use std::{
collections::{BTreeMap, VecDeque},
marker::PhantomData,
Expand Down
7 changes: 3 additions & 4 deletions substrate/client/consensus/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use log::{debug, error, info, log_enabled, trace, warn};
use sc_client_api::{Backend, FinalityNotification, FinalityNotifications, HeaderBackend};
use sc_network_gossip::GossipEngine;
use sc_utils::{mpsc::TracingUnboundedReceiver, notification::NotificationReceiver};
use sp_api::{BlockId, ProvideRuntimeApi};
use sp_api::ProvideRuntimeApi;
use sp_arithmetic::traits::{AtLeast32Bit, Saturating};
use sp_consensus::SyncOracle;
use sp_consensus_beefy::{
Expand All @@ -46,7 +46,7 @@ use sp_consensus_beefy::{
VersionedFinalityProof, VoteMessage, BEEFY_ENGINE_ID,
};
use sp_runtime::{
generic::OpaqueDigestItemId,
generic::{BlockId, OpaqueDigestItemId},
traits::{Block, Header, NumberFor, Zero},
SaturatedConversion,
};
Expand Down Expand Up @@ -1074,13 +1074,12 @@ pub(crate) mod tests {
use sc_client_api::{Backend as BackendT, HeaderBackend};
use sc_network_sync::SyncingService;
use sc_network_test::TestNetFactory;
use sp_api::HeaderT;
use sp_blockchain::Backend as BlockchainBackendT;
use sp_consensus_beefy::{
generate_equivocation_proof, known_payloads, known_payloads::MMR_ROOT_ID,
mmr::MmrRootProvider, Keyring, Payload, SignedCommitment,
};
use sp_runtime::traits::One;
use sp_runtime::traits::{Header as HeaderT, One};
use substrate_test_runtime_client::{
runtime::{Block, Digest, DigestItem, Header},
Backend,
Expand Down
15 changes: 8 additions & 7 deletions substrate/client/executor/src/wasm_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ mod tests {
use codec::Encode;
use sp_api::{Core, RuntimeApiInfo};
use sp_runtime::RuntimeString;
use sp_version::{create_apis_vec, RuntimeVersion};
use sp_wasm_interface::HostFunctions;
use substrate_test_runtime::Block;

Expand Down Expand Up @@ -470,7 +471,7 @@ mod tests {
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 1)]),
apis: create_apis_vec!([(<dyn Core::<Block>>::ID, 1)]),
};

let version = decode_version(&old_runtime_version.encode()).unwrap();
Expand All @@ -486,21 +487,21 @@ mod tests {
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 3)]),
apis: create_apis_vec!([(<dyn Core::<Block>>::ID, 3)]),
};

decode_version(&old_runtime_version.encode()).unwrap_err();
}

#[test]
fn new_runtime_version_decodes() {
let old_runtime_version = sp_api::RuntimeVersion {
let old_runtime_version = RuntimeVersion {
spec_name: "test".into(),
impl_name: "test".into(),
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 3)]),
apis: create_apis_vec!([(<dyn Core::<Block>>::ID, 3)]),
transaction_version: 3,
state_version: 4,
};
Expand All @@ -509,13 +510,13 @@ mod tests {
assert_eq!(3, version.transaction_version);
assert_eq!(0, version.state_version);

let old_runtime_version = sp_api::RuntimeVersion {
let old_runtime_version = RuntimeVersion {
spec_name: "test".into(),
impl_name: "test".into(),
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 4)]),
apis: create_apis_vec!([(<dyn Core::<Block>>::ID, 4)]),
transaction_version: 3,
state_version: 4,
};
Expand All @@ -538,7 +539,7 @@ mod tests {
authoring_version: 100,
spec_version: 100,
impl_version: 100,
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 4)]),
apis: create_apis_vec!([(<dyn Core::<Block>>::ID, 4)]),
transaction_version: 100,
state_version: 1,
};
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/merkle-mountain-range/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ use jsonrpsee::{
};
use serde::{Deserialize, Serialize};

use sp_api::{ApiExt, NumberFor, ProvideRuntimeApi};
use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
use sp_core::{
offchain::{storage::OffchainDb, OffchainDbExt, OffchainStorage},
Bytes,
};
use sp_mmr_primitives::{Error as MmrError, Proof};
use sp_runtime::traits::Block as BlockT;
use sp_runtime::traits::{Block as BlockT, NumberFor};

pub use sp_mmr_primitives::MmrApi as MmrRuntimeApi;

Expand Down
2 changes: 2 additions & 0 deletions substrate/client/rpc-spec-v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ tokio = { version = "1.22.0", features = ["sync"] }
array-bytes = "6.1"
log = "0.4.17"
futures-util = { version = "0.3.19", default-features = false }

[dev-dependencies]
serde_json = "1.0.108"
tokio = { version = "1.22.0", features = ["macros"] }
substrate-test-runtime-client = { path = "../../test-utils/runtime/client" }
substrate-test-runtime = { path = "../../test-utils/runtime" }
sp-consensus = { path = "../../primitives/consensus/common" }
sp-externalities = { path = "../../primitives/externalities" }
sp-maybe-compressed-blob = { path = "../../primitives/maybe-compressed-blob" }
sc-block-builder = { path = "../block-builder" }
sc-service = { path = "../service", features = ["test-helpers"]}
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/rpc-spec-v2/src/archive/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ use jsonrpsee::core::{async_trait, RpcResult};
use sc_client_api::{
Backend, BlockBackend, BlockchainEvents, CallExecutor, ExecutorProvider, StorageProvider,
};
use sp_api::{CallApiAt, CallContext, NumberFor};
use sp_api::{CallApiAt, CallContext};
use sp_blockchain::{
Backend as BlockChainBackend, Error as BlockChainError, HeaderBackend, HeaderMetadata,
};
use sp_core::Bytes;
use sp_runtime::{
traits::{Block as BlockT, Header as HeaderT},
traits::{Block as BlockT, Header as HeaderT, NumberFor},
SaturatedConversion,
};
use std::{collections::HashSet, marker::PhantomData, sync::Arc};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use std::{collections::VecDeque, marker::PhantomData, sync::Arc};

use sc_client_api::{Backend, ChildInfo, StorageKey, StorageProvider};
use sc_utils::mpsc::TracingUnboundedSender;
use sp_api::BlockT;
use sp_core::storage::well_known_keys;
use sp_runtime::traits::Block as BlockT;

use crate::chain_head::event::OperationStorageItems;

Expand Down
7 changes: 4 additions & 3 deletions substrate/client/rpc-spec-v2/src/chain_head/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ use sc_client_api::{
StorageData, StorageEventStream, StorageKey, StorageProvider,
};
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedSender};
use sp_api::{CallApiAt, CallApiAtParams, NumberFor, RuntimeVersion};
use sp_api::{CallApiAt, CallApiAtParams};
use sp_blockchain::{BlockStatus, CachedHeaderMetadata, HeaderBackend, HeaderMetadata, Info};
use sp_consensus::BlockOrigin;
use sp_runtime::{
generic::SignedBlock,
traits::{Block as BlockT, Header as HeaderT},
traits::{Block as BlockT, Header as HeaderT, NumberFor},
Justifications,
};
use sp_version::RuntimeVersion;
use std::sync::Arc;
use substrate_test_runtime::{Block, Hash, Header};

Expand Down Expand Up @@ -235,7 +236,7 @@ impl<Block: BlockT, Client: CallApiAt<Block>> CallApiAt<Block> for ChainHeadMock
fn initialize_extensions(
&self,
at: <Block as BlockT>::Hash,
extensions: &mut sp_api::Extensions,
extensions: &mut sp_externalities::Extensions,
) -> Result<(), sp_api::ApiError> {
self.client.initialize_extensions(at, extensions)
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/rpc-spec-v2/src/chain_head/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ use jsonrpsee::{
use sc_block_builder::BlockBuilderBuilder;
use sc_client_api::ChildInfo;
use sc_service::client::new_in_mem;
use sp_api::BlockT;
use sp_blockchain::HeaderBackend;
use sp_consensus::BlockOrigin;
use sp_core::{
storage::well_known_keys::{self, CODE},
testing::TaskExecutor,
Blake2Hasher, Hasher,
};
use sp_runtime::traits::Block as BlockT;
use sp_version::RuntimeVersion;
use std::{
collections::{HashMap, HashSet},
Expand Down
1 change: 1 addition & 0 deletions substrate/client/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
ansi_term = "0.12.1"
atty = "0.2.13"
chrono = "0.4.27"
codec = { package = "parity-scale-codec", version = "3.6.1" }
lazy_static = "1.4.0"
libc = "0.2.121"
log = { version = "0.4.17" }
Expand Down
3 changes: 2 additions & 1 deletion substrate/client/tracing/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use std::{
time::Instant,
};

use codec::Encode;
use parking_lot::Mutex;
use tracing::{
dispatcher,
Expand All @@ -34,7 +35,7 @@ use tracing::{

use crate::{SpanDatum, TraceEvent, Values};
use sc_client_api::BlockBackend;
use sp_api::{Core, Encode, Metadata, ProvideRuntimeApi};
use sp_api::{Core, Metadata, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
use sp_core::hexdisplay::HexDisplay;
use sp_rpc::tracing::{BlockTrace, Span, TraceBlockResponse};
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/beefy-mmr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use sp_runtime::traits::{Convert, Member};
use sp_std::prelude::*;

use codec::Decode;
use pallet_mmr::{LeafDataProvider, ParentNumberAndHash};
use sp_consensus_beefy::{
mmr::{BeefyAuthoritySet, BeefyDataProvider, BeefyNextAuthoritySet, MmrLeaf, MmrLeafVersion},
Expand Down Expand Up @@ -226,7 +227,7 @@ sp_api::decl_runtime_apis! {
/// API useful for BEEFY light clients.
pub trait BeefyMmrApi<H>
where
BeefyAuthoritySet<H>: sp_api::Decode,
BeefyAuthoritySet<H>: Decode,
{
/// Return the currently active BEEFY authority set proof.
fn authority_set_proof() -> BeefyAuthoritySet<H>;
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/contracts/src/storage/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ use frame_support::{
},
DefaultNoBound, RuntimeDebugNoBound,
};
use sp_api::HashT;
use sp_runtime::{
traits::{Saturating, Zero},
traits::{Hash as HashT, Saturating, Zero},
DispatchError, FixedPointNumber, FixedU128,
};
use sp_std::{fmt::Debug, marker::PhantomData, vec, vec::Vec};
Expand Down
7 changes: 4 additions & 3 deletions substrate/frame/nfts/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] }
pallet-nfts = { path = "..", default-features = false}
sp-api = { path = "../../../primitives/api", default-features = false}
pallet-nfts = { path = "..", default-features = false }
sp-api = { path = "../../../primitives/api", default-features = false }
sp-std = { path = "../../../primitives/std", default-features = false }

[features]
default = [ "std" ]
std = [ "codec/std", "pallet-nfts/std", "sp-api/std" ]
std = [ "codec/std", "pallet-nfts/std", "sp-api/std", "sp-std/std" ]
2 changes: 1 addition & 1 deletion substrate/frame/nfts/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Decode, Encode};
use sp_api::vec::Vec;
use sp_std::vec::Vec;

sp_api::decl_runtime_apis! {
pub trait NftsApi<AccountId, CollectionId, ItemId>
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/support/test/tests/construct_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ use frame_support::{
};
use frame_system::limits::{BlockLength, BlockWeights};
use scale_info::TypeInfo;
use sp_api::RuntimeVersion;
use sp_core::{sr25519, ConstU64};
use sp_runtime::{
generic,
traits::{BlakeTwo256, Verify},
DispatchError, ModuleError,
};
use sp_version::RuntimeVersion;

parameter_types! {
pub static IntegrityTestExec: u32 = 0;
Expand Down
16 changes: 8 additions & 8 deletions substrate/primitives/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
sp-api-proc-macro = { path = "proc-macro" }
sp-core = { path = "../core", default-features = false}
sp-std = { path = "../std", default-features = false}
sp-runtime = { path = "../runtime", default-features = false}
sp-externalities = { path = "../externalities", default-features = false, optional = true}
sp-version = { path = "../version", default-features = false}
sp-state-machine = { path = "../state-machine", default-features = false, optional = true}
sp-trie = { path = "../trie", default-features = false, optional = true}
sp-core = { path = "../core", default-features = false }
sp-std = { path = "../std", default-features = false }
sp-runtime = { path = "../runtime", default-features = false }
sp-externalities = { path = "../externalities", default-features = false, optional = true }
sp-version = { path = "../version", default-features = false }
sp-state-machine = { path = "../state-machine", default-features = false, optional = true }
sp-trie = { path = "../trie", default-features = false, optional = true }
hash-db = { version = "0.16.0", optional = true }
thiserror = { version = "1.0.48", optional = true }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
sp-metadata-ir = { path = "../metadata-ir", default-features = false, optional = true}
sp-metadata-ir = { path = "../metadata-ir", default-features = false, optional = true }
log = { version = "0.4.17", default-features = false }

[dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions substrate/primitives/api/proc-macro/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ use syn::{
/// Generates the access to the `sc_client` crate.
pub fn generate_crate_access() -> TokenStream {
match crate_name("sp-api") {
Ok(FoundCrate::Itself) => quote!(sp_api),
Ok(FoundCrate::Itself) => quote!(sp_api::__private),
Ok(FoundCrate::Name(renamed_name)) => {
let renamed_name = Ident::new(&renamed_name, Span::call_site());
quote!(#renamed_name)
quote!(#renamed_name::__private)
},
Err(e) =>
if let Ok(FoundCrate::Name(name)) = crate_name(&"frame") {
let path = format!("{}::deps::{}", name, "sp_api");
let path = format!("{}::deps::sp_api::__private", name);
let path = syn::parse_str::<syn::Path>(&path).expect("is a valid path; qed");
quote!( #path )
} else {
Expand Down
Loading

0 comments on commit 138b387

Please sign in to comment.