Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Move client only primitives to another dir #9220

Merged
merged 8 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 17 additions & 26 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ members = [
"client/network/test",
"client/offchain",
"client/peerset",
"client/allocator",
"client/proposer-metrics",
"client/rpc",
"client/rpc-api",
Expand Down Expand Up @@ -129,7 +130,6 @@ members = [
"frame/uniques",
"frame/utility",
"frame/vesting",
"primitives/allocator",
"primitives/api",
"primitives/api/proc-macro",
"primitives/api/test",
Expand All @@ -141,7 +141,6 @@ members = [
"primitives/authorship",
"primitives/block-builder",
"primitives/blockchain",
"primitives/chain-spec",
"primitives/consensus/aura",
"primitives/consensus/babe",
"primitives/consensus/common",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[package]
name = "sp-allocator"
name = "sc-allocator"
version = "3.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "Apache-2.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"
description = "Collection of allocator implementations."
documentation = "https://docs.rs/sp-allocator"
documentation = "https://docs.rs/sc-allocator"
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
sp-std = { version = "3.0.0", path = "../std", default-features = false }
sp-core = { version = "3.0.0", path = "../core", default-features = false }
sp-wasm-interface = { version = "3.0.0", path = "../wasm-interface", default-features = false }
sp-std = { version = "3.0.0", path = "../../primitives/std", default-features = false }
sp-core = { version = "3.0.0", path = "../../primitives/core", default-features = false }
sp-wasm-interface = { version = "3.0.0", path = "../../primitives/wasm-interface", default-features = false }
log = { version = "0.4.11", optional = true }
thiserror = { version = "1.0.21", optional = true }
thiserror = { version = "1.0.21" }

[features]
default = [ "std" ]
Expand All @@ -27,5 +27,4 @@ std = [
"sp-core/std",
"sp-wasm-interface/std",
"log",
"thiserror",
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Collection of allocator implementations.

This crate provides the following allocator implementations:
- A freeing-bump allocator: [`FreeingBumpHeapAllocator`](https://docs.rs/sp-allocator/latest/sp_allocator/struct.FreeingBumpHeapAllocator.html)
- A freeing-bump allocator: [`FreeingBumpHeapAllocator`](https://docs.rs/sc-allocator/latest/sc_allocator/struct.FreeingBumpHeapAllocator.html)

License: Apache-2.0
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

/// The error type used by the allocators.
#[derive(sp_core::RuntimeDebug)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
#[derive(thiserror::Error)]
pub enum Error {
/// Someone tried to allocate more memory than the allowed maximum per allocation.
#[cfg_attr(feature = "std", error("Requested allocation size is too large"))]
#[error("Requested allocation size is too large")]
RequestedAllocationTooLarge,
/// Allocator run out of space.
#[cfg_attr(feature = "std", error("Allocator ran out of space"))]
#[error("Allocator ran out of space")]
AllocatorOutOfSpace,
/// Some other error occurred.
#[cfg_attr(feature = "std", error("Other: {0}"))]
#[error("Other: {0}")]
Other(&'static str)
}
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl Memory for [u8] {
let range =
heap_range(ptr, 8, self.len()).ok_or_else(|| error("write out of heap bounds"))?;
let bytes = val.to_le_bytes();
&mut self[range].copy_from_slice(&bytes[..]);
self[range].copy_from_slice(&bytes[..]);
Ok(())
}
fn size(&self) -> u32 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
//! This crate provides the following allocator implementations:
//! - A freeing-bump allocator: [`FreeingBumpHeapAllocator`](freeing_bump::FreeingBumpHeapAllocator)

#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)]

mod error;
Expand Down
1 change: 0 additions & 1 deletion client/chain-spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ sp-core = { version = "3.0.0", path = "../../primitives/core" }
serde = { version = "1.0.101", features = ["derive"] }
serde_json = "1.0.41"
sp-runtime = { version = "3.0.0", path = "../../primitives/runtime" }
sp-chain-spec = { version = "3.0.0", path = "../../primitives/chain-spec" }
sc-telemetry = { version = "3.0.0", path = "../telemetry" }
codec = { package = "parity-scale-codec", version = "2.0.0" }
sc-consensus-babe = { version = "0.9.0", path = "../consensus/babe" }
Expand Down
26 changes: 25 additions & 1 deletion client/chain-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,38 @@ pub use chain_spec::{
};
pub use extension::{Group, Fork, Forks, Extension, GetExtension, get_extension};
pub use sc_chain_spec_derive::{ChainSpecExtension, ChainSpecGroup};
pub use sp_chain_spec::{Properties, ChainType};

use serde::{Serialize, de::DeserializeOwned};
use sp_runtime::BuildStorage;
use sc_network::config::MultiaddrWithPeerId;
use sc_telemetry::TelemetryEndpoints;
use sp_core::storage::Storage;

/// The type of a chain.
///
/// This can be used by tools to determine the type of a chain for displaying
/// additional information or enabling additional features.
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
pub enum ChainType {
/// A development chain that runs mainly on one node.
Development,
/// A local chain that runs locally on multiple nodes for testing purposes.
Local,
/// A live chain.
Live,
/// Some custom chain type.
Custom(String),
}

impl Default for ChainType {
fn default() -> Self {
Self::Live
}
}

/// Arbitrary properties defined in chain spec as a JSON object
pub type Properties = serde_json::map::Map<String, serde_json::Value>;

/// A set of traits for the runtime genesis config.
pub trait RuntimeGenesis: Serialize + DeserializeOwned + BuildStorage {}
impl<T: Serialize + DeserializeOwned + BuildStorage> RuntimeGenesis for T {}
Expand Down
2 changes: 1 addition & 1 deletion client/executor/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pwasm-utils = "0.18.0"
codec = { package = "parity-scale-codec", version = "2.0.0" }
wasmi = "0.9.0"
sp-core = { version = "3.0.0", path = "../../../primitives/core" }
sp-allocator = { version = "3.0.0", path = "../../../primitives/allocator" }
sc-allocator = { version = "3.0.0", path = "../../allocator" }
sp-wasm-interface = { version = "3.0.0", path = "../../../primitives/wasm-interface" }
sp-maybe-compressed-blob = { version = "3.0.0", path = "../../../primitives/maybe-compressed-blob" }
sp-serializer = { version = "3.0.0", path = "../../../primitives/serializer" }
Expand Down
2 changes: 1 addition & 1 deletion client/executor/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub enum Error {
Other(String),

#[error(transparent)]
Allocator(#[from] sp_allocator::Error),
Allocator(#[from] sc_allocator::Error),

#[error("Host function {0} execution failed with: {1}")]
FunctionExecution(String, String),
Expand Down
4 changes: 2 additions & 2 deletions client/executor/runtime-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository = "https://github.com/paritytech/substrate/"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
sp-allocator = { version = "3.0.0", default-features = false, path = "../../../primitives/allocator" }
sc-allocator = { version = "3.0.0", default-features = false, path = "../../allocator" }
sp-core = { version = "3.0.0", default-features = false, path = "../../../primitives/core" }
sp-io = { version = "3.0.0", default-features = false, path = "../../../primitives/io" }
sp-runtime = { version = "3.0.0", default-features = false, path = "../../../primitives/runtime" }
Expand All @@ -27,7 +27,7 @@ substrate-wasm-builder = { version = "4.0.0", path = "../../../utils/wasm-builde
[features]
default = [ "std" ]
std = [
"sp-allocator/std",
"sc-allocator/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
Expand Down
8 changes: 0 additions & 8 deletions client/executor/runtime-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ sp_core::wasm_export_functions! {
code
}


fn test_sandbox_get_global_val(code: Vec<u8>) -> i64 {
let env_builder = sp_sandbox::EnvironmentDefinitionBuilder::new();
let instance = if let Ok(i) = sp_sandbox::Instance::new(&code, &env_builder, &mut ()) {
Expand All @@ -227,12 +226,10 @@ sp_core::wasm_export_functions! {
}
}


fn test_offchain_index_set() {
sp_io::offchain_index::set(b"k", b"v");
}


fn test_offchain_local_storage() -> bool {
let kind = sp_core::offchain::StorageKind::PERSISTENT;
assert_eq!(sp_io::offchain::local_storage_get(kind, b"test"), None);
Expand Down Expand Up @@ -286,11 +283,6 @@ sp_core::wasm_export_functions! {
run().is_some()
}

// Just some test to make sure that `sp-allocator` compiles on `no_std`.
fn test_sp_allocator_compiles() {
sp_allocator::FreeingBumpHeapAllocator::new(0);
}

fn test_enter_span() -> u64 {
wasm_tracing::enter_span(Default::default())
}
Expand Down
2 changes: 1 addition & 1 deletion client/executor/wasmi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ log = "0.4.8"
wasmi = "0.9.0"
codec = { package = "parity-scale-codec", version = "2.0.0" }
sc-executor-common = { version = "0.9.0", path = "../common" }
sc-allocator = { version = "3.0.0", path = "../../allocator" }
sp-wasm-interface = { version = "3.0.0", path = "../../../primitives/wasm-interface" }
sp-runtime-interface = { version = "3.0.0", path = "../../../primitives/runtime-interface" }
sp-core = { version = "3.0.0", path = "../../../primitives/core" }
sp-allocator = { version = "3.0.0", path = "../../../primitives/allocator" }
4 changes: 2 additions & 2 deletions client/executor/wasmi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use sc_executor_common::runtime_blob::{RuntimeBlob, DataSegmentsSnapshot};

struct FunctionExecutor<'a> {
sandbox_store: sandbox::Store<wasmi::FuncRef>,
heap: sp_allocator::FreeingBumpHeapAllocator,
heap: sc_allocator::FreeingBumpHeapAllocator,
memory: MemoryRef,
table: Option<TableRef>,
host_functions: &'a [&'static dyn Function],
Expand All @@ -59,7 +59,7 @@ impl<'a> FunctionExecutor<'a> {
) -> Result<Self, Error> {
Ok(FunctionExecutor {
sandbox_store: sandbox::Store::new(),
heap: sp_allocator::FreeingBumpHeapAllocator::new(heap_base),
heap: sc_allocator::FreeingBumpHeapAllocator::new(heap_base),
memory: m,
table: t,
host_functions,
Expand Down
2 changes: 1 addition & 1 deletion client/executor/wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sc-executor-common = { version = "0.9.0", path = "../common" }
sp-wasm-interface = { version = "3.0.0", path = "../../../primitives/wasm-interface" }
sp-runtime-interface = { version = "3.0.0", path = "../../../primitives/runtime-interface" }
sp-core = { version = "3.0.0", path = "../../../primitives/core" }
sp-allocator = { version = "3.0.0", path = "../../../primitives/allocator" }
sc-allocator = { version = "3.0.0", path = "../../allocator" }
wasmtime = "0.27.0"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion client/executor/wasmtime/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::util;
use std::{cell::RefCell, rc::Rc};
use log::trace;
use codec::{Encode, Decode};
use sp_allocator::FreeingBumpHeapAllocator;
use sc_allocator::FreeingBumpHeapAllocator;
use sc_executor_common::error::Result;
use sc_executor_common::sandbox::{self, SandboxCapabilities, SupervisorFuncIndex};
use sp_core::sandbox as sandbox_primitives;
Expand Down
Loading