Skip to content

Commit

Permalink
integrate core eth relay domain runtime (#1305)
Browse files Browse the repository at this point in the history
* integrate core eth relay domain runtime with subspace node and domain cli
  • Loading branch information
ParthDesai authored Apr 2, 2023
1 parent ccd4d35 commit 0043ed4
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 52 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ where

let wasm_bundle = match *domain_id {
DomainId::SYSTEM => system_wasm_bundle,
DomainId::CORE_PAYMENTS => {
DomainId::CORE_PAYMENTS | DomainId::CORE_ETH_RELAY => {
read_core_domain_runtime_blob(system_wasm_bundle.as_ref(), *domain_id)
.map_err(|err| {
VerificationError::RuntimeCode(format!(
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ targets = ["x86_64-unknown-linux-gnu"]
bytesize = "1.2.0"
clap = { version = "4.1.6", features = ["derive"] }
cross-domain-message-gossip = { version = "0.1.0", path = "../../domains/client/cross-domain-message-gossip" }
core-eth-relay-runtime = { version = "0.1.0", path = "../../domains/runtime/core-eth-relay" }
core-payments-domain-runtime = { version = "0.1.0", path = "../../domains/runtime/core-payments" }
dirs = "4.0.0"
domain-client-executor = { version = "0.1.0", path = "../../domains/client/domain-executor" }
Expand Down
44 changes: 44 additions & 0 deletions crates/subspace-node/src/bin/subspace-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ impl NativeExecutionDispatch for CorePaymentsDomainExecutorDispatch {
}
}

/// Core eth relay domain executor instance.
pub struct CoreEthRelayDomainExecutorDispatch;

impl NativeExecutionDispatch for CoreEthRelayDomainExecutorDispatch {
#[cfg(feature = "runtime-benchmarks")]
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
#[cfg(not(feature = "runtime-benchmarks"))]
type ExtendHostFunctions = ();

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
core_eth_relay_runtime::api::dispatch(method, data)
}

fn native_version() -> sc_executor::NativeVersion {
core_eth_relay_runtime::native_version()
}
}

/// Subspace node error.
#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down Expand Up @@ -655,6 +673,32 @@ fn main() -> Result<(), Error> {

core_domain_node.network_starter.start_network();
}
DomainId::CORE_ETH_RELAY => {
let core_domain_node =
domain_service::new_full_core::<
_,
_,
_,
_,
_,
_,
_,
_,
core_eth_relay_runtime::RuntimeApi,
CoreEthRelayDomainExecutorDispatch,
>(core_domain_params)
.await?;

domain_tx_pool_sinks.insert(
core_domain_cli.domain_id,
core_domain_node.tx_pool_sink,
);
primary_chain_node
.task_manager
.add_child(core_domain_node.task_manager);

core_domain_node.network_starter.start_network();
}
core_domain_id => {
return Err(Error::Other(format!(
"{core_domain_id:?} unimplemented",
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-node/src/core_domain.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub(crate) mod cli;
pub(crate) mod core_eth_relay_chain_spec;
pub(crate) mod core_payments_chain_spec;
4 changes: 3 additions & 1 deletion crates/subspace-node/src/core_domain/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::core_domain::core_payments_chain_spec;
use crate::core_domain::{core_eth_relay_chain_spec, core_payments_chain_spec};
use crate::parser::parse_relayer_id;
use clap::Parser;
use domain_runtime_primitives::RelayerId;
Expand Down Expand Up @@ -153,6 +153,7 @@ impl SubstrateCli for CoreDomainCli {
// TODO: add core domain chain spec an extension of system domain chain spec.
match self.domain_id {
DomainId::CORE_PAYMENTS => core_payments_chain_spec::load_chain_spec(id),
DomainId::CORE_ETH_RELAY => core_eth_relay_chain_spec::load_chain_spec(id),
domain_id => unreachable!("Unsupported core domain: {domain_id:?}"),
}
}
Expand All @@ -163,6 +164,7 @@ impl SubstrateCli for CoreDomainCli {
.expect("Initialized when constructing this struct")
{
&DomainId::CORE_PAYMENTS => &core_payments_domain_runtime::VERSION,
&DomainId::CORE_ETH_RELAY => &core_eth_relay_runtime::VERSION,
domain_id => unreachable!("Unsupported core domain: {domain_id:?}"),
}
}
Expand Down
229 changes: 229 additions & 0 deletions crates/subspace-node/src/core_domain/core_eth_relay_chain_spec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
// Copyright (C) 2021 Subspace Labs, Inc.
// SPDX-License-Identifier: GPL-3.0-or-later

// This program 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.

// This program 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 this program. If not, see <https://www.gnu.org/licenses/>.

//! Core eth relay domain configurations.

use crate::chain_spec_utils::{chain_spec_properties, get_account_id_from_seed};
use core_eth_relay_runtime::{
AccountId, BalancesConfig, EthereumBeaconClientConfig, GenesisConfig, MessengerConfig,
SudoConfig, SystemConfig, WASM_BINARY,
};
use domain_runtime_primitives::RelayerId;
use sc_service::ChainType;
use sc_subspace_chain_specs::ExecutionChainSpec;
use sp_core::crypto::Ss58Codec;
use subspace_runtime_primitives::SSC;

pub type ChainSpec = ExecutionChainSpec<GenesisConfig>;

pub fn development_config() -> ExecutionChainSpec<GenesisConfig> {
ExecutionChainSpec::from_genesis(
// Name
"Development",
// ID
"core_eth_relay_domain_dev",
ChainType::Development,
move || {
testnet_genesis(
vec![
get_account_id_from_seed("Alice"),
get_account_id_from_seed("Bob"),
get_account_id_from_seed("Alice//stash"),
get_account_id_from_seed("Bob//stash"),
],
Some(get_account_id_from_seed("Alice")),
vec![(
get_account_id_from_seed("Alice"),
get_account_id_from_seed("Alice"),
)],
)
},
vec![],
None,
None,
None,
Some(chain_spec_properties()),
None,
)
}

pub fn local_testnet_config() -> ExecutionChainSpec<GenesisConfig> {
ExecutionChainSpec::from_genesis(
// Name
"Local Testnet",
// ID
"core_eth_relay_domain_local_testnet",
ChainType::Local,
move || {
testnet_genesis(
vec![
get_account_id_from_seed("Alice"),
get_account_id_from_seed("Bob"),
get_account_id_from_seed("Charlie"),
get_account_id_from_seed("Dave"),
get_account_id_from_seed("Eve"),
get_account_id_from_seed("Ferdie"),
get_account_id_from_seed("Alice//stash"),
get_account_id_from_seed("Bob//stash"),
get_account_id_from_seed("Charlie//stash"),
get_account_id_from_seed("Dave//stash"),
get_account_id_from_seed("Eve//stash"),
get_account_id_from_seed("Ferdie//stash"),
],
Some(get_account_id_from_seed("Alice")),
vec![
(
get_account_id_from_seed("Alice"),
get_account_id_from_seed("Alice"),
),
(
get_account_id_from_seed("Bob"),
get_account_id_from_seed("Bob"),
),
],
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
Some("template-local"),
None,
// Properties
Some(chain_spec_properties()),
// Extensions
None,
)
}

pub fn gemini_3d_config() -> ExecutionChainSpec<GenesisConfig> {
ExecutionChainSpec::from_genesis(
// Name
"Subspace Gemini 3d Core Eth Relay Domain",
// ID
"subspace_gemini_3d_core_eth_relay_domain",
ChainType::Live,
move || {
let sudo_account =
AccountId::from_ss58check("5CXTmJEusve5ixyJufqHThmy4qUrrm6FyLCR7QfE4bbyMTNC")
.expect("Invalid Sudo account");
testnet_genesis(
vec![
// Genesis executor
AccountId::from_ss58check("5Df6w8CgYY8kTRwCu8bjBsFu46fy4nFa61xk6dUbL6G4fFjQ")
.expect("Wrong executor account address"),
// Sudo account
sudo_account.clone(),
],
Some(sudo_account),
Default::default(),
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
Some("subspace-gemini-3d-core-core-eth-relay-domain"),
None,
// Properties
Some(chain_spec_properties()),
// Extensions
None,
)
}

pub fn devnet_config() -> ExecutionChainSpec<GenesisConfig> {
ExecutionChainSpec::from_genesis(
// Name
"Subspace Devnet Core Eth Relay Domain",
// ID
"subspace_devnet_core_eth_relay_domain",
ChainType::Custom("Testnet".to_string()),
move || {
let sudo_account =
AccountId::from_ss58check("5CXTmJEusve5ixyJufqHThmy4qUrrm6FyLCR7QfE4bbyMTNC")
.expect("Invalid Sudo account");
testnet_genesis(
vec![
// Genesis executor
AccountId::from_ss58check("5Df6w8CgYY8kTRwCu8bjBsFu46fy4nFa61xk6dUbL6G4fFjQ")
.expect("Wrong executor account address"),
// Sudo account
sudo_account.clone(),
],
Some(sudo_account.clone()),
vec![(
sudo_account,
RelayerId::from_ss58check("5D7kgfacBsP6pkMB628221HG98mz2euaytthdoeZPGceQusS")
.expect("Wrong relayer account address"),
)],
)
},
// Bootnodes
vec![],
// Telemetry
None,
// Protocol ID
Some("subspace-devnet-core-eth-relay-domain"),
None,
// Properties
Some(chain_spec_properties()),
// Extensions
None,
)
}

pub fn load_chain_spec(spec_id: &str) -> std::result::Result<Box<dyn sc_cli::ChainSpec>, String> {
let chain_spec = match spec_id {
"dev" => development_config(),
"gemini-3d" => gemini_3d_config(),
"devnet" => devnet_config(),
"" | "local" => local_testnet_config(),
path => ChainSpec::from_json_file(std::path::PathBuf::from(path))?,
};
Ok(Box::new(chain_spec))
}

fn testnet_genesis(
endowed_accounts: Vec<AccountId>,
maybe_sudo_account: Option<AccountId>,
relayers: Vec<(AccountId, RelayerId)>,
) -> GenesisConfig {
GenesisConfig {
system: SystemConfig {
code: WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
},
sudo: SudoConfig {
key: maybe_sudo_account,
},
transaction_payment: Default::default(),
balances: BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, 1_000_000 * SSC))
.collect(),
},
messenger: MessengerConfig { relayers },
ethereum_beacon_client: EthereumBeaconClientConfig {
initial_sync: Default::default(),
},
}
}
Loading

0 comments on commit 0043ed4

Please sign in to comment.