Update priv validator format in stack.sh to support tm v0.28.0+

Signed-off-by: David Dashyan <mail@davie.li>
This commit is contained in:
David Dashyan 2020-09-07 20:58:21 +03:00
parent d77ab60651
commit 62ae66fef7
4 changed files with 89 additions and 20 deletions

View File

@ -22,21 +22,14 @@
name: "tm_config_gen"
image: "{{ tendermint_image_name }}:{{ tendermint_image_tag }}"
detach: true
env:
STACK_SIZE: "{{ stack_size }}"
TM_DOCKER_NAME: "{{ tendermint_docker_name }}"
volumes:
- "{{ tendermint_host_mount_config_dir }}{{ tendermint_home }}:{{ tendermint_home }}"
- "../scripts:/scripts"
entrypoint: ''
command: |
bash -c 'tendermint init &&
jq ".validators=[]" /tendermint/config/genesis.json > /tendermint/config/genesis.tmp &&
mv /tendermint/config/genesis.tmp /tendermint/config/genesis.json && rm /tendermint/config/node_key.json &&
for i in $( seq {{ stack_size }} );do
tendermint gen_validator > /tendermint/config/priv_validator$i.json;
tendermint gen_node_key > /tendermint/config/node_id$i; mv /tendermint/config/node_key.json /tendermint/config/node_key$i.json;
cat tendermint/config/priv_validator$i.json | jq ".Key.pub_key" | jq ". as \$k | {pub_key: \$k, power: \"10\",
name: \"{{ tendermint_docker_name }}$i\"}" > pub_validator$i.json;
cat /tendermint/config/genesis.json | jq ".validators |= .+ [$(cat pub_validator$i.json)]" > tmpgenesis;
mv tmpgenesis /tendermint/config/genesis.json;
done'
command: /usr/bin/env bash -c "/scripts/tm_config_gen"
when: stack_type|lower == "docker" or stack_type|lower == "cloud"
tags: [tendermint]
@ -56,15 +49,15 @@
- "{{ tendermint_host_mount_dir }}{{ item|string }}{{ tendermint_home }}:{{ tendermint_home }}"
- "{{ tendermint_host_mount_dir }}{{ item|string }}{{ tendermint_data }}:{{ tendermint_data }}"
- "{{ tendermint_host_mount_config_dir }}{{ tendermint_home }}:/tendermint_config"
- "../scripts:/scripts"
entrypoint: ''
command: bash -c 'cp /tendermint_config/genesis.json /tendermint/config/genesis.json &&
jq ".Key" /tendermint_config/priv_validator"{{ item|string }}".json > /tendermint/config/priv_validator_key.json &&
jq ".LastSignState" /tendermint_config/priv_validator"{{ item|string }}".json > /tendermint/data/priv_validator_state.json &&
mv /tendermint_config/node_key"{{ item|string }}".json /tendermint/config/node_key.json &&
peers=() && for i in $( seq {{ stack_size }} );do peers+=($(cat /tendermint_config/node_id$i)@"{{ tendermint_docker_name }}$i:{{ tendermint_p2p_port }}");done &&
peers=$(IFS=","; echo "${peers[*]}") && echo $peers &&
tendermint node --p2p.persistent_peers="$peers" --p2p.laddr "tcp://"{{ tendermint_docker_name }}{{ item|string }}":26656"
--proxy_app="tcp://"{{ bigchaindb_docker_name }}{{ item|string }}":26658" --consensus.create_empty_blocks=false --p2p.pex=false'
command: bash -c "/scripts/tm_start"
env:
STACK_SIZE: "{{ stack_size|string }}"
TM_DOCKER_NAME: "{{ tendermint_docker_name|string }}"
TM_P2P_PORT: "{{ tendermint_p2p_port|string }}"
BIGCHAINDB_DOCKER_NAME: "{{ bigchaindb_docker_name|string }}"
_ITEM: "{{ item|string }}"
state: started
keep_volumes: true
with_sequence: start=1 end="{{ stack_size|int }}" stride=1

View File

@ -16,6 +16,7 @@ stack_repo=${STACK_REPO:="bigchaindb/bigchaindb"}
stack_size=${STACK_SIZE:=4}
stack_type=${STACK_TYPE:="docker"}
stack_type_provider=${STACK_TYPE_PROVIDER:=""}
# NOTE versions prior v0.28.0 have different priv_validator format!
tm_version=${TM_VERSION:="v0.31.5"}
mongo_version=${MONGO_VERSION:="3.6"}
stack_vm_memory=${STACK_VM_MEMORY:=2048}

39
pkg/scripts/tm_config_gen Normal file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Comment: This script is was carved out of start.yml task command. It's
# purpose is to generated tendermint configuration files for each node in
# `stack', and compile genesis.json file. These files are further used in
# tm_start script.
# NOTE following environment have to be set!
# $STACK_SIZE -- self explanatory
# $TM_DOCKER_NAME -- used to identify tendermint containers in the network
tendermint init
cat /tendermint/config/genesis.json \
| jq ".validators=[]" > /tendermint/config/genesis.tmp
mv /tendermint/config/genesis.tmp /tendermint/config/genesis.json
rm /tendermint/config/node_key.json
for i in $(seq $STACK_SIZE); do
tendermint gen_validator > /tendermint/config/priv_validator$i.json;
tendermint gen_node_key > /tendermint/config/node_id$i;
cat tendermint/config/priv_validator$i.json \
| jq ".Key.pub_key" \
| jq ". as \$k | {pub_key: \$k, \
power: \"10\", \
name: \"$TM_DOCKER_NAME$i\"}" \
> pub_validator$i.json;
# added
cat tendermint/config/priv_validator$i.json \
| jq ".Key" > tendermint/config/priv_validator_key$1.json
cat /tendermint/config/genesis.json \
| jq ".validators |= .+ [$(cat pub_validator$i.json)]" \
> tmpgenesis;
mv tmpgenesis /tendermint/config/genesis.json;
done

36
pkg/scripts/tm_start Normal file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Comment: This script is was carved out of start.yml task command. It's
# purpose is to copy generated in tm_config_gen configuration files from mounted
# volume, compile `--p2p.persistent_peers' cmd argument and start tendermint
# node.
# NOTE following environment have to be set!
# $_ITEM -- stack size position identifier
# $STACK_SIZE -- self explanatory
# $TM_DOCKER_NAME -- used to identify tendermint containers in the network
# $BIGCHAINDB_DOCKER_NAME -- self explanatory
# $TM_P2P_PORT -- self explanatory
# Copy confguration files from mounted config volume
cp /tendermint_config/genesis.json \
/tendermint/config/genesis.json
cp /tendermint_config/priv_validator_key$_ITEM.json \
/tendermint/config/priv_validator_key.json
cp /tendermint_config/node_key$_ITEM.json \
/tendermint/config/node_key.json
# Create peers array (to be passed to `tendermint node' command
peers=()
for i in $(seq $STACK_SIZE); do
peers+=($(cat /tendermint_config/node_id$i)@"$TM_DOCKER_NAME$i:$TM_P2P_PORT");
done
peers=$(IFS=","; echo "${peers[*]}")
echo "starting node with persistent peers set to:"
echo $peers
tendermint node \
--p2p.persistent_peers="$peers" \
--p2p.laddr "tcp://"$TM_DOCKER_NAME$_ITEM":26656" \
--proxy_app="tcp://"$BIGCHAINDB_DOCKER_NAME$_ITEM":26658" \
--consensus.create_empty_blocks=false \
--p2p.pex=false