diff --git a/Cargo.lock b/Cargo.lock index b0268cde..0cf67514 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2525,25 +2525,6 @@ dependencies = [ "thousands", ] -[[package]] -name = "frame-executive" -version = "28.0.0" -source = "git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin#c4a04f05a2d1c5e463385e74014d36a867d73adf" -dependencies = [ - "aquamarine", - "frame-support", - "frame-system", - "frame-try-runtime", - "log", - "parity-scale-codec", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std 14.0.0 (git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin)", - "sp-tracing 16.0.0 (git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin)", -] - [[package]] name = "frame-metadata" version = "16.0.0" @@ -2658,21 +2639,6 @@ dependencies = [ "sp-weights", ] -[[package]] -name = "frame-system-benchmarking" -version = "28.0.0" -source = "git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin#c4a04f05a2d1c5e463385e74014d36a867d73adf" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "parity-scale-codec", - "scale-info", - "sp-core", - "sp-runtime", - "sp-std 14.0.0 (git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin)", -] - [[package]] name = "frame-system-rpc-runtime-api" version = "26.0.0" @@ -5508,39 +5474,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" -[[package]] -name = "polkadot-sdk-frame" -version = "0.1.0" -source = "git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin#c4a04f05a2d1c5e463385e74014d36a867d73adf" -dependencies = [ - "docify", - "frame-benchmarking", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-benchmarking", - "frame-system-rpc-runtime-api", - "frame-try-runtime", - "log", - "parity-scale-codec", - "scale-info", - "sp-api", - "sp-arithmetic", - "sp-block-builder", - "sp-consensus-aura", - "sp-consensus-grandpa", - "sp-core", - "sp-inherents", - "sp-io", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-std 14.0.0 (git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin)", - "sp-storage 19.0.0 (git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin)", - "sp-transaction-pool", - "sp-version", -] - [[package]] name = "polkavm" version = "0.9.3" @@ -8132,22 +8065,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "sp-consensus-aura" -version = "0.32.0" -source = "git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin#c4a04f05a2d1c5e463385e74014d36a867d73adf" -dependencies = [ - "async-trait", - "parity-scale-codec", - "scale-info", - "sp-api", - "sp-application-crypto", - "sp-consensus-slots", - "sp-inherents", - "sp-runtime", - "sp-timestamp", -] - [[package]] name = "sp-consensus-grandpa" version = "13.0.0" @@ -8165,17 +8082,6 @@ dependencies = [ "sp-runtime", ] -[[package]] -name = "sp-consensus-slots" -version = "0.32.0" -source = "git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin#c4a04f05a2d1c5e463385e74014d36a867d73adf" -dependencies = [ - "parity-scale-codec", - "scale-info", - "serde", - "sp-timestamp", -] - [[package]] name = "sp-core" version = "28.0.0" @@ -8642,18 +8548,6 @@ dependencies = [ "sp-debug-derive 14.0.0 (git+https://github.com/paritytech/polkadot-sdk)", ] -[[package]] -name = "sp-timestamp" -version = "26.0.0" -source = "git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin#c4a04f05a2d1c5e463385e74014d36a867d73adf" -dependencies = [ - "async-trait", - "parity-scale-codec", - "sp-inherents", - "sp-runtime", - "thiserror", -] - [[package]] name = "sp-tracing" version = "16.0.0" @@ -8968,7 +8862,6 @@ dependencies = [ "jsonrpsee", "pallet-bitcoin", "parity-scale-codec", - "polkadot-sdk-frame", "sc-cli", "sc-client-api", "sc-consensus", @@ -9018,15 +8911,23 @@ name = "subcoin-runtime" version = "0.1.0" dependencies = [ "frame-support", + "frame-system", + "frame-system-rpc-runtime-api", "log", "pallet-bitcoin", "pallet-executive", "parity-scale-codec", - "polkadot-sdk-frame", "scale-info", "sp-api", + "sp-block-builder", + "sp-core", "sp-genesis-builder", + "sp-inherents", "sp-runtime", + "sp-session", + "sp-std 14.0.0 (git+https://github.com/liuchengxu/polkadot-sdk?branch=subcoin)", + "sp-transaction-pool", + "sp-version", "subcoin-runtime-primitives", "substrate-wasm-builder", ] diff --git a/Cargo.toml b/Cargo.toml index aacb45cc..0b58985c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,8 +53,8 @@ tracing = "0.1" frame-benchmarking-cli = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } frame-support = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } frame-system = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } +frame-system-rpc-runtime-api = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } frame-try-runtime = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } -frame = { package = "polkadot-sdk-frame", git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } pallet-balances = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } pallet-transaction-payment = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } # Disable the default `rocksdb` feature @@ -76,6 +76,7 @@ sc-transaction-pool-api = { git = "https://github.com/liuchengxu/polkadot-sdk", sc-utils = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin" } sp-api = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } sp-blockchain = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } +sp-block-builder = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } sp-consensus = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } sp-core = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } sp-database = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } @@ -86,10 +87,12 @@ sp-inherents = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "s sp-io = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } sp-rpc = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin" } sp-runtime = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } +sp-session = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } sp-state-machine = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin" } sp-std = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } sp-storage = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } sp-tracing = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } +sp-transaction-pool = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } sp-trie = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } sp-version = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin", default-features = false } substrate-build-script-utils = { git = "https://github.com/liuchengxu/polkadot-sdk", branch = "subcoin" } diff --git a/crates/pallet-bitcoin/Cargo.toml b/crates/pallet-bitcoin/Cargo.toml index 179cec72..8122f829 100644 --- a/crates/pallet-bitcoin/Cargo.toml +++ b/crates/pallet-bitcoin/Cargo.toml @@ -34,3 +34,7 @@ std = [ "sp-std/std", "subcoin-runtime-primitives/std", ] +try-runtime = [ + "frame-system/try-runtime", + "sp-runtime/try-runtime", +] diff --git a/crates/subcoin-node/Cargo.toml b/crates/subcoin-node/Cargo.toml index 48d96b68..1c88c3db 100644 --- a/crates/subcoin-node/Cargo.toml +++ b/crates/subcoin-node/Cargo.toml @@ -8,7 +8,7 @@ license.workspace = true [[bin]] name = "subcoin" -path = "src/main.rs" +path = "src/bin/subcoin.rs" [dependencies] async-trait = { workspace = true } @@ -16,7 +16,6 @@ bitcoin = { workspace = true } bitcoin-explorer = { workspace = true, default-features = false } clap = { workspace = true, features = ["derive"] } codec = { workspace = true } -frame = { workspace = true } frame-benchmarking-cli = { workspace = true } futures = { workspace = true } hex = { workspace = true } diff --git a/crates/subcoin-node/src/bin/subcoin.rs b/crates/subcoin-node/src/bin/subcoin.rs new file mode 100644 index 00000000..5a356c40 --- /dev/null +++ b/crates/subcoin-node/src/bin/subcoin.rs @@ -0,0 +1,4 @@ +fn main() -> sc_cli::Result<()> { + subcoin_node::run()?; + Ok(()) +} diff --git a/crates/subcoin-node/src/main.rs b/crates/subcoin-node/src/lib.rs similarity index 89% rename from crates/subcoin-node/src/main.rs rename to crates/subcoin-node/src/lib.rs index 104dd33e..0daeceae 100644 --- a/crates/subcoin-node/src/main.rs +++ b/crates/subcoin-node/src/lib.rs @@ -2,10 +2,7 @@ mod cli; mod commands; mod substrate_cli; -fn main() -> sc_cli::Result<()> { - cli::run()?; - Ok(()) -} +pub use self::cli::run; pub struct CoinStorageKey; diff --git a/crates/subcoin-runtime/Cargo.toml b/crates/subcoin-runtime/Cargo.toml index d8faa599..3c10cee0 100644 --- a/crates/subcoin-runtime/Cargo.toml +++ b/crates/subcoin-runtime/Cargo.toml @@ -9,16 +9,23 @@ repository.workspace = true [dependencies] codec = { workspace = true, default-features = false } -# this is a frame-based runtime, thus importing `frame` with runtime feature enabled. -frame = { workspace = true, default-features = false, features = ["experimental", "runtime"] } pallet-executive = { workspace = true, default-features = false } +frame-system = { workspace = true, default-features = false } +frame-system-rpc-runtime-api = { workspace = true, default-features = false } frame-support = { workspace = true, default-features = false } log = { workspace = true, default-features = false } pallet-bitcoin = { workspace = true, default-features = false } scale-info = { workspace = true, default-features = false } sp-api = { workspace = true, default-features = false } +sp-block-builder = { workspace = true, default-features = false } +sp-core = { workspace = true, default-features = false } sp-genesis-builder = { workspace = true, default-features = false } +sp-inherents = { workspace = true, default-features = false } sp-runtime = { workspace = true, default-features = false } +sp-session = { workspace = true, default-features = false } +sp-std = { workspace = true, default-features = false } +sp-transaction-pool = { workspace = true, default-features = false } +sp-version = { workspace = true, default-features = false } subcoin-runtime-primitives = { workspace = true, default-features = false } [build-dependencies] @@ -28,15 +35,23 @@ substrate-wasm-builder = { workspace = true, optional = true } default = ["std"] std = [ "codec/std", - "frame/std", "pallet-executive/std", + "frame-system/std", + "frame-system-rpc-runtime-api/std", "frame-support/std", "log/std", "pallet-bitcoin/std", "scale-info/std", "sp-api/std", + "sp-block-builder/std", + "sp-core/std", "sp-genesis-builder/std", + "sp-inherents/std", "sp-runtime/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", "substrate-wasm-builder", "subcoin-runtime-primitives/std", ] diff --git a/crates/subcoin-runtime/src/lib.rs b/crates/subcoin-runtime/src/lib.rs index 9b053776..1c59d8fe 100644 --- a/crates/subcoin-runtime/src/lib.rs +++ b/crates/subcoin-runtime/src/lib.rs @@ -24,19 +24,21 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -use frame::prelude::*; -use frame::runtime::apis::{ - self, impl_runtime_apis, ApplyExtrinsicResult, CheckInherentsResult, ExtrinsicInclusionMode, - OpaqueMetadata, -}; -#[cfg(feature = "std")] -use frame::runtime::prelude::NativeVersion; -use frame::runtime::prelude::{ - construct_runtime, create_runtime_str, derive_impl, parameter_types, runtime_version, - RuntimeVersion, -}; use frame_support::genesis_builder_helper::{build_state, get_preset}; +use frame_support::{construct_runtime, derive_impl, parameter_types}; +use frame_system::pallet_prelude::*; use pallet_executive::Executive; +use sp_api::impl_runtime_apis; +use sp_core::{ConstU32, OpaqueMetadata}; +use sp_inherents::{CheckInherentsResult, InherentData}; +use sp_runtime::transaction_validity::{TransactionSource, TransactionValidity}; +use sp_runtime::{ApplyExtrinsicResult, ExtrinsicInclusionMode}; +use sp_std::boxed::Box; +use sp_std::vec; +use sp_std::vec::Vec; +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::{create_runtime_str, runtime_version, RuntimeVersion}; #[runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { @@ -88,8 +90,8 @@ impl pallet_bitcoin::Config for Runtime { type WeightInfo = (); } -type Signature = frame::runtime::types_common::Signature; -type Block = frame::runtime::types_common::BlockOf; +type Signature = crate::types_common::Signature; +type Block = crate::types_common::BlockOf; // TODO: Proper address pub type Address = sp_runtime::MultiAddress; pub type Header = HeaderFor; @@ -100,7 +102,7 @@ type RuntimeExecutive = Executive, Runtime, AllPalletsWithSystem>; impl_runtime_apis! { - impl apis::Core for Runtime { + impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION } @@ -114,7 +116,7 @@ impl_runtime_apis! { } } - impl apis::Metadata for Runtime { + impl sp_api::Metadata for Runtime { fn metadata() -> OpaqueMetadata { OpaqueMetadata::new(Runtime::metadata().into()) } @@ -129,7 +131,7 @@ impl_runtime_apis! { } // Cannot be removed as required by frame-benchmarking-cli. - impl apis::BlockBuilder for Runtime { + impl sp_block_builder::BlockBuilder for Runtime { fn apply_extrinsic(extrinsic: ExtrinsicFor) -> ApplyExtrinsicResult { RuntimeExecutive::apply_extrinsic(extrinsic) } @@ -150,7 +152,7 @@ impl_runtime_apis! { } } - impl apis::TaggedTransactionQueue for Runtime { + impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { fn validate_transaction( source: TransactionSource, tx: ExtrinsicFor, @@ -163,20 +165,20 @@ impl_runtime_apis! { // Cannot be removed as required by `sc_service::spawn_tasks()`. // // TODO: remove if we introduce our own version of spawn_tasks. - impl apis::SessionKeys for Runtime { + impl sp_session::SessionKeys for Runtime { fn generate_session_keys(_seed: Option>) -> Vec { Default::default() } fn decode_session_keys( _encoded: Vec, - ) -> Option, apis::KeyTypeId)>> { + ) -> Option, sp_session::KeyTypeId)>> { Default::default() } } // Cannot be removed as required by SystemApiServer in rpc. - impl apis::AccountNonceApi for Runtime { + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { fn account_nonce(account: interface::AccountId) -> interface::Nonce { System::account_nonce(account) } @@ -207,6 +209,59 @@ impl_runtime_apis! { } } +/// A set of opinionated types aliases commonly used in runtimes. +/// +/// This is one set of opinionated types. They are compatible with one another, but are not +/// guaranteed to work if you start tweaking a portion. +/// +/// Some note-worthy opinions in this prelude: +/// +/// - `u32` block number. +/// - [`sp_runtime::MultiAddress`] and [`sp_runtime::MultiSignature`] are used as the account id +/// and signature types. This implies that this prelude can possibly used with an +/// "account-index" system (eg `pallet-indices`). And, in any case, it should be paired with +/// `AccountIdLookup` in [`frame_system::Config::Lookup`]. +mod types_common { + use frame_system::Config as SysConfig; + use sp_runtime::{generic, traits, OpaqueExtrinsic}; + + /// A signature type compatible capably of handling multiple crypto-schemes. + pub type Signature = sp_runtime::MultiSignature; + + /// The corresponding account-id type of [`Signature`]. + pub type AccountId = + <::Signer as traits::IdentifyAccount>::AccountId; + + /// The block-number type, which should be fed into [`frame_system::Config`]. + pub type BlockNumber = u32; + + /// TODO: Ideally we want the hashing type to be equal to SysConfig::Hashing? + type HeaderInner = generic::Header; + + // NOTE: `AccountIndex` is provided for future compatibility, if you want to introduce + // something like `pallet-indices`. + type ExtrinsicInner = generic::UncheckedExtrinsic< + sp_runtime::MultiAddress, + ::RuntimeCall, + Signature, + Extra, + >; + + /// The block type, which should be fed into [`frame_system::Config`]. + /// + /// Should be parameterized with `T: frame_system::Config` and a tuple of `SignedExtension`. + /// When in doubt, use [`SystemSignedExtensionsOf`]. + // Note that this cannot be dependent on `T` for block-number because it would lead to a + // circular dependency (self-referential generics). + pub type BlockOf = generic::Block>; + + /// The opaque block type. This is the same [`BlockOf`], but it has + /// [`sp_runtime::OpaqueExtrinsic`] as its final extrinsic type. + /// + /// This should be provided to the client side as the extrinsic type. + pub type OpaqueBlock = generic::Block; +} + /// Some re-exports that the node side code needs to know. Some are useful in this context as well. /// /// Other types should preferably be private. @@ -214,10 +269,9 @@ impl_runtime_apis! { // https://github.com/paritytech/substrate/issues/10579#issuecomment-1600537558 pub mod interface { use super::Runtime; - use frame::deps::frame_system; pub type Block = super::Block; - pub use frame::runtime::types_common::OpaqueBlock; + pub use crate::types_common::OpaqueBlock; pub type AccountId = ::AccountId; pub type Nonce = ::Nonce; pub type Hash = ::Hash;