Skip to content

Commit

Permalink
Refactor Container chain spawner logic in separate crate (#637)
Browse files Browse the repository at this point in the history
* refactor into separate crate

* cleanup

* POC: start embeded CC node in rpc provider

* forward features

* use same chainspec Extensions type

* move orchestrator_para_id in CollationParams
  • Loading branch information
nanocryk authored Jul 30, 2024
1 parent 3d6ee41 commit 8947ce5
Show file tree
Hide file tree
Showing 19 changed files with 1,403 additions and 900 deletions.
66 changes: 66 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ container-chain-template-simple-runtime = { path = "container-chains/runtime-tem

dancebox-runtime = { path = "runtime/dancebox", default-features = false }
flashbox-runtime = { path = "runtime/flashbox", default-features = false }

manual-xcm-rpc = { path = "client/manual-xcm" }
node-common = { path = "client/node-common" }
services-payment-rpc = { path = "client/services-payment" }
Expand All @@ -88,6 +89,8 @@ tanssi-relay-service = { path = "solo-chains/node/tanssi-relay-service", default
tanssi-runtime-common = { path = "runtime/common", default-features = false }
tc-consensus = { path = "client/consensus" }
tc-orchestrator-chain-rpc-interface = { path = "client/orchestrator-chain-rpc-interface" }
tc-service-container-chain = { path = "client/service-container-chain" }

tp-author-noting-inherent = { path = "primitives/author-noting-inherent", default-features = false }
tp-fungibles-ext = { path = "primitives/fungibles-ext", default-features = false }
tp-maths = { path = "primitives/maths", default-features = false }
Expand Down
103 changes: 103 additions & 0 deletions client/service-container-chain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
[package]
name = "tc-service-container-chain"
authors = { workspace = true }
build = "build.rs"
edition = "2021"
license = "GPL-3.0-only"
version = "0.1.0"

[lints]
workspace = true

[dependencies]
async-trait = { workspace = true }
clap = { workspace = true, features = [ "derive" ] }
flume = { workspace = true }
fs2 = { workspace = true }
futures = { workspace = true }
jsonrpsee = { workspace = true }
log = { workspace = true }
serde = { workspace = true }
tokio = { workspace = true }
tokio-util = { workspace = true }

# Local
ccp-authorities-noting-inherent = { workspace = true }
dancebox-runtime = { workspace = true, features = [ "std" ] }
manual-xcm-rpc = { workspace = true }
node-common = { workspace = true }
pallet-author-noting-runtime-api = { workspace = true, features = [ "std" ] }
services-payment-rpc = { workspace = true }
stream-payment-rpc = { workspace = true }
tc-consensus = { workspace = true }

# Dancekit
dc-orchestrator-chain-interface = { workspace = true }
dp-container-chain-genesis-data = { workspace = true, features = [ "json", "std" ] }
dp-slot-duration-runtime-api = { workspace = true }

# Substrate
sc-basic-authorship = { workspace = true }
sc-chain-spec = { workspace = true }
sc-cli = { workspace = true }
sc-client-api = { workspace = true }
sc-consensus = { workspace = true }
sc-consensus-manual-seal = { workspace = true }
sc-executor = { workspace = true }
sc-network = { workspace = true }
sc-network-sync = { workspace = true }
sc-rpc = { workspace = true }
sc-service = { workspace = true }
sc-telemetry = { workspace = true }
sc-tracing = { workspace = true }
sc-transaction-pool = { workspace = true }
sc-transaction-pool-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-consensus = { workspace = true }
substrate-frame-rpc-system = { workspace = true }
substrate-prometheus-endpoint = { workspace = true }

sp-api = { workspace = true, features = [ "std" ] }
sp-block-builder = { workspace = true, features = [ "std" ] }
sp-consensus-aura = { workspace = true, features = [ "std" ] }
sp-core = { workspace = true, features = [ "std" ] }
sp-keystore = { workspace = true, features = [ "std" ] }
sp-runtime = { workspace = true, features = [ "std" ] }
sp-timestamp = { workspace = true, features = [ "std" ] }

# Polkadot
polkadot-primitives = { workspace = true }

# Cumulus
cumulus-client-collator = { workspace = true }
cumulus-client-consensus-aura = { workspace = true }
cumulus-client-consensus-common = { workspace = true }
cumulus-client-consensus-proposer = { workspace = true }
cumulus-client-service = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-relay-chain-interface = { workspace = true }

# Nimbus
nimbus-consensus = { workspace = true }
nimbus-primitives = { workspace = true }

[build-dependencies]
substrate-build-script-utils = { workspace = true }

[features]
default = []
runtime-benchmarks = [
"cumulus-primitives-core/runtime-benchmarks",
"dancebox-runtime/runtime-benchmarks",
"nimbus-primitives/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"dancebox-runtime/try-runtime",
"nimbus-primitives/try-runtime",
"sp-runtime/try-runtime",
]

fast-runtime = [ "dancebox-runtime/fast-runtime" ]
23 changes: 23 additions & 0 deletions client/service-container-chain/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.

// Tanssi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Tanssi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed};

fn main() {
generate_cargo_keys();

rerun_if_git_head_changed();
}
78 changes: 78 additions & 0 deletions client/service-container-chain/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.

// Tanssi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Tanssi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use {
sc_chain_spec::{ChainSpecExtension, ChainSpecGroup},
serde::{Deserialize, Serialize},
std::collections::BTreeMap,
};

/// Specialized `ChainSpec` for container chains that only allows raw genesis format.
pub type RawChainSpec = sc_service::GenericChainSpec<RawGenesisConfig, Extensions>;

/// Helper type that implements the traits needed to be used as a "GenesisConfig",
/// but whose implementation panics because we only expect it to be used with raw ChainSpecs,
/// so it will never be serialized or deserialized.
/// This is because container chains must use raw chain spec files where the "genesis"
/// field only has one field: "raw".
pub struct RawGenesisConfig {
pub storage_raw: BTreeMap<Vec<u8>, Vec<u8>>,
}

impl Serialize for RawGenesisConfig {
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
panic!("RawGenesisConfigDummy should never be serialized")
}
}

impl<'de> Deserialize<'de> for RawGenesisConfig {
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
panic!("Attempted to read a non-raw ContainerChain ChainSpec.\nHelp: add `--raw` flag to `build-spec` command to generate a raw chain spec")
}
}

impl sp_runtime::BuildStorage for RawGenesisConfig {
fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> {
storage
.top
.extend(self.storage_raw.iter().map(|(k, v)| (k.clone(), v.clone())));

Ok(())
}
}

/// The extensions for the [`ChainSpec`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
pub struct Extensions {
/// The relay chain of the Parachain.
pub relay_chain: String,
/// The id of the Parachain.
pub para_id: u32,
}

impl Extensions {
/// Try to get the extension from the given `ChainSpec`.
pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {
sc_chain_spec::get_extension(chain_spec.extensions())
}
}
Loading

0 comments on commit 8947ce5

Please sign in to comment.