mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-24 17:11:05 +00:00
node: fix shutdown (#1308)
* node: remove grandpa authority flags * node: exit-guard grandpa and aura spawned futures * node: wait for futures to stop running on shutdown * core: run connectivity tests on same ports * core: pass on_exit future when starting aura and grandpa * node: add issue number to todo * core: fix aura and grandpa tests
This commit is contained in:
committed by
Robert Habermeier
parent
ef8b94656e
commit
f8f932d123
@@ -179,16 +179,15 @@ pub fn start_aura_thread<B, C, E, I, SO, Error>(
|
||||
}
|
||||
};
|
||||
|
||||
runtime.spawn(start_aura(
|
||||
let _ = runtime.block_on(start_aura(
|
||||
slot_duration,
|
||||
local_key,
|
||||
client,
|
||||
block_import,
|
||||
env,
|
||||
sync_oracle,
|
||||
on_exit,
|
||||
));
|
||||
|
||||
runtime.block_on(on_exit).expect("Exit future should not fail");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -200,6 +199,7 @@ pub fn start_aura<B, C, E, I, SO, Error>(
|
||||
block_import: Arc<I>,
|
||||
env: Arc<E>,
|
||||
sync_oracle: SO,
|
||||
on_exit: impl Future<Item=(),Error=()>,
|
||||
) -> impl Future<Item=(),Error=()> where
|
||||
B: Block,
|
||||
C: Authorities<B> + ChainHead<B>,
|
||||
@@ -352,7 +352,7 @@ pub fn start_aura<B, C, E, I, SO, Error>(
|
||||
})
|
||||
};
|
||||
|
||||
future::loop_fn((), move |()| {
|
||||
let work = future::loop_fn((), move |()| {
|
||||
let authorship_task = ::std::panic::AssertUnwindSafe(make_authorship());
|
||||
authorship_task.catch_unwind().then(|res| {
|
||||
match res {
|
||||
@@ -369,7 +369,9 @@ pub fn start_aura<B, C, E, I, SO, Error>(
|
||||
|
||||
Ok(future::Loop::Continue(()))
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
work.select(on_exit).then(|_| Ok(()))
|
||||
}
|
||||
|
||||
// a header which has been checked
|
||||
@@ -760,6 +762,7 @@ mod tests {
|
||||
client,
|
||||
environ.clone(),
|
||||
DummyOracle,
|
||||
futures::empty(),
|
||||
);
|
||||
|
||||
runtime.spawn(aura);
|
||||
|
||||
@@ -1186,6 +1186,7 @@ pub fn run_grandpa<B, E, Block: BlockT<Hash=H256>, N, RA>(
|
||||
config: Config,
|
||||
link: LinkHalf<B, E, Block, RA>,
|
||||
network: N,
|
||||
on_exit: impl Future<Item=(),Error=()> + Send + 'static,
|
||||
) -> ::client::error::Result<impl Future<Item=(),Error=()> + Send + 'static> where
|
||||
Block::Hash: Ord,
|
||||
B: Backend<Block, Blake2Hasher> + 'static,
|
||||
@@ -1312,5 +1313,5 @@ pub fn run_grandpa<B, E, Block: BlockT<Hash=H256>, N, RA>(
|
||||
}))
|
||||
}).map_err(|e| warn!("GRANDPA Voter failed: {:?}", e));
|
||||
|
||||
Ok(voter_work)
|
||||
Ok(voter_work.select(on_exit).then(|_| Ok(())))
|
||||
}
|
||||
|
||||
@@ -376,6 +376,7 @@ fn finalize_3_voters_no_observers() {
|
||||
},
|
||||
link,
|
||||
MessageRouting::new(net.clone(), peer_id),
|
||||
futures::empty(),
|
||||
).expect("all in order with client and network");
|
||||
|
||||
assert_send(&voter);
|
||||
@@ -436,6 +437,7 @@ fn finalize_3_voters_1_observer() {
|
||||
},
|
||||
link,
|
||||
MessageRouting::new(net.clone(), peer_id),
|
||||
futures::empty(),
|
||||
).expect("all in order with client and network");
|
||||
|
||||
runtime.spawn(voter);
|
||||
@@ -592,6 +594,7 @@ fn transition_3_voters_twice_1_observer() {
|
||||
},
|
||||
link,
|
||||
MessageRouting::new(net.clone(), peer_id),
|
||||
futures::empty(),
|
||||
).expect("all in order with client and network");
|
||||
|
||||
runtime.spawn(voter);
|
||||
|
||||
@@ -107,7 +107,7 @@ pub struct Service<Components: components::Components> {
|
||||
/// Configuration of this Service
|
||||
pub config: FactoryFullConfiguration<Components::Factory>,
|
||||
_rpc: Box<::std::any::Any + Send + Sync>,
|
||||
_telemetry: Option<tel::Telemetry>,
|
||||
_telemetry: Option<Arc<tel::Telemetry>>,
|
||||
}
|
||||
|
||||
/// Creates bare client without any networking.
|
||||
@@ -263,7 +263,7 @@ impl<Components: components::Components> Service<Components> {
|
||||
let impl_name = config.impl_name.to_owned();
|
||||
let version = version.clone();
|
||||
let chain_name = config.chain_spec.name().to_owned();
|
||||
Some(tel::init_telemetry(tel::TelemetryConfig {
|
||||
Some(Arc::new(tel::init_telemetry(tel::TelemetryConfig {
|
||||
url: url,
|
||||
on_connect: Box::new(move || {
|
||||
telemetry!("system.connected";
|
||||
@@ -276,7 +276,7 @@ impl<Components: components::Components> Service<Components> {
|
||||
"authority" => is_authority
|
||||
);
|
||||
}),
|
||||
}))
|
||||
})))
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
@@ -306,6 +306,10 @@ impl<Components: components::Components> Service<Components> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn telemetry(&self) -> Option<Arc<tel::Telemetry>> {
|
||||
self._telemetry.as_ref().map(|t| t.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<Components> Service<Components> where Components: components::Components {
|
||||
|
||||
@@ -33,7 +33,7 @@ use std::iter;
|
||||
use std::sync::Arc;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::time::Duration;
|
||||
use futures::Stream;
|
||||
use futures::{Future, Stream};
|
||||
use tempdir::TempDir;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::timer::Interval;
|
||||
@@ -188,7 +188,7 @@ pub fn connectivity<F: ServiceFactory, Inherent>(spec: FactoryChainSpec<F>) wher
|
||||
const NUM_NODES: u32 = 10;
|
||||
{
|
||||
let temp = TempDir::new("substrate-connectivity-test").expect("Error creating test dir");
|
||||
{
|
||||
let runtime = {
|
||||
let mut network = TestNet::<F>::new(&temp, spec.clone(), NUM_NODES, 0, vec![], 30400);
|
||||
info!("Checking star topology");
|
||||
let first_address = network.full_nodes[0].1.network().node_id().expect("No node address");
|
||||
@@ -198,13 +198,17 @@ pub fn connectivity<F: ServiceFactory, Inherent>(spec: FactoryChainSpec<F>) wher
|
||||
network.run_until_all_full(|_index, service|
|
||||
service.network().status().num_peers == NUM_NODES as usize - 1
|
||||
);
|
||||
}
|
||||
network.runtime
|
||||
};
|
||||
|
||||
runtime.shutdown_on_idle().wait().expect("Error shutting down runtime");
|
||||
|
||||
temp.close().expect("Error removing temp dir");
|
||||
}
|
||||
{
|
||||
let temp = TempDir::new("substrate-connectivity-test").expect("Error creating test dir");
|
||||
{
|
||||
let mut network = TestNet::<F>::new(&temp, spec, NUM_NODES, 0, vec![], 30500);
|
||||
let mut network = TestNet::<F>::new(&temp, spec, NUM_NODES, 0, vec![], 30400);
|
||||
info!("Checking linked topology");
|
||||
let mut address = network.full_nodes[0].1.network().node_id().expect("No node address");
|
||||
for (_, service) in network.full_nodes.iter().skip(1) {
|
||||
|
||||
Reference in New Issue
Block a user