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:
parent
5f064a9076
commit
b4af8df535
@ -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()); }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user