2017-08-28 20:34:36 +04:00
#! /usr/bin/env bash
2017-02-24 20:11:51 +04:00
2017-12-06 22:51:57 +04:00
set -e
2017-08-28 20:34:36 +04:00
client_dirs = ( )
init_sandboxed_client( ) {
id = " $1 "
shift 1
rpc = $(( 18730 + id))
2018-02-03 18:08:18 +04:00
client_dir = " $( mktemp -d -t tezos-tmp-client.XXXXXXXX) "
2017-08-28 20:34:36 +04:00
client_dirs += ( " $client_dir " )
2018-06-15 18:32:19 +04:00
signer = " $local_signer -d $client_dir "
2018-04-28 12:19:21 +04:00
if [ -n " $USE_TLS " ] ; then
client = " $local_client -S -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
admin_client = " $local_admin_client -S -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
alpha_baker = " $local_alpha_baker -S -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
2018-06-13 13:05:20 +04:00
alpha_endorser = " $local_alpha_endorser -S -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
alpha_accuser = " $local_alpha_accuser -S -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
signer = " $local_signer -S -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
2018-04-28 12:19:21 +04:00
else
client = " $local_client -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
admin_client = " $local_admin_client -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
alpha_baker = " $local_alpha_baker -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
2018-06-13 13:05:20 +04:00
alpha_endorser = " $local_alpha_endorser -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
alpha_accuser = " $local_alpha_accuser -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
signer = " $local_signer -base-dir $client_dir -addr 127.0.0.1 -port $rpc "
2018-04-28 12:19:21 +04:00
fi
2018-04-04 18:20:03 +04:00
parameters_file = " ${ parameters_file :- $client_dir /protocol_parameters.json } "
if ! [ -f " $parameters_file " ] ; then
cat > " $parameters_file " <<EOF
2018-06-19 01:46:22 +04:00
{ "bootstrap_accounts" : [
2018-04-04 18:20:03 +04:00
[ "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav" , "4000000000000" ] ,
[ "edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9" , "4000000000000" ] ,
[ "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV" , "4000000000000" ] ,
[ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU" , "4000000000000" ] ,
2018-06-19 01:46:22 +04:00
[ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n" , "4000000000000" ] ,
2018-06-23 20:08:33 +04:00
[ "tz1PooUKBaoxjBiCR2dxEtbtTUjLX3iaZQoJ" , "100" ] ,
[ "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2" , "1" ] ] ,
"bootstrap_contracts" : [
{ "delegate" : "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV" ,
"amount" : "10000000" ,
2018-06-19 01:46:22 +04:00
"script" :
{ "code" :
[ { "prim" : "parameter" ,
"args" : [ { "prim" : "key_hash" } ] } ,
{ "prim" : "storage" ,
"args" : [ { "prim" : "timestamp" } ] } ,
{ "prim" : "code" ,
"args" :
[ [ [ [ { "prim" : "DUP" } , { "prim" : "CAR" } ,
{ "prim" : "DIP" , "args" : [ [ { "prim" : "CDR" } ] ] } ] ] ,
{ "prim" : "SWAP" } ,
{ "prim" : "PUSH" , "args" : [ { "prim" : "int" } , { "int" : "300" } ] } ,
{ "prim" : "ADD" , "annots" : [ "@FIVE_MINUTES_LATER" ] } ,
{ "prim" : "NOW" } ,
[ [ { "prim" : "COMPARE" } , { "prim" : "GE" } ] ,
{ "prim" : "IF" ,
"args" :
[ [ ] ,
[ [ { "prim" : "UNIT" } ,
{ "prim" : "FAILWITH" } ] ] ] } ] ,
{ "prim" : "IMPLICIT_ACCOUNT" } ,
{ "prim" : "PUSH" , "args" : [ { "prim" : "mutez" } , { "int" : "1000000" } ] } ,
{ "prim" : "UNIT" } ,
{ "prim" : "TRANSFER_TOKENS" } ,
{ "prim" : "NIL" , "args" : [ { "prim" : "operation" } ] } ,
{ "prim" : "SWAP" } ,
{ "prim" : "CONS" } ,
{ "prim" : "DIP" , "args" : [ [ { "prim" : "NOW" } ] ] } ,
{ "prim" : "PAIR" } ] ] } ] ,
2018-06-23 20:08:33 +04:00
"storage" : { "int" : "0" } } } ] ,
2018-05-16 11:07:15 +04:00
"time_between_blocks" : [ "1" , "0" ] ,
2018-04-09 18:28:43 +04:00
"blocks_per_roll_snapshot" : 4,
"blocks_per_cycle" : 8,
2018-06-19 01:46:22 +04:00
"preserved_cycles" : 2,
"proof_of_work_threshold" : "-1"
2018-04-04 18:20:03 +04:00
}
EOF
fi
2017-08-28 20:34:36 +04:00
}
cleanup_clients( ) {
rm -rf " ${ client_dirs [@] } "
}
2017-03-09 17:43:59 +04:00
## Waiter ##################################################################
wait_for_the_node_to_be_ready( ) {
2017-08-28 11:56:57 +04:00
local count = 0
2018-04-16 02:44:24 +04:00
if $client rpc get /chains/main/blocks/head/hash >/dev/null 2>& 1; then return ; fi
2017-03-09 17:43:59 +04:00
printf "Waiting for the node to initialize..."
sleep 1
2018-04-16 02:44:24 +04:00
while ! $client rpc get /chains/main/blocks/head/hash >/dev/null 2>& 1
2017-02-24 20:11:51 +04:00
do
2017-08-28 11:56:57 +04:00
count = $(( count+1))
if [ " $count " -ge 30 ] ; then
echo " timeout."
exit 2
fi
2017-03-09 17:43:59 +04:00
printf "."
sleep 1
2017-02-24 20:11:51 +04:00
done
2017-03-09 17:43:59 +04:00
echo " done."
2017-02-24 20:11:51 +04:00
}
2017-03-09 17:43:59 +04:00
wait_for_the_node_to_be_bootstraped( ) {
wait_for_the_node_to_be_ready
echo "Waiting for the node to synchronize with the network..."
$client bootstrapped
2017-02-24 20:11:51 +04:00
}
2017-03-09 17:43:59 +04:00
## Baker ###################################################################
check_baker( ) {
2018-06-13 13:05:20 +04:00
pids = $( pgrep -x tezos-alpha-baker 2>/dev/null)
2017-03-09 17:43:59 +04:00
for pid in $pids ; do
2018-06-13 13:05:20 +04:00
if grep -- "-max-priority" " /proc/ $pid /cmdline " >/dev/null 2>& 1 ; then
2017-03-09 17:43:59 +04:00
return 0
fi
2017-02-24 20:11:51 +04:00
done
2017-03-09 17:43:59 +04:00
return 1
2017-02-24 20:11:51 +04:00
}
2017-03-09 17:43:59 +04:00
run_baker( ) {
if check_baker; then
echo "Cannot run two bakers in the same container."
exit 1
fi
echo "Start baker..."
2018-06-13 13:05:20 +04:00
exec $alpha_baker launch daemon -max-priority 64 " $@ " > " $client_dir /baker.log "
2017-03-09 17:43:59 +04:00
}
stop_baker( ) {
2018-06-13 13:05:20 +04:00
pids = $( pgrep -x tezos-alpha-baker 2>/dev/null)
2017-03-09 17:43:59 +04:00
for pid in $pids ; do
2018-06-13 13:05:20 +04:00
if grep -- "-max-priority" " /proc/ $pid /cmdline " >/dev/null 2>& 1 ; then
2017-03-09 17:43:59 +04:00
echo "Killing the baker..."
kill " $pid "
fi
2017-02-24 20:11:51 +04:00
done
}
2017-03-09 17:43:59 +04:00
log_baker( ) {
if ! check_baker ; then
echo
echo "##############################################"
echo "## ##"
echo "## Warning: The tezos baker is not running! ##"
echo "## ##"
echo "##############################################"
echo
tail " $client_dir /baker.log "
2017-02-24 20:11:51 +04:00
else
2017-03-09 17:43:59 +04:00
tail -f " $client_dir /baker.log "
2017-02-24 20:11:51 +04:00
fi
}
2017-03-09 17:43:59 +04:00
## Endorser ################################################################
check_endorser( ) {
2018-06-13 13:05:20 +04:00
pids = $( pgrep -x tezos-alpha-endorser 2>/dev/null)
2017-03-09 17:43:59 +04:00
for pid in $pids ; do
2018-06-13 13:05:20 +04:00
if grep -- "tezos-alpha-endorser" " /proc/ $pid /cmdline " > /dev/null 2>& 1 ; then
2017-03-09 17:43:59 +04:00
return 0
fi
done
return 1
}
run_endorser( ) {
if check_endorser; then
echo "Cannot run two endorsers in the same container."
exit 1
fi
echo "Start endorser..."
2018-06-13 13:05:20 +04:00
exec $alpha_endorser launch daemon" $@ " > " $client_dir /endorser.log "
2017-03-09 17:43:59 +04:00
}
stop_endorser( ) {
2018-06-13 13:05:20 +04:00
pids = $( pgrep -x tezos-alpha-endorser 2>/dev/null)
2017-03-09 17:43:59 +04:00
for pid in $pids ; do
2018-06-13 13:05:20 +04:00
if grep -- "tezos-alpha-endorser" " /proc/ $pid /cmdline " > /dev/null 2>& 1 ; then
2017-03-09 17:43:59 +04:00
kill " $pid "
fi
done
}
log_endorser( ) {
if ! check_endorser ; then
echo
echo "#################################################"
echo "## ##"
echo "## Warning: The tezos endorser is not running! ##"
echo "## ##"
echo "#################################################"
echo
tail " $client_dir /endorser.log "
2017-02-24 20:11:51 +04:00
else
2017-03-09 17:43:59 +04:00
tail -f " $client_dir /endorser.log "
2017-02-24 20:11:51 +04:00
fi
}
2017-08-28 11:56:57 +04:00
## Sandboxed client ########################################################
# key pairs from $src_dir/test/sandbox.json
2017-08-28 20:34:36 +04:00
BOOTSTRAP1_IDENTITY = "tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"
2017-08-28 11:56:57 +04:00
BOOTSTRAP1_PUBLIC = "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav"
2018-05-26 15:22:47 +04:00
BOOTSTRAP1_SECRET = "unencrypted:edsk3gUfUPyBSfrS9CCgmCiQsTCHGkviBDusMxDJstFtojtc1zcpsh"
2017-08-28 11:56:57 +04:00
2017-08-28 20:34:36 +04:00
BOOTSTRAP2_IDENTITY = "tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN"
2017-08-28 11:56:57 +04:00
BOOTSTRAP2_PUBLIC = "edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9"
2018-05-26 15:22:47 +04:00
BOOTSTRAP2_SECRET = "unencrypted:edsk39qAm1fiMjgmPkw1EgQYkMzkJezLNewd7PLNHTkr6w9XA2zdfo"
2017-08-28 11:56:57 +04:00
2017-08-28 20:34:36 +04:00
BOOTSTRAP3_IDENTITY = "tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU"
2017-08-28 11:56:57 +04:00
BOOTSTRAP3_PUBLIC = "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV"
2018-05-26 15:22:47 +04:00
BOOTSTRAP3_SECRET = "unencrypted:edsk4ArLQgBTLWG5FJmnGnT689VKoqhXwmDPBuGx3z4cvwU9MmrPZZ"
2017-08-28 11:56:57 +04:00
2017-08-28 20:34:36 +04:00
BOOTSTRAP4_IDENTITY = "tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv"
2017-08-28 11:56:57 +04:00
BOOTSTRAP4_PUBLIC = "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU"
2018-05-26 15:22:47 +04:00
BOOTSTRAP4_SECRET = "unencrypted:edsk2uqQB9AY4FvioK2YMdfmyMrer5R8mGFyuaLLFfSRo8EoyNdht3"
2017-08-28 11:56:57 +04:00
2017-08-28 20:34:36 +04:00
BOOTSTRAP5_IDENTITY = "tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv"
2017-08-28 11:56:57 +04:00
BOOTSTRAP5_PUBLIC = "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n"
2018-05-26 15:22:47 +04:00
BOOTSTRAP5_SECRET = "unencrypted:edsk4QLrcijEffxV31gGdN2HU7UpyJjA8drFoNcmnB28n89YjPNRFm"
2017-08-28 11:56:57 +04:00
2018-06-28 16:03:12 +04:00
ACTIVATOR_SECRET = "unencrypted:edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6"
2017-08-28 11:56:57 +04:00
add_sandboxed_bootstrap_identities( ) {
2018-05-26 15:22:47 +04:00
${ client } import secret key bootstrap1 ${ BOOTSTRAP1_SECRET }
${ client } import secret key bootstrap2 ${ BOOTSTRAP2_SECRET }
${ client } import secret key bootstrap3 ${ BOOTSTRAP3_SECRET }
${ client } import secret key bootstrap4 ${ BOOTSTRAP4_SECRET }
${ client } import secret key bootstrap5 ${ BOOTSTRAP5_SECRET }
2017-08-28 11:56:57 +04:00
2018-06-28 16:03:12 +04:00
${ client } import secret key activator ${ ACTIVATOR_SECRET }
2017-08-28 11:56:57 +04:00
}
2017-08-28 20:34:36 +04:00
activate_alpha( ) {
${ client } \
-block genesis \
2018-06-30 19:27:05 +04:00
activate protocol PtCJ7pwoxe8JasnHY8YonnLYjcVHmhiARPJvqcC6VfHT5s8k8sY \
2017-08-28 20:34:36 +04:00
with fitness 1 \
2018-06-28 16:03:12 +04:00
and key activator \
2018-04-21 19:16:01 +04:00
and parameters " ${ parameters_file } " \
2018-05-30 14:39:35 +04:00
--timestamp $( TZ = 'AAA+1' date +%FT%TZ)
2017-08-28 20:34:36 +04:00
}
2017-12-06 22:51:57 +04:00
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."
}
main ( ) {
local bin_dir = " $( cd " $( dirname " $0 " ) " && echo " $( pwd -P) / " ) "
if [ $( basename " $bin_dir " ) = "bin_client" ] ; then
2018-02-14 14:01:23 +04:00
local_client = " ${ local_client :- $bin_dir /../../_build/default/src/bin_client/main_client.exe } "
2018-02-14 19:24:08 +04:00
local_admin_client = " ${ local_admin_client :- $bin_dir /../../_build/default/src/bin_client/main_admin.exe } "
2018-03-21 18:40:13 +04:00
local_alpha_baker = " ${ local_alpha_baker :- $bin_dir /../../_build/default/src/proto_alpha/bin_baker/main_baker_alpha.exe } "
2018-06-15 18:32:19 +04:00
local_signer = " ${ local_signer :- $bin_dir /../../_build/default/src/bin_signer/main_signer.exe } "
2018-06-13 13:05:20 +04:00
local_alpha_endorser = " ${ local_alpha_endorser :- $bin_dir /../../_build/default/src/proto_alpha/bin_endorser/main_endorser_alpha.exe } "
local_alpha_accuser = " ${ local_alpha_accuser :- $bin_dir /../../_build/default/src/proto_alpha/bin_accuser/main_accuser_alpha.exe } "
2018-04-04 18:20:03 +04:00
parameters_file = " ${ parameters_file :- $bin_dir /../../scripts/protocol_parameters.json } "
2018-01-22 12:20:46 +04:00
else
2018-02-21 21:34:55 +04:00
# we assume a clean install with tezos-(admin-)client in the path
local_client = " ${ local_client :- $( which tezos-client) } "
local_admin_client = " ${ local_admin_client :- $( which tezos-admin-client) } "
2018-03-21 18:40:13 +04:00
local_alpha_baker = " ${ local_alpha_baker :- $( which tezos-alpha-baker) } "
2018-06-13 13:05:20 +04:00
local_alpha_endorser = " ${ local_alpha_endorser :- $( which tezos-alpha-endorser) } "
local_alpha_accuser = " ${ local_alpha_accuser :- $( which tezos-alpha-accuser) } "
2018-05-22 20:04:37 +04:00
local_signer = " ${ local_signer :- $( which tezos-signer) } "
2017-12-06 22:51:57 +04:00
fi
if [ $# -lt 1 ] || [ " $1 " -le 0 ] || [ 10 -le " $1 " ] ; then
usage
exit 1
fi
init_sandboxed_client " $1 "
add_sandboxed_bootstrap_identities | sed -e 's/^/## /' 1>& 2
2018-02-03 18:08:18 +04:00
mkdir -p $client_dir /bin
2018-03-21 18:40:13 +04:00
2018-02-03 18:08:18 +04:00
echo '#!/bin/sh' > $client_dir /bin/tezos-client
echo " exec $client \"\$@\" " >> $client_dir /bin/tezos-client
chmod +x $client_dir /bin/tezos-client
2018-03-21 18:40:13 +04:00
2018-02-03 18:08:18 +04:00
echo '#!/bin/sh' > $client_dir /bin/tezos-admin-client
2018-02-14 19:24:08 +04:00
echo " exec $admin_client \"\$@\" " >> $client_dir /bin/tezos-admin-client
2018-02-03 18:08:18 +04:00
chmod +x $client_dir /bin/tezos-admin-client
2018-03-21 18:40:13 +04:00
echo '#!/bin/sh' > $client_dir /bin/tezos-alpha-baker
echo " exec $alpha_baker \"\$@\" " >> $client_dir /bin/tezos-alpha-baker
chmod +x $client_dir /bin/tezos-alpha-baker
2018-06-13 13:05:20 +04:00
echo '#!/bin/sh' > $client_dir /bin/tezos-alpha-endorser
echo " exec $alpha_endorser \"\$@\" " >> $client_dir /bin/tezos-alpha-endorser
chmod +x $client_dir /bin/tezos-alpha-endorser
echo '#!/bin/sh' > $client_dir /bin/tezos-alpha-accuser
echo " exec $alpha_accuser \"\$@\" " >> $client_dir /bin/tezos-alpha-accuser
chmod +x $client_dir /bin/tezos-alpha-accuser
2018-05-22 20:04:37 +04:00
echo '#!/bin/sh' > $client_dir /bin/tezos-signer
echo " exec $signer \"\$@\" " >> $client_dir /bin/tezos-signer
chmod +x $client_dir /bin/tezos-signer
2017-12-06 22:51:57 +04:00
cat <<EOF
if type tezos-client-reset >/dev/null 2>& 1 ; then tezos-client-reset; fi ;
2018-02-03 18:08:18 +04:00
PATH = " $client_dir /bin:\$PATH " ; export PATH ;
2018-06-30 19:27:05 +04:00
alias tezos-activate-alpha= " $client -block genesis activate protocol PtCJ7pwoxe8JasnHY8YonnLYjcVHmhiARPJvqcC6VfHT5s8k8sY with fitness 1 and key activator and parameters $parameters_file --timestamp $( TZ = 'AAA+1' date +%FT%TZ) " ;
2018-02-03 18:08:18 +04:00
alias tezos-client-reset= " rm -rf \" $client_dir \"; unalias tezos-activate-alpha tezos-client-reset " ;
alias tezos-autocomplete= " if [ \$ZSH_NAME ] ; then autoload bashcompinit ; bashcompinit ; fi ; source \" $bin_dir /bash-completion.sh\" " ;
2017-12-06 22:51:57 +04:00
trap tezos-client-reset EXIT ;
2018-02-21 21:34:55 +04:00
2017-12-06 22:51:57 +04:00
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:
2018-06-10 12:45:11 +04:00
tezos-client rpc get /chains/main/blocks/head/metadata
2017-12-06 22:51:57 +04:00
Note: if the current protocol version, as reported by the previous
2018-06-30 19:33:28 +04:00
command, is "Ps9mPmXaRzmzk35gbAYNCAw6UXdE2qoABTHbN2oEEc1qM7CwT9P" , you
2017-12-06 22:51:57 +04:00
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.
Activate tab completion by running:
tezos-autocomplete
EOF
}
if [ " $0 " = = " $BASH_SOURCE " ] ; then
main " $@ "
fi