README: add instructions for running a sandboxed node

This commit is contained in:
Grégoire Henry 2017-08-28 09:56:57 +02:00
parent d2ad611c3d
commit e033176820
6 changed files with 207 additions and 151 deletions

View File

@ -76,20 +76,6 @@ download and install them from, eg,
https://pkgs.org/download/libsodium18 and
https://pkgs.org/download/libsodium-dev
Running the node in a sandbox
-----------------------------
To run a single instance of a Tezos node in sandbox mode:
```
./tezos-node run --sandbox --rpc-addr localhost:8732 --data-dir /tmp/tezos-sandbox
```
This "sandboxed" node will not participate in the P2P network, but will accept
RPC from localhost on port 8732. See below from more details on the RPC
interface.
Running the node
----------------
@ -149,6 +135,74 @@ with the following commands line:
./tezos-node config update --data-dir "$dir" --net-addr localhost:9734
```
Running the node in a sandbox
-----------------------------
To run a 'localhost-only' instance of a Tezos network, we provide two
helper scripts:
- `./scripts/launch-sandboxed-node.sh`
- `./scripts/init-sandboxed-client.sh`
For instance, if you want to run local network with two nodes, in a
first terminal, the following command will initialize a node listening
for peers on port `19731` and listening for RPC on port `18731`.
```
./scripts/launch-sandboxed-node.sh 1
```
This node will store its data in a temporary directory which will be
removed when the node is killed.
To launch the second node, just run the following command, it will
listen on port `19739` and `18739`:
```
./scripts/launch-sandboxed-node.sh 9
```
You might replace `1` or `9` by any number in between if you want to
run more than two nodes. But, if you intend to run a single node
network, you might remove the spurious "Too few connections" warnings
by lowering the number of expected connection, by running the
following command instead:
```
./scripts/launch-sandboxed-node.sh 1 --connections 0
```
Once your node(s) is/are running, open a new terminal and initialize
the "sandboxed" client data:
```
eval `./scripts/init-sandboxed-client.sh 1`
```
It will initialize the client data in a temporary directory. It will
also defines in the current shell session an alias `tezos-client`
preconfigured for communicating the same-numbered node. For instance:
```
$ tezos-client rpc call blocks/head/hash
{ "hash": "BLockGenesisGenesisGenesisGenesisGenesisGeneskvg68z" }
```
When you bootstrap a new network, the network is initialized with a
dummy economic protocol, called "genesis". If you want to run the same
protocol than the alphanet, `init-sandboxed-client` also defines an
alias `tezos-activate-alpha`, that you need to execute once for
activating the whole network. For instance:
```
$ tezos-client rpc call blocks/head/protocol
{ "protocol": "ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im" }
$ tezos-activate-alpha
Injected BMBcK869jaHQDc
$ tezos-client rpc call blocks/head/protocol
{ "protocol": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" }
```
Configuration options
---------------------

View File

@ -6,11 +6,17 @@ client="${client:=tezos-client -base-dir $client_dir}"
## Waiter ##################################################################
wait_for_the_node_to_be_ready() {
local count=0
if $client rpc call blocks/head/hash >/dev/null 2>&1; then return; fi
printf "Waiting for the node to initialize..."
sleep 1
while ! $client rpc call blocks/head/hash >/dev/null 2>&1
do
count=$((count+1))
if [ "$count" -ge 30 ]; then
echo " timeout."
exit 2
fi
printf "."
sleep 1
done
@ -128,3 +134,44 @@ log_endorser() {
fi
}
## Sandboxed client ########################################################
# key pairs from $src_dir/test/sandbox.json
BOOTSTRAP1_PUBLIC="edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"
BOOTSTRAP1_SECRET="edskRuR1azSfboG86YPTyxrQgosh5zChf5bVDmptqLTb5EuXAm9rsnDYfTKhq7rDQujdn5WWzwUMeV3agaZ6J2vPQT58jJAJPi"
BOOTSTRAP2_PUBLIC="edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9"
BOOTSTRAP2_SECRET="edskRkJz4Rw2rM5NtabEWMbbg2bF4b1nfFajaqEuEk4SgU7eeDbym9gVQtBTbYo32WUg2zb5sNBkD1whRN7zX43V9bftBbtaKc"
BOOTSTRAP3_PUBLIC="edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV"
BOOTSTRAP3_SECRET="edskS3qsqsNgdjUqeMsVcEwBn8dkZ5iDRz6aF21KhcCtRiAkWBypUSbicccR4Vgqm9UdW2Vabuos6seezqgbXTrmcbLUG4rdAC"
BOOTSTRAP4_PUBLIC="edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU"
BOOTSTRAP4_SECRET="edskRg9qcPqaVQa6jXWNMU5p71tseSuR7NzozgqZ9URsVDi81wTyPJdFSBdeakobyHUi4Xgu61jgKRQvkhXrPmEdEUfiqfiJFL"
BOOTSTRAP5_PUBLIC="edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n"
BOOTSTRAP5_SECRET="edskS7rLN2Df3nbS1EYvwJbWo4umD7yPM1SUeX7gp1WhCVpMFXjcCyM58xs6xsnTsVqHQmJQ2RxoAjJGedWfvFmjQy6etA3dgZ"
DICTATOR_SECRET="edskRhxswacLW6jF6ULavDdzwqnKJVS4UcDTNiCyiH6H8ZNnn2pmNviL7pRNz9kRxxaWQFzEQEcZExGHKbwmuaAcoMegj5T99z"
add_sandboxed_bootstrap_identities() {
${client} add public key bootstrap1 ${BOOTSTRAP1_PUBLIC}
${client} add secret key bootstrap1 ${BOOTSTRAP1_SECRET}
${client} add public key bootstrap2 ${BOOTSTRAP2_PUBLIC}
${client} add secret key bootstrap2 ${BOOTSTRAP2_SECRET}
${client} add public key bootstrap3 ${BOOTSTRAP3_PUBLIC}
${client} add secret key bootstrap3 ${BOOTSTRAP3_SECRET}
${client} add public key bootstrap4 ${BOOTSTRAP4_PUBLIC}
${client} add secret key bootstrap4 ${BOOTSTRAP4_SECRET}
${client} add public key bootstrap5 ${BOOTSTRAP5_PUBLIC}
${client} add secret key bootstrap5 ${BOOTSTRAP5_SECRET}
${client} add secret key dictator ${DICTATOR_SECRET}
}

View File

@ -0,0 +1,58 @@
#! /bin/sh
set -e
script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
src_dir="$(dirname "$script_dir")"
cd "$src_dir"
usage() {
echo "Small script to initialize a client to a local and closed test network with a maximum of 9 nodes."
echo
echo "Usage: eval \`$0 <id>\`"
echo " where <id> should be an integer between 1 and 9."
}
if [ $# -lt 1 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then
usage
exit 1
fi
id="$1"
shift 1
rpc=$((18730 + id))
client_dir="$(mktemp -td tezos-client-XXXXX)"
client="./tezos-client -base-dir $client_dir -addr 127.0.0.1 -port $rpc"
. "$script_dir/client_lib.inc.sh"
add_sandboxed_bootstrap_identities | sed -e 's/^/## /' 1>&2
cat <<EOF
if type tezos-client-reset >/dev/null 2>&1 ; then tezos-client-reset; fi ;
alias tezos-client="$client" ;
alias tezos-activate-alpha="$client -block genesis activate protocol ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK with fitness 1 and key dictator" ;
alias tezos-client-reset="rm -rf \"$client_dir\"; unalias tezos-client tezos-activate-alpha tezos-client-reset" ;
trap tezos-client-reset EXIT ;
EOF
(cat | sed -e 's/^/## /') 1>&2 <<EOF
The client is now properly initialized. In the rest of this shell
session, you might now run \`tezos-client\` to communicate with a
tezos node launched with \`launch-sandboxed-node $1\`. For instance:
tezos-client rpc call blocks/head/protocol
Note: if the current protocol version, as reported by the previous
command, is "ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im", you
may have to activate in your "sandboxed network" the same economic
protocol than used by the alphanet by running:
tezos-activate-alpha
Warning: all the client data will be removed when you close this shell
or if you run this command a second time.
EOF

View File

@ -1,79 +0,0 @@
#! /bin/bash
set -e
script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
src_dir="$(dirname "$script_dir")"
cd "$src_dir"
function usage() {
echo "Small script client to a local and closed test network with a maximum of 9 nodes."
echo
echo "Usage: $0 <id> [ bake [id] | endorse [id] | exec ... ]"
echo " where <id> should be an integer between 1 and 9."
}
if [ $# -lt 2 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then
usage
exit 1
fi
id="$1"
cmd="$2"
shift 2
rpc=$((18730 + id))
base_dir="/tmp/tezos-client-$rpc"
client="./tezos-client -base-dir $base_dir -addr 127.0.0.1 -port $rpc"
. "$script_dir/client_lib.inc.sh"
function cmd_bake() {
wait_for_the_node_to_be_ready
if [ $# -eq 0 ]; then
create_identity
create_account
fi
start_baker "$@"
}
function cmd_endorse() {
wait_for_the_node_to_be_ready
if [ $# -eq 0 ]; then
create_account
endorsement
fi
start_endorser "$@"
}
function cmd_exec() {
$client "$@"
}
function cmd_clear() {
rm -fr "$base_dir"
}
if [ ! -d "$base_dir" ] && [ "$cmd" != "clear" ]; then
$client bootstrap
fi
case $cmd in
bake)
cmd_bake "$@"
;;
endorse)
cmd_endorse "$@"
;;
exec)
cmd_exec "$@"
;;
clear)
cmd_clear
;;
*)
usage
exit 1
;;
esac

View File

@ -1,41 +0,0 @@
#! /bin/sh
set -e
script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
src_dir="$(dirname "$script_dir")"
cd "$src_dir"
if [ $# -lt 1 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then
echo "Small script to launch local and closed test network with a maximum of 9 nodes."
echo
echo "Usage: $0 <id>"
echo " where <id> should be an integer between 1 and 9."
exit 1
fi
id="$1"
shift 1
port=$((19730 + id))
rpc=$((18730 + id))
expected_pow=10
data_dir="$(mktemp -td tezos-node-XXXXX)"
peers="--no-bootstrap-peers $(seq -f '--peer localhost:1973%.f' 1 9) --closed"
node="$src_dir/tezos-node"
cleanup () {
set +e
echo Cleaning up...
rm -rf "$data_dir"
}
trap cleanup EXIT INT
$node config init \
--data-dir "$data_dir" \
--net-addr ":$port" \
--rpc-addr "[::]:$rpc" \
--expected-pow "$expected_pow" \
--connections 2 $peers
$node identity generate "$expected_pow" --data-dir "$data_dir"
$node run --data-dir "$data_dir" "$@"

View File

@ -1,25 +1,42 @@
#!/usr/bin/env bash
#! /bin/sh
set -e
script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
export TZPATH="$(dirname $script_dir)"
src_dir="$(dirname "$script_dir")"
cd "$src_dir"
. $TZPATH/test/test_utils.sh
if [ $# -lt 1 ] || [ "$1" -le 0 ] || [ 10 -le "$1" ]; then
echo "Small script to launch local and closed test network with a maximum of 9 nodes."
echo
echo "Usage: $0 <id>"
echo " where <id> should be an integer between 1 and 9."
exit 1
fi
start_sandboxed_node
sleep 3
id="$1"
shift 1
activate_alpha |& sed 's/^/## /' > /dev/stderr
port=$((19730 + id))
rpc=$((18730 + id))
expected_pow="${expected_pow:-0.0}"
node_dir="$(mktemp -td tezos-node-XXXXX)"
peers="--no-bootstrap-peers $(seq -f '--peer localhost:1973%.f' 1 9) --closed"
node="$src_dir/tezos-node"
sandbox_param="--sandbox=$script_dir/sandbox.json"
trap - EXIT
cleanup () {
set +e
echo Cleaning up...
rm -rf "$node_dir"
}
trap cleanup EXIT INT
display_aliases
echo | sed 's/^/## /' 1>&2 <<EOF
Successfully launched a sandboxed node.
Run 'tezos-client' to communicate with the sandboxed node.
Run 'tezos-sandbox-stop' to stop the node and remove the sandbox data.
EOF
$node config init \
--data-dir "$node_dir" \
--net-addr ":$port" \
--rpc-addr "[::]:$rpc" \
--expected-pow "$expected_pow" \
--connections 2 $peers
$node identity generate "$expected_pow" --data-dir "$node_dir"
$node run --data-dir "$node_dir" "$sandbox_param" "$@"