add Engine stop method
This commit is contained in:
parent
c7f1260775
commit
56e9dab9de
@ -1445,6 +1445,12 @@ impl ProvingBlockChainClient for Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for Client {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.engine.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
|
@ -207,6 +207,9 @@ pub trait Engine : Sync + Send {
|
|||||||
/// Register an account which signs consensus messages.
|
/// Register an account which signs consensus messages.
|
||||||
fn set_signer(&self, _address: Address, _password: String) {}
|
fn set_signer(&self, _address: Address, _password: String) {}
|
||||||
|
|
||||||
|
/// Stops any services that the may hold the Engine and makes it safe to drop.
|
||||||
|
fn stop(&self) {}
|
||||||
|
|
||||||
/// Add a channel for communication with Client which can be used for sealing.
|
/// Add a channel for communication with Client which can be used for sealing.
|
||||||
fn register_message_channel(&self, _message_channel: IoChannel<ClientIoMessage>) {}
|
fn register_message_channel(&self, _message_channel: IoChannel<ClientIoMessage>) {}
|
||||||
|
|
||||||
|
@ -191,6 +191,7 @@ impl Tendermint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Broadcast all messages since last issued block to get the peers up to speed.
|
||||||
fn broadcast_old_messages(&self) {
|
fn broadcast_old_messages(&self) {
|
||||||
for m in self.votes.get_up_to(self.height.load(AtomicOrdering::SeqCst)).into_iter() {
|
for m in self.votes.get_up_to(self.height.load(AtomicOrdering::SeqCst)).into_iter() {
|
||||||
self.broadcast_message(m);
|
self.broadcast_message(m);
|
||||||
@ -561,6 +562,10 @@ impl Engine for Tendermint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn stop(&self) {
|
||||||
|
self.step_service.stop()
|
||||||
|
}
|
||||||
|
|
||||||
fn is_new_best_block(&self, _best_total_difficulty: U256, best_header: HeaderView, _parent_details: &BlockDetails, new_header: &HeaderView) -> bool {
|
fn is_new_best_block(&self, _best_total_difficulty: U256, best_header: HeaderView, _parent_details: &BlockDetails, new_header: &HeaderView) -> bool {
|
||||||
let new_number = new_header.number();
|
let new_number = new_header.number();
|
||||||
let best_number = best_header.number();
|
let best_number = best_header.number();
|
||||||
@ -741,7 +746,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
|
||||||
fn allows_correct_proposer() {
|
fn allows_correct_proposer() {
|
||||||
let (spec, tap) = setup();
|
let (spec, tap) = setup();
|
||||||
let engine = spec.engine;
|
let engine = spec.engine;
|
||||||
@ -772,7 +776,8 @@ mod tests {
|
|||||||
match engine.verify_block_unordered(&header, None) {
|
match engine.verify_block_unordered(&header, None) {
|
||||||
Err(Error::Engine(EngineError::NotAuthorized(_))) => {},
|
Err(Error::Engine(EngineError::NotAuthorized(_))) => {},
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
}
|
};
|
||||||
|
engine.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -815,7 +820,8 @@ mod tests {
|
|||||||
match engine.verify_block_unordered(&header, None) {
|
match engine.verify_block_unordered(&header, None) {
|
||||||
Err(Error::Engine(EngineError::NotAuthorized(_))) => {},
|
Err(Error::Engine(EngineError::NotAuthorized(_))) => {},
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
}
|
};
|
||||||
|
engine.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -826,6 +832,7 @@ mod tests {
|
|||||||
|
|
||||||
let (b, seal) = propose_default(&spec, proposer);
|
let (b, seal) = propose_default(&spec, proposer);
|
||||||
assert!(b.try_seal(spec.engine.as_ref(), seal).is_ok());
|
assert!(b.try_seal(spec.engine.as_ref(), seal).is_ok());
|
||||||
|
spec.engine.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -860,6 +867,7 @@ mod tests {
|
|||||||
vote(&engine, |mh| tap.sign(v1, None, mh).map(H520::from), h, r, Step::Precommit, proposal);
|
vote(&engine, |mh| tap.sign(v1, None, mh).map(H520::from), h, r, Step::Precommit, proposal);
|
||||||
vote(&engine, |mh| tap.sign(v0, None, mh).map(H520::from), h, r, Step::Precommit, proposal);
|
vote(&engine, |mh| tap.sign(v0, None, mh).map(H520::from), h, r, Step::Precommit, proposal);
|
||||||
|
|
||||||
|
engine.stop();
|
||||||
// Wait a bit for async stuff.
|
// Wait a bit for async stuff.
|
||||||
::std::thread::sleep(::std::time::Duration::from_millis(100));
|
::std::thread::sleep(::std::time::Duration::from_millis(100));
|
||||||
seal[2] = precommit_signatures(&tap, h, r, Some(b.header().bare_hash()), v0, v1);
|
seal[2] = precommit_signatures(&tap, h, r, Some(b.header().bare_hash()), v0, v1);
|
||||||
|
Loading…
Reference in New Issue
Block a user