Commit 4be627d6 authored by Sergey Shiktarev's avatar Sergey Shiktarev
Browse files

first commit

parents
output
temp
FROM registry.vostokservices.com/vostok/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/
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
#ENTRYPOINT "/bin/sh"
ENTRYPOINT "/node/generate.sh"
accounts-generator {
waves-crypto = ${waves_crypto}
chain-id = ${chain_id}
amount = ${amount}
wallet = "/node/wallet"
wallet-password = "${wallet_password}"
reload-node-wallet {
enabled = false
url = "http://localhost:6869/utils/reload-wallet"
}
}
#!/bin/bash
tar xvfz /node/jcp/jcp* --directory /node/jcp
rm /node/jcp/jcp*.gz
cd /node/jcp/$(ls /node/jcp)
/bin/sh setup_console.sh /opt/jdk1.8.0_202 -force -en -install -jcp -jcryptop
cd /node
java ru.CryptoPro.JCP.Random.BioRandomConsole
if [[ $SIGN_GENESIS == 1 ]]; then
echo "Node config is ${NODE_CONFIG}"
yes '' | java -jar /node/generator.jar GenesisBlockGenerator $NODE_CONFIG # >>__<<
exit 0
fi
#generate keys
envsubst < /node/accounts_template.conf > /node/accounts.conf
yes '' | java -jar /node/generator.jar AccountsGeneratorApp /node/accounts.conf # >>__<<
rm -rf /output/*
tar cvfz /output/wallet.tar.gz.b64 /node/wallet
First:
pip install -r requirements.txt
average-block-delay = "40s"
initial-base-target = 10000000000
timestamp = 1567505972000
block-timestamp = 1567505992000
initial-balance = 100000000000000000
genesis-public-key-base-58 = "4opxpkEE3fyCHezcdyw1eVtonXDkGWyaJbzTjjnGQjLHYnKnLJdXcZaY83DgZz71xfdMmiAjBZRor1PjDh22Ju1G"
signature = "61qULWNEBQAhzGCbNnuKC1V5sc3Dqp7jNN7mvHscGDjnzgidFZuxerh3KsjuvzLdTqMn1MFA18dbQq7wwtjDVcbw"
transactions = [
{
recipient = "3EJ3VkEP7sCsyftvZGxJnpR8Ys5AAz7nTxR"
amount = 33333333333333332
}
{
recipient = "3EMzUip8eCfeaTj2UHBaSEAFHRvBNgQCpLb"
amount = 33333333333333334
}
{
recipient = "3EKm8mz5G4q6qFYUKZ9ZJ5nHt2UVS8qnYyB"
amount = 33333333333333334
}
]
network-participants = [
{
public-key = "36hoAFELaVVfcvC4c1C7xUH8ZEsqPALSDogiKe9ZzD1cNE7ED7PGSNhwhkPzzVBKXAd8DFwAKMKKieC1zje2nqfg"
roles = [
"miner"
"permissioner"
"connection_manager"
]
}
{
public-key = "2eRHTa7khSbi5KiS4Vqt9GeiRfgkAngybcyDXTyWF5rnfpiy7ogjLHQPjRy3E31skDLKu6jbWisg6oprovoEwtEK"
roles = [
"miner"
"permissioner"
"connection_manager"
]
}
{
public-key = "3GEP2v6jdtoYcb7gYTDhD4fPHA6x4Hjeyi469f1budgicrRrUckCpwjuJmVuwu9uZrYhnLBrgQyKgbVLAsFg3FSU"
roles = [
"miner"
"permissioner"
"connection_manager"
]
}
]
\ No newline at end of file
#!/usr/bin/env python3
from pyhocon import ConfigFactory
from pyhocon import HOCONConverter
from optparse import OptionParser
from shutil import copyfile
from pprint import pprint
import subprocess
import random
import codecs
import string
import shutil
import sys
import os
import re
import yaml
import base64
import time
def randomString(stringLength=10):
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(stringLength))
def get_current_path():
return os.path.dirname(os.path.realpath(__file__))
def create_configmap(config_name, filetype='text'):
configmap_path = '{}/output/configmap.yaml'.format(get_current_path())
template_configmap_path = '{}/node_config_templates/configmap_template.yaml'.format(get_current_path())
config_path = '{}/output/{}'.format(get_current_path(), config_name)
if not os.path.exists(configmap_path):
yaml_template = open(template_configmap_path, 'r').read()
else:
yaml_template = open(configmap_path, 'r').read()
if filetype == 'binary':
config = open(config_path, 'rb').read()
config = base64.b64encode(config)
else:
config = open(config_path, 'r').read()
yaml_obj = yaml.safe_load(yaml_template)
yaml_obj['data'][config_name] = config
yaml_obj['metadata']['name'] = 'dcp-conf'
yaml_obj['metadata']['namespace'] = '${NAMESPACE}'
yaml_dump = yaml.dump(yaml_obj, default_style='|')
configmap_handle = open(configmap_path, 'w')
configmap_handle.write(yaml_dump)
configmap_handle.close()
if __name__=="__main__":
parser = OptionParser()
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="no", help="Generate kubernetes configmap for nodes (yes/no)")
parser.add_option("--existing-genesis", type="string", dest="use_existing_genesis", default="yes", help="Use existing genesis from genesis_backup.conf if exist?")
options, args = parser.parse_args()
if os.path.exists('/usr/bin/docker'):
docker = '/usr/bin/docker'
elif os.path.exists('/usr/local/bin/docker'):
docker = '/usr/local/bin/docker'
else:
print('docker not found')
sys.exit(1)
if not os.path.isfile('{}/genesis_backup.conf'.format(get_current_path())):
print("Setting --existing-genesis to no, because there are no file " + '{}/genesis_backup.conf'.format(get_current_path()))
options.use_existing_genesis = 'no'
src_dir = "../../../lib"
jcp_name = "jcp-2.0.39014.tar.gz"
src_jcp = "{}/{}".format(src_dir, jcp_name)
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)
copyfile(src_jcp, "{}/{}".format(dst_jcp, jcp_name))
build_image_cmd = [docker, 'build', '-t', 'node_config_generator', '.']
subprocess.run(build_image_cmd)
generate_cmd = [docker, 'run', '-it',
'-e', 'VOSTOK_NODE_OWNER_PASSWORD={}'.format(options.password),
'-e', 'VOSTOK_NODE_OWNER_PASSWORD_EMPTY=true',
'-e', 'waves_crypto={}'.format(options.waves_crypto),
'-e', 'chain_id={}'.format(options.chain_id),
'-e', 'amount={}'.format(options.amount),
'-e', 'wallet_password={}'.format(options.password),
'--rm', '-v', '{}/output:/output'.format(os.getcwd()), 'node_config_generator']
#print(' '.join(map(str,generate_cmd)))
#sys.exit(0)
log = subprocess.run(generate_cmd, universal_newlines=True, stdout=subprocess.PIPE).stdout
keys = re.findall(r'Address: (3.{34}).+?key: (\w+)', log) # >>__<<
print(log)
if os.path.exists(dst_jcp):
shutil.rmtree(dst_jcp)
#generate config template
conf = ConfigFactory.parse_file('{}/node_config_templates/main.conf'.format(get_current_path()))
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_remain = initial_balance
keys_remain = options.amount
transactions = []
for key in keys:
transactions.append({"recipient": key[0], 'amount': initial_balance_remain//keys_remain - initial_balance_remain%keys_remain})
initial_balance_remain = initial_balance_remain - initial_balance_remain//keys_remain + initial_balance_remain%keys_remain
keys_remain = keys_remain - 1
conf_transactions = ConfigFactory.from_dict(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']['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'))
f.close()
#set genesis block
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
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.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"
f = open("./output/node-{}.conf".format(i), "w")
f.write(HOCONConverter.convert(signed_template_yaml, 'hocon'))
f.close()
if options.kuber_config == "yes":
create_configmap("node-{}.conf".format(i))
if options.kuber_config == "yes":
create_configmap('wallet.tar.gz.b64', 'binary')
apiVersion: v1
kind: ConfigMap
metadata:
name: conf-name
namespace: namespace-name
data:
node-0.conf: |
vostok {
wallet {
file = "wallet"
password = "svupkey"
}
owner-address = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
privacy.storage.url = "jdbc:postgresql://example.com:5432/database_name?user=username&password=password&sslmode=require"
}
vostok {
network.enable-blacklisting = no
synchronization.synchronization-timeout = 3m
waves-crypto = no
logging-level = DEBUG
directory = "/node/data/"
data-directory = "/node/data/data"
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
api-key-hash = DACAEAAK1MosP6Jjjhff2TVNDkBBszgqssD32GfU4iBf
privacy-api-key-hash = DACAEAAK1MosP6Jjjhff2TVNDkBBszgqssD32GfU4iBf #svupkey
}
}
include "local_template.conf"
pyhocon
pyyaml
hvac
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