Skip to content
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
17 changes: 17 additions & 0 deletions Cargo.lock

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

22 changes: 12 additions & 10 deletions domains/client/domain-executor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use sp_runtime::generic::{BlockId, Digest, DigestItem};
use sp_runtime::traits::{BlakeTwo256, Hash as HashT, Header as HeaderT};
use std::collections::HashSet;
use subspace_core_primitives::BlockNumber;
use subspace_test_service::mock::MockPrimaryNode;
use subspace_wasm_tools::read_core_domain_runtime_blob;
use tempfile::TempDir;

Expand All @@ -35,23 +36,19 @@ async fn test_executor_full_node_catching_up() {
let tokio_handle = tokio::runtime::Handle::current();

// Start Ferdie
let (ferdie, ferdie_network_starter) = run_primary_chain_validator_node(
let mut ferdie = MockPrimaryNode::run_mock_primary_node(
tokio_handle.clone(),
Ferdie,
vec![],
BasePath::new(directory.path().join("ferdie")),
)
.await;
ferdie_network_starter.start_network();
);

// Run Alice (a system domain authority node)
let alice = domain_test_service::SystemDomainNodeBuilder::new(
tokio_handle.clone(),
Alice,
BasePath::new(directory.path().join("alice")),
)
.connect_to_primary_chain_node(&ferdie)
.build(Role::Authority, false, false)
.build_with_mock_primary_node(Role::Authority, &mut ferdie)
.await;

// Run Bob (a system domain full node)
Expand All @@ -60,12 +57,17 @@ async fn test_executor_full_node_catching_up() {
Bob,
BasePath::new(directory.path().join("bob")),
)
.connect_to_primary_chain_node(&ferdie)
.build(Role::Full, false, false)
.build_with_mock_primary_node(Role::Full, &mut ferdie)
.await;

// Bob is able to sync blocks.
futures::future::join(alice.wait_for_blocks(3), bob.wait_for_blocks(3)).await;
futures::join!(
alice.wait_for_blocks(3),
bob.wait_for_blocks(3),
ferdie.produce_n_blocks(3),
)
.2
.unwrap();

let alice_block_hash = alice
.client
Expand Down
128 changes: 128 additions & 0 deletions domains/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use std::sync::Arc;
use subspace_networking::libp2p::identity;
use subspace_runtime_primitives::opaque::Block as PBlock;
use subspace_service::{DsnConfig, SubspaceNetworking};
use subspace_test_service::mock::MockPrimaryNode;
use substrate_test_client::{
BlockchainEventsExt, RpcHandlersExt, RpcTransactionError, RpcTransactionOutput,
};
Expand Down Expand Up @@ -104,6 +105,7 @@ pub type Client =
///
/// A primary chain full node and system domain node will be started, similar to the behaviour in
/// the production.
/// TODO: remove once all the existing tests integrated with `MockPrimaryNode`
#[sc_tracing::logging::prefix_logs_with(system_domain_config.network.node_name.as_str())]
async fn run_executor(
system_domain_config: ServiceConfiguration,
Expand Down Expand Up @@ -262,6 +264,93 @@ async fn run_executor(
))
}

/// Start an executor with the given system domain `Configuration` and the mock primary node.
#[sc_tracing::logging::prefix_logs_with(system_domain_config.network.node_name.as_str())]
async fn run_executor_with_mock_primary_node(
system_domain_config: ServiceConfiguration,
mock_primary_node: &mut MockPrimaryNode,
) -> sc_service::error::Result<(
TaskManager,
Arc<Client>,
Arc<Backend>,
Arc<CodeExecutor>,
Arc<NetworkService<Block, H256>>,
RpcHandlers,
Executor,
)> {
let (gossip_msg_sink, gossip_msg_stream) =
sc_utils::mpsc::tracing_unbounded("cross_domain_gossip_messages", 100);
let system_domain_config = DomainConfiguration {
service_config: system_domain_config,
maybe_relayer_id: None,
};
let executor_streams = ExecutorStreams {
primary_block_import_throttling_buffer_size: 10,
subspace_imported_block_notification_stream: mock_primary_node
.imported_block_notification_stream(),
client_imported_block_notification_stream: mock_primary_node
.client
.every_import_notification_stream(),
new_slot_notification_stream: mock_primary_node.new_slot_notification_stream(),
_phantom: Default::default(),
};
let system_domain_node = domain_service::new_full_system::<
_,
_,
_,
_,
_,
_,
domain_test_runtime::RuntimeApi,
RuntimeExecutor,
>(
system_domain_config,
mock_primary_node.client.clone(),
MockPrimaryNode::sync_oracle(),
&mock_primary_node.select_chain,
executor_streams,
gossip_msg_sink,
)
.await?;

let domain_service::NewFullSystem {
task_manager,
client,
backend,
code_executor,
network,
network_starter,
rpc_handlers,
executor,
tx_pool_sink,
} = system_domain_node;

let mut domain_tx_pool_sinks = BTreeMap::new();
domain_tx_pool_sinks.insert(DomainId::SYSTEM, tx_pool_sink);
let cross_domain_message_gossip_worker =
GossipWorker::<Block>::new(network.clone(), domain_tx_pool_sinks);

task_manager
.spawn_essential_handle()
.spawn_essential_blocking(
"cross-domain-gossip-message-worker",
None,
Box::pin(cross_domain_message_gossip_worker.run(gossip_msg_stream)),
);

network_starter.start_network();

Ok((
task_manager,
client,
backend,
code_executor,
network,
rpc_handlers,
executor,
))
}

/// A Cumulus test node instance used for testing.
pub struct SystemDomainNode {
/// TaskManager's instance.
Expand Down Expand Up @@ -371,6 +460,7 @@ impl SystemDomainNodeBuilder {
}

/// Build the [`SystemDomainNode`].
/// TODO: remove once all the existing tests integrated with `MockPrimaryNode`
pub async fn build(
self,
role: Role,
Expand Down Expand Up @@ -420,6 +510,43 @@ impl SystemDomainNodeBuilder {
executor,
}
}

/// Build the [`SystemDomainNode`] with `MockPrimaryNode` as the embedded primary node.
pub async fn build_with_mock_primary_node(
self,
role: Role,
mock_primary_node: &mut MockPrimaryNode,
) -> SystemDomainNode {
let system_domain_config = node_config(
self.tokio_handle.clone(),
self.key,
self.system_domain_nodes,
self.system_domain_nodes_exclusive,
role,
BasePath::new(self.base_path.path().join("system")),
)
.expect("could not generate system domain node Configuration");

let multiaddr = system_domain_config.network.listen_addresses[0].clone();
let (task_manager, client, backend, code_executor, network, rpc_handlers, executor) =
run_executor_with_mock_primary_node(system_domain_config, mock_primary_node)
.await
.expect("could not start system domain node");

let peer_id = network.local_peer_id();
let addr = MultiaddrWithPeerId { multiaddr, peer_id };

SystemDomainNode {
task_manager,
client,
backend,
code_executor,
network,
addr,
rpc_handlers,
executor,
}
}
}

/// Create a system domain node `Configuration`.
Expand Down Expand Up @@ -610,6 +737,7 @@ pub fn construct_extrinsic(
///
/// This is essentially a wrapper around
/// [`run_validator_node`](subspace_test_service::run_validator_node).
/// TODO: remove once all the existing tests integrated with `MockPrimaryNode`
pub async fn run_primary_chain_validator_node(
tokio_handle: tokio::runtime::Handle,
key: Sr25519Keyring,
Expand Down
2 changes: 1 addition & 1 deletion test/subspace-test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub const MILLISECS_PER_BLOCK: u64 = 2000;

// NOTE: Currently it is not possible to change the slot duration after the chain has started.
// Attempting to do so will brick block production.
const SLOT_DURATION: u64 = 2000;
pub const SLOT_DURATION: u64 = 2000;

/// 1 in 6 slots (on average, not counting collisions) will have a block.
/// Must match ratio between block and slot duration in constants above.
Expand Down
17 changes: 17 additions & 0 deletions test/subspace-test-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,47 @@ include = [
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
async-trait = "0.1.58"
frame-system = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
futures = "0.3.26"
futures-timer = "3.0.1"
rand = "0.8.5"
pallet-balances = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
pallet-transaction-payment = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sc-block-builder = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sc-client-api = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sc-consensus = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sc-consensus-slots = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sc-executor = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sc-consensus-fraud-proof = { version = "0.1.0", path = "../../crates/sc-consensus-fraud-proof" }
sc-network = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sc-network-common = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sc-service = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232", default-features = false }
sc-tracing = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sc-utils = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sp-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sp-application-crypto = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sp-arithmetic = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sp-blockchain = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sp-consensus = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sp-consensus-subspace = { version = "0.1.0", path = "../../crates/sp-consensus-subspace" }
sp-consensus-slots = { version = "0.10.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sp-keyring = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sp-inherents = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
sp-runtime = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
subspace-core-primitives = { version = "0.1.0", default-features = false, path = "../../crates/subspace-core-primitives" }
subspace-fraud-proof = { path = "../../crates/subspace-fraud-proof" }
subspace-networking = { path = "../../crates/subspace-networking" }
subspace-runtime-primitives = { path = "../../crates/subspace-runtime-primitives" }
subspace-service = { path = "../../crates/subspace-service" }
subspace-solving = { version = "0.1.0", default-features = false, path = "../../crates/subspace-solving" }
subspace-test-client = { path = "../subspace-test-client" }
subspace-test-runtime = { version = "0.1.0", features = ["do-not-enforce-cost-of-storage"], path = "../subspace-test-runtime" }
subspace-transaction-pool = { path = "../../crates/subspace-transaction-pool" }
substrate-test-client = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232" }
tokio = "1.25.0"
tracing = "0.1.37"

[dev-dependencies]
sc-cli = { git = "https://github.com/subspace/substrate", rev = "456cfad45a178617f6886ec400c312f2fea59232", default-features = false }
Expand Down
5 changes: 5 additions & 0 deletions test/subspace-test-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ use substrate_test_client::{
BlockchainEventsExt, RpcHandlersExt, RpcTransactionError, RpcTransactionOutput,
};

/// TODO: Replace `PrimaryTestNode` with `mock::MockPrimaryNode` once all the existing tests
/// integrated with the new testing framework.
#[allow(dead_code)]
pub mod mock;

/// Create a Subspace `Configuration`.
///
/// By default an in-memory socket will be used, therefore you need to provide boot
Expand Down
Loading