From 14ef4128c7f8d0ebc6dbc59c53e0d082f0e8932e Mon Sep 17 00:00:00 2001 From: "lexon@lexbuntu" <co.liang.ol@gmail.com> Date: Fri, 20 May 2016 00:15:29 -0400 Subject: [PATCH] Created arch/arm; Changed MaxUint32 to MaxInt32 of erisdb/pipe/blockchain.go --- .gitignore | 2 + arch/arm/docker/Dockerfile | 95 ++++++++++++++++++++ arch/arm/docker/build.sh | 28 ++++++ arch/arm/docker/chain_api.sh | 4 + arch/arm/docker/chain_install.sh | 69 +++++++++++++++ arch/arm/docker/chain_new.sh | 42 +++++++++ arch/arm/docker/chain_register.sh | 34 ++++++++ arch/arm/docker/chain_run.sh | 11 +++ arch/arm/docker/config.toml | 10 +++ arch/arm/docker/start.sh | 140 ++++++++++++++++++++++++++++++ arch/arm/docker/version.sh | 2 + erisdb/pipe/blockchain.go | 2 +- 12 files changed, 438 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 arch/arm/docker/Dockerfile create mode 100755 arch/arm/docker/build.sh create mode 100755 arch/arm/docker/chain_api.sh create mode 100755 arch/arm/docker/chain_install.sh create mode 100755 arch/arm/docker/chain_new.sh create mode 100755 arch/arm/docker/chain_register.sh create mode 100755 arch/arm/docker/chain_run.sh create mode 100644 arch/arm/docker/config.toml create mode 100755 arch/arm/docker/start.sh create mode 100644 arch/arm/docker/version.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..95d52a51 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Temporary / cached +*.swp diff --git a/arch/arm/docker/Dockerfile b/arch/arm/docker/Dockerfile new file mode 100644 index 00000000..76dd58bf --- /dev/null +++ b/arch/arm/docker/Dockerfile @@ -0,0 +1,95 @@ +# Pull base image. +FROM eris4iot/base:armhf +MAINTAINER Eris Industries <support@erisindustries.com> + +#----------------------------------------------------------------------------- +# dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + libgmp3-dev jq && \ + rm -rf /var/lib/apt/lists/* + +#----------------------------------------------------------------------------- +# install tendermint + +# set the repo and install tendermint -- should track vendored commit +ENV REPO_ALIAS github.com/tendermint/tendermint +ENV REPO github.com/eris-ltd/tendermint +#ENV COMMIT 4ee387d0770ed379e2d524f7077938517b38cd7c +ENV COMMIT working +# note, we want to lock in the same commit number +# as eris-db has vendored. +RUN mkdir --parents $GOPATH/src/$REPO +WORKDIR $GOPATH/src/$REPO_ALIAS +RUN git clone --quiet https://$REPO . && \ + git checkout --quiet $COMMIT && \ + go build -o /usr/local/bin/tendermint ./cmd/tendermint + +#----------------------------------------------------------------------------- +# install mint-client tools + +# set the repo and install mint-client +ENV REPO github.com/eris-ltd/mint-client +ENV BRANCH master +RUN mkdir --parents $GOPATH/src/$REPO +WORKDIR $GOPATH/src/$REPO +RUN git clone --quiet https://$REPO . && \ + git checkout --quiet $BRANCH && \ + go install ./... && \ + mv $GOPATH/bin/mint* /usr/local/bin && \ + mv ./mint-client /usr/local/bin/ + +#----------------------------------------------------------------------------- +# install erisdb + +# set the repo and install erisdb +ENV REPO $GOPATH/src/github.com/eris-ltd/eris-db +COPY . $REPO +WORKDIR $REPO +RUN cd ./cmd/erisdb && go build -o /usr/local/bin/erisdb && cd ../.. + +#----------------------------------------------------------------------------- +# cleanup + +RUN rm -rf $GOPATH/src/* && \ + unset REPO && \ + unset REPO_ALIAS && \ + unset COMMIT && \ + unset BRANCH + +#----------------------------------------------------------------------------- +# start script + +# install the wrapper/start script +COPY DOCKER/start.sh /usr/local/bin/erisdb-wrapper + +#----------------------------------------------------------------------------- +# chain manager scripts and default mint config + +ENV ECM_PATH /usr/local/lib/ecm +RUN mkdir -p $ECM_PATH +COPY DOCKER/chain_* $ECM_PATH/ +COPY DOCKER/config.toml $ECM_PATH/ +COPY DOCKER/version.sh $ECM_PATH/ + +#----------------------------------------------------------------------------- +# permission the directories +RUN chown -R eris /usr/local/bin +RUN chown -R eris $ECM_PATH + +#----------------------------------------------------------------------------- +# root dir + +# persist data, set user +VOLUME /home/$USER/.eris +WORKDIR /home/$USER/.eris +USER $USER +RUN mkdir --parents /home/$USER/.eris/chains/tendermint +ENV TMROOT /home/$USER/.eris/chains/tendermint + +# run tendermint +# ports: 1337:eris-db API; 46656:mint-peer; 46657:mint-rpc +EXPOSE 1337 +EXPOSE 46656 +EXPOSE 46657 +CMD "erisdb-wrapper" diff --git a/arch/arm/docker/build.sh b/arch/arm/docker/build.sh new file mode 100755 index 00000000..0ab7e88a --- /dev/null +++ b/arch/arm/docker/build.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +if [ "$CIRCLE_BRANCH" ] +then + repo=`pwd` +else + base=github.com/eris-ltd/eris-db + repo=$GOPATH/src/$base +fi +branch=${CIRCLE_BRANCH:=master} + +release_min=$(cat $repo/version/version.go | tail -n 1 | cut -d \ -f 4 | tr -d '"') +release_maj=$(echo $release_min | cut -d . -f 1-2) + +start=`pwd` +image_base=quay.io/eris/erisdb + +cd $repo + +if [ "$branch" = "master" ]; then + docker build -t $image_base:latest -f DOCKER/Dockerfile . + docker tag $image_base:latest $image_base:$release_maj + docker tag $image_base:latest $image_base:$release_min +else + docker build -t $image_base:$release_min -f DOCKER/Dockerfile . +fi + +cd $start \ No newline at end of file diff --git a/arch/arm/docker/chain_api.sh b/arch/arm/docker/chain_api.sh new file mode 100755 index 00000000..8fecb978 --- /dev/null +++ b/arch/arm/docker/chain_api.sh @@ -0,0 +1,4 @@ +#! /bin/bash + +echo "Running chain $CHAIN_ID (via ErisDB API)" +erisdb $TMROOT diff --git a/arch/arm/docker/chain_install.sh b/arch/arm/docker/chain_install.sh new file mode 100755 index 00000000..55aaabba --- /dev/null +++ b/arch/arm/docker/chain_install.sh @@ -0,0 +1,69 @@ +#! /bin/bash + +#----------------------------------------------------------------------- +# get genesis, seed, copy config + +export MINTX_NODE_ADDR=$NODE_ADDR + +# get genesis if not already +if [ ! -e "${CHAIN_DIR}/genesis.json" ]; then + # etcb chain (given by $NODE_ADDR) + REFS_CHAIN_ID=$(mintinfo genesis chain_id) + ifExit "Error fetching default chain id from $NODE_ADDR" + REFS_CHAIN_ID=$(echo "$REFS_CHAIN_ID" | tr -d '"') # remove surrounding quotes + + echo "etcb chain: $REFS_CHAIN_ID" + + # get the genesis.json for a refs chain from the /genesis rpc endpoint + # for a different chain, use etcb (ie namereg on the ref chain) + if [ "$CHAIN_ID" = "$REFS_CHAIN_ID" ] ; then + # grab genesis.json + mintinfo genesis > "${CHAIN_DIR}/genesis.json" + ifExit "Error fetching genesis.json from $NODE_ADDR" + else + # fetch genesis from etcb + GENESIS=$(mintinfo names "${CHAIN_ID}/genesis" data) + ifExit "Error fetching genesis.json for $CHAIN_ID: $GENESIS" + + echo $GENESIS > "${CHAIN_DIR}/genesis.json" + + SEED_NODE=$(mintinfo names "${CHAIN_ID}/seeds" data) + ifExit "Error grabbing seed node from $NODE_ADDR for $CHAIN_ID" + fi +fi + +# copy in config if not already +if [ ! -e "${CHAIN_DIR}/config.toml" ]; then + echo "laying default config..." + mintconfig > $CHAIN_DIR/config.toml + ifExit "Error creating config" + + if [ "$SEED_NODE" = "" ]; then + SEED_NODE=$P2P_ADDR + fi + + if [ "$HOST_NAME" = "" ]; then + HOST_NAME=mint_user + fi +fi + +# set seed node and host name +if [ "$SEED_NODE" != "" ]; then + echo "Seed node: $SEED_NODE" + # NOTE the NODE_ADDR must not have any slashes (no http://) + sed -i "s/^\(seeds\s*=\s*\).*\$/\1\"$SEED_NODE\"/" "${CHAIN_DIR}/config.toml" + ifExit "Error setting seed node in config.toml" +fi + +if [ "$HOST_NAME" != "" ]; then + echo "Host name: $HOST_NAME" + sed -i "s/^\(moniker\s*=\s*\).*\$/\1\"$HOST_NAME\"/" "${CHAIN_DIR}/config.toml" + ifExit "Error setting host name in config.toml" +fi + +#----------------------------------------------------------------------- + +# would be nice if we could stop syncing once we're caught up ... +echo "Running mint in ${CHAIN_DIR}" +tendermint node --fast_sync +ifExit "Error running tendermint!" diff --git a/arch/arm/docker/chain_new.sh b/arch/arm/docker/chain_new.sh new file mode 100755 index 00000000..a487564a --- /dev/null +++ b/arch/arm/docker/chain_new.sh @@ -0,0 +1,42 @@ +#! /bin/bash + +echo "your new chain, kind marmot: $CHAIN_ID" + +# lay the genesis +# if it exists, just overwrite the chain id +if [ ! -f $CHAIN_DIR/genesis.json ]; then + if [ "$CSV" = "" ]; then + mintgen random --dir="$CHAIN_DIR" 1 $CHAIN_ID + ifExit "Error creating random genesis file" + else + mintgen known --csv="$CSV" $CHAIN_ID > $CHAIN_DIR/genesis.json + ifExit "Error creating genesis file from csv" + fi +else + # apparently just outputing to $CHAIN_DIR/genesis.json doesn't work so we copy + cat $CHAIN_DIR/genesis.json | jq .chain_id=\"$CHAIN_ID\" > genesis.json + cp genesis.json $CHAIN_DIR/genesis.json +fi + + +# if no config was given, lay one with the given options +if [ ! -f $CHAIN_DIR/config.toml ]; then + echo "running mintconfig $CONFIG_OPTS" + mintconfig $CONFIG_OPTS > $CHAIN_DIR/config.toml +else + echo "found config file:" + cat $CHAIN_DIR/config.toml +fi + +# run the node. +# TODO: maybe bring back this stopping option if we think its useful +# tendermint node & last_pid=$! && sleep 1 && kill -KILL $last_pid +if [ $ERISDB_API ]; then + echo "Running chain $CHAIN_ID (via ErisDB API)" + erisdb $TMROOT + ifExit "Error starting erisdb" +else + echo Running chain $CHAIN_ID + tendermint node + ifExit "Error starting tendermint" +fi diff --git a/arch/arm/docker/chain_register.sh b/arch/arm/docker/chain_register.sh new file mode 100755 index 00000000..cbd2beec --- /dev/null +++ b/arch/arm/docker/chain_register.sh @@ -0,0 +1,34 @@ +#! /bin/bash + +echo "registering $CHAIN_ID in the grand registry of marmot mayhem and marmalade" + +# lay the genesis +# if it exists, just overwrite the chain id +if [ ! -f "$CHAIN_DIR/genesis.json" ]; then + "Could not find genesis file in $CHAIN_DIR. Did you run `eris chains new $CHAIN_ID`?" + exit 1 +fi + + +echo "or less dramatically, registering $CHAIN_ID with the $ETCB_CHAIN_ID chain at $MINTX_NODE_ADDR from address $PUBKEY" + +echo "NAME ${CHAIN_ID}_genesis" +cat $CHAIN_DIR/genesis.json + +# register the genesis +RES=`mintx name --pubkey=$PUBKEY --name="${CHAIN_ID}/genesis" --data-file=$CHAIN_DIR/genesis.json --amt=10000 --fee=0 --sign --broadcast --chainID=$ETCB_CHAIN_ID --wait` +ifExit "$RES" "Error registering genesis with etcb_testnet" +echo $RES | grep "Incorrect" +if0Exit "$RES" "Error registering genesis with etcb_testnet" +echo $RES + +echo "successfully registered genesis on etcb chain" + +# register the seed/s +RES=`mintx name --pubkey=$PUBKEY --name="${CHAIN_ID}/seeds" --data="$NEW_P2P_SEEDS" --amt=10000 --fee=0 --sign --broadcast --chainID=$ETCB_CHAIN_ID --wait` +ifExit "$RES" "Error registering seeds with etcb_testnet" +echo $RES | grep "Incorrect" +if0Exit "$RES" "Error registering seeds with etcb_testnet" +echo $RES + +echo "successfully registered seed on etcb chain" diff --git a/arch/arm/docker/chain_run.sh b/arch/arm/docker/chain_run.sh new file mode 100755 index 00000000..6728d41c --- /dev/null +++ b/arch/arm/docker/chain_run.sh @@ -0,0 +1,11 @@ +#! /bin/bash + +if [ $ERISDB_API ]; then + echo "Running chain $CHAIN_ID (via ErisDB API)" + erisdb $TMROOT + ifExit "Error starting erisdb" +else + echo Running chain $CHAIN_ID + tendermint node + ifExit "Error starting tendermint" +fi diff --git a/arch/arm/docker/config.toml b/arch/arm/docker/config.toml new file mode 100644 index 00000000..b6dadf56 --- /dev/null +++ b/arch/arm/docker/config.toml @@ -0,0 +1,10 @@ +# This is a TOML config file. +# For more information, see https://github.com/toml-lang/toml + +moniker = "eris_chains" +node_laddr = "0.0.0.0:46656" +seeds = "" +fast_sync = false +db_backend = "leveldb" +log_level = "debug" +rpc_laddr = "0.0.0.0:46657" diff --git a/arch/arm/docker/start.sh b/arch/arm/docker/start.sh new file mode 100755 index 00000000..7f3194e5 --- /dev/null +++ b/arch/arm/docker/start.sh @@ -0,0 +1,140 @@ +#! /bin/bash + +ifExit(){ + if [[ $? != 0 ]]; then + echo "ifExit" + echo "$1" + for var in "$@" + do + echo "$var" + done + exit 1 + fi +} + +if0Exit(){ + if [[ $? == 0 ]]; then + echo "if0Exit" + echo "$1" + for var in "$@" + do + echo "$var" + done + exit 1 + fi +} + + +export -f ifExit +export -f if0Exit + +#------------------------------------------------ +# set and export directories + +if [ "$CHAIN_ID" = "" ]; then + echo "ecm requires CHAIN_ID be set" + exit 1 +fi + +# TODO: deal with chain numbers +# and eg. $CONTAINER_NAME +CHAIN_DIR="/home/$USER/.eris/chains/$CHAIN_ID" + +# set the tendermint directory +TMROOT=$CHAIN_DIR + +if [ ! -d "$CHAIN_DIR" ]; then + mkdir -p $CHAIN_DIR + ifExit "Error making root dir $CHAIN_DIR" +fi + +# our root chain +if [ ! $ROOT_CHAIN_ID ]; then + ROOT_CHAIN_ID=etcb_testnet +fi +if [ ! $NODE_ADDR ]; then + NODE_ADDR=interblock.io:46657 +fi +if [ ! $P2P_ADDR ]; then + P2P_ADDR=interblock.io:46656 +fi + +# where the etcb client scripts are +if [ ! $ECM_PATH ]; then + ECM_PATH=. +fi + +#------------------------------------------------ +# dump key files if they are in env vars + +if [ -z "$KEY" ] +then + echo "No Key Given" +else + echo "Key Given. Writing priv_validator.json" + echo "$KEY" >> $CHAIN_DIR/priv_validator.json +fi + +if [ -z "$GENESIS" ] +then + echo "No Genesis Given" +else + echo "Genesis Given. Writing genesis.json" + echo "$GENESIS" > $CHAIN_DIR/genesis.json +fi + +if [ -z "$GENESIS_CSV" ] +then + echo "No Genesis_CSV Given" +else + echo "Genesis_CSV Given. Writing genesis.csv" + echo "$GENESIS_CSV" > $CHAIN_DIR/genesis.csv +fi + +if [ -z "$CHAIN_CONFIG" ] +then + echo "No Chain Config Given" +else + echo "Chain Config Given. Writing config.toml" + echo "$CHAIN_CONFIG" > $CHAIN_DIR/config.toml +fi + +if [ -z "$SERVER_CONFIG" ] +then + echo "No Server Config Given" +else + echo "Server Config Given. Writing server_conf.toml" + echo "$SERVER_CONFIG" > $CHAIN_DIR/server_conf.toml +fi + +#------------------------------------------------ +# export important vars + +export TMROOT +export CHAIN_DIR +export NODE_ADDR +export P2P_ADDR +export ECM_PATH # set by Dockerfile + +export MINTX_NODE_ADDR=$NODE_ADDR +export MINTX_SIGN_ADDR=keys:4767 + +# print the version +bash $ECM_PATH/version.sh + +#----------------------------------------------------------------------- +# either we are fetching a chain for the first time, +# creating one from scratch, or running one we already have +CMD=$1 +case $CMD in +"install" ) $ECM_PATH/chain_install.sh + ;; +"new" ) $ECM_PATH/chain_new.sh + ;; +"run" ) $ECM_PATH/chain_run.sh + ;; +"register" ) $ECM_PATH/chain_register.sh + ;; +*) echo "Enter a command for starting the chain (new, install, run, register)" + ;; +esac diff --git a/arch/arm/docker/version.sh b/arch/arm/docker/version.sh new file mode 100644 index 00000000..7acc21f4 --- /dev/null +++ b/arch/arm/docker/version.sh @@ -0,0 +1,2 @@ +# json break +echo "ecm version 0.12.0" diff --git a/erisdb/pipe/blockchain.go b/erisdb/pipe/blockchain.go index cb01eb4b..80067ea0 100644 --- a/erisdb/pipe/blockchain.go +++ b/erisdb/pipe/blockchain.go @@ -147,7 +147,7 @@ func (this *BlockHeightFilter) Configure(fd *FilterData) error { if fd.Value == "min" { val = 0 } else if fd.Value == "max" { - val = math.MaxUint32 + val = math.MaxInt32 } else { tv, err := strconv.ParseInt(fd.Value, 10, 0) if err != nil { -- GitLab