Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
When updating the client or when called from RPC, sleep should mean s…
Browse files Browse the repository at this point in the history
…leep (#10814)

Closes #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.
  • Loading branch information
dvdplm authored and s3krit committed Aug 12, 2019
1 parent 956c759 commit 1c19ed3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,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;
}
}
Expand All @@ -1119,7 +1119,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);
}
Expand Down Expand Up @@ -1218,10 +1218,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.");
Expand Down Expand Up @@ -1730,7 +1730,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()); }
}
}
Expand Down

0 comments on commit 1c19ed3

Please sign in to comment.