From c6b235294f64974880ef3ddce695c4fec40c7984 Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Mon, 6 Apr 2020 15:58:24 +0200 Subject: [PATCH 1/2] fix miner problem in that it wont listen to events --- base_layer/core/src/mining/miner.rs | 75 ++++++++++++++++------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/base_layer/core/src/mining/miner.rs b/base_layer/core/src/mining/miner.rs index 925f54e7d9..c4a3201628 100644 --- a/base_layer/core/src/mining/miner.rs +++ b/base_layer/core/src/mining/miner.rs @@ -231,44 +231,51 @@ impl Miner { true => task::spawn(self.mining()), false => task::spawn(self.not_mining()), }; - futures::select! { - msg = block_event.select_next_some() => { - match *msg { - BlockEvent::Verified((_, ref result)) => { - //Miner does not care if the chain reorg'ed or just added a new block. Both cases means a new chain tip, so it needs to restart. - match *result { - BlockAddResult::Ok | BlockAddResult::ChainReorg(_) => { - stop_mining_flag.store(true, Ordering::Relaxed); - start_mining = true; + // This flag will let the future select loop again if the miner has not been issued a shutdown command. + let mut wait_for_miner = false; + 'inner: while (!wait_for_miner) { + futures::select! { + msg = block_event.select_next_some() => { + match *msg { + BlockEvent::Verified((_, ref result)) => { + //Miner does not care if the chain reorg'ed or just added a new block. Both cases means a new chain tip, so it needs to restart. + match *result { + BlockAddResult::Ok | BlockAddResult::ChainReorg(_) => { + stop_mining_flag.store(true, Ordering::Relaxed); + start_mining = true; + wait_for_miner = true; + }, + _ => {} + } }, - _ => {} - } + _ => (), + } }, - _ => (), - } - }, - event = state_event.select_next_some() => { - use StateEvent::*; - stop_mining_flag.store(true, Ordering::Relaxed); - match *event { - BlocksSynchronized | NetworkSilence => { - info!(target: LOG_TARGET, - "Our chain has synchronised with the network, or is a seed node. Starting miner"); - start_mining = true; - }, - FallenBehind(SyncStatus::Lagging(_, _)) => { - info!(target: LOG_TARGET, "Our chain has fallen behind the network. Pausing miner"); - start_mining = false; - }, - _ => {}, + event = state_event.select_next_some() => { + use StateEvent::*; + stop_mining_flag.store(true, Ordering::Relaxed); + match *event { + BlocksSynchronized | NetworkSilence => { + info!(target: LOG_TARGET, + "Our chain has synchronised with the network, or is a seed node. Starting miner"); + start_mining = true; + wait_for_miner = true; + }, + FallenBehind(SyncStatus::Lagging(_, _)) => { + info!(target: LOG_TARGET, "Our chain has fallen behind the network. Pausing miner"); + start_mining = false; + wait_for_miner = true; + }, + _ => {}, + } + }, + _ = kill_signal => { + info!(target: LOG_TARGET, "Mining kill signal received! Miner is shutting down"); + stop_mining_flag.store(true, Ordering::Relaxed); + break 'main; } - }, - _ = kill_signal => { - info!(target: LOG_TARGET, "Mining kill signal received! Miner is shutting down"); - stop_mining_flag.store(true, Ordering::Relaxed); - break 'main; + }; } - }; self = mining_future.await.expect("Miner crashed").expect("Miner crashed"); } debug!(target: LOG_TARGET, "Mining thread stopped."); From 856ce2e351c1ff5dab6d5448d7628bd8d7e1e690 Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Mon, 6 Apr 2020 16:31:13 +0200 Subject: [PATCH 2/2] clippy warnings --- base_layer/core/src/mining/miner.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base_layer/core/src/mining/miner.rs b/base_layer/core/src/mining/miner.rs index c4a3201628..e5897a994f 100644 --- a/base_layer/core/src/mining/miner.rs +++ b/base_layer/core/src/mining/miner.rs @@ -233,7 +233,7 @@ impl Miner { }; // This flag will let the future select loop again if the miner has not been issued a shutdown command. let mut wait_for_miner = false; - 'inner: while (!wait_for_miner) { + while !wait_for_miner { futures::select! { msg = block_event.select_next_some() => { match *msg {