The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/test/deploy.sh

195 lines
4.5 KiB

#!/usr/bin/env bash
set -eo pipefail
unset -v progdir
case "${0}" in
*/*) progdir="${0%/*}" ;;
*) progdir=. ;;
esac
ROOT="${progdir}/.."
USER=$(whoami)
OS=$(uname -s)
. "${ROOT}/scripts/setup_bls_build_flags.sh"
6 years ago
function cleanup() {
"${progdir}/kill_node.sh"
}
function build() {
if [[ "${NOBUILD}" != "true" ]]; then
pushd ${ROOT}
export GO111MODULE=on
if [[ "$OS" == "Darwin" ]]; then
# MacOS doesn't support static build
scripts/go_executable_build.sh -S
else
# Static build on Linux platform
scripts/go_executable_build.sh -s
fi
popd
fi
}
function setup() {
# Setup blspass file
mkdir -p ${ROOT}/.hmy
if [[ ! -f "${ROOT}/.hmy/blspass.txt" ]]; then
touch "${ROOT}/.hmy/blspass.txt"
fi
# Kill nodes if any
cleanup
# Note that the binarys only works on MacOS & Linux
build
# Create a tmp folder for logs
t=$(date +"%Y%m%d-%H%M%S")
log_folder="${ROOT}/tmp_log/log-$t"
mkdir -p "${log_folder}"
LOG_FILE=${log_folder}/r.log
}
function launch_bootnode() {
echo "launching boot node ..."
${DRYRUN} ${ROOT}/bin/bootnode -port 19876 >"${log_folder}"/bootnode.log 2>&1 | tee -a "${LOG_FILE}" &
sleep 1
BN_MA=$(grep "BN_MA" "${log_folder}"/bootnode.log | awk -F\= ' { print $2 } ')
echo "bootnode launched." + " $BN_MA"
}
function launch_localnet() {
launch_bootnode
unset -v base_args
declare -a base_args args
if ${VERBOSE}; then
verbosity=5
else
verbosity=3
fi
base_args=(--log_folder "${log_folder}" --min_peers "${MIN}" --bootnodes "${BN_MA}" "--network_type=$NETWORK" --blspass file:"${ROOT}/.hmy/blspass.txt" "--dns=false" "--verbosity=${verbosity}")
sleep 2
# Start nodes
i=-1
while IFS='' read -r line || [[ -n "$line" ]]; do
i=$((i + 1))
# Read config for i-th node form config file
IFS=' ' read -r ip port mode bls_key shard <<<"${line}"
Node API Refactor - pt3 (Stage 3.1 of Node API Overhaul) (#3297) * [rosetta] Add server with example block & network services * Update go.mod for rosetta SDK Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [internal/configs] Add RosettaServer to node config Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Add rosetta port flag Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Add rosetta server start & rename api.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Change server start to use nodeconfig of rosetta Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Cleanup debugging prints Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix stdout print & document placeholders Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix lint & make StartSevers more consistent Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Disable rosetta by default Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [test] Make explorer deploy rosetta server Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Use direct http server for start * Make go.mod changes minimal Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix fmt Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix fmt of go.mod Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Use port 9700 instead of 10000 Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Bump config version Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Add v1.0.0 config backwards compatibility test * Included update message if old config is loaded Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [test] Do not broadcast invalid tx on localnet Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Correct for invalid port when loading old config Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [cmd] Make rosetta variable names consistent Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
args=("${base_args[@]}" --ip "${ip}" --port "${port}" --key "/tmp/${ip}-${port}.key" --db_dir "${ROOT}/db-${ip}-${port}" "--broadcast_invalid_tx=false")
if [[ -z "$ip" || -z "$port" ]]; then
echo "skip empty node"
continue
fi
if [[ $EXPOSEAPIS == "true" ]]; then
args=("${args[@]}" "--http.ip=0.0.0.0" "--ws.ip=0.0.0.0")
fi
# Setup BLS key for i-th localnet node
if [[ ! -e "$bls_key" ]]; then
args=("${args[@]}" --blskey_file "BLSKEY")
elif [[ -f "$bls_key" ]]; then
args=("${args[@]}" --blskey_file "${ROOT}/${bls_key}")
elif [[ -d "$bls_key" ]]; then
args=("${args[@]}" --blsfolder "${ROOT}/${bls_key}")
else
echo "skipping unknown node"
continue
fi
# Setup flags for i-th node based on config
case "${mode}" in
explorer)
Rosetta Implementation - pt2 (Stage 3.2 of Node API Overhaul) (#3312) * [rosetta] Add server stop Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Make network naming consistent Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Correct common package name & add error enum Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Remove needless forward of network info to services * Implement /network/list Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Refactor errors & add operation statuses and types Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement NetworkOptions & update NetworkAPIService * Rename *_service.go files to remove the suffix * Update StartServers to use new operation types Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Impl NetworkStatus - Finish init impl of /network endpoint * Fix import structure for rosetta.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [test] Make explorer run as archival for localnet Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add unit tests * Force errors to remain the same with unit tests * Force operations to remain the same with unit tests * Ensure network checking works for all cases with unit tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add InvalidNetworkError and correct error codes Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add UnmarshalFromInterface for SubNetworkMetadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add network checking Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Nit fixes & add unit test for Peer Info * Make names consistent Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add BlockNotFoundError & TransactionNotFoundError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement skeleton for block transactions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add ReceiptNotFoundError Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add receipt to formatTransaction sig for contract fails Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add currency, ExpendGasOperation, & ContractCreationOperation * Add Error creator Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Init impl of plain transaction formatting Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Update network.go for new error constructor Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Implement stx formatter & refactor BlockTransaction * Updated todo comments & function formatting Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Impl Block & make currency non-ptr for easy copy with custom metadata Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix collect rewards amount on transaction fetch Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix block look-up edge case & add recovery middleware Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add bocks unit tests Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix checkPeerID unit test in network_test.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix staking tx amount for tx ops & update inline docs Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix lint Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Refactor getStakingOperations Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix undelegate value Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Nit - fix formatting for network.go Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Move genesis allocation to core & remove unused ContractDeployerKey Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix precision error & add cx receipt hash on blk fetch * Add unit tests for supporting helper functions Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix fmt Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Fix cx receipt hashes for blocks * Print stack trace on panic recovery Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Nit - fix comment for StopRosetta Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [node] Expose GetMaxPeerHeight Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Add SyncStatus enum Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu> * [rosetta] Nit - remove redundant 'service' name in services namespace Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
4 years ago
args=("${args[@]}" "--node_type=explorer" "--shard_id=${shard}" "--http.rosetta=true" "--run.archive")
;;
archival)
args=("${args[@]}" --is_archival --run.legacy)
;;
leader)
args=("${args[@]}" --is_leader --run.legacy)
;;
external)
;;
client)
args=("${args[@]}" --run.legacy)
;;
validator)
args=("${args[@]}" --run.legacy)
;;
esac
# Start the node
${DRYRUN} "${ROOT}/bin/harmony" "${args[@]}" "${extra_args[@]}" 2>&1 | tee -a "${LOG_FILE}" &
done <"${config}"
}
trap cleanup SIGINT SIGTERM
function usage() {
local ME=$(basename $0)
echo "
USAGE: $ME [OPTIONS] config_file_name [extra args to node]
-h print this help message
-D duration test run duration (default: $DURATION)
-m min_peers minimal number of peers to start consensus (default: $MIN)
-s shards number of shards (default: $SHARDS)
-n dryrun mode (default: $DRYRUN)
-N network network type (default: $NETWORK)
-B don't build the binary
-v verbosity in log (default: $VERBOSE)
-e expose WS & HTTP ip (default: $EXPOSEAPIS)
This script will build all the binaries and start harmony and based on the configuration file.
EXAMPLES:
$ME local_config.txt
"
exit 0
}
DURATION=60000
MIN=3
SHARDS=2
DRYRUN=
NETWORK=localnet
VERBOSE=false
NOBUILD=false
EXPOSEAPIS=false
while getopts "hD:m:s:nBN:ve" option; do
case ${option} in
h) usage ;;
D) DURATION=$OPTARG ;;
m) MIN=$OPTARG ;;
s) SHARDS=$OPTARG ;;
n) DRYRUN=echo ;;
B) NOBUILD=true ;;
N) NETWORK=$OPTARG ;;
v) VERBOSE=true ;;
e) EXPOSEAPIS=true ;;
*) usage ;;
esac
done
shift $((OPTIND - 1))
config=$1
shift 1 || usage
unset -v extra_args
declare -a extra_args
extra_args=("$@")
setup
launch_localnet
sleep "${DURATION}"
cleanup || true