Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions codechain/run_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::env;
use std::fs;
use std::path::Path;
use std::sync::{Arc, Weak};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use std::time::{SystemTime, UNIX_EPOCH};

use ccore::{
AccountProvider, AccountProviderError, ChainNotify, Client, ClientConfig, ClientService, EngineInfo, EngineType,
Expand All @@ -35,7 +34,6 @@ use csync::{BlockSyncExtension, BlockSyncSender, SnapshotService, TransactionSyn
use ctimer::TimerLoop;
use ctrlc::CtrlC;
use fdlimit::raise_fd_limit;
use finally_block::finally;
use kvdb::KeyValueDB;
use kvdb_rocksdb::{Database, DatabaseConfig};
use parking_lot::{Condvar, Mutex};
Expand Down Expand Up @@ -227,17 +225,6 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> {

let config = load_config(matches)?;

// FIXME: It is the hotfix for #348.
// Remove the below code if you find the proper way to solve #348.
let _wait = finally(|| {
const DEFAULT: u64 = 1;
let wait_before_shutdown = env::var_os("WAIT_BEFORE_SHUTDOWN")
.and_then(|sec| sec.into_string().ok())
.and_then(|sec| sec.parse().ok())
.unwrap_or(DEFAULT);
::std::thread::sleep(Duration::from_secs(wait_before_shutdown));
});

let scheme = match &config.operating.chain {
Some(chain) => chain.scheme()?,
None => return Err("chain is not specified".to_string()),
Expand Down
30 changes: 27 additions & 3 deletions core/src/verification/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ pub struct VerificationQueue<K: Kind> {
engine: Arc<CodeChainEngine>,
verification: Arc<Verification<K>>,
processing: RwLock<HashMap<H256, U256>>, // hash to score
#[allow(dead_code)]
deleting: Arc<AtomicBool>,
ready_signal: Arc<QueueSignal>,
total_score: RwLock<U256>,
#[allow(dead_code)]
empty: Arc<SCondvar>,
more_to_verify: Arc<SCondvar>,
#[allow(dead_code)]
verifier_handles: Vec<JoinHandle<()>>,
max_queue_size: usize,
max_mem_use: usize,
Expand Down Expand Up @@ -161,11 +159,20 @@ impl<K: Kind> VerificationQueue<K> {
let more_to_verify = more_to_verify.clone();
let ready_signal = ready_signal.clone();
let empty = empty.clone();
let deleting = Arc::clone(&deleting);

let handle = thread::Builder::new()
.name(format!("Verifier #{}", i))
.spawn(move || {
VerificationQueue::verify(&verification, &*engine, &*ready_signal, &*empty, &*more_to_verify, i)
VerificationQueue::verify(
&verification,
&*engine,
&*ready_signal,
&*empty,
&*more_to_verify,
&*deleting,
i,
)
})
.expect("Failed to create verifier thread.");
verifier_handles.push(handle);
Expand All @@ -192,6 +199,7 @@ impl<K: Kind> VerificationQueue<K> {
ready_signal: &QueueSignal,
empty: &SCondvar,
more_to_verify: &SCondvar,
deleting: &AtomicBool,
_id: usize,
) {
loop {
Expand All @@ -204,9 +212,15 @@ impl<K: Kind> VerificationQueue<K> {
}

while verification.unverified.lock().is_empty() {
if deleting.load(AtomicOrdering::SeqCst) {
return
}
more_to_verify_mutex = more_to_verify.wait(more_to_verify_mutex).unwrap();
}
}
if deleting.load(AtomicOrdering::SeqCst) {
return
}

// do work.
let item = {
Expand Down Expand Up @@ -474,6 +488,16 @@ impl<K: Kind> VerificationQueue<K> {
}
}

impl<K: Kind> Drop for VerificationQueue<K> {
fn drop(&mut self) {
self.deleting.store(true, AtomicOrdering::SeqCst);
self.more_to_verify.notify_all();
for handle in self.verifier_handles.drain(0..) {
handle.join().unwrap();
}
}
}

// the internal queue sizes.
struct Sizes {
unverified: AtomicUsize,
Expand Down
2 changes: 0 additions & 2 deletions test/src/helper/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ export default class CodeChain {
}
const useDebugBuild = process.env.NODE_ENV !== "production";
process.env.RUST_LOG = logLevel;
// NOTE: https://github.com/CodeChain-io/codechain/issues/348
process.env.WAIT_BEFORE_SHUTDOWN = "0";

const baseArgs = [...this.argv, ...argv];
if (disableIpc) {
Expand Down