Skip to content

Commit

Permalink
bigchaindb scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dloghin committed Nov 16, 2021
1 parent 61183aa commit 8cf5364
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 6 deletions.
3 changes: 2 additions & 1 deletion go.mod
Expand Up @@ -24,13 +24,14 @@ require (
github.com/mediocregopher/radix/v3 v3.8.0
github.com/mroth/weightedrand v0.4.1 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20210609091139-0a56a4bca00b // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pkg/errors v0.9.1
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/rs/cors v1.8.0 // indirect
github.com/rs/zerolog v1.26.0 // indirect
github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect
github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa // indirect
github.com/spf13/viper v1.9.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tendermint/tendermint v0.35.0
Expand Down
7 changes: 4 additions & 3 deletions scripts/start_bigchaindb.sh
Expand Up @@ -40,12 +40,13 @@ POWERS=`tail +2 power.txt | tr -d '\n'`
for idx in `seq 2 $END_IDX`; do
IDS=`tail +2 ids_$idx.txt | tr -d '\n'`
IPS=`tail +2 ips_$idx.txt | tr -d '\n'`
scp -o StrictHostKeyChecking=no tendermint_config.py root@$PREFIX$idx:/usr/src/app/scripts/
ssh -o StrictHostKeyChecking=no root@$PREFIX$idx "cd /usr/src/app/scripts && ./tendermint_config.py root $GENESIS generate $VALIDATORS $POWERS $IDS $IPS"
scp -o StrictHostKeyChecking=no tendermint_config_v1.py root@$PREFIX$idx:/usr/src/app/scripts/
ssh -o StrictHostKeyChecking=no root@$PREFIX$idx "cd /usr/src/app/scripts && ./tendermint_config_v1.py root $GENESIS generate $VALIDATORS $POWERS $IDS $IPS"
done

rm validators.txt power.txt ids*.txt ips*.txt

for idx in `seq 2 $END_IDX`; do
ssh -o StrictHostKeyChecking=no root@$PREFIX$idx "killall -9 tendermint; sleep 1; /usr/local/bin/tendermint node --p2p.laddr 'tcp://0.0.0.0:26656' --proxy_app='tcp://0.0.0.0:26658' --consensus.create_empty_blocks=false --p2p.pex=false > tendermint.log 2>&1 &"
ssh -o StrictHostKeyChecking=no root@$PREFIX$idx "killall -9 tendermint; sleep 1; /usr/local/bin/tendermint node --p2p.laddr 'tcp://0.0.0.0:26656' --proxy_app='tcp://0.0.0.0:26658' --p2p.pex=false > tendermint.log 2>&1 &"
done
# --consensus.create_empty_blocks=false --p2p.pex=false
4 changes: 2 additions & 2 deletions scripts/stop_bigchaindb.sh
@@ -1,4 +1,4 @@
#!/bin/bash

./multi_node.sh "killall -9 tendermint; killall -9 bigchaindb; killall -9 bigchaindb_ws; killall -9 bigchaindb_exchange; killall -9 mongod"
./multi_node.sh "rm -r /data/db/*"
./multi_node.sh "killall -9 tendermint; killall -9 bigchaindb; killall -9 bigchaindb_ws; killall -9 bigchaindb_exchange; killall -9 mongod; killall -9 gunicorn"
./multi_node.sh "rm -rf /data/db/*; rm -rf /root/.tendermint"
115 changes: 115 additions & 0 deletions scripts/tendermint_config_v1.py
@@ -0,0 +1,115 @@
#!/usr/bin/env python3
import json
import re
import sys
from base64 import b64decode

(TENDERMINT_USER, # str
GENESIS_TIME, # str
CHAIN_ID, # str
B64_VALIDATORS, # base64 encoded json string
VALIDATOR_POWERS, # comma separated string of ints or `default`
NODE_IDS, # comma separated list of node ids
NODE_IPS # comma separated list of node ips
) = sys.argv[1:]

#GENESIS_FILE = ('/home/{tu}/.tendermint/config/genesis.json'
# .format(tu=TENDERMINT_USER))
#TM_CONFIG_FILE = ('/home/{tu}/.tendermint/config/config.toml'
# .format(tu=TENDERMINT_USER))
GENESIS_FILE = '/root/.tendermint/config/genesis.json'
TM_CONFIG_FILE = '/root/.tendermint/config/config.toml'

def edit_genesis() -> None:
"""Insert validators genesis time and chain_id to genesis file."""

validators = json.loads('[{}]'.format(b64decode(B64_VALIDATORS).decode()))

# Update validators powers
for v, p in zip(validators, VALIDATOR_POWERS.split(',')):
if p != 'default':
v['power'] = p

with open(GENESIS_FILE, 'r') as gf:
genesis_conf = json.load(gf)
genesis_conf['validators'] = validators
genesis_conf['genesis_time'] = GENESIS_TIME
genesis_conf['chain_id'] = CHAIN_ID

with open(GENESIS_FILE, 'w') as gf:
json.dump(genesis_conf, gf, indent=True)

return None


def edit_config() -> None:
"""Insert peers ids and addresses to tendermint config file."""

ips = NODE_IPS.split(',')
ids = NODE_IDS.split(',')

persistent_peers = ',\\\n'.join([
'{}@{}:26656'.format(nid, nip) for nid, nip in zip(ids, ips)
])

with open(TM_CONFIG_FILE, 'r') as f:
tm_config_toml = f.read()

with open(TM_CONFIG_FILE, 'w') as f:
f.write(
re.sub(
r'^persistent_peers\s*=\s*".*"',
r'persistent_peers="{pp}"'.format(pp=persistent_peers),
tm_config_toml,
flags=re.MULTILINE
)
)

with open(TM_CONFIG_FILE, 'r') as f:
tm_config_toml = f.read()

s1 = re.sub(
'addr_book_strict = true',
'addr_book_strict = false',
tm_config_toml
)

s2 = re.sub(
'size = 5000',
'size = 100000',
s1
)

s3 = re.sub(
'max-packet-msg-payload-size = 1400',
'max-packet-msg-payload-size = 4096',
s2
)

s4 = re.sub(
'send-rate = 5120000',
'send-rate = 20000000',
s3
)

s5 = re.sub(
'recv-rate = 5120000',
'recv-rate = 20000000',
s4
)

s4 = re.sub(
'log_level = "main:info,state:info,\*:error"',
'log_level = "*:info"',
s3
)

with open(TM_CONFIG_FILE, 'w') as f:
f.write(s2)

return None


if __name__ == '__main__':
edit_genesis()
edit_config()

0 comments on commit 8cf5364

Please sign in to comment.