Skip to content

Commit 409f2bb

Browse files
authored
Merge pull request #966 from subspace/dsn-sync-for-node
Fix DSN sync for node
2 parents 6a700d2 + cccff3c commit 409f2bb

File tree

4 files changed

+59
-13
lines changed

4 files changed

+59
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/subspace-node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ sc-cli = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate"
3838
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/subspace/substrate", rev = "6d57dbc639bb3d9460dabeccb063cc6556452535" }
3939
sc-consensus = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "6d57dbc639bb3d9460dabeccb063cc6556452535" }
4040
sc-consensus-slots = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "6d57dbc639bb3d9460dabeccb063cc6556452535" }
41+
sc-consensus-subspace = { version = "0.1.0", path = "../sc-consensus-subspace" }
4142
sc-subspace-chain-specs = { version = "0.1.0", path = "../sc-subspace-chain-specs" }
4243
sc-executor = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "6d57dbc639bb3d9460dabeccb063cc6556452535", features = ["wasmtime"] }
4344
sc-service = { version = "0.10.0-dev", git = "https://github.com/subspace/substrate", rev = "6d57dbc639bb3d9460dabeccb063cc6556452535", default-features = false, features = ["wasmtime"] }
@@ -58,7 +59,6 @@ subspace-runtime-primitives = { version = "0.1.0", path = "../subspace-runtime-p
5859
subspace-service = { version = "0.1.0", path = "../subspace-service" }
5960
system-domain-runtime = { version = "0.1.0", path = "../../domains/runtime/system" }
6061
thiserror = "1.0.32"
61-
tokio = "1.21.2"
6262

6363
[build-dependencies]
6464
substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/subspace/substrate", rev = "6d57dbc639bb3d9460dabeccb063cc6556452535" }

crates/subspace-node/src/bin/subspace-node.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,21 @@ fn main() -> Result<(), Error> {
196196
client,
197197
import_queue,
198198
task_manager,
199+
other: (_block_import, subspace_link, _telemetry),
199200
..
200201
} = subspace_service::new_partial::<RuntimeApi, ExecutorDispatch>(&config)?;
202+
203+
sc_consensus_subspace::start_subspace_archiver(
204+
&subspace_link,
205+
client.clone(),
206+
None,
207+
&task_manager.spawn_essential_handle(),
208+
config.role.is_authority(),
209+
);
210+
201211
Ok((
202-
cmd.run(client, import_queue).map_err(Error::SubstrateCli),
212+
cmd.run(client, import_queue, task_manager.spawn_essential_handle())
213+
.map_err(Error::SubstrateCli),
203214
task_manager,
204215
))
205216
})?;

crates/subspace-node/src/import_blocks_from_dsn.rs

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use sc_consensus::{BlockImportError, BlockImportStatus, IncomingBlock, Link};
2222
use sc_service::ImportQueue;
2323
use sc_tracing::tracing::{debug, info, trace};
2424
use sp_consensus::BlockOrigin;
25+
use sp_core::traits::SpawnEssentialNamed;
2526
use sp_runtime::generic::BlockId;
2627
use sp_runtime::traits::{Block as BlockT, Header, NumberFor};
2728
use std::sync::Arc;
@@ -58,15 +59,26 @@ pub struct ImportBlocksFromDsnCmd {
5859

5960
impl ImportBlocksFromDsnCmd {
6061
/// Run the import-blocks command
61-
pub async fn run<B, C, IQ>(&self, client: Arc<C>, import_queue: IQ) -> sc_cli::Result<()>
62+
pub async fn run<B, C, IQ>(
63+
&self,
64+
client: Arc<C>,
65+
import_queue: IQ,
66+
spawner: impl SpawnEssentialNamed,
67+
) -> sc_cli::Result<()>
6268
where
6369
C: HeaderBackend<B> + BlockBackend<B> + Send + Sync + 'static,
6470
B: BlockT + for<'de> serde::Deserialize<'de>,
6571
IQ: sc_service::ImportQueue<B> + 'static,
6672
{
67-
import_blocks(self.bootstrap_node.clone(), client, import_queue, false)
68-
.await
69-
.map_err(Into::into)
73+
import_blocks(
74+
self.bootstrap_node.clone(),
75+
client,
76+
import_queue,
77+
&spawner,
78+
false,
79+
)
80+
.await
81+
.map_err(Into::into)
7082
}
7183
}
7284

@@ -109,7 +121,7 @@ impl<B: BlockT> Link<B> for WaitLink<B> {
109121
B::Hash,
110122
)>,
111123
) {
112-
println!("Imported {imported} blocks");
124+
debug!("Imported {imported} blocks");
113125
self.imported_blocks += imported as u64;
114126

115127
for result in results {
@@ -126,6 +138,7 @@ async fn import_blocks<B, IQ, C>(
126138
bootstrap_nodes: Vec<Multiaddr>,
127139
client: Arc<C>,
128140
mut import_queue: IQ,
141+
spawner: &impl SpawnEssentialNamed,
129142
force: bool,
130143
) -> Result<(), sc_service::Error>
131144
where
@@ -142,9 +155,13 @@ where
142155
.await
143156
.map_err(|error| sc_service::Error::Other(error.to_string()))?;
144157

145-
tokio::spawn(async move {
146-
node_runner.run().await;
147-
});
158+
spawner.spawn_essential(
159+
"node-runner",
160+
Some("subspace-networking"),
161+
Box::pin(async move {
162+
node_runner.run().await;
163+
}),
164+
);
148165

149166
debug!("Waiting for connected peers...");
150167
let _ = node.wait_for_connected_peers().await;
@@ -263,10 +280,28 @@ where
263280
}
264281
}
265282

283+
while link.imported_blocks < imported_blocks {
284+
futures::future::poll_fn(|ctx| {
285+
import_queue.poll_actions(ctx, &mut link);
286+
287+
Poll::Ready(())
288+
})
289+
.await;
290+
291+
if let Some(WaitLinkError { error, hash }) = &link.error {
292+
return Err(sc_service::Error::Other(format!(
293+
"Stopping block import after #{} blocks on {} because of an error: {}",
294+
link.imported_blocks, hash, error
295+
)));
296+
}
297+
}
298+
266299
info!(
267-
"🎉 Imported {} blocks, best #{}, exiting...",
300+
"🎉 Imported {} blocks, best #{}/#{}, check against reliable sources to make sure it is a \
301+
block on canonical chain",
268302
imported_blocks,
269-
client.info().best_number
303+
client.info().best_number,
304+
client.info().best_hash
270305
);
271306

272307
Ok(())

0 commit comments

Comments
 (0)