Skip to content

Commit

Permalink
Merge pull request #425 from doitian/config-rework
Browse files Browse the repository at this point in the history
feat: bundle app config
  • Loading branch information
doitian authored Apr 10, 2019
2 parents e300a55 + f8aaec0 commit 3473406
Show file tree
Hide file tree
Showing 60 changed files with 1,983 additions and 1,223 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ tags
.vagrant

# runtime folder
/nodes/
/ckb.toml
/ckb-miner.toml
/data
/specs
115 changes: 13 additions & 102 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ toml = "0.5"
log = "0.4"
futures = "0.1"
crossbeam-channel = "0.3"
config-tool = { package= "config", version = "0.9" }
ckb-util = { path = "util" }
ckb-core = { path = "core" }
ckb-chain = { path = "chain" }
Expand All @@ -26,10 +25,10 @@ ckb-db = { path = "db" }
ckb-pow = { path = "pow" }
ckb-network = { path = "network"}
ckb-rpc = { path = "rpc"}
ckb-resource = { path = "resource"}
logger = { path = "util/logger" }
numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] }
numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] }
dir = { path = "util/dir" }
ctrlc = { version = "3.1", features = ["termination"] }
ckb-sync = { path = "sync"}
crypto = { path = "util/crypto"}
Expand All @@ -52,7 +51,6 @@ members = [
"util/merkle-tree",
"util/jsonrpc-types",
"util/crypto",
"util/dir",
"util/instrument",
"util/build-info",
"util/occupied-capacity",
Expand All @@ -72,7 +70,8 @@ members = [
"verification",
"script",
"pow",
"benches"
"benches",
"resource",
]

[profile.release]
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ gen-clean:
$(CFBC) -o $(shell dirname $@) $*.bfbs
rm -f $*.bfbs $*_builder.rs

.PHONY: build prod prod-test docker gen gen-clean
clean:
rm -rf ckb.toml ckb-miner.toml specs/

.PHONY: build prod prod-test docker gen gen-clean clean
.PHONY: fmt test clippy doc doc-deps check stats
.PHONY: ci info security-audit
127 changes: 5 additions & 122 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,126 +34,9 @@ The contribution workflow is described in [CONTRIBUTING.md](CONTRIBUTING.md), an

---

## Build dependencies
## Documentations

CKB is currently tested mainly with `stable-1.33.0` on Linux and Mac OSX.

We recommend installing Rust through [rustup](https://www.rustup.rs/)

```bash
# Get rustup from rustup.rs, then in your `ckb` folder:
rustup override set 1.33.0
rustup component add rustfmt
rustup component add clippy
```

Report new breakage is welcome.

You also need to get the following packages:

* Ubuntu and Debian:

```shell
sudo apt-get install git gcc libc6-dev pkg-config libssl-dev libclang-dev clang
```

* Arch Linux

```shell
sudo pacman -Sy git gcc pkgconf clang
```

* macOS:

```shell
brew install autoconf libtool
```

---

## Build from source & testing

```bash
# get ckb source code
git clone https://github.com/nervosnetwork/ckb.git
cd ckb

# build in release mode
make build
```

You can run the full test suite, or just run a specific package test:

```bash
# Run the full suite
cargo test --all
# Run a specific package test
cargo test -p ckb-chain
```

---

## Quick Start

### Start Node

Create the default runtime directory:

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

Use the config file to start the node

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

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

The default config file saves data in `nodes/default/`.

### Use RPC

Find RPC port in the log output, the following command assumes 8114 is used:

```shell
curl -d '{"id": 1, "jsonrpc": "2.0", "method":"get_tip_header","params": []}' \
-H 'content-type:application/json' 'http://localhost:8114'
```

### Run Miner

Run miner, gets a block template to mine.

```shell
target/release/ckb miner
```

### Advanced

Run multiple nodes in different data directories.

Create the config file for new nodes, for example:

```shell
cp nodes/default.toml nodes/node2.toml
```

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

```
data_dir = "node2"
```

Then start the new node using the new config file

```shell
target/release/ckb run -c nodes/node2.toml
```

The option `ckb.chain` configures the chain spec. It accepts a path to the spec toml 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.
- [Get CKB](docs/get-ckb.md)
- [Quick Start](docs/quick-start.md)
- [Configure CKB](docs/configure.md)
- [CKB Core Development](docs/ckb-core-dev.md)
2 changes: 1 addition & 1 deletion core/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ mod tests {

#[test]
fn always_success_script_hash() {
let always_success = include_bytes!("../../nodes_template/spec/cells/always_success");
let always_success = include_bytes!("../../resource/specs/cells/always_success");
let always_success_hash: H256 = (&blake2b_256(&always_success[..])).into();

let script = Script::new(0, vec![], always_success_hash);
Expand Down
1 change: 1 addition & 0 deletions db/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::PathBuf;

#[derive(Clone, Debug, Deserialize, Default)]
pub struct DBConfig {
#[serde(default)]
pub path: PathBuf,
pub options: Option<HashMap<String, String>>,
}
3 changes: 0 additions & 3 deletions docker/hub/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ COPY --from=ckb-builder /ckb/target/release/ckb /bin/ckb
RUN echo "#!/bin/bash \n ckb \$@" > ./entrypoint.sh
RUN chmod +x ./entrypoint.sh

# copy "nodes_template" to `WORKDIR`/nodes/
COPY --chown=ckb:ckb nodes_template/ nodes/

#switch use
USER ckb

Expand Down
31 changes: 31 additions & 0 deletions docs/ckb-core-dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# CKB Core Development

## Running Test

Install dependencies

```
rustup component add rustfmt
rustup component add clippy
```

Run tests

```
make ci
```

Run acceptance integration tests


```
cargo build
cd test && cargo run ../target/debug/ckb
```

## Chain Spec

The subcommand `ckb init` has an option `--export-spec` to export spec files
as well, which allows editing the chain spec for development.

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.-
81 changes: 81 additions & 0 deletions docs/configure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Configure CKB

## How CKB Locates Config File

CKB looks for configuration files in `<config-dir>`, which is the current working directory by default. Different subcommands use different config file names:

- `ckb run`: `ckb.toml`
- `ckb miner`: `ckb-miner.toml`
- `ckb import`: `ckb.toml`
- `ckb export`: `ckb.toml`
- `ckb cli`: no config file required yet

Command line argument `-C <path>` sets the value of `<config-dir>` to `<path>`, which must come before subcommand.

If configuration file is missing, the default config files bundled in the executable will be used.

Some config file may refer to other files, for example, `chain.spec` in
`ckb.toml` and `system_cells` in chain spec file. The file is referred via
either absolute path, or a path relative to the directory containing the
config file currently being parsed. Take following directory hierarchy as an
example:

```
ckb.toml
specs/dev.toml
specs/cells/always_success
```

Then `ckb.toml` refers `dev.toml` as `specs/dev.toml`, while
`specs/dev.toml` refers `always_success` as `cells/always_success`.

For security reason, there is a limitation of the file reference. The bundled
file can only refer to bundled files, while a file located in the file system
can either refer to another file in the file system or a bundled one.

## How to Change Config

First export the bundled config files into current directory using subcommand `init`.

```
ckb init
```

Then edit the generated config files according to the in-line comments.

## Chain Spec

The option `ckb.chain` configures the chain spec, which controls which kind of chain to run.
This option is set to a spec used for development by default.

The subcommand `init` supports exporting the default options for different
chain specs. The following command lists all supported chain specs.

```
ckb init --list-specs
```

Here is an example to export config files for testnet.

```
ckb init --spec testnet
```

Nodes running different chain specs cannot synchronize with each other, so be carefully when editing this option.

## How to Run Multiple Nodes

Each node requires its own `<config-dir>`. Since the default ports will conflict, please export the config files and edit the listen ports in the config files.

```
mkdir node1 node2
ckb -C node1 init
ckb -C node2 init
# Change listen ports 8114/8115 to 8116/8117 in node2/ckb.toml.
# Change `rpc_url` in node2/ckb.toml to use 8116.
# You may also want to add each other as a boot node in the configuration file.
# start node1
ckb -C node1 run
# start node2
ckb -C node2 run
```
62 changes: 62 additions & 0 deletions docs/get-ckb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Get CKB

## Download from Releases

We will publish binaries for each release via [Github Releases](https://github.com/nervosnetwork/ckb/releases). If your system
is listed there, you can download the package directory.


## Build from Source

### Install Build Dependencies

CKB is currently tested mainly with `stable-1.33.0` on Linux and macOS.

We recommend installing Rust through [rustup](https://www.rustup.rs/)

```bash
# Get rustup from rustup.rs, then in your `ckb` folder:
rustup override set 1.33.0
```

Report new breakage is welcome.

You also need to get the following packages:

#### Ubuntu and Debian

```shell
sudo apt-get install git gcc libc6-dev pkg-config libssl-dev libclang-dev clang
```

#### Arch Linux

```shell
sudo pacman -Sy git gcc pkgconf clang
```

#### macOS

```shell
brew install autoconf libtool
```

### Build

```bash
# get ckb source code
git clone https://github.com/nervosnetwork/ckb.git
cd ckb

# build in release mode
make build
```

This will build the executable `target/release/ckb`. Please add the directory
to `PATH` or copy/link the file into a directory already in the `PATH`.

```base
export PATH="$(pwd)/target/release:$PATH"
# or
# ln -snf "$(pwd)/target/release/ckb" /usr/local/bin/ckb
```
Loading

0 comments on commit 3473406

Please sign in to comment.