Skip to content

Commit

Permalink
Dedicated Parachain Runtime (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshOrndorff authored Apr 2, 2024
1 parent e18e601 commit 16906d1
Show file tree
Hide file tree
Showing 17 changed files with 653 additions and 154 deletions.
38 changes: 34 additions & 4 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"tuxedo-core/no_bound",
"tuxedo-parachain-core/register_validate_block",
"tuxedo-parachain-core",
"tuxedo-parachain-runtime",
"wallet",
"wardrobe/amoeba",
"wardrobe/money",
Expand Down
8 changes: 2 additions & 6 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
cli::{Cli, Subcommand},
service,
};
use node_template_runtime::Runtime;
use node_template_runtime::opaque::Block as OpaqueBlock;
use sc_cli::SubstrateCli;
use sc_service::PartialComponents;

Expand Down Expand Up @@ -121,11 +121,7 @@ pub fn run() -> sc_cli::Result<()> {
}
Some(Subcommand::ChainInfo(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| {
cmd.run::<<Runtime as sp_runtime::traits::GetRuntimeBlockType>::RuntimeBlock>(
&config,
)
})
runner.sync_run(|config| cmd.run::<OpaqueBlock>(&config))
}
Some(Subcommand::Custom(_)) => {
todo!()
Expand Down
2 changes: 1 addition & 1 deletion parachain-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ parity-scale-codec = { workspace = true }
serde = { features = [ "derive" ], workspace = true }

# Local
parachain-template-runtime = { features = [ "parachain" ], package = "tuxedo-template-runtime", path = "../tuxedo-template-runtime" }
parachain-template-runtime = { package = "tuxedo-parachain-runtime", path = "../tuxedo-parachain-runtime" }
tuxedo-core = { path = "../tuxedo-core" }

# Substrate
Expand Down
72 changes: 72 additions & 0 deletions tuxedo-parachain-runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[package]
description = "An example and template runtime built with Tuxedo."
edition = "2021"
license = "Apache-2.0"
name = "tuxedo-parachain-runtime"
repository = "https://github.com/Off-Narative-Labs/Tuxedo"
version = "1.0.0-dev"

[dependencies]
log = { workspace = true }
parity-scale-codec = { features = [ "derive" ], workspace = true }
parity-util-mem = { optional = true, workspace = true }
scale-info = { features = [ "derive", "serde" ], workspace = true }
serde = { features = [ "derive" ], workspace = true }

sp-api = { default_features = false, workspace = true }
sp-block-builder = { default_features = false, workspace = true }
sp-core = { features = [ "serde" ], default_features = false, workspace = true }
sp-debug-derive = { features = [ "force-debug" ], default_features = false, workspace = true }
sp-inherents = { default_features = false, workspace = true }
sp-io = { features = [ "with-tracing" ], default_features = false, workspace = true }
sp-runtime = { features = [ "serde" ], default_features = false, workspace = true }
sp-session = { default_features = false, workspace = true }
sp-std = { default_features = false, workspace = true }
sp-storage = { default_features = false, workspace = true }
sp-timestamp = { default_features = false, workspace = true }
sp-transaction-pool = { default_features = false, workspace = true }
sp-version = { default_features = false, workspace = true }

# The inner runtime
inner-runtime = { default-features = false, package = "tuxedo-template-runtime", path = "../tuxedo-template-runtime" }

# These were added for Aura / Grandpa API support
hex-literal = { workspace = true }
sp-application-crypto = { default_features = false, workspace = true }
sp-consensus-aura = { default_features = false, workspace = true }
sp-consensus-grandpa = { default_features = false, workspace = true }

# Parachain related ones
cumulus-primitives-core = { default-features = false, workspace = true }
parachain-piece = { default-features = false, path = "../wardrobe/parachain" }
tuxedo-parachain-core = { default-features = false, path = "../tuxedo-parachain-core" }

[build-dependencies]
substrate-wasm-builder = { workspace = true }

[features]
default = [ "std" ]
std = [
"sp-debug-derive/std",
"sp-block-builder/std",
"sp-inherents/std",
"parity-scale-codec/std",
"sp-core/std",
"sp-std/std",
"serde/std",
"sp-api/std",
"sp-session/std",
"sp-io/std",
"sp-runtime/std",
"sp-transaction-pool/std",
"sp-version/std",
"parity-util-mem",
"sp-storage/std",
"sp-consensus-aura/std",
"sp-application-crypto/std",
"sp-consensus-grandpa/std",
"inner-runtime/std",
"cumulus-primitives-core/std",
"parachain-piece/std",
"tuxedo-parachain-core/std",
]
13 changes: 13 additions & 0 deletions tuxedo-parachain-runtime/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[cfg(feature = "std")]
fn main() {
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
}

/// The wasm builder is deactivated when compiling
/// this crate for wasm to speed up the compilation.
#[cfg(not(feature = "std"))]
fn main() {}
51 changes: 51 additions & 0 deletions tuxedo-parachain-runtime/src/genesis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//! Helper module to build a genesis configuration for the template runtime.

use super::{OuterConstraintChecker, OuterVerifier, WASM_BINARY};
use hex_literal::hex;
use inner_runtime::{money::Coin, OuterConstraintChecker as InnerConstraintChecker};
use tuxedo_parachain_core::tuxedo_core::{
genesis::TuxedoGenesisConfig,
verifier::{Sr25519Signature, ThresholdMultiSignature},
ConstraintChecker,
};

/// Helper type for the ChainSpec.
pub type RuntimeGenesisConfig = TuxedoGenesisConfig<OuterVerifier, OuterConstraintChecker>;

const SHAWN_PUB_KEY_BYTES: [u8; 32] =
hex!("d2bf4b844dfefd6772a8843e669f943408966a977e3ae2af1dd78e0f55f4df67");
const ANDREW_PUB_KEY_BYTES: [u8; 32] =
hex!("baa81e58b1b4d053c2e86d93045765036f9d265c7dfe8b9693bbc2c0f048d93a");

pub fn development_genesis_config() -> RuntimeGenesisConfig {
let signatories = vec![SHAWN_PUB_KEY_BYTES.into(), ANDREW_PUB_KEY_BYTES.into()];

let user_genesis_transactions = [
// Money Transactions
Coin::<0>::mint::<_, _, InnerConstraintChecker>(
100,
Sr25519Signature::new(SHAWN_PUB_KEY_BYTES),
)
.transform(),
Coin::<0>::mint::<_, _, InnerConstraintChecker>(
100,
ThresholdMultiSignature::new(1, signatories),
)
.transform(),
// No Kitty or anything else in this one. Keep it simple.
]
.into_iter()
.map(Into::into);

// The inherents are computed using the appropriate method, and placed before the user transactions.
// Ideally this will get better upstream eventually.
let mut genesis_transactions = OuterConstraintChecker::genesis_transactions();
genesis_transactions.extend(user_genesis_transactions);

RuntimeGenesisConfig::new(
WASM_BINARY
.expect("Runtime WASM binary must exist.")
.to_vec(),
genesis_transactions,
)
}
Loading

0 comments on commit 16906d1

Please sign in to comment.