From e1a3653c251135c371b488dd04f995c8621abf86 Mon Sep 17 00:00:00 2001 From: Edward Evans Date: Mon, 11 May 2020 16:19:20 +1000 Subject: [PATCH 1/4] Handle the list of `besu_bootnodes` the same way we handle other lists Signed-off-by: Edward Evans --- templates/config.toml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/config.toml.j2 b/templates/config.toml.j2 index 1b9c1c6..e39e144 100644 --- a/templates/config.toml.j2 +++ b/templates/config.toml.j2 @@ -92,7 +92,7 @@ permissions-nodes-contract-address="{{ besu_permissions_nodes_contract_address } {% if besu_bootnodes|length > 0 %} # bootnodes -bootnodes={{besu_bootnodes}} +bootnodes=[{{besu_bootnodes|map('to_json')|join(',')}}] {% endif %} {% if orion_version is defined %} From 80d7dbb6cd8aeb77f98d89907be6643d7839d94d Mon Sep 17 00:00:00 2001 From: Edward Evans Date: Mon, 11 May 2020 16:19:48 +1000 Subject: [PATCH 2/4] Add option to configure max-peers Signed-off-by: Edward Evans --- README.md | 1 + templates/config.toml.j2 | 3 +++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index f68668e..2d4ef4e 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults | `besu_identity` | ___unset___ | Configuration of Identity in the Client ID | | `besu_host_ip` | "" | The host IP that Besu uses for the P2P network. This specifies the host on which P2P listens | | `besu_default_ip` | "{{ default(ansible_host) \| default('127.0.0.1') }}" | The fallback default for `besu_host_ip` | +| `besu_max_peers` | ___unset___ | The maximum number of P2P connections you can establish | | `besu_network` | mainnet | The network that this node will join. Other values are 'ropsten', 'rinkeby', 'goerli', 'dev' and 'custom' | | `besu_genesis_path` | ___unset___ | The path to the genesis file, only valid when `besu_network` is `custom` | | `besu_sync_mode` | FAST | Specifies the synchronization mode. Other values are 'FULL' | diff --git a/templates/config.toml.j2 b/templates/config.toml.j2 index e39e144..901965b 100644 --- a/templates/config.toml.j2 +++ b/templates/config.toml.j2 @@ -60,6 +60,9 @@ graphql-http-cors-origins=[{{besu_graphql_http_cors_origins|map('to_json')|join( p2p-host="{{besu_host_ip}}" {% endif %} p2p-port={{besu_p2p_port}} +{% if besu_max_peers is defined %} +max_peers={{besu_max_peers}} +{% endif %} # metrics metrics-enabled=true From 37ceab3780bf4fedf5174df9acda41ab97a08f23 Mon Sep 17 00:00:00 2001 From: Edward Evans Date: Mon, 11 May 2020 16:35:15 +1000 Subject: [PATCH 3/4] Quote cmdline args for use in shell Signed-off-by: Edward Evans --- templates/besu.service.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/besu.service.j2 b/templates/besu.service.j2 index 65ff9cd..610265c 100644 --- a/templates/besu.service.j2 +++ b/templates/besu.service.j2 @@ -12,7 +12,7 @@ Environment=LOG4J_CONFIGURATION_FILE={{ besu_log4j_config_file }} Environment=BESU_OPTS={{ besu_env_opts }} Type=simple {% if besu_cmdline_args %} -ExecStart=/bin/sh -c "{{ besu_current_dir }}/bin/besu --config-file={{ besu_config_dir }}/config.toml {{ besu_cmdline_args }} >> {{besu_log_dir}}/besu.log 2>&1" +ExecStart=/bin/sh -c "{{ besu_current_dir }}/bin/besu --config-file={{ besu_config_dir }}/config.toml {{ besu_cmdline_args|quote }} >> {{besu_log_dir}}/besu.log 2>&1" {% else %} ExecStart=/bin/sh -c "{{ besu_current_dir }}/bin/besu --config-file={{ besu_config_dir }}/config.toml >> {{besu_log_dir}}/besu.log 2>&1" {% endif %} From 92e14a6e7b09bf4ea454c241a7643a89d4b12ac8 Mon Sep 17 00:00:00 2001 From: Edward Evans Date: Thu, 14 May 2020 15:44:38 +1000 Subject: [PATCH 4/4] Add formatting filter for BESU_ENV_OPTS It allows for the `besu_env_opts` variable to be either a whitespace separated string or a list Signed-off-by: Edward Evans --- README.md | 2 +- filter_plugins/besu_filters.py | 18 ++++++++++++++++++ templates/besu.service.j2 | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 filter_plugins/besu_filters.py diff --git a/README.md b/README.md index 2d4ef4e..b3f2fc2 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults | `besu_permissions_accounts_contract_address` | ___unset___ | The contract address for onchain accounts permissioning | | `besu_permissions_nodes_contract_address` | ___unset___ | The contract address for onchain nodes permissioning | | `besu_cmdline_args` | "" | Command line args that are passed in as overrides | -| `besu_env_opts` | "" | Environmental variable BESU_OPTS that gets passed to the JVM. eg: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 | +| `besu_env_opts` | [] | Settings passed to the JVM through `BESU_OPTS` environment variable. eg: `-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005` | | `orion_version` | ___unset___ | Version of Orion installed. When supplied, adds required privacy config items and requires `orion_config_dir` and `orion_key_name` to be set | | `orion_config_dir` | ___unset___ | Path to Orion configuration directory | | `orion_key_name` | ___unset___ | Name of the Node Key | diff --git a/filter_plugins/besu_filters.py b/filter_plugins/besu_filters.py new file mode 100644 index 0000000..7bdba9e --- /dev/null +++ b/filter_plugins/besu_filters.py @@ -0,0 +1,18 @@ +#! /usr/bin/env python + +from typing import Union, List + + +class FilterModule(object): + def filters(self): + return { + 'besu_opts_format': self.besuOptsFormat, + } + + def besuOptsFormat(self, besu_env_opts: Union[str, List[str]]): + if isinstance(besu_env_opts, str): + besu_env_opts = besu_env_opts.split() + + escaped_besu_env_opts = [item.replace('"', '\\"') for item in besu_env_opts] + + return f'''"{'" "'.join(escaped_besu_env_opts)}"''' diff --git a/templates/besu.service.j2 b/templates/besu.service.j2 index 610265c..9dd5d23 100644 --- a/templates/besu.service.j2 +++ b/templates/besu.service.j2 @@ -9,7 +9,7 @@ Environment=HOME=/home/{{ besu_user }} {% if besu_log4j_config_file %} Environment=LOG4J_CONFIGURATION_FILE={{ besu_log4j_config_file }} {% endif %} -Environment=BESU_OPTS={{ besu_env_opts }} +Environment='BESU_OPTS={{ besu_env_opts|besu_opts_format }}' Type=simple {% if besu_cmdline_args %} ExecStart=/bin/sh -c "{{ besu_current_dir }}/bin/besu --config-file={{ besu_config_dir }}/config.toml {{ besu_cmdline_args|quote }} >> {{besu_log_dir}}/besu.log 2>&1"