Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): Simplify config and data dir parsing #19

Merged
merged 6 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ indent_style = space
indent_size = 4
tab_width = 4

[*.json]
indent_style = space
indent_size = 4
tab_width = 4

[Makefile]
indent_style = tab
indent_size = 4
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ tags
# vagrant file
.vagrant

# nervos runtime folder
.nervos
# runtime folder
/nodes/
42 changes: 0 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,23 @@ cargo test -p ckb-chain

### Start Node

Create the defualt runtime directory:

```shell
cp -r nodes_template/ nodes
```

Use the config file to start the node

```shell
target/release/ckb run
```

blockchain data is located in
It searches config file `ckb.json`, `nodes/default.json` in the shell
working directory in that order. Alternatively, the argument `-c` can specify
the config file used to start the node.

Platform | Value | Example
-------- | ------|---------
Linux | $XDG_DATA_HOME/ckb or $HOME/.local/share/ckb | /home/alice/.local/share/ckb
macOS | $HOME/Library/Application Support/ckb | /Users/Alice/Library/Application Support/ckb
The default config file saves data in `nodes/default/`.

### Send Transaction via RPC

Expand All @@ -130,19 +137,26 @@ curl -d '{"id": 2, "jsonrpc": "2.0", "method":"send_transaction","params": [{"ve

### Advanced

Run multiple nodes in different `data-dir`:
Run multiple nodes in different data directories.

Create the config file for new nodes, for example:

```shell
target/release/ckb run --data-dir=/tmp/node1
target/release/ckb run --data-dir=/tmp/node2
cp nodes/default.json nodes/node2.json
```

Update `data_dir` configuration in config file to a different directory.

```
"data_dir": "node2"
```

The file `config.json` in `data-dir` overrides default configurations. Start with the default one:
Then start the new node using the new config file

```shell
cp src/config/default.json /tmp/node1/config.json
target/release/ckb -c nodes/node2.json run
```

The option `ckb.chain` configures the chain spec. It accepts a pre-defined spec or the path to a customized spec JSON file. The directory `spec/res` has all the pre-defined specs. Please note that nodes with different chain specs may fail to connect with each other.
The option `ckb.chain` configures the chain spec. It accepts a path to the spec JSON file. The directory `nodes_template/spec` has all the pre-defined specs. Please note that nodes with different chain specs may fail to connect with each other.

The chain spec can switch between different PoW engines. Wiki has the [instructions](https://github.com/nervosnetwork/ckb/wiki/PoW-Engines) about how to configure it.
10 changes: 5 additions & 5 deletions src/config/default.json → nodes_template/default.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"data_dir": "default",
"ckb": {
"chain": "dev"
"chain": "spec/dev.json"
},
"logger": {
"file": "ckb.log",
"filter": "info",
"color": true
},
"network": {
"listen_addresses": [
"/ip4/0.0.0.0/tcp/8115"
],
"listen_addresses": ["/ip4/0.0.0.0/tcp/8115"],
"boot_nodes": [],
"reserved_nodes": [],
"only_reserved_peers": false,
Expand All @@ -37,6 +36,7 @@
"max_tx": 1024,
"max_prop": 1024,
"new_transactions_threshold": 8,
"type_hash": "0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff"
"type_hash":
"0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff"
}
}
File renamed without changes.
9 changes: 4 additions & 5 deletions spec/res/dev.json → nodes_template/spec/dev.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"__comments__": {
"system_cells": [
"When loading dev.yaml, we will modify the path here to simplify loading,",
"but if you are copying this file elsewhere, you will need to provide full path ",
"or relative path to where ckb is executing."
"path to cells files",
"which is absolute or relative to the directory containing this config file."
],

"edge_bits": [
Expand Down Expand Up @@ -36,8 +35,8 @@
"initial_block_reward": 50000
},
"system_cells": [
{"path": "verify"},
{"path": "always_success"}
{"path": "cells/verify"},
{"path": "cells/always_success"}
],
"pow": {
"Cuckoo": {
Expand Down
5 changes: 4 additions & 1 deletion pool/src/tests/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use ckb_shared::store::ChainKVStore;
use ckb_time::now_ms;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::sync::Arc;
use std::time;
use txs_pool::pool::TransactionPoolService;
Expand Down Expand Up @@ -596,7 +597,9 @@ fn test_transaction_with_capacity(
// Since the main point here is to test pool functionality, not scripting
// behavior, we use a dummy script here that always passes in testing
fn create_valid_script() -> Script {
let mut file = File::open("../spec/res/cells/always_success").unwrap();
let mut file = File::open(
Path::new(env!("CARGO_MANIFEST_DIR")).join("../nodes_template/spec/cells/always_success"),
).unwrap();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();

Expand Down
24 changes: 17 additions & 7 deletions script/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,20 @@ mod tests {
use hash::sha3_256;
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;

fn open_cell_verify() -> File {
File::open(Path::new(env!("CARGO_MANIFEST_DIR")).join("../nodes_template/spec/cells/verify"))
.unwrap()
}
fn open_cell_always_success() -> File {
File::open(Path::new(env!("CARGO_MANIFEST_DIR")).join("../nodes_template/spec/cells/always_success"))
.unwrap()
}

#[test]
fn check_signature() {
let mut file = File::open("../spec/res/cells/verify").unwrap();
let mut file = open_cell_verify();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();

Expand Down Expand Up @@ -190,7 +200,7 @@ mod tests {

#[test]
fn check_invalid_signature() {
let mut file = File::open("../spec/res/cells/verify").unwrap();
let mut file = open_cell_verify();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();

Expand Down Expand Up @@ -235,7 +245,7 @@ mod tests {

#[test]
fn check_valid_dep_reference() {
let mut file = File::open("../spec/res/cells/verify").unwrap();
let mut file = open_cell_verify();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();

Expand Down Expand Up @@ -285,7 +295,7 @@ mod tests {

#[test]
fn check_invalid_dep_reference() {
let mut file = File::open("../spec/res/cells/verify").unwrap();
let mut file = open_cell_verify();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();

Expand Down Expand Up @@ -331,7 +341,7 @@ mod tests {
}

fn create_always_success_script() -> Script {
let mut file = File::open("../spec/res/cells/always_success").unwrap();
let mut file = open_cell_always_success();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();

Expand All @@ -340,7 +350,7 @@ mod tests {

#[test]
fn check_output_contract() {
let mut file = File::open("../spec/res/cells/verify").unwrap();
let mut file = open_cell_verify();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();

Expand Down Expand Up @@ -387,7 +397,7 @@ mod tests {

#[test]
fn check_invalid_output_contract() {
let mut file = File::open("../spec/res/cells/verify").unwrap();
let mut file = open_cell_verify();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();

Expand Down
Loading