Skip to content

Commit 3c769e0

Browse files
authored
Merge branch 'master' into feature/do-not-precommit-past-future-block
2 parents 0ab67a6 + cce562e commit 3c769e0

File tree

22 files changed

+690
-416
lines changed

22 files changed

+690
-416
lines changed

Cargo.lock

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ codechain-key = { path = "key" }
2323
codechain-keystore = { path = "keystore" }
2424
codechain-merkle = { path = "util/merkle" }
2525
codechain-network = { path = "network" }
26-
codechain-reactor = { path = "util/reactor" }
2726
codechain-rpc = { path = "rpc" }
2827
codechain-state = { path = "state" }
2928
codechain-sync = { path = "sync" }

codechain/codechain.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ args:
6060
long: chain
6161
help: Set the blockchain type out of solo, simple_poa, tendermint, cuckoo, blake_pow, corgi, mainnet or a path to chain scheme file.
6262
takes_value: true
63+
- base-path:
64+
long: base-path
65+
value_name: PATH
66+
help: Specify the base directory path on which the "db" and "keys" directory will be created.
67+
takes_value: true
6368
- db-path:
6469
long: db-path
6570
value_name: PATH

codechain/config/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ pub struct Ipc {
202202
pub struct Operating {
203203
pub quiet: Option<bool>,
204204
pub instance_id: Option<usize>,
205+
pub base_path: Option<String>,
205206
pub db_path: Option<String>,
206207
pub keys_path: Option<String>,
207208
pub password_path: Option<String>,
@@ -316,6 +317,9 @@ impl Operating {
316317
if other.instance_id.is_some() {
317318
self.instance_id = other.instance_id;
318319
}
320+
if other.base_path.is_some() {
321+
self.base_path = other.base_path.clone();
322+
}
319323
if other.db_path.is_some() {
320324
self.db_path = other.db_path.clone();
321325
}
@@ -337,6 +341,9 @@ impl Operating {
337341
if let Some(instance_id) = matches.value_of("instance-id") {
338342
self.instance_id = Some(instance_id.parse().map_err(|e| format!("{}", e))?);
339343
}
344+
if let Some(base_path) = matches.value_of("base-path") {
345+
self.base_path = Some(base_path.to_string());
346+
}
340347
if let Some(db_path) = matches.value_of("db-path") {
341348
self.db_path = Some(db_path.to_string());
342349
}

codechain/config/presets/config.dev.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[codechain]
22
quiet = false
3-
db_path = "db"
4-
keys_path = "keys"
3+
base_path = "."
54
chain = "solo"
65

76
[mining]

codechain/config/presets/config.prod.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[codechain]
22
quiet = false
3-
db_path = "db"
4-
keys_path = "keys"
3+
base_path = "."
54
chain = "mainnet"
65

76
[mining]

codechain/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
pub const DEFAULT_KEYS_PATH: &str = "keys";
18+
pub const DEFAULT_DB_PATH: &str = "db";

codechain/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ extern crate codechain_keystore as ckeystore;
3636
extern crate codechain_logger as clogger;
3737
extern crate cidr;
3838
extern crate codechain_network as cnetwork;
39-
extern crate codechain_reactor as creactor;
4039
extern crate codechain_rpc as crpc;
4140
extern crate codechain_state as cstate;
4241
extern crate codechain_sync as csync;

codechain/run_node.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use std::env;
1817
use std::fs;
1918
use std::path::Path;
2019
use std::sync::{Arc, Weak};
21-
use std::time::{Duration, SystemTime, UNIX_EPOCH};
20+
use std::time::{SystemTime, UNIX_EPOCH};
2221

2322
use ccore::{
2423
AccountProvider, AccountProviderError, ChainNotify, Client, ClientConfig, ClientService, EngineInfo, EngineType,
@@ -31,18 +30,16 @@ use ckeystore::KeyStore;
3130
use clap::ArgMatches;
3231
use clogger::{self, LoggerConfig};
3332
use cnetwork::{Filters, NetworkConfig, NetworkControl, NetworkService, RoutingTable, SocketAddr};
34-
use creactor::EventLoop;
3533
use csync::{BlockSyncExtension, BlockSyncSender, SnapshotService, TransactionSyncExtension};
3634
use ctimer::TimerLoop;
3735
use ctrlc::CtrlC;
3836
use fdlimit::raise_fd_limit;
39-
use finally_block::finally;
4037
use kvdb::KeyValueDB;
4138
use kvdb_rocksdb::{Database, DatabaseConfig};
4239
use parking_lot::{Condvar, Mutex};
4340

4441
use crate::config::{self, load_config};
45-
use crate::constants::DEFAULT_KEYS_PATH;
42+
use crate::constants::{DEFAULT_DB_PATH, DEFAULT_KEYS_PATH};
4643
use crate::dummy_network_service::DummyNetworkService;
4744
use crate::json::PasswordFile;
4845
use crate::rpc::{rpc_http_start, rpc_ipc_start, rpc_ws_start};
@@ -203,8 +200,9 @@ fn unlock_accounts(ap: &AccountProvider, pf: &PasswordFile) -> Result<(), String
203200
}
204201

205202
pub fn open_db(cfg: &config::Operating, client_config: &ClientConfig) -> Result<Arc<KeyValueDB>, String> {
206-
let db_path = cfg.db_path.as_ref().map(String::as_str).unwrap();
207-
let client_path = Path::new(db_path);
203+
let base_path = cfg.base_path.as_ref().unwrap().clone();
204+
let db_path = cfg.db_path.as_ref().map(String::clone).unwrap_or_else(|| base_path + "/" + DEFAULT_DB_PATH);
205+
let client_path = Path::new(&db_path);
208206
let mut db_config = DatabaseConfig::with_columns(NUM_COLUMNS);
209207

210208
db_config.memory_budget = client_config.db_cache_size;
@@ -223,24 +221,11 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> {
223221
// increase max number of open files
224222
raise_fd_limit();
225223

226-
let _event_loop = EventLoop::spawn();
227224
let timer_loop = TimerLoop::new(2);
228225

229226
let config = load_config(matches)?;
230227

231-
// FIXME: It is the hotfix for #348.
232-
// Remove the below code if you find the proper way to solve #348.
233-
let _wait = finally(|| {
234-
const DEFAULT: u64 = 1;
235-
let wait_before_shutdown = env::var_os("WAIT_BEFORE_SHUTDOWN")
236-
.and_then(|sec| sec.into_string().ok())
237-
.and_then(|sec| sec.parse().ok())
238-
.unwrap_or(DEFAULT);
239-
::std::thread::sleep(Duration::from_secs(wait_before_shutdown));
240-
});
241-
242228
let time_gap_params = config.mining.create_time_gaps();
243-
244229
let scheme = match &config.operating.chain {
245230
Some(chain) => chain.scheme()?,
246231
None => return Err("chain is not specified".to_string()),
@@ -256,11 +241,10 @@ pub fn run_node(matches: &ArgMatches) -> Result<(), String> {
256241
clogger::init(&LoggerConfig::new(instance_id)).expect("Logger must be successfully initialized");
257242

258243
let pf = load_password_file(&config.operating.password_path)?;
259-
let keys_path = match config.operating.keys_path {
260-
Some(ref keys_path) => keys_path,
261-
None => DEFAULT_KEYS_PATH,
262-
};
263-
let ap = prepare_account_provider(keys_path)?;
244+
let base_path = config.operating.base_path.as_ref().unwrap().clone();
245+
let keys_path =
246+
config.operating.keys_path.as_ref().map(String::clone).unwrap_or_else(|| base_path + "/" + DEFAULT_KEYS_PATH);
247+
let ap = prepare_account_provider(&keys_path)?;
264248
unlock_accounts(&*ap, &pf)?;
265249

266250
let client_config: ClientConfig = Default::default();

core/src/blockchain/headerchain.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,16 @@ impl HeaderChain {
285285
///
286286
/// Used in BlockChain::update_best_as_committed().
287287
pub fn update_best_as_committed(&self, batch: &mut DBTransaction, block_hash: H256) {
288-
ctrace!(HEADERCHAIN, "Update the best block to {}", block_hash);
289288
assert!(self.pending_best_header_hash.read().is_none());
289+
290+
let prev_best_header_number = self.best_header().number();
291+
let committed_header_number =
292+
self.block_header_data(&block_hash).expect("The given hash should exist").number();
293+
if prev_best_header_number > committed_header_number {
294+
return
295+
}
296+
297+
ctrace!(HEADERCHAIN, "Update the best block to {}", block_hash);
290298
let block_detail = self.block_details(&block_hash).expect("The given hash should exist");
291299
let mut new_hashes = HashMap::new();
292300
new_hashes.insert(block_detail.number, block_hash);

0 commit comments

Comments
 (0)