From 910b43726b8a3c6e8613582ace2313bc6c18b98a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Sat, 11 Nov 2017 03:34:12 +0100 Subject: [PATCH] Shell: add CLI options for `bootstrap_threshold` --- README.md | 11 +++++++++ src/node/main/node_config_file.ml | 38 ++++++++++++++++++++++++++---- src/node/main/node_config_file.mli | 6 +++++ src/node/main/node_run_command.ml | 2 +- src/node/main/node_shared_arg.ml | 16 +++++++++---- src/node/main/node_shared_arg.mli | 1 + 6 files changed, 63 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6bd6a5428..1e00b73b5 100644 --- a/README.md +++ b/README.md @@ -334,6 +334,17 @@ help writing your own configuration file if needed. http://ocsigen.org/lwt/dev/api/Lwt_log_core#2_Logtemplates. */ "template": "$(date) - $(section): $(message)" + }, + + /* Configuration for the validator and mempool parameters */ + + "shell": { + + /* The number of peers to synchronize with + before declaring the node 'bootstrapped'. */ + + "bootstrap_threshold": 4 + } } ``` diff --git a/src/node/main/node_config_file.ml b/src/node/main/node_config_file.ml index 586feeb96..0f5d7b855 100644 --- a/src/node/main/node_config_file.ml +++ b/src/node/main/node_config_file.ml @@ -22,6 +22,7 @@ type t = { net : net ; rpc : rpc ; log : log ; + shell : shell ; } and net = { @@ -51,6 +52,10 @@ and log = { template : Logging.template ; } +and shell = { + bootstrap_threshold : int ; +} + let default_net_limits : P2p.limits = { authentification_timeout = 5. ; min_connections = 10 ; @@ -96,11 +101,16 @@ let default_log = { template = Logging.default_template ; } +let default_shell = { + bootstrap_threshold = 4 ; +} + let default_config = { data_dir = default_data_dir ; net = default_net ; rpc = default_rpc ; log = default_log ; + shell = default_shell ; } let limit : P2p.limits Data_encoding.t = @@ -235,16 +245,27 @@ let log = (opt "rules" string) (dft "template" string default_log.template)) +let shell = + let open Data_encoding in + conv + (fun { bootstrap_threshold } -> bootstrap_threshold) + (fun bootstrap_threshold -> { bootstrap_threshold }) + (obj1 + (dft "bootstrap_threshold" uint8 default_shell.bootstrap_threshold)) + let encoding = let open Data_encoding in conv - (fun { data_dir ; rpc ; net ; log } -> (data_dir, rpc, net, log)) - (fun (data_dir, rpc, net, log) -> { data_dir ; rpc ; net ; log }) - (obj4 + (fun { data_dir ; rpc ; net ; log ; shell } -> + (data_dir, rpc, net, log, shell)) + (fun (data_dir, rpc, net, log, shell) -> + { data_dir ; rpc ; net ; log ; shell }) + (obj5 (dft "data-dir" string default_data_dir) (dft "rpc" rpc default_rpc) (req "net" net) - (dft "log" log default_log)) + (dft "log" log default_log) + (dft "shell" shell default_shell)) let read fp = if Sys.file_exists fp then begin @@ -281,6 +302,7 @@ let update ?(cors_headers = []) ?rpc_tls ?log_output + ?bootstrap_threshold cfg = let data_dir = Utils.unopt ~default:cfg.data_dir data_dir in Node_data_version.ensure_data_dir data_dir >>=? fun () -> @@ -342,8 +364,14 @@ let update cfg.log with output = Utils.unopt ~default:cfg.log.output log_output ; } + and shell : shell = { + bootstrap_threshold = + Utils.unopt + ~default:cfg.shell.bootstrap_threshold + bootstrap_threshold ; + } in - return { data_dir ; net ; rpc ; log } + return { data_dir ; net ; rpc ; log ; shell } let resolve_addr ?default_port ?(passive = false) peer = let addr, port = Utils.parse_addr_port peer in diff --git a/src/node/main/node_config_file.mli b/src/node/main/node_config_file.mli index b61bf0d73..dc4c985a3 100644 --- a/src/node/main/node_config_file.mli +++ b/src/node/main/node_config_file.mli @@ -12,6 +12,7 @@ type t = { net : net ; rpc : rpc ; log : log ; + shell : shell ; } and net = { @@ -41,6 +42,10 @@ and log = { template : Logging.template ; } +and shell = { + bootstrap_threshold : int ; +} + val default_data_dir: string val default_net_port: int val default_rpc_port: int @@ -65,6 +70,7 @@ val update: ?cors_headers:string list -> ?rpc_tls:tls -> ?log_output:Logging.Output.t -> + ?bootstrap_threshold:int -> t -> t tzresult Lwt.t val to_string: t -> string diff --git a/src/node/main/node_run_command.ml b/src/node/main/node_run_command.ml index 538e56aa5..644413c11 100644 --- a/src/node/main/node_run_command.ml +++ b/src/node/main/node_run_command.ml @@ -142,7 +142,7 @@ let init_node ?sandbox (config : Node_config_file.t) = context_root = context_dir config.data_dir ; p2p = p2p_config ; test_network_max_tll = Some (48 * 3600) ; (* 2 days *) - bootstrap_threshold = 4 ; (* TODO add parameter *) + bootstrap_threshold = config.shell.bootstrap_threshold ; } in Node.create node_config diff --git a/src/node/main/node_shared_arg.ml b/src/node/main/node_shared_arg.ml index c49f16343..371c128e8 100644 --- a/src/node/main/node_shared_arg.ml +++ b/src/node/main/node_shared_arg.ml @@ -32,6 +32,7 @@ type t = { cors_headers: string list ; rpc_tls: Node_config_file.tls option ; log_output: Logging.Output.t option ; + bootstrap_threshold: int option ; } let wrap @@ -55,10 +56,11 @@ let wrap (* when `--expected-connections` is used, override all the bounds defined in the configuration file. *) - let min_connections, expected_connections, max_connections = + let bootstrap_threshold, + min_connections, expected_connections, max_connections = match connections with - | None -> None, None, None - | Some x -> Some (x/2), Some x, Some (3*x/2) in + | None -> None, None, None, None + | Some x -> Some (min (x/4) 2), Some (x/2), Some x, Some (3*x/2) in { data_dir ; config_file ; @@ -79,6 +81,7 @@ let wrap rpc_tls ; log_output ; peer_table_size ; + bootstrap_threshold ; } module Manpage = struct @@ -258,7 +261,9 @@ let read_and_patch_config_file ?(ignore_bootstrap_peers=false) args = listen_addr ; closed ; rpc_listen_addr ; rpc_tls ; cors_origins ; cors_headers ; - log_output } = args in + log_output ; + bootstrap_threshold ; + } = args in let bootstrap_peers = if no_bootstrap_peers || ignore_bootstrap_peers then begin @@ -271,4 +276,5 @@ let read_and_patch_config_file ?(ignore_bootstrap_peers=false) args = ?max_download_speed ?max_upload_speed ?binary_chunks_size ?peer_table_size ?expected_pow ~bootstrap_peers ?listen_addr ?rpc_listen_addr - ~closed ~cors_origins ~cors_headers ?rpc_tls ?log_output cfg + ~closed ~cors_origins ~cors_headers ?rpc_tls ?log_output + ?bootstrap_threshold cfg diff --git a/src/node/main/node_shared_arg.mli b/src/node/main/node_shared_arg.mli index 37dd80fd5..695cd7b23 100644 --- a/src/node/main/node_shared_arg.mli +++ b/src/node/main/node_shared_arg.mli @@ -27,6 +27,7 @@ type t = { cors_headers: string list ; rpc_tls: Node_config_file.tls option ; log_output: Logging.Output.t option ; + bootstrap_threshold: int option ; } module Term : sig