When updating the client or when called from RPC, sleep should mean sleep (#10814)

Closes https://github.com/paritytech/parity-ethereum/issues/10687

`sleep()` is called from several places but when called from `disable()` or through the `setMode` RPC, we should ignore queue contents and go to sleep.
This commit is contained in:
David 2019-07-02 21:26:26 +02:00 committed by GitHub
parent 5f064a9076
commit b4af8df535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1108,7 +1108,7 @@ impl Client {
let mut ss = self.sleep_state.lock();
if let Some(t) = ss.last_activity {
if Instant::now() > t + timeout {
self.sleep();
self.sleep(false);
ss.last_activity = None;
}
}
@ -1118,7 +1118,7 @@ impl Client {
let now = Instant::now();
if let Some(t) = ss.last_activity {
if now > t + timeout {
self.sleep();
self.sleep(false);
ss.last_activity = None;
ss.last_autosleep = Some(now);
}
@ -1217,10 +1217,10 @@ impl Client {
}
}
fn sleep(&self) {
fn sleep(&self, force: bool) {
if self.liveness.load(AtomicOrdering::Relaxed) {
// only sleep if the import queue is mostly empty.
if self.queue_info().total_queue_size() <= MAX_QUEUE_SIZE_TO_SLEEP_ON {
if force || (self.queue_info().total_queue_size() <= MAX_QUEUE_SIZE_TO_SLEEP_ON) {
self.liveness.store(false, AtomicOrdering::Relaxed);
self.notify(|n| n.stop());
info!(target: "mode", "sleep: Sleeping.");
@ -1733,7 +1733,7 @@ impl BlockChainClient for Client {
}
match new_mode {
Mode::Active => self.wake_up(),
Mode::Off => self.sleep(),
Mode::Off => self.sleep(true),
_ => {(*self.sleep_state.lock()).last_activity = Some(Instant::now()); }
}
}