Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Puig committed Oct 2, 2017
0 parents commit 81e7517
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 0 deletions.
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ALASTRIA #

## Requisitos del sistema

Caracteristicas de la máquina:

* **CPU's**: 2

* **Memoria**: 4 Gb

* **Disco duro**: 30 Gb

* **Sistema operativo**: Ubuntu 16.04 64 bits

Es necesario habilitar los siguientes puertos de E/S en la maquina en la que vamos a desplegar el nodo:

* **21000**: TCP/UDP - Puerto para establecer la comunicación entre procesos geth.

* **41000**: TCP - Puerto para el consenso RAFT de Quorum.

* **9000**: TCP - Puerto para la comunicación de Constellation.

* **22000**: TCP - Puerto para establecer la comunicación RPC.

## Instalación de nodo Quorum + Constellation

Para configurar e instalar Quorum y Constellation, debe clonar el repositorio git que indicamos a continuación en el servidor de aplicaciones y ejecutar el siguiente script `scripts/bootstrap.sh`.

```
$ git clone https://github.com/marcossanlab/alastria-node.git
$ cd alastria-node/scripts/
$ sudo -H ./bootstrap.sh
```

## Configuración del nodo
Es necesario seguir los siguientes pasos para la configuración de los nodos:

1. **Ejecutar script init.sh**

Configura el nodo Quorum junto con Constellation.

Al ejecutar este script debemos de pasar como parametro la IP pública del nodo que estamos configurando.
```
$ ./init.sh <<PUBLIC_IP_HOST_MACHINE>>
```

2. **Configuración del fichero de nodos Quorum**

El nodo quorum que estamos desplegando se configura automaticamente con el script de inicialización ejecutado en el paso anterior.

Una vez que comprobemos que el fichero de nodos `static-nodes.json` tiene añadido nuestro enode, es necesario subirlo de nuevo al repositorio git, para que todos los integrantes de la red tengan actualizado su fichero de nodos.

3. **Configurción del fichero de nodos de Constellation**

El nodo Constellation que estamos desplegando se configura automaticamente con el script de inicialización ejecutado en el paso anterior.

Una vez que comprobemos que el fichero de nodos de constellation `constellation-nodes.json` tiene añadido nuestro nodo, es necesario subirlo de nuevo al repositorio git, para que todos los integrantes de la red tengan actualizado su fichero de nodos de constellation.

**NOTA**
En este punto ya tendriamos desplegado un nuevo nodo en la red, que incluiria el despliegue y configuración de Quorum y Constellation.

Si necesitamos desplegar mas nodos para nuestra red, es necesario volver a realizar los pasos descritos anteriormente.

## Arranque de nodo Quorum + Constellation
Una vez instalado y configurado todo ya podemos arrancar nuestro nodo. Para arrancar ejecutamos la siguiente orden:
```
$ ./start.sh
```
**NOTA**
Si el nodo que vamos a levantar es el primer nodo de la red, debemos arrancar con la siguiente orden:
```
$ ./start.sh init
```

## Habilitar el nodo para empezar a realizar transacciones
A la hora de realizar transacciones en la red de Alastria es necesario realizar el siguiente procedimiento:

Una vez que se levantado el nodo, es necesaria la realización de una transferencia de fondos de la cuenta principal a la cuenta que acaba de ser generada al iniciarse el nodo.

Con el fin de realizar este procedimiento se debe indicar al administrador del primer nodo de la red, poseedor de la cuenta principal, la cuenta que se ha generado al levantar el nodo. Tras esto, el administrador deberá asignar a la cuenta del nodo la cantidad que se haya acordado.
7 changes: 7 additions & 0 deletions data/constellation-nodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
"http://52.56.69.220:9000/",
"http://35.176.197.87:9000/",
"http://52.56.69.220:9100/",
"http://52.169.13.168:9000",
"http://52.164.228.204:9000"
]
16 changes: 16 additions & 0 deletions data/genesis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"alloc": {
"0x58b8527743f89389b754c63489262fdfc9ba9db6" : {"balance" : "1000000000000000000000000000"}
},
"coinbase": "0x0000000000000000000000000000000000000000",
"config": {
"homesteadBlock": 0
},
"difficulty": "0x0",
"extraData": "0x",
"gasLimit": "0x2FEFD800",
"mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
"nonce": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x00"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"58b8527743f89389b754c63489262fdfc9ba9db6","crypto":{"cipher":"aes-128-ctr","ciphertext":"20f46e1aacd6bf28b66e37b5b6cf9b1cefc42ac8a4461e86893ae4ccd7e671c7","cipherparams":{"iv":"4d455255a895091952f653c4b59c92c7"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"74b089663af7571962992c5a1bb68c1e82e5f8308c646b68cfe576c1c6f38d5c"},"mac":"5ce860f522494ff1322f776d93ee6fb149eb1cddb53722e2e59191c4d0bdd8c9"},"id":"2db34512-2c46-44b7-a8a9-6b73302dde1e","version":3}
7 changes: 7 additions & 0 deletions data/static-nodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
"enode://ef65a78e2c785f64561449ff6d7954a31d771a7bbf3ef36119f13f91b1bb9c2e0100e3cb5e8298e6bbce643142d2ba530396c7b5a2f9e2d5662dc33ec7598812@52.56.69.220:21000?raftport=41000",
"enode://95444283ac4585db5e8118a9b0d949fd0bc0bcfb24c8a0994bb7764e9acb19b55c6fda9c45eafb8c21220cfb312a5f290cb376e7f9205553a6df7cda18367fed@35.176.197.87:21000?raftport=41000",
"enode://f4d45250117bfc9414e6af97fbc7f61371575c2dcebb68b32e125128a57ff50b1ed97618b03a96a85f222085eef4fd2a2462ecbce04788c5997ec2bd0c192307@52.56.69.220:23000?raftport=41000",
"enode://8968447208d65c25044a4d93a9449a0ed003b72405e9b37d896eb2483d05921b2188fba6fd377a3d70bea6a2eee641c0f2e0fbbd32adcf29bdcd7196a30ce296@52.169.13.168:21000?raftport=41000",
"enode://c54bd82e7954887795334037a90e3f33845bd7a1a1f8a878cd65d28a385c9468047ad570c5094dca4dd6cf9b164f42aae2bf0ce25cc7ef0121865062444415cb@52.164.228.204:21000?raftport=41000"
]
38 changes: 38 additions & 0 deletions scripts/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

set -e

GOREL="go1.7.3.linux-amd64.tar.gz"
PATH="$PATH:/usr/local/go/bin"

sudo rm -Rf /usr/local/go

sudo apt-get update && sudo apt-get install -y

#INSTALACION DE LIBRERIAS
sudo apt-get install -y software-properties-common unzip wget git make gcc libsodium-dev build-essential libdb-dev zlib1g-dev libtinfo-dev sysvbanner wrk psmisc

#INSTALACION ETHEREUM
sudo add-apt-repository -y ppa:ethereum/ethereum && sudo apt-get update && sudo apt-get install -y solc

#INSTALACION CONSTELLATION 0.1.0
wget -q https://github.com/jpmorganchase/constellation/releases/download/v0.1.0/constellation-0.1.0-ubuntu1604.tar.xz
unxz constellation-0.1.0-ubuntu1604.tar.xz
tar -xf constellation-0.1.0-ubuntu1604.tar
sudo cp constellation-0.1.0-ubuntu1604/constellation-node /usr/local/bin && sudo chmod 0755 /usr/local/bin/constellation-node
sudo rm -rf constellation-0.1.0-ubuntu1604.tar.xz constellation-0.1.0-ubuntu1604.tar constellation-0.1.0-ubuntu1604

#INSTALACION DE GO
wget -q "https://storage.googleapis.com/golang/${GOREL}"
tar -xvzf "${GOREL}"
mv go /usr/local/go
sudo rm "${GOREL}"

#INSTALACION DE QUORUM
git clone https://github.com/jpmorganchase/quorum.git
cd quorum && git checkout tags/v1.1.0 && make all && cp build/bin/geth /usr/local/bin && cp build/bin/bootnode /usr/local/bin

cd ..
sudo rm -rf constellation-0.1.0-ubuntu1604.tar.xz constellation-0.1.0-ubuntu1604.tar constellation-0.1.0-ubuntu1604 quorum

set +e
119 changes: 119 additions & 0 deletions scripts/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/bash
set -u
set -e

MESSAGE="Usage: init CURRENT_HOST_IP | auto"
if ( [ $# -ne 1 ] ); then
echo "$MESSAGE"
exit
fi

CURRENT_HOST_IP="$1"

if ( [ "auto" == "$1" ]); then
echo "Autodiscovering public host IP ..."
CURRENT_HOST_IP="$(dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null || curl -s --retry 2 icanhazip.com)"
echo "Public host IP found: $CURRENT_HOST_IP"
fi

PWD="$(pwd)"
CONSTELLATION_NODES=$(cat ../data/constellation-nodes.json)
STATIC_NODES=$(cat ../data/static-nodes.json)

update_constellation_nodes() {
NODE_IP="$1"
CONSTELLATION_PORT="$2"
URL=",
\"http://$NODE_IP:$CONSTELLATION_PORT/\"
]"
CONSTELLATION_NODES=${CONSTELLATION_NODES::-2}
CONSTELLATION_NODES="$CONSTELLATION_NODES$URL"
echo "$CONSTELLATION_NODES" > ~/alastria-node/data/constellation-nodes.json
}

update_static_nodes() {
ENODE=",
\"$1\"
]"
STATIC_NODES=${STATIC_NODES::-2}
STATIC_NODES="$STATIC_NODES$ENODE"
echo "$STATIC_NODES" > ~/alastria-node/data/static-nodes.json
}

generate_conf() {
#define parameters which are passed in.
NODE_IP="$1"
CONSTELLATION_PORT="$2"
OTHER_NODES="$3"
PWD="$4"

#define the template.
cat << EOF
# Externally accessible URL for this node (this is what's advertised)
url = "http://$NODE_IP:$CONSTELLATION_PORT/"
# Port to listen on for the public API
port = $CONSTELLATION_PORT
# Socket file to use for the private API / IPC
socket = "$PWD/alastria/data/constellation/constellation.ipc"
# Initial (not necessarily complete) list of other nodes in the network.
# Constellation will automatically connect to other nodes not in this list
# that are advertised by the nodes below, thus these can be considered the
# "boot nodes."
othernodes = $OTHER_NODES
# The set of public keys this node will host
publickeys = ["$PWD/alastria/data/constellation/keystore/node.pub"]
# The corresponding set of private keys
privatekeys = ["$PWD/alastria/data/constellation/keystore/node.key"]
# Optional file containing the passwords to unlock the given privatekeys
# (one password per line -- add an empty line if one key isn't locked.)
passwords = "$PWD/alastria/data/passwords.txt"
# Where to store payloads and related information
storage = "$PWD/alastria/data/constellation/data"
# Verbosity level (each level includes all prior levels)
# - 0: Only fatal errors
# - 1: Warnings
# - 2: Informational messages
# - 3: Debug messages
verbosity = 2
EOF
}

echo "[*] Cleaning up temporary data directories"
rm -rf ~/alastria
mkdir -p ~/alastria/data/{keystore,geth,constellation}
mkdir -p ~/alastria/data/constellation/{data,keystore}
mkdir -p ~/alastria/logs

# Creamos el fichero de passwords con la contraseña de las cuentas
echo "Passw0rd" > ~/alastria/data/passwords.txt

echo "[*] Initializing quorum"
geth --datadir ~/alastria/data init ~/alastria-node/data/genesis.json
cd ~/alastria/data/geth
ENODE_KEY=$(bootnode -genkey nodekey -writeaddress)
cd ~
update_static_nodes "enode://${ENODE_KEY}@${CURRENT_HOST_IP}:21000?raftport=41000"
cp ~/alastria-node/data/static-nodes.json ~/alastria/data/static-nodes.json

echo " Por favor, introduzca como contraseña 'Passw0rd'."
geth --datadir ~/alastria/data account new

echo "[*] Initializing Constellation node"
update_constellation_nodes "${CURRENT_HOST_IP}" "9000"
generate_conf "${CURRENT_HOST_IP}" "9000" "$CONSTELLATION_NODES" "${PWD}" > ~/alastria/data/constellation/constellation.conf
cd ~/alastria/data/constellation/keystore
cat ~/alastria/data/passwords.txt | constellation-node --generatekeys=node
echo "______"
cd ~

set +u
set +e
76 changes: 76 additions & 0 deletions scripts/restart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
set -u
set -e

MESSAGE="Usage: restart CURRENT_HOST_IP | auto"
if ( [ $# -ne 1 ] ); then
echo "$MESSAGE"
exit
fi

CONSTELLATION_NODES=$(cat ../data/constellation-nodes.json)
STATIC_NODES=$(cat ../data/static-nodes.json)
CURRENT_HOST_IP="$1"
PWD="$HOME"

if ( [ "auto" == "$1" ]); then
echo "Autodiscovering public host IP ..."
CURRENT_HOST_IP="$(dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null || curl -s --retry 2 icanhazip.com)"
echo "Public host IP found: $CURRENT_HOST_IP"
fi


generate_conf() {
#define parameters which are passed in.
NODE_IP="$1"
CONSTELLATION_PORT="$2"
OTHER_NODES="$3"
PWD="$4"

#define the template.
cat << EOF
# Externally accessible URL for this node (this is what's advertised)
url = "http://$NODE_IP:$CONSTELLATION_PORT/"
# Port to listen on for the public API
port = $CONSTELLATION_PORT
# Socket file to use for the private API / IPC
socket = "$PWD/alastria/data/constellation/constellation.ipc"
# Initial (not necessarily complete) list of other nodes in the network.
# Constellation will automatically connect to other nodes not in this list
# that are advertised by the nodes below, thus these can be considered the
# "boot nodes."
othernodes = $OTHER_NODES
# The set of public keys this node will host
publickeys = ["$PWD/alastria/data/constellation/keystore/node.pub"]
# The corresponding set of private keys
privatekeys = ["$PWD/alastria/data/constellation/keystore/node.key"]
# Optional file containing the passwords to unlock the given privatekeys
# (one password per line -- add an empty line if one key isn't locked.)
passwords = "$PWD/alastria/data/passwords.txt"
# Where to store payloads and related information
storage = "$PWD/alastria/data/constellation/data"
# Verbosity level (each level includes all prior levels)
# - 0: Only fatal errors
# - 1: Warnings
# - 2: Informational messages
# - 3: Debug messages
verbosity = 2
EOF
}

cp ~/alastria-node/data/static-nodes.json ~/alastria/data/static-nodes.json
generate_conf "${CURRENT_HOST_IP}" "9000" "$CONSTELLATION_NODES" "${PWD}" > ~/alastria/data/constellation/constellation.conf

~/alastria-node/scripts/start.sh

set +u
set +e
23 changes: 23 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -u
set -e

NETID=96323
GLOBAL_ARGS="--networkid $NETID --raft --rpc --rpcaddr 0.0.0.0 --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum"

_TIME=$(date +%Y%m%d%H%M%S)

echo "[*] Starting Constellation node"
nohup constellation-node ~/alastria/data/constellation/constellation.conf 2>> ~/alastria/logs/constellation_"${_TIME}".log &
sleep 6

echo "[*] Starting quorum node"
PRIVATE_CONFIG=~/alastria/data/constellation/constellation.conf
if ( [ $# -ne 1 ] ); then
nohup geth --datadir ~/alastria/data $GLOBAL_ARGS --rpcport 22000 --port 21000 --password ~/alastria/data/passwords.txt 2>> ~/alastria/logs/quorum_"${_TIME}".log &
else
nohup geth --datadir ~/alastria/data $GLOBAL_ARGS --rpcport 22000 --port 21000 --unlock 0 --password ~/alastria/data/passwords.txt 2>> ~/alastria/logs/quorum_"${_TIME}".log &
fi

set +u
set +e
7 changes: 7 additions & 0 deletions scripts/stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e

pkill -f alastria

set +e

0 comments on commit 81e7517

Please sign in to comment.