Commit 3e071861 authored by Victor Khilin's avatar Victor Khilin
Browse files

Multi nodes generator

parent 735ea93a
FROM anapsix/alpine-java:8_server-jre
ARG node_version=1.0.2
COPY Dockerfile_content/accounts_template.conf /node/
COPY Dockerfile_content/generate.sh /node/
COPY tmp/jcp-2.0.39014.tar.gz /node/jcp/
COPY tmp/jcp-*.tar.gz /node/jcp/
RUN chmod +x /node/generate.sh && \
apk update && \
apk add wget gettext bash libxext libxrender libxtst libxi && \
wget -q https://github.com/vostokplatform/Vostok-Releases/releases/download/${node_version}/generators-${node_version}.jar -O /node/generator.jar || true
wget -q https://artifacts.vostokservices.com/repository/fileshare/node_build/generators-${node_version}.jar -O /node/generator.jar
ENTRYPOINT "/node/generate.sh"
......@@ -49,12 +49,14 @@ def create_configmap(config_name, filetype='text'):
if __name__=="__main__":
parser = OptionParser()
parser.add_option("-n", "--node_version", type="string", dest="node_version", default="we1.0", help="define node version")
parser.add_option("-c", "--chain-id", type="string", dest="chain_id", default="V", help="network byte")
parser.add_option("-w", "--waves-crypto", type="choice", action="store", dest="waves_crypto", choices=["yes","no"], default="yes", help="use waves crypto(yes - waves, no - gost)")
parser.add_option("-a", "--amount", type="int", dest="amount", default=3, help="amount of keys")
parser.add_option("-p", "--password", type="string", dest="password", default=randomString(), help="wallet password(default: autogenerated)")
parser.add_option("--create-configmap", type="string", dest="kuber_config", default="yes", help="Generate kubernetes configmap for nodes (yes/no)")
parser.add_option("--existing-genesis", type="string", dest="use_existing_genesis", default="no", help="Use existing genesis from genesis_backup.conf if exist?")
parser.add_option("-e", "--node_evolved", type="string", dest="node_evolved", default="Y", help="Y is it is release-we1.0 or higher and N in another case")
options, args = parser.parse_args()
if os.path.exists('/usr/bin/docker'):
docker = '/usr/bin/docker'
......@@ -69,20 +71,23 @@ if __name__=="__main__":
options.use_existing_genesis = 'no'
jcp_name = 'jcp-2.0.39014.tar.gz'
jcp_name = {'N' : 'jcp-2.0.39014.tar.gz', 'Y' : 'jcp-2.0.40035.tar.gz'}
dst_jcp = './tmp/'
if not os.path.exists(dst_jcp):
os.mkdir(dst_jcp)
if os.path.exists(dst_jcp):
shutil.rmtree(dst_jcp)
os.mkdir(dst_jcp)
r = requests.get('https://artifacts.vostokservices.com/repository/fileshare/node_build/jcp-2.0.39014.tar.gz')
with open('{}/{}'.format(dst_jcp,jcp_name), 'wb') as f:
r_url = 'https://artifacts.vostokservices.com/repository/fileshare/node_build/' + jcp_name[options.node_evolved]
r = requests.get(r_url)
with open('{}/{}'.format(dst_jcp,jcp_name[options.node_evolved]), 'wb') as f:
f.write(r.content)
build_image_cmd = [docker, 'build', '-t', 'node_config_generator', '.']
subprocess.run(build_image_cmd)
generate_cmd = [docker, 'run', '-it',
'-e', 'node_version={}',format(options.node_version),
'-e', 'VOSTOK_NODE_OWNER_PASSWORD={}'.format(options.password),
'-e', 'VOSTOK_NODE_OWNER_PASSWORD_EMPTY=true',
'-e', 'waves_crypto={}'.format(options.waves_crypto),
......@@ -102,12 +107,17 @@ if __name__=="__main__":
shutil.rmtree(dst_jcp)
#generate config template
conf = ConfigFactory.parse_file('{}/node_config_templates/main.conf'.format(get_current_path()))
if options.node_evolved == 'Y':
conf = ConfigFactory.parse_file('{}/node_config_templates/main.conf'.format(get_current_path()))
vostok = 'vostok'
else:
conf = ConfigFactory.parse_file('{}/node_config_templates/we_main.conf'.format(get_current_path()))
vostok = 'node'
conf['vostok']['wallet']['password'] = options.password
conf['vostok']['blockchain']['custom']['address-scheme-character'] = options.chain_id
conf[vostok]['wallet']['password'] = options.password
conf[vostok]['blockchain']['custom']['address-scheme-character'] = options.chain_id
initial_balance = conf['vostok']['blockchain']['custom']['genesis']['initial-balance']
initial_balance = conf[vostok]['blockchain']['custom']['genesis']['initial-balance']
initial_balance_remain = initial_balance
keys_remain = options.amount
......@@ -119,17 +129,17 @@ if __name__=="__main__":
keys_remain = keys_remain - 1
conf_transactions = ConfigFactory.from_dict(transactions)
conf['vostok']['blockchain']['custom']['genesis']['transactions'] = conf_transactions
conf[vostok]['blockchain']['custom']['genesis']['transactions'] = conf_transactions
network_participants = []
for key in keys:
network_participants.append({'public-key': key[1], 'roles': ['miner', 'permissioner', 'connection_manager']})
conf_network_participants = ConfigFactory.from_dict(network_participants)
conf['vostok']['blockchain']['custom']['genesis']['network-participants'] = conf_network_participants
conf[vostok]['blockchain']['custom']['genesis']['network-participants'] = conf_network_participants
conf['vostok']['blockchain']['custom']['genesis']['timestamp'] = int(time.time())*1000
conf['vostok']['blockchain']['custom']['genesis']['block-timestamp'] = (int(time.time())+20)*1000
conf[vostok]['blockchain']['custom']['genesis']['timestamp'] = int(time.time())*1000
conf[vostok]['blockchain']['custom']['genesis']['block-timestamp'] = (int(time.time())+20)*1000
f = open('{}/output/presign_genesis.conf'.format(get_current_path()), 'w')
f.write(HOCONConverter.convert(conf, 'hocon'))
......@@ -139,21 +149,21 @@ if __name__=="__main__":
if options.use_existing_genesis == 'yes':
genesis_yaml = ConfigFactory.parse_file('{}/genesis_backup.conf'.format(get_current_path()))
signed_template_yaml = ConfigFactory.parse_file('{}/output/presign_genesis.conf'.format(get_current_path()))
signed_template_yaml['vostok']['blockchain']['custom']['genesis'] = genesis_yaml
signed_template_yaml[vostok]['blockchain']['custom']['genesis'] = genesis_yaml
else:
subprocess.run(['docker', 'run', '-it', '--rm', '-v', '{}/output:/output'.format(os.getcwd()), '-e', 'SIGN_GENESIS=1', '-e', 'NODE_CONFIG=/output/presign_genesis.conf', 'node_config_generator' ])
signed_template_yaml = ConfigFactory.parse_file('{}/output/presign_genesis.conf'.format(get_current_path()))
f = open('{}/genesis_backup.conf'.format(get_current_path()), 'w')
f.write(HOCONConverter.convert(signed_template_yaml['vostok']['blockchain']['custom']['genesis'], 'hocon'))
f.write(HOCONConverter.convert(signed_template_yaml[vostok]['blockchain']['custom']['genesis'], 'hocon'))
f.close()
#generate config for nodes
for i in range(len(keys)):
signed_template_yaml['vostok']['owner-address'] = keys[i][0]
signed_template_yaml['vostok']['miner']['quorum'] = len(keys)-1
signed_template_yaml['vostok']['docker-engine']['node-rest-api'] = "https://${EXTERNAL_ENDPOINT}/node-" + str(i)
signed_template_yaml['vostok']['privacy']['storage']['url'] = "jdbc:postgresql://node-" + str(i) + "-${PG_HOST_NODE}:5432/dcp_privacy_node_" + str(i) + "?user=user_dcp_privacy_node_" + str(i) + "&password=${PG_PASS_NODE}&sslmode=require"
signed_template_yaml[vostok]['owner-address'] = keys[i][0]
signed_template_yaml[vostok]['miner']['quorum'] = len(keys)-1
signed_template_yaml[vostok]['docker-engine']['node-rest-api'] = "https://${EXTERNAL_ENDPOINT}/node-" + str(i)
signed_template_yaml[vostok]['privacy']['storage']['url'] = "jdbc:postgresql://node-" + str(i) + "-${PG_HOST_NODE}:5432/dcp_privacy_node_" + str(i) + "?user=user_dcp_privacy_node_" + str(i) + "&password=${PG_PASS_NODE}&sslmode=require"
f = open("./output/node-{}.conf".format(i), "w")
f.write(HOCONConverter.convert(signed_template_yaml, 'hocon'))
f.close()
......
vostok {
node {
wallet {
file = "wallet"
password = "svupkey"
......
node {
network.enable-blacklisting = no
synchronization.synchronization-timeout = 3m
waves-crypto = no
logging-level = DEBUG
directory = "/node/data/"
data-directory = "/node/data/data"
ntp.fatal-timeout = "1 minute"
ntp.server = "0.ru.pool.ntp.org"
blockchain {
fees {
genesis = 0
genesis-permit = 0
issue = 0
transfer = 0
reissue = 0
burn = 5000000
exchange = 500000
lease = 1000000
lease-cancel = 1000000
create-alias = 0
mass-transfer = 5000000
data = 0
set-script = 50000000
sponsor-fee = 100000000
set-asset-script = 100000000
permit = 0
create-contract = 0
call-contract = 0
executed-contract = 0
disable-contract = 1000000
update-contract = 0
register-node = 0
create-policy = 0
update-policy = 0
policy-data-hash = 0
additional {
mass-transfer = 1000000
data = 1000000
}
}
type = CUSTOM
consensus {
type = poa
round-duration = 10s
sync-duration = 1s
ban-duration-blocks = 20
warnings-for-ban = 5
max-bans-percentage = 30
}
custom {
address-scheme-character = ""
functionality {
feature-check-blocks-period = 15000
blocks-for-feature-activation = 10000
pre-activated-features = {
2 = 0
3 = 0
4 = 0
5 = 0
6 = 0
7 = 0
9 = 0
10 = 0
}
}
genesis {
average-block-delay: 40s
initial-base-target: 10000000000
timestamp: 1565783396000
block-timestamp: 1565783396000
initial-balance: 100000000000000000
genesis-public-key-base-58: ""
signature: ""
transactions = [
]
network-participants = [
]
}
}
}
transaction-rebroadcaster {
enable = no
delay = 0s
types = []
}
miner {
quorum = 1
interval-after-last-block-then-generation-is-allowed = 35d
micro-block-interval = 2s
min-micro-block-age = 3s
max-transactions-in-micro-block = 500
minimal-block-generation-offset = 200ms
}
privacy {
# Node privacy settings (allow all nodes to join or not)
allow-all-nodes = false
# DB connection config
storage {
enabled = true
driver = "org.postgresql.Driver"
profile = "slick.jdbc.PostgresProfile$"
connectionPool = HikariCP
connectionTimeout = 5000
connectionTestQuery = "SELECT 1"
queueSize = 10000
numThreads = 10
schema = "public"
migration-dir = "db/migration"
}
}
docker-engine {
docker-host = "http://proxy-to-dockerhost:8081"
enable = yes
node-rest-api = "https://${EXTERNAL_ENDPOINT}/node-0"
allow-net-access = yes
check-image-hash = no
execution-limits {
timeout = 10s
memory = 512
memory-swap = 512
}
}
network {
# Network address
bind-address = "0.0.0.0"
# Port number
port = 6864
# Node name to send during handshake. Comment this string out to set random node name.
# String with IP address and port to send as external address during handshake. Could be set automatically if uPnP is enabled.
declared-address = "0.0.0.0:6864"
known-peers = ["node-0:6864", "node-1:6864", "node-2:6864"]
}
rest-api {
enable = yes
bind-address = "0.0.0.0"
port = 6862
auth {
type: "api-key"
api-key-hash = DACAEAAK1MosP6Jjjhff2TVNDkBBszgqssD32GfU4iBf
privacy-api-key-hash = DACAEAAK1MosP6Jjjhff2TVNDkBBszgqssD32GfU4iBf #svupkey
}
}
}
include "local_template.conf"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment