diff --git a/defaults/main.yml b/defaults/main.yml index 21ea102..c7b7cea 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -47,7 +47,7 @@ geth_websocket_port: '{{ geth_rpc_port + 1 | int }}' geth_websocket_api: 'eth,net,web3,personal,admin' geth_websocket_origins: 'localhost' -# Sync mode: full, fast, light +# Sync mode: full, fast, light, snap geth_sync_mode: 'light' # Maximum number of untrusted peers that can connect geth_max_peers: 50 @@ -64,6 +64,12 @@ geth_trusted_peers_file: '{{ geth_cont_vol }}/data/trusted-nodes.json' # Any additional flags you want to provide geth_extra_flags: [] +# Some custom testnets require a custom init +geth_init_enabled: false +geth_init_genesis_path: '{{ geth_cont_vol }}/genesis.json' +#geth_init_url: ~ +#geth_init_sha256: ~ + # Custom bootnodes geth_bootnodes: [] diff --git a/tasks/generate.yml b/tasks/generate.yml index 470ccda..23e3497 100644 --- a/tasks/generate.yml +++ b/tasks/generate.yml @@ -44,6 +44,7 @@ docker_container: name: '{{ geth_cont_name }}' image: '{{ geth_cont_image }}' + detach: false pull: true auto_remove: yes command: | diff --git a/tasks/init.yml b/tasks/init.yml new file mode 100644 index 0000000..1f3af53 --- /dev/null +++ b/tasks/init.yml @@ -0,0 +1,42 @@ +--- +- name: Download genesis config file + get_url: + url: '{{ geth_init_url | mandatory }}' + dest: '{{ geth_init_genesis_path | mandatory }}' + checksum: 'sha256: {{ geth_init_sha256 | mandatory }}' + owner: dockremap + group: docker + mode: 0644 + +- name: Check if chaindata was created + stat: + path: '{{ geth_cont_vol }}/data/geth/chaindata' + register: geth_chaindata_dir_before + +- name: Initialize network definition + when: not geth_chaindata_dir_before.stat.exists + block: + - name: Run init command with config + docker_container: + name: '{{ geth_cont_name }}-init' + image: '{{ geth_cont_image }}' + user: root + detach: false + auto_remove: true + volumes: + - '{{ geth_cont_vol }}/keys:/keys:rw' + - '{{ geth_cont_vol }}/data:/data:rw' + - '{{ geth_init_genesis_path }}:/genesis.json:rw' + command: | + {{ geth_extra_flags | join(" ") }} --datadir=/data init /genesis.json + + - name: Check if chaindata was created + stat: + path: '{{ geth_cont_vol }}/data/geth/chaindata' + register: geth_chaindata_dir_after + + - name: Verify chaindata folder was created + assert: + that: '{{ geth_chaindata_dir_after.stat.exists }}' + fail_msg: 'Failed to init node genesis state!' + quiet: true diff --git a/tasks/main.yml b/tasks/main.yml index 61350a6..ced5975 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,6 +2,8 @@ - import_tasks: checks.yml - import_tasks: generate.yml - import_tasks: trusted_peers.yml +- import_tasks: init.yml + when: geth_init_enabled - import_tasks: container.yml - import_tasks: firewall.yml - import_tasks: wrappers.yml