Skip to content

Commit

Permalink
v2.5.0: scriptgen and keygen=N flags for PBFT kickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitamendelbaum committed Nov 12, 2018
1 parent c5da683 commit 8d70396
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
docker-compose*
docker-compose*
my-node-scripts
57 changes: 13 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[![BlockApps logo](http://blockapps.net/img/logo_cropped.png)](http://blockapps.net)

# STRATO Developer Edition - Getting Started guide
# STRATO - Getting Started guide

### Architecture
> For more detailed information about the STRATO deployment please refer to [BlockApps Developers' Website](https://developers.blockapps.net)
### STRATO Architecture

![STRATO-Architecture](STRATOArc.png?raw=true "STRATO-Architecture")

Expand All @@ -12,16 +14,13 @@
- Cirrus: Index and search smart-contracts, SQL-like query API for looking up smart-contracts and state changes.
- STRATO Management Dashboard (SMD): Web based UI for your Private Ethereum Blockchain Network using Bloc/STRATO API for User and Contracts management & offering SQL like query interface for smart-contracts.

### Sign-up for trial

To use this guide you will need to have signed up for our Developer Edition Trial, if you have not already done so sign up here: [http://developers.blockapps.net/trial](http://developers.blockapps.net/trial)

### Pre-requisites

**Linux/MacOSX:**

- [Install Docker](https://www.docker.com/community-edition) on your machine
- [Install Docker Compose](https://docs.docker.com/compose/install/) on your machine
- Python 2.7 for PBFT network deployment

- For Mac users: Install `wget` using [Homebrew](https://brew.sh/) (use the steps below):

Expand All @@ -41,26 +40,17 @@ To use this guide you will need to have signed up for our Developer Edition Tria

### Setup

**Steps to setup and run STRATO Developer Edition using Docker on your machine:**
**Steps to setup and run single STRATO node using Docker on your machine:**

1. Clone [STRATO Getting Started repo](https://github.com/blockapps/strato-getting-started) using ```git clone``` or download and extract .zip archive. And `chdir` or `cd` into that folder.
2. Copy and paste these credentials into your terminal to login to the Docker container:
2. Launch STRATO single node:
```
docker login -u blockapps-repo -p P@ssw0rd registry-aws.blockapps.net:5000
./strato --single
```
3. Launch STRATO services:
- Run:
```
chmod +x strato.sh
```
- Then run the script:
```
./strato.sh --single
```
>If running on the remote machine, provide the NODE_HOST variable with the machine's external IP address or domain (reachable through the network) when running the STRATO: ```NODE_HOST=example.com ./strato.sh --single```

>If running on the remote machine, provide the NODE_HOST variable with the machine's external IP address or domain (reachable through the network) when running the STRATO: ```NODE_HOST=example.com ./strato.sh --single```
>Windows users should always provide the NODE_HOST variable with the docker machine IP address (in most cases it is `192.168.99.100`) when running the STRATO: ```NODE_HOST=192.168.99.100 ./strato.sh --single```
>Windows users should always provide the NODE_HOST variable with the docker machine IP address (in most cases it is `192.168.99.100`) when running the STRATO: ```NODE_HOST=192.168.99.100 ./strato.sh --single```
4. Check if STRATO services are running (using `docker ps`) & view the Strato Management Dashboard at `http://localhost/` (or `http://<remote_node_host>/` when running on remote machine)
Expand Down Expand Up @@ -88,20 +78,14 @@ To use this guide you will need to have signed up for our Developer Edition Tria
### Stopping STRATO
*To stop a running instance of STRATO Developer Edition on your machine, run this command (from within the git cloned `getting-started` folder)*
```
./strato.sh --stop
./strato --stop
```

*To stop and wipe out a running instance of STRATO Developer Edition on your machine, run this command (from within the git cloned `getting-started` folder)(you will lose state of any transactions/data created in the blockchain)*
```
./strato.sh --wipe
./strato --wipe
```

### Public STRATO instance

*If you can't run your own STRATO instance on your machine, try our public instance (accessible to anyone with the credentials, so don't host Production or Production-like apps/content):*

http://stratodev.blockapps.net/

### Ports used

STRATO services need the following ports to be available on the machine (refer docker-compose.yml for details):
Expand All @@ -111,21 +95,6 @@ STRATO services need the following ports to be available on the machine (refer d
:30303, :30303/UDP (for Strato P2P)
```

## Multinode Network (Public STRATO Testnet)

- *In early alpha, bootnode may go down and blockchain data wiped out during refreshes and upgrades*
- *Use only for testing*

You can now run your local STRATO node peering it to the main bootnode and experience a multinode blockchain test network.

Here's the command to start your local node to connect and sync with our bootnode:

```
BOOT_NODE_IP=52.179.13.55 ./strato.sh
```
- The bootnode is: stratodev.blockapps.net
- Bootnode Dashboard: https://stratodev.blockapps.net/

## License Agreement

See [BlockApps’ Developer Edition Terms of Use](https://signup.blockapps.net/trial-license)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.2
2.5.0
6 changes: 6 additions & 0 deletions node-list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"ip": "255.255.255.0",
"host": "example.com"
}
]
92 changes: 92 additions & 0 deletions scriptgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env python

import json
import os
import re
import shutil
import sys

from subprocess import check_output

node_list_file = 'node-list.json'
output_directory = 'my-node-scripts'

def format_script(address, ip, host, boot_node_ip, prvkey, vals):
output = """\
#!/usr/bin/env sh
# Address: {0}
# IP: {1}
NODE_HOST="{2}" \\
BOOT_NODE_IP="{3}" \\
blockstanbulPrivateKey="{4}" \\
seqDebugMode="${{seqDebugMode:-true}}" \\
blockstanbul="${{blockstanbul:-true}}" \\
validators='{5}' \\
./strato""" \
.format(address, ip, host.strip(), boot_node_ip.strip() if boot_node_ip else '', prvkey, json.dumps(vals, separators=(',', ':')))
# Single node deployment workaround - remove BOOT_NODE_IP line
if not boot_node_ip:
output = re.sub(".*BOOT_NODE_IP=.*\n?","",output)
return output


def get_strato_image_name():
if 'STRATO_IMAGE' in os.environ:
strato_image = os.environ['STRATO_IMAGE']
else:
try:
strato_img_dc_line = next(line for line in open("docker-compose.yml") if 'STRATO_IMAGE' in line)
strato_image = re.search(':-(.*)}', strato_img_dc_line).group(1)
except:
print(
'Error: Unable to read strato image name from docker-compose.yml - provide STRATO_IMAGE env var or a valid docker-compose.yml to proceed')
sys.exit(1)
print('STRATO image used: {0}'.format(strato_image))
return strato_image


if __name__ == "__main__":
# TODO: try-catch json load
try:
with open(node_list_file) as file:
nodes = json.load(file)
except:
print('Error: Unable to parse JSON in {0}'.format(node_list_file))
sys.exit(2)
if not nodes:
print('ERROR: no nodes found in {0}'.format(node_list_file))
sys.exit(3)
num_hosts = len(nodes)
common_boot_ip = nodes[0]['ip'] if num_hosts > 1 else None
other_boot_ip = nodes[1]['ip'] if num_hosts > 1 else None
strato_image = get_strato_image_name()
keys_bytes = check_output(["docker", "run", "--entrypoint=keygen", strato_image, "--count={0}".format(num_hosts)])
print(keys_bytes.decode('utf-8'))
keys_json = json.loads(keys_bytes.decode('utf-8'))

validators = keys_json['all_validators']

if os.path.exists(output_directory) and len(os.listdir(output_directory)):
print("Output directory {0}/ exists and not empty.\nAre you sure you want to remove it? (y/n):")
choice = raw_input().lower()
if choice in {'yes','y'}:
shutil.rmtree(output_directory)
else:
print('Error: Output directory {0}/ is not empty and removal was not confirmed by the user'.format(output_directory))
sys.exit(2)
os.makedirs(output_directory)

for (node, key_address_pair) in zip(nodes, keys_json['key_address_pairs']):
with open(os.path.join(output_directory, '{0}_run.sh'.format(node['ip'].strip())), 'w') as file:
file.write(
format_script(
key_address_pair['address'],
node['ip'],
node['host'],
common_boot_ip if node['ip'] != common_boot_ip else other_boot_ip,
key_address_pair['private_key'],
validators
)
)

print('Successfully finished. Check {0}/ directory for scripts'.format(output_directory))
20 changes: 16 additions & 4 deletions strato
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ ${Yellow}Optional flags:${NC}
--wipe - stop and remove STRATO containers and wipe out volumes;
--compose - fetch the latest stable docker-compose.yml;
--pull - pull images used in docker-compose.yml;
--keygen <n> - Generate n private keys and their addresses for PBFT;
--scriptgen - generate PBFT nodes kickstart script files based on node list in node-list.json
--keygen=N - Generate n private keys and their addresses for PBFT;
${Yellow}Environment variables:${NC}
NODE_HOST - (default: localhost) the hostname or IP of the machine (used for APIs and Dashoboard);
Expand Down Expand Up @@ -68,6 +69,10 @@ function pullImages {
docker-compose pull
}

function generatePbftScripts {
python scriptgen.py
}

if [ ! -f $(pwd)/strato.sh ]; then
echo -e "${Red}Should be run from within the strato-getting-started directory. Exiting.${NC}"
exit 4
Expand Down Expand Up @@ -124,11 +129,18 @@ while [ ${#} -gt 0 ]; do
pullImages
exit 0
;;
--keygen)
--keygen=*)
if [ ! -f docker-compose.yml ]; then getCompose; fi
DC_STRATO_IMAGE=$(cat docker-compose.yml | grep "STRATO_IMAGE" | sed -e "s/.*:-//" -e "s/}//")
docker run --entrypoint=keygen ${STRATO_IMAGE:-$DC_STRATO_IMAGE} --count=$2
shift
docker run --entrypoint=keygen ${STRATO_IMAGE:-$DC_STRATO_IMAGE} --count="${1#*=}"
exit 0
;;
--keygen)
echo "Error: '--keygen N' syntax is deprecated. Use '--keygen=N' instead."
exit 1
;;
--scriptgen)
generatePbftScripts
exit 0
;;
*)
Expand Down

0 comments on commit 8d70396

Please sign in to comment.