Node: more CLI argument

This commit is contained in:
Grégoire Henry 2017-01-23 11:10:07 +01:00
parent 2da0c83b5a
commit b228904bc7
7 changed files with 737 additions and 451 deletions

View File

@ -61,7 +61,7 @@ Running the node in a sandbox
To run a single instance of a Tezos node in sandbox mode: To run a single instance of a Tezos node in sandbox mode:
``` ```
./tezos-node --sandbox /path/to/a/custom/data/dir --rpc-addr :::8732 ./tezos-node --sandbox --rpc-addr :::8732
``` ```
This "sandboxed" node will not participate in the P2P network, but will accept This "sandboxed" node will not participate in the P2P network, but will accept
@ -77,20 +77,22 @@ test network. Use the following command to run a node that will accept incoming
connections: connections:
``` ```
./tezos-node ./tezos-node --generate-identity --expected-pow 24.
``` ```
The node will listen to connections coming in on `0.0.0.0:9732` (and This will first generate a new node identity and compute the associated stamp
`[::]:9732`). All used data is stored at `$HOME/.tezos-node/`. For example, of proof-of-work. Then, the node will listen to connections coming in on
the default configuration file is at `$HOME/.tezos-node/config`. `0.0.0.0:9732` (and`[::]:9732`). All used data is stored at
`$HOME/.tezos-node/`. For example, the default configuration file is
at `$HOME/.tezos-node/config.json`.
To run multiple nodes on the same machine, you can duplicate and edit To run multiple nodes on the same machine, you can duplicate and edit
`$HOME/.tezos-node/config` while making sure they don't share paths to the `$HOME/.tezos-node/config.json` while making sure they don't share paths to the
database or any other data file (cf. options `db.store` ; `db.context` ; database or any other data file (cf. options `db.store` ; `db.context` ;
`net.peers` and `protocol.dir`). `db.protocol`, `net.peers-metadata` and `net.identity`).
You could also let Tezos generate a config file by specifying options on the You could also let Tezos generate a config file by specifying options on the
command line. For instance, if `$dir/config` does not exist, the following command line. For instance, if `$dir/config.json` does not exist, the following
command will generate it and replace the default values with the values from command will generate it and replace the default values with the values from
the command line: the command line:
@ -102,20 +104,23 @@ The Tezos server has a built-in mechanism to discover peers on the local
network (using UDP packets broadcasted on port 7732). network (using UDP packets broadcasted on port 7732).
If this mechanism is not sufficient, one can provide Tezos with a list of If this mechanism is not sufficient, one can provide Tezos with a list of
initial peers, either by editing the option `net.bootstrap.peers` in the initial peers, either by editing the option `net.bootstrap-peers` in the
`config` file, or by specifying a command line parameter: `config.json` file, or by specifying a command line parameter:
``` ```
./tezos-node --base-dir "$dir" --net-addr 127.0.0.1:2023 \ ./tezos-node --base-dir "$dir" --net-addr 127.0.0.1:2023 \
--peer 127.0.0.1:2021 --peer 127.0.0.1:2022 --peer 127.0.0.1:2021 --peer 127.0.0.1:2022
``` ```
If `"$dir"/config` exists, the command line options override those read in the If `"$dir"/config.json` exists, the command line options override those
config file. Tezos won't modify the content of an existing `"$dir"/config` read in the config file. By default, Tezos won't modify the content of an
file. existing `"$dir"/config.json` file. But, you may explicit ask the node
to reset or to update the file according to the command line parameters
with the following commands line:
``` ```
./tezos-node --config-file "$dir"/config ./tezos-node --reset-config --base-dir "$dir" --net-addr 127.0.0.1:9733
./tezos-node --update-config --base-dir "$dir" --net-addr 127.0.0.1:9734
``` ```
@ -129,7 +134,7 @@ Typically, if you are not trying to run a local network and just want to
explore the RPC, you would run: explore the RPC, you would run:
``` ```
./tezos-node --sandbox /path/to/a/custom/data/dir --rpc-addr :::8732 ./tezos-node --sandbox --rpc-addr :::8732
``` ```
The RPC interface is self-documented and the `tezos-client` executable is able The RPC interface is self-documented and the `tezos-client` executable is able
@ -151,7 +156,7 @@ You might also want the JSON schema describing the expected input and output of
a RPC. For instance: a RPC. For instance:
``` ```
./tezos-client rpc schema /block/genesis/hash ./tezos-client rpc schema /blocks/genesis/hash
``` ```
Note: you can get the same information, but as a raw JSON object, with a simple Note: you can get the same information, but as a raw JSON object, with a simple
@ -170,4 +175,4 @@ The minimal CLI client
Work in progress. Work in progress.
See `./tezos-client -help` for available commands. See `./tezos-client -help` for available commands.

View File

@ -449,7 +449,7 @@ module Gid_info = struct
let load path metadata_encoding = let load path metadata_encoding =
let enc = Data_encoding.list (encoding metadata_encoding) in let enc = Data_encoding.list (encoding metadata_encoding) in
if Sys.file_exists path then if path <> "/dev/null" && Sys.file_exists path then
Data_encoding_ezjsonm.read_file path >>=? fun json -> Data_encoding_ezjsonm.read_file path >>=? fun json ->
return (Data_encoding.Json.destruct enc json) return (Data_encoding.Json.destruct enc json)
else else

View File

@ -215,9 +215,17 @@ let init_p2p net_params =
Lwt.async (fun () -> Tezos_p2p.maintain p2p) ; Lwt.async (fun () -> Tezos_p2p.maintain p2p) ;
Lwt.return p2p Lwt.return p2p
type config = {
genesis: Store.genesis ;
store_root: string ;
context_root: string ;
test_protocol: Protocol_hash.t option ;
patch_context: (Context.t -> Context.t Lwt.t) option ;
p2p: (P2p.config * P2p.limits) option ;
}
let create let create { genesis ; store_root ; context_root ;
~genesis ~store_root ~context_root ?test_protocol ?patch_context net_params = test_protocol ; patch_context ; p2p = net_params } =
lwt_debug "-> Node.create" >>= fun () -> lwt_debug "-> Node.create" >>= fun () ->
init_p2p net_params >>= fun p2p -> init_p2p net_params >>= fun p2p ->
lwt_log_info "reading state..." >>= fun () -> lwt_log_info "reading state..." >>= fun () ->

View File

@ -9,14 +9,16 @@
type t type t
val create: type config = {
genesis:Store.genesis -> genesis: Store.genesis ;
store_root:string -> store_root: string ;
context_root:string -> context_root: string ;
?test_protocol:Protocol_hash.t -> test_protocol: Protocol_hash.t option ;
?patch_context:(Context.t -> Context.t Lwt.t) -> patch_context: (Context.t -> Context.t Lwt.t) option ;
(P2p.config * P2p.limits) option -> p2p: (P2p.config * P2p.limits) option ;
t tzresult Lwt.t }
val create: config -> t tzresult Lwt.t
module RPC : sig module RPC : sig

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,8 @@ set -e
DIR=$(dirname "$0") DIR=$(dirname "$0")
cd "${DIR}" cd "${DIR}"
DATA_DIR=$(mktemp -d /tmp/tezos_node.XXXXXXXXXX) DATA_DIR="$(mktemp -td tezos_node.XXXXXXXXXX)"
CLIENT_DIR=$(mktemp -d /tmp/tezos_client.XXXXXXXXXX) CLIENT_DIR="$(mktemp -td tezos_client.XXXXXXXXXX)"
cleanup() { cleanup() {
rm -fr ${DATA_DIR} ${CLIENT_DIR} rm -fr ${DATA_DIR} ${CLIENT_DIR}
@ -17,8 +17,8 @@ trap cleanup EXIT QUIT INT
NODE=../tezos-node NODE=../tezos-node
CLIENT="../tezos-client -base-dir ${CLIENT_DIR}" CLIENT="../tezos-client -base-dir ${CLIENT_DIR}"
CUSTOM_PARAM="--sandbox-param ./sandbox.json" CUSTOM_PARAM="--sandbox ./sandbox.json"
${NODE} --sandbox "${DATA_DIR}" ${CUSTOM_PARAM} --rpc-addr :::8732 > LOG 2>&1 & ${NODE} --base-dir "${DATA_DIR}" ${CUSTOM_PARAM} --rpc-addr :::8732 > LOG 2>&1 &
NODE_PID="$!" NODE_PID="$!"
sleep 3 sleep 3

View File

@ -50,8 +50,8 @@ let fork_node () =
Unix.create_process Unix.create_process
Filename.(concat (dirname (Sys.getcwd ())) "tezos-node") Filename.(concat (dirname (Sys.getcwd ())) "tezos-node")
[| "tezos-node" ; [| "tezos-node" ;
"--sandbox"; data_dir ; "--base-dir"; data_dir ;
"--sandbox-param"; "./sandbox.json"; "--sandbox"; "./sandbox.json";
"--rpc-addr"; ":::8732" |] "--rpc-addr"; ":::8732" |]
null_fd log_fd log_fd in null_fd log_fd log_fd in
Printf.printf "Created node, pid: %d, log: %s\n%!" pid log_file_name ; Printf.printf "Created node, pid: %d, log: %s\n%!" pid log_file_name ;