From 7e446739a1171adc0482b580f5ba0171756baf91 Mon Sep 17 00:00:00 2001 From: KKudryavtsev Date: Thu, 4 Feb 2016 15:42:49 +0000 Subject: [PATCH 01/22] install parity script --- install-parity.sh | 1018 ++++++++++++++++++++++++--------------------- 1 file changed, 550 insertions(+), 468 deletions(-) diff --git a/install-parity.sh b/install-parity.sh index 848c25c6d..0ce943f9b 100755 --- a/install-parity.sh +++ b/install-parity.sh @@ -1,475 +1,557 @@ #!/usr/bin/env bash + +#TODO: replace with the main repo url +PARITY_DEB_URL=https://github.com/jesuscript/scripts/raw/master/parity.deb + function run_installer() { - ####### Init vars - - HOMEBREW_PREFIX=/usr/local - HOMEBREW_CACHE=/Library/Caches/Homebrew - HOMEBREW_REPO=https://github.com/Homebrew/homebrew - OSX_REQUIERED_VERSION="10.7.0" - - - declare OS_TYPE - declare OSX_VERSION - declare GIT_PATH - declare RUBY_PATH - declare BREW_PATH - declare INSTALL_FILES="" - - errorMessages="" - isOsVersion=false - isGit=false - isRuby=false - isBrew=false - canContinue=true - depCount=0 - depFound=0 - - - - ####### Setup colors - - red=`tput setaf 1` - green=`tput setaf 2` - yellow=`tput setaf 3` - blue=`tput setaf 4` - magenta=`tput setaf 5` - cyan=`tput setaf 6` - white=`tput setaf 7` - b=`tput bold` - u=`tput sgr 0 1` - ul=`tput smul` - xl=`tput rmul` - stou=`tput smso` - xtou=`tput rmso` - dim=`tput dim` - reverse=`tput rev` - reset=`tput sgr0` - - - function head() { - echo "${blue}${b}==>${white} $1${reset}" - } - - function info() { - echo "${blue}${b}==>${reset} $1" - } - - function successHeading() { - echo "${green}${b}==> $1${reset}" - } - - function success() { - echo "${green}${b}==>${reset}${green} $1${reset}" - } - - function error() { - echo "${red}==> ${u}${b}${red}$1${reset}" - } - - function smallError() { - echo "${red}==>${reset} $1" - } - - function green() { - echo "${green}$1${reset}" - } - - function red() { - echo "${red}$1${reset}" - } - - function check() { - echo "${green}${bold} ✓${reset} $1${reset}" - } - - function uncheck() { - echo "${red}${bold} ✘${reset} $1${reset}" - } - - - - ####### Setup methods - - function wait_for_user() { - while : - do - read -p "${blue}==>${reset} $1 [Y/n] " imp - case $imp in - [yY] ) echo; break ;; - '' ) echo; break ;; - [nN] ) abortInstall "${red}==>${reset} Process stopped by user. To resume the install run the one-liner command again." ;; - * ) echo "Unrecognized option provided. Please provide either 'Y' or 'N'"; - esac - done - } - - - - function exe() { - echo "\$ $@"; "$@" - } - - function detectOS() { - if [[ "$OSTYPE" == "linux-gnu" ]] - then - OS_TYPE="linux" - get_linux_dependencies - elif [[ "$OSTYPE" == "darwin"* ]] - then - OS_TYPE="osx" - get_osx_dependencies - else - OS_TYPE="win" - abortInstall "${red}==>${reset} ${b}OS not supported:${reset} parity one-liner currently support OS X and Linux.\nFor instructions on installing parity on other platforms please visit ${u}${blue}http://ethcore.io/${reset}" - fi - - echo - - if [[ $depCount == $depFound ]] - then - green "Found all dependencies ($depFound/$depCount)" - else - if [[ $canContinue == true ]] - then - red "Some dependencies are missing ($depFound/$depCount)" - elif [[ $canContinue == false && $depFound == 0 ]] - then - red "All dependencies are missing and cannot be auto-installed ($depFound/$depCount)" - abortInstall "$errorMessages"; - elif [[ $canContinue == false ]] - then - red "Some dependencies which cannot be auto-installed are missing ($depFound/$depCount)" - abortInstall "$errorMessages"; - fi - fi - } - - function get_osx_dependencies() - { - macos_version - find_git - find_ruby - find_brew - } - - function macos_version() - { - declare -a reqVersion - declare -a localVersion - - depCount=$((depCount+1)) - OSX_VERSION=`/usr/bin/sw_vers -productVersion 2>/dev/null` - - if [ -z "$OSX_VERSION" ] - then - uncheck "OS X version not supported 🔥" - isOsVersion=false - canContinue=false - else - IFS='.' read -a localVersion <<< "$OSX_VERSION" - IFS='.' read -a reqVersion <<< "$OSX_REQUIERED_VERSION" - - if (( ${reqVersion[0]} <= ${localVersion[0]} )) && (( ${reqVersion[1]} <= ${localVersion[1]} )) - then - check "OS X Version ${OSX_VERSION}" - isOsVersion=true - depFound=$((depFound+1)) - return - else - uncheck "OS X version not supported" - isOsVersion=false - canContinue=false - fi - fi - - errorMessages+="${red}==>${reset} ${b}Mac OS version too old:${reset} eth requires OS X version ${red}$OSX_REQUIERED_VERSION${reset} at least in order to run.\n" - errorMessages+=" Please update the OS and reload the install process.\n" - } - - function find_eth() - { - ETH_PATH=`which parity 2>/dev/null` - - if [[ -f $ETH_PATH ]] - then - check "Found parity: $ETH_PATH" - echo "$($ETH_PATH -V)" - isEth=true - else - uncheck "parity is missing" - isEth=false - fi - } - - function find_git() - { - depCount=$((depCount+1)) - - GIT_PATH=`which git 2>/dev/null` - - if [[ -f $GIT_PATH ]] - then - check "$($GIT_PATH --version)" - isGit=true - depFound=$((depFound+1)) - else - uncheck "Git is missing" - isGit=false - fi - } - - function find_ruby() - { - depCount=$((depCount+1)) - - RUBY_PATH=`which ruby 2>/dev/null` - - if [[ -f $RUBY_PATH ]] - then - RUBY_VERSION=`ruby -e "print RUBY_VERSION"` - check "Ruby ${RUBY_VERSION}" - isRuby=true - depFound=$((depFound+1)) - else - uncheck "Ruby is missing 🔥" - isRuby=false - canContinue=false - errorMessages+="${red}==>${reset} ${b}Couldn't find Ruby:${reset} Brew requires Ruby which could not be found.\n" - errorMessages+=" Please install Ruby using these instructions ${u}${blue}https://www.ruby-lang.org/en/documentation/installation/${reset}.\n" - fi - } - - function find_brew() - { - BREW_PATH=`which brew 2>/dev/null` - - if [[ -f $BREW_PATH ]] - then - check "$($BREW_PATH -v)" - isBrew=true - depFound=$((depFound+1)) - else - uncheck "Homebrew is missing" - isBrew=false - - INSTALL_FILES+="${blue}${dim}==> Homebrew:${reset}\n" - INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/bin/brew\n" - INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/Library\n" - INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/share/man/man1/brew.1\n" - fi - - depCount=$((depCount+1)) - } - - function install_brew() - { - if [[ $isBrew == false ]] - then - head "Installing Homebrew" - - if [[ $isRuby == true ]] - then - ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - else - cd /usr - - if [[ ! -d $HOMEBREW_PREFIX ]] - then - sudo mkdir $HOMEBREW_PREFIX - sudo chmod g+rwx $HOMEBREW_PREFIX - fi - - if [[ ! -d $HOMEBREW_CACHE ]] - then - sudo mkdir $HOMEBREW_CACHE - sudo chmod g+rwx $HOMEBREW_CACHE - fi - - DEVELOPER_DIR=`/usr/bin/xcode-select -print-path 2>/dev/null` - - if [[ ! $(ls -A $DEVELOPER_DIR) || ! -f $DEVELOPER_DIR/usr/bin/git ]] - then - info "Installing the Command Line Tools (expect a GUI popup):" - sudo /usr/bin/xcode-select --install - - echo "Press any key when the installation has completed" - fi - - cd $HOMEBREW_PREFIX - - bash -o pipefail -c "curl -fsSL ${HOMEBREW_REPO}/tarball/master | tar xz -m --strip 1" - fi - - find_brew - echo - - if [[ $isBrew == false ]] - then - abortInstall "Couldn't install brew" - fi - fi - } - - function osx_installer() - { - osx_dependency_installer - - info "Adding ethcore repository" - exe brew tap ethcore/ethcore git@github.com:ethcore/homebrew-ethcore.git - echo - - info "Updating brew" - exe brew update - echo - - info "Installing parity" - if [[ $isEth == true ]] - then - exe brew reinstall parity - else - exe brew install parity - exe brew linkapps parity - fi - echo - } - - function osx_dependency_installer() - { - if [[ $isGit == false ]]; - then - echo "Installing Git" - fi - - if [[ $isRuby == false ]]; - then - echo "Installing Ruby" - fi - - if [[ $isBrew == false ]]; - then - install_brew - fi - } - - function get_linux_dependencies() - { - find_apt - } - - function find_apt() - { - APT_PATH=`which apt-get 2>/dev/null` - - if [[ -f $APT_PATH ]] - then - check "apt-get" - echo "$($APT_PATH -v)" - isApt=true - else - uncheck "apt-get is missing" - isApt=false - fi - } - function linux_rocksdb_installer() - { - oldpwd=`pwd` - cd /tmp - exe git clone --branch v4.1 --depth=1 https://github.com/facebook/rocksdb.git - cd rocksdb - exe make shared_lib - sudo cp -a librocksdb.so* /usr/lib - sudo ldconfig - cd /tmp - rm -rf /tmp/rocksdb - cd $oldpwd - } - - function linux_installer() - { - info "Installing git" - sudo apt-get install -q -y git - echo - - info "Installing rocksdb" - linux_rocksdb_installer - echo - - info "Installing multirust" - curl -sf https://raw.githubusercontent.com/brson/multirust/master/blastoff.sh | sudo sh -s -- --yes - sudo multirust update nightly - sudo multirust default nightly - echo - - info "Installing parity" - wget --quiet --output-document=- http://ethcore.io/download/parity.deb | dpkg --install - - } - - function install() - { - echo - head "Installing Parity build dependencies" - - if [[ $OS_TYPE == "osx" ]] - then - osx_installer - elif [[ $OS_TYPE == "linux" ]] - then - linux_installer - fi - } - - function verify_installation() - { - info "Verifying installation" - find_eth - - if [[ $isEth == false ]] - then - abortInstall - fi - } - - function abortInstall() - { - echo - error "Installation failed" - echo -e "$1" - echo - exit 0 - } - - function finish() - { -# echo -# successHeading "Installation successful!" -# head "Next steps" -# info "Run ${cyan}\`\`${reset} to get started.${reset}" -# echo - exit 0 - } - - # Check dependencies - head "Checking OS dependencies" - detectOS - - echo - head "In addition to the parity build dependencies, this script will install:" - echo "$INSTALL_FILES" - echo - - # Prompt user to continue or abort - wait_for_user "${b}OK,${reset} let's go!" - - # Install dependencies and eth - install - - # Check installation - verify_installation - - # Display goodby message - finish + ####### Init vars + + HOMEBREW_PREFIX=/usr/local + HOMEBREW_CACHE=/Library/Caches/Homebrew + HOMEBREW_REPO=https://github.com/Homebrew/homebrew + OSX_REQUIERED_VERSION="10.7.0" + + + declare OS_TYPE + declare OSX_VERSION + declare GIT_PATH + declare RUBY_PATH + declare BREW_PATH + declare INSTALL_FILES="" + + errorMessages="" + isOsVersion=false + isGit=false + isRuby=false + isBrew=false + isDocker=false + canContinue=true + depCount=0 + depFound=0 + + + + ####### Setup colors + + red=`tput setaf 1` + green=`tput setaf 2` + yellow=`tput setaf 3` + blue=`tput setaf 4` + magenta=`tput setaf 5` + cyan=`tput setaf 6` + white=`tput setaf 7` + b=`tput bold` + u=`tput sgr 0 1` + ul=`tput smul` + xl=`tput rmul` + stou=`tput smso` + xtou=`tput rmso` + dim=`tput dim` + reverse=`tput rev` + reset=`tput sgr0` + + + function head() { + echo "${blue}${b}==>${white} $1${reset}" + } + + function info() { + echo "${blue}${b}==>${reset} $1" + } + + function successHeading() { + echo "${green}${b}==> $1${reset}" + } + + function success() { + echo "${green}${b}==>${reset}${green} $1${reset}" + } + + function error() { + echo "${red}==> ${u}${b}${red}$1${reset}" + } + + function smallError() { + echo "${red}==>${reset} $1" + } + + function green() { + echo "${green}$1${reset}" + } + + function red() { + echo "${red}$1${reset}" + } + + function check() { + echo "${green}${bold} ✓${reset} $1${reset}" + } + + function uncheck() { + echo "${red}${bold} ✘${reset} $1${reset}" + } + + + + ####### Setup methods + + function wait_for_user() { + while : + do + read -p "${blue}==>${reset} $1 [Y/n] " imp + case $imp in + [yY] ) return 0; break ;; + '' ) echo; break ;; + [nN] ) return 1 ;; + * ) echo "Unrecognized option provided. Please provide either 'Y' or 'N'"; + esac + done + } + + function prompt_for_input() { + while : + do + read -p "$1 " imp + echo $imp + return + done + } + + + function detectOS() { + if [[ "$OSTYPE" == "linux-gnu" ]] + then + OS_TYPE="linux" + get_linux_dependencies + elif [[ "$OSTYPE" == "darwin"* ]] + then + OS_TYPE="osx" + get_osx_dependencies + else + OS_TYPE="win" + abortInstall "${red}==>${reset} ${b}OS not supported:${reset} parity one-liner currently support OS X and Linux.\nFor instructions on installing parity on other platforms please visit ${u}${blue}http://ethcore.io/${reset}" + fi + + echo + + if [[ $depCount == $depFound ]] + then + green "Found all dependencies ($depFound/$depCount)" + else + if [[ $canContinue == true ]] + then + red "Some dependencies are missing ($depFound/$depCount)" + elif [[ $canContinue == false && $depFound == 0 ]] + then + red "All dependencies are missing and cannot be auto-installed ($depFound/$depCount)" + abortInstall "$errorMessages"; + elif [[ $canContinue == false ]] + then + red "Some dependencies which cannot be auto-installed are missing ($depFound/$depCount)" + abortInstall "$errorMessages"; + fi + fi + } + + function get_osx_dependencies() + { + macos_version + find_git + find_ruby + find_brew + } + + function macos_version() + { + declare -a reqVersion + declare -a localVersion + + depCount=$((depCount+1)) + OSX_VERSION=`/usr/bin/sw_vers -productVersion 2>/dev/null` + + if [ -z "$OSX_VERSION" ] + then + uncheck "OS X version not supported 🔥" + isOsVersion=false + canContinue=false + else + IFS='.' read -a localVersion <<< "$OSX_VERSION" + IFS='.' read -a reqVersion <<< "$OSX_REQUIERED_VERSION" + + if (( ${reqVersion[0]} <= ${localVersion[0]} )) && (( ${reqVersion[1]} <= ${localVersion[1]} )) + then + check "OS X Version ${OSX_VERSION}" + isOsVersion=true + depFound=$((depFound+1)) + return + else + uncheck "OS X version not supported" + isOsVersion=false + canContinue=false + fi + fi + + errorMessages+="${red}==>${reset} ${b}Mac OS version too old:${reset} eth requires OS X version ${red}$OSX_REQUIERED_VERSION${reset} at least in order to run.\n" + errorMessages+=" Please update the OS and reload the install process.\n" + } + + function find_eth() + { + ETH_PATH=`which parity 2>/dev/null` + + if [[ -f $ETH_PATH ]] + then + check "Found parity: $ETH_PATH" + isEth=true + else + uncheck "parity is missing" + isEth=false + fi + } + + function find_git() + { + depCount=$((depCount+1)) + + GIT_PATH=`which git 2>/dev/null` + + if [[ -f $GIT_PATH ]] + then + check "$($GIT_PATH --version)" + isGit=true + depFound=$((depFound+1)) + else + uncheck "Git is missing" + isGit=false + fi + } + + function find_ruby() + { + depCount=$((depCount+1)) + + RUBY_PATH=`which ruby 2>/dev/null` + + if [[ -f $RUBY_PATH ]] + then + RUBY_VERSION=`ruby -e "print RUBY_VERSION"` + check "Ruby ${RUBY_VERSION}" + isRuby=true + depFound=$((depFound+1)) + else + uncheck "Ruby is missing 🔥" + isRuby=false + canContinue=false + errorMessages+="${red}==>${reset} ${b}Couldn't find Ruby:${reset} Brew requires Ruby which could not be found.\n" + errorMessages+=" Please install Ruby using these instructions ${u}${blue}https://www.ruby-lang.org/en/documentation/installation/${reset}.\n" + fi + } + + function find_brew() + { + BREW_PATH=`which brew 2>/dev/null` + + if [[ -f $BREW_PATH ]] + then + check "$($BREW_PATH -v)" + isBrew=true + depFound=$((depFound+1)) + else + uncheck "Homebrew is missing" + isBrew=false + + INSTALL_FILES+="${blue}${dim}==> Homebrew:${reset}\n" + INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/bin/brew\n" + INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/Library\n" + INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/share/man/man1/brew.1\n" + fi + + depCount=$((depCount+1)) + } + + function install_brew() + { + if [[ $isBrew == false ]] + then + head "Installing Homebrew" + + if [[ $isRuby == true ]] + then + ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + else + cd /usr + + if [[ ! -d $HOMEBREW_PREFIX ]] + then + sudo mkdir $HOMEBREW_PREFIX + sudo chmod g+rwx $HOMEBREW_PREFIX + fi + + if [[ ! -d $HOMEBREW_CACHE ]] + then + sudo mkdir $HOMEBREW_CACHE + sudo chmod g+rwx $HOMEBREW_CACHE + fi + + DEVELOPER_DIR=`/usr/bin/xcode-select -print-path 2>/dev/null` + + if [[ ! $(ls -A $DEVELOPER_DIR) || ! -f $DEVELOPER_DIR/usr/bin/git ]] + then + info "Installing the Command Line Tools (expect a GUI popup):" + sudo /usr/bin/xcode-select --install + + echo "Press any key when the installation has completed" + fi + + cd $HOMEBREW_PREFIX + + bash -o pipefail -c "curl -fsSL ${HOMEBREW_REPO}/tarball/master | tar xz -m --strip 1" + fi + + find_brew + echo + + if [[ $isBrew == false ]] + then + abortInstall "Couldn't install brew" + fi + fi + } + + function osx_installer() + { + osx_dependency_installer + + info "Adding ethcore repository" + brew tap ethcore/ethcore git@github.com:ethcore/homebrew-ethcore.git + echo + + info "Updating brew" + brew update + echo + + info "Installing parity" + if [[ $isEth == true ]] + then + brew reinstall parity + else + brew install parity + brew linkapps parity + fi + echo + } + + function osx_dependency_installer() + { + if [[ $isGit == false ]]; + then + echo "Installing Git" + fi + + if [[ $isRuby == false ]]; + then + echo "Installing Ruby" + fi + + if [[ $isBrew == false ]]; + then + install_brew + fi + } + + function get_linux_dependencies() + { + find_apt + find_docker + } + + function find_apt() + { + APT_PATH=`which apt-get 2>/dev/null` + + if [[ -f $APT_PATH ]] + then + check "apt-get" + echo "$($APT_PATH -v)" + isApt=true + else + uncheck "apt-get is missing" + isApt=false + fi + } + + function find_docker() + { + DOCKER_PATH=`which docker 2>/dev/null` + + if [[ -f $DOCKER_PATH ]] + then + check "docker" + echo "$($DOCKER_PATH -v)" + isDocker=true + else + isDocker=false + fi + } + function linux_rocksdb_installer() + { + sudo add-apt-repository -y ppa:giskou/librocksdb + sudo apt-get -f -y install + sudo apt-get update + sudo apt-get install -y librocksdb + } + + function linux_installer() + { + info "Installing dependencies" + sudo apt-get update && sudo apt-get install -q -y git curl g++ wget + echo + + info "Installing rocksdb" + linux_rocksdb_installer + echo + + info "Installing parity" + file=/tmp/parity.deb + + + wget $PARITY_DEB_URL -qO $file + sudo dpkg -i $file + rm $file + } + + function install_netstats() + { + echo "install netstats" + + if [[ $isDocker == false ]] + then + info "installing docker" + curl -sSL https://get.docker.com/ | sh + fi + + dir=$HOME/.netstats + + secret=$(prompt_for_input "Please enter the netstats secret:") + instance_name=$(prompt_for_input "Please enter your instance name:") + contact_details=$(prompt_for_input "Please enter your contact details (optional):") + + + mkdir -p $dir + cat > $dir/app.json << EOL +[ + { + "name" : "node-app", + "script" : "app.js", + "log_date_format" : "YYYY-MM-DD HH:mm Z", + "merge_logs" : false, + "watch" : false, + "max_restarts" : 10, + "exec_interpreter" : "node", + "exec_mode" : "fork_mode", + "env": + { + "NODE_ENV" : "production", + "RPC_HOST" : "localhost", + "RPC_PORT" : "8545", + "LISTENING_PORT" : "30303", + "INSTANCE_NAME" : "${instance_name}", + "CONTACT_DETAILS" : "${contact_details}", + "WS_SERVER" : "wss://rpc.ethstats.net", + "WS_SECRET" : "${secret}", + "VERBOSITY" : 2 + + } + } +] +EOL + + sudo docker rm --force netstats-client 2> /dev/null + sudo docker pull ethcore/netstats-client + sudo docker run -d --net=host --name netstats-client -v $dir/app.json:/home/ethnetintel/eth-net-intelligence-api/app.json ethcore/netstats-client + } + + function install() + { + echo + head "Installing Parity build dependencies" + + if [[ $OS_TYPE == "osx" ]] + then + osx_installer + elif [[ $OS_TYPE == "linux" ]] + then + linux_installer + fi + } + + function verify_installation() + { + info "Verifying installation" + find_eth + + if [[ $isEth == false ]] + then + abortInstall + fi + } + + function abortInstall() + { + echo + error "Installation failed" + echo -e "$1" + echo + exit 0 + } + + function finish() + { + echo + successHeading "Installation successful!" + # head "Next steps" + # info "Run ${cyan}\`\`${reset} to get started.${reset}" + echo + exit 0 + } + + # Check dependencies + head "Checking OS dependencies" + detectOS + + echo + head "In addition to the parity build dependencies, this script will install:" + echo "$INSTALL_FILES" + echo + + # Prompt user to continue or abort + if wait_for_user "${b}OK,${reset} let's go!" + then + echo "Installing..." + else + abortInstall "${red}==>${reset} Process stopped by user. To resume the install run the one-liner command again." + fi + + # Install dependencies and eth + install + + if [[ $OS_TYPE == "linux" ]] + then + echo "Netstats:" + head "Would you like to install and configure a netstats client?" + if wait_for_user "${b}OK,${reset} let's go!" + then + install_netstats + fi + fi + + # Check installation + verify_installation + + # Display goodby message + finish } run_installer From 79409a175ee7deec3638e49cedc603771ae1cea0 Mon Sep 17 00:00:00 2001 From: KKudryavtsev Date: Thu, 4 Feb 2016 15:53:32 +0000 Subject: [PATCH 02/22] tabify --- install-parity.sh | 1058 ++++++++++++++++++++++----------------------- 1 file changed, 529 insertions(+), 529 deletions(-) diff --git a/install-parity.sh b/install-parity.sh index 0ce943f9b..58a7c6884 100755 --- a/install-parity.sh +++ b/install-parity.sh @@ -6,552 +6,552 @@ PARITY_DEB_URL=https://github.com/jesuscript/scripts/raw/master/parity.deb function run_installer() { - ####### Init vars - - HOMEBREW_PREFIX=/usr/local - HOMEBREW_CACHE=/Library/Caches/Homebrew - HOMEBREW_REPO=https://github.com/Homebrew/homebrew - OSX_REQUIERED_VERSION="10.7.0" - - - declare OS_TYPE - declare OSX_VERSION - declare GIT_PATH - declare RUBY_PATH - declare BREW_PATH - declare INSTALL_FILES="" - - errorMessages="" - isOsVersion=false - isGit=false - isRuby=false - isBrew=false - isDocker=false - canContinue=true - depCount=0 - depFound=0 - - - - ####### Setup colors - - red=`tput setaf 1` - green=`tput setaf 2` - yellow=`tput setaf 3` - blue=`tput setaf 4` - magenta=`tput setaf 5` - cyan=`tput setaf 6` - white=`tput setaf 7` - b=`tput bold` - u=`tput sgr 0 1` - ul=`tput smul` - xl=`tput rmul` - stou=`tput smso` - xtou=`tput rmso` - dim=`tput dim` - reverse=`tput rev` - reset=`tput sgr0` - - - function head() { - echo "${blue}${b}==>${white} $1${reset}" - } - - function info() { - echo "${blue}${b}==>${reset} $1" - } - - function successHeading() { - echo "${green}${b}==> $1${reset}" - } - - function success() { - echo "${green}${b}==>${reset}${green} $1${reset}" - } - - function error() { - echo "${red}==> ${u}${b}${red}$1${reset}" - } - - function smallError() { - echo "${red}==>${reset} $1" - } - - function green() { - echo "${green}$1${reset}" - } - - function red() { - echo "${red}$1${reset}" - } - - function check() { - echo "${green}${bold} ✓${reset} $1${reset}" - } - - function uncheck() { - echo "${red}${bold} ✘${reset} $1${reset}" - } - - - - ####### Setup methods - - function wait_for_user() { - while : - do - read -p "${blue}==>${reset} $1 [Y/n] " imp - case $imp in - [yY] ) return 0; break ;; - '' ) echo; break ;; - [nN] ) return 1 ;; - * ) echo "Unrecognized option provided. Please provide either 'Y' or 'N'"; - esac - done - } - - function prompt_for_input() { - while : - do - read -p "$1 " imp - echo $imp - return - done - } - - - function detectOS() { - if [[ "$OSTYPE" == "linux-gnu" ]] - then - OS_TYPE="linux" - get_linux_dependencies - elif [[ "$OSTYPE" == "darwin"* ]] - then - OS_TYPE="osx" - get_osx_dependencies - else - OS_TYPE="win" - abortInstall "${red}==>${reset} ${b}OS not supported:${reset} parity one-liner currently support OS X and Linux.\nFor instructions on installing parity on other platforms please visit ${u}${blue}http://ethcore.io/${reset}" - fi - - echo - - if [[ $depCount == $depFound ]] - then - green "Found all dependencies ($depFound/$depCount)" - else - if [[ $canContinue == true ]] - then - red "Some dependencies are missing ($depFound/$depCount)" - elif [[ $canContinue == false && $depFound == 0 ]] - then - red "All dependencies are missing and cannot be auto-installed ($depFound/$depCount)" - abortInstall "$errorMessages"; - elif [[ $canContinue == false ]] - then - red "Some dependencies which cannot be auto-installed are missing ($depFound/$depCount)" - abortInstall "$errorMessages"; - fi - fi - } - - function get_osx_dependencies() - { - macos_version - find_git - find_ruby - find_brew - } - - function macos_version() - { - declare -a reqVersion - declare -a localVersion - - depCount=$((depCount+1)) - OSX_VERSION=`/usr/bin/sw_vers -productVersion 2>/dev/null` - - if [ -z "$OSX_VERSION" ] - then - uncheck "OS X version not supported 🔥" - isOsVersion=false - canContinue=false - else - IFS='.' read -a localVersion <<< "$OSX_VERSION" - IFS='.' read -a reqVersion <<< "$OSX_REQUIERED_VERSION" - - if (( ${reqVersion[0]} <= ${localVersion[0]} )) && (( ${reqVersion[1]} <= ${localVersion[1]} )) - then - check "OS X Version ${OSX_VERSION}" - isOsVersion=true - depFound=$((depFound+1)) - return - else - uncheck "OS X version not supported" - isOsVersion=false - canContinue=false - fi - fi - - errorMessages+="${red}==>${reset} ${b}Mac OS version too old:${reset} eth requires OS X version ${red}$OSX_REQUIERED_VERSION${reset} at least in order to run.\n" - errorMessages+=" Please update the OS and reload the install process.\n" - } - - function find_eth() - { - ETH_PATH=`which parity 2>/dev/null` - - if [[ -f $ETH_PATH ]] - then - check "Found parity: $ETH_PATH" - isEth=true - else - uncheck "parity is missing" - isEth=false - fi - } - - function find_git() - { - depCount=$((depCount+1)) - - GIT_PATH=`which git 2>/dev/null` - - if [[ -f $GIT_PATH ]] - then - check "$($GIT_PATH --version)" - isGit=true - depFound=$((depFound+1)) - else - uncheck "Git is missing" - isGit=false - fi - } - - function find_ruby() - { - depCount=$((depCount+1)) - - RUBY_PATH=`which ruby 2>/dev/null` - - if [[ -f $RUBY_PATH ]] - then - RUBY_VERSION=`ruby -e "print RUBY_VERSION"` - check "Ruby ${RUBY_VERSION}" - isRuby=true - depFound=$((depFound+1)) - else - uncheck "Ruby is missing 🔥" - isRuby=false - canContinue=false - errorMessages+="${red}==>${reset} ${b}Couldn't find Ruby:${reset} Brew requires Ruby which could not be found.\n" - errorMessages+=" Please install Ruby using these instructions ${u}${blue}https://www.ruby-lang.org/en/documentation/installation/${reset}.\n" - fi - } - - function find_brew() - { - BREW_PATH=`which brew 2>/dev/null` - - if [[ -f $BREW_PATH ]] - then - check "$($BREW_PATH -v)" - isBrew=true - depFound=$((depFound+1)) - else - uncheck "Homebrew is missing" - isBrew=false - - INSTALL_FILES+="${blue}${dim}==> Homebrew:${reset}\n" - INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/bin/brew\n" - INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/Library\n" - INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/share/man/man1/brew.1\n" - fi - - depCount=$((depCount+1)) - } - - function install_brew() - { - if [[ $isBrew == false ]] - then - head "Installing Homebrew" - - if [[ $isRuby == true ]] - then - ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - else - cd /usr - - if [[ ! -d $HOMEBREW_PREFIX ]] - then - sudo mkdir $HOMEBREW_PREFIX - sudo chmod g+rwx $HOMEBREW_PREFIX - fi - - if [[ ! -d $HOMEBREW_CACHE ]] - then - sudo mkdir $HOMEBREW_CACHE - sudo chmod g+rwx $HOMEBREW_CACHE - fi - - DEVELOPER_DIR=`/usr/bin/xcode-select -print-path 2>/dev/null` - - if [[ ! $(ls -A $DEVELOPER_DIR) || ! -f $DEVELOPER_DIR/usr/bin/git ]] - then - info "Installing the Command Line Tools (expect a GUI popup):" - sudo /usr/bin/xcode-select --install - - echo "Press any key when the installation has completed" - fi - - cd $HOMEBREW_PREFIX - - bash -o pipefail -c "curl -fsSL ${HOMEBREW_REPO}/tarball/master | tar xz -m --strip 1" - fi - - find_brew - echo - - if [[ $isBrew == false ]] - then - abortInstall "Couldn't install brew" - fi - fi - } - - function osx_installer() - { - osx_dependency_installer - - info "Adding ethcore repository" - brew tap ethcore/ethcore git@github.com:ethcore/homebrew-ethcore.git - echo - - info "Updating brew" - brew update - echo - - info "Installing parity" - if [[ $isEth == true ]] - then - brew reinstall parity - else - brew install parity - brew linkapps parity - fi - echo - } - - function osx_dependency_installer() - { - if [[ $isGit == false ]]; - then - echo "Installing Git" - fi - - if [[ $isRuby == false ]]; - then - echo "Installing Ruby" - fi - - if [[ $isBrew == false ]]; - then - install_brew - fi - } - - function get_linux_dependencies() - { - find_apt - find_docker - } - - function find_apt() - { - APT_PATH=`which apt-get 2>/dev/null` - - if [[ -f $APT_PATH ]] - then - check "apt-get" - echo "$($APT_PATH -v)" - isApt=true - else - uncheck "apt-get is missing" - isApt=false - fi - } - - function find_docker() - { - DOCKER_PATH=`which docker 2>/dev/null` - - if [[ -f $DOCKER_PATH ]] - then - check "docker" - echo "$($DOCKER_PATH -v)" - isDocker=true - else - isDocker=false - fi - } - function linux_rocksdb_installer() - { - sudo add-apt-repository -y ppa:giskou/librocksdb - sudo apt-get -f -y install - sudo apt-get update - sudo apt-get install -y librocksdb - } - - function linux_installer() - { - info "Installing dependencies" - sudo apt-get update && sudo apt-get install -q -y git curl g++ wget - echo - - info "Installing rocksdb" - linux_rocksdb_installer - echo - - info "Installing parity" - file=/tmp/parity.deb - - - wget $PARITY_DEB_URL -qO $file - sudo dpkg -i $file - rm $file - } - - function install_netstats() - { - echo "install netstats" - - if [[ $isDocker == false ]] - then - info "installing docker" - curl -sSL https://get.docker.com/ | sh - fi - - dir=$HOME/.netstats - - secret=$(prompt_for_input "Please enter the netstats secret:") - instance_name=$(prompt_for_input "Please enter your instance name:") - contact_details=$(prompt_for_input "Please enter your contact details (optional):") - - - mkdir -p $dir - cat > $dir/app.json << EOL + ####### Init vars + + HOMEBREW_PREFIX=/usr/local + HOMEBREW_CACHE=/Library/Caches/Homebrew + HOMEBREW_REPO=https://github.com/Homebrew/homebrew + OSX_REQUIERED_VERSION="10.7.0" + + + declare OS_TYPE + declare OSX_VERSION + declare GIT_PATH + declare RUBY_PATH + declare BREW_PATH + declare INSTALL_FILES="" + + errorMessages="" + isOsVersion=false + isGit=false + isRuby=false + isBrew=false + isDocker=false + canContinue=true + depCount=0 + depFound=0 + + + + ####### Setup colors + + red=`tput setaf 1` + green=`tput setaf 2` + yellow=`tput setaf 3` + blue=`tput setaf 4` + magenta=`tput setaf 5` + cyan=`tput setaf 6` + white=`tput setaf 7` + b=`tput bold` + u=`tput sgr 0 1` + ul=`tput smul` + xl=`tput rmul` + stou=`tput smso` + xtou=`tput rmso` + dim=`tput dim` + reverse=`tput rev` + reset=`tput sgr0` + + + function head() { + echo "${blue}${b}==>${white} $1${reset}" + } + + function info() { + echo "${blue}${b}==>${reset} $1" + } + + function successHeading() { + echo "${green}${b}==> $1${reset}" + } + + function success() { + echo "${green}${b}==>${reset}${green} $1${reset}" + } + + function error() { + echo "${red}==> ${u}${b}${red}$1${reset}" + } + + function smallError() { + echo "${red}==>${reset} $1" + } + + function green() { + echo "${green}$1${reset}" + } + + function red() { + echo "${red}$1${reset}" + } + + function check() { + echo "${green}${bold} ✓${reset} $1${reset}" + } + + function uncheck() { + echo "${red}${bold} ✘${reset} $1${reset}" + } + + + + ####### Setup methods + + function wait_for_user() { + while : + do + read -p "${blue}==>${reset} $1 [Y/n] " imp + case $imp in + [yY] ) return 0; break ;; + '' ) echo; break ;; + [nN] ) return 1 ;; + * ) echo "Unrecognized option provided. Please provide either 'Y' or 'N'"; + esac + done + } + + function prompt_for_input() { + while : + do + read -p "$1 " imp + echo $imp + return + done + } + + + function detectOS() { + if [[ "$OSTYPE" == "linux-gnu" ]] + then + OS_TYPE="linux" + get_linux_dependencies + elif [[ "$OSTYPE" == "darwin"* ]] + then + OS_TYPE="osx" + get_osx_dependencies + else + OS_TYPE="win" + abortInstall "${red}==>${reset} ${b}OS not supported:${reset} parity one-liner currently support OS X and Linux.\nFor instructions on installing parity on other platforms please visit ${u}${blue}http://ethcore.io/${reset}" + fi + + echo + + if [[ $depCount == $depFound ]] + then + green "Found all dependencies ($depFound/$depCount)" + else + if [[ $canContinue == true ]] + then + red "Some dependencies are missing ($depFound/$depCount)" + elif [[ $canContinue == false && $depFound == 0 ]] + then + red "All dependencies are missing and cannot be auto-installed ($depFound/$depCount)" + abortInstall "$errorMessages"; + elif [[ $canContinue == false ]] + then + red "Some dependencies which cannot be auto-installed are missing ($depFound/$depCount)" + abortInstall "$errorMessages"; + fi + fi + } + + function get_osx_dependencies() + { + macos_version + find_git + find_ruby + find_brew + } + + function macos_version() + { + declare -a reqVersion + declare -a localVersion + + depCount=$((depCount+1)) + OSX_VERSION=`/usr/bin/sw_vers -productVersion 2>/dev/null` + + if [ -z "$OSX_VERSION" ] + then + uncheck "OS X version not supported 🔥" + isOsVersion=false + canContinue=false + else + IFS='.' read -a localVersion <<< "$OSX_VERSION" + IFS='.' read -a reqVersion <<< "$OSX_REQUIERED_VERSION" + + if (( ${reqVersion[0]} <= ${localVersion[0]} )) && (( ${reqVersion[1]} <= ${localVersion[1]} )) + then + check "OS X Version ${OSX_VERSION}" + isOsVersion=true + depFound=$((depFound+1)) + return + else + uncheck "OS X version not supported" + isOsVersion=false + canContinue=false + fi + fi + + errorMessages+="${red}==>${reset} ${b}Mac OS version too old:${reset} eth requires OS X version ${red}$OSX_REQUIERED_VERSION${reset} at least in order to run.\n" + errorMessages+=" Please update the OS and reload the install process.\n" + } + + function find_eth() + { + ETH_PATH=`which parity 2>/dev/null` + + if [[ -f $ETH_PATH ]] + then + check "Found parity: $ETH_PATH" + isEth=true + else + uncheck "parity is missing" + isEth=false + fi + } + + function find_git() + { + depCount=$((depCount+1)) + + GIT_PATH=`which git 2>/dev/null` + + if [[ -f $GIT_PATH ]] + then + check "$($GIT_PATH --version)" + isGit=true + depFound=$((depFound+1)) + else + uncheck "Git is missing" + isGit=false + fi + } + + function find_ruby() + { + depCount=$((depCount+1)) + + RUBY_PATH=`which ruby 2>/dev/null` + + if [[ -f $RUBY_PATH ]] + then + RUBY_VERSION=`ruby -e "print RUBY_VERSION"` + check "Ruby ${RUBY_VERSION}" + isRuby=true + depFound=$((depFound+1)) + else + uncheck "Ruby is missing 🔥" + isRuby=false + canContinue=false + errorMessages+="${red}==>${reset} ${b}Couldn't find Ruby:${reset} Brew requires Ruby which could not be found.\n" + errorMessages+=" Please install Ruby using these instructions ${u}${blue}https://www.ruby-lang.org/en/documentation/installation/${reset}.\n" + fi + } + + function find_brew() + { + BREW_PATH=`which brew 2>/dev/null` + + if [[ -f $BREW_PATH ]] + then + check "$($BREW_PATH -v)" + isBrew=true + depFound=$((depFound+1)) + else + uncheck "Homebrew is missing" + isBrew=false + + INSTALL_FILES+="${blue}${dim}==> Homebrew:${reset}\n" + INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/bin/brew\n" + INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/Library\n" + INSTALL_FILES+=" ${blue}${dim}➜${reset} $HOMEBREW_PREFIX/share/man/man1/brew.1\n" + fi + + depCount=$((depCount+1)) + } + + function install_brew() + { + if [[ $isBrew == false ]] + then + head "Installing Homebrew" + + if [[ $isRuby == true ]] + then + ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + else + cd /usr + + if [[ ! -d $HOMEBREW_PREFIX ]] + then + sudo mkdir $HOMEBREW_PREFIX + sudo chmod g+rwx $HOMEBREW_PREFIX + fi + + if [[ ! -d $HOMEBREW_CACHE ]] + then + sudo mkdir $HOMEBREW_CACHE + sudo chmod g+rwx $HOMEBREW_CACHE + fi + + DEVELOPER_DIR=`/usr/bin/xcode-select -print-path 2>/dev/null` + + if [[ ! $(ls -A $DEVELOPER_DIR) || ! -f $DEVELOPER_DIR/usr/bin/git ]] + then + info "Installing the Command Line Tools (expect a GUI popup):" + sudo /usr/bin/xcode-select --install + + echo "Press any key when the installation has completed" + fi + + cd $HOMEBREW_PREFIX + + bash -o pipefail -c "curl -fsSL ${HOMEBREW_REPO}/tarball/master | tar xz -m --strip 1" + fi + + find_brew + echo + + if [[ $isBrew == false ]] + then + abortInstall "Couldn't install brew" + fi + fi + } + + function osx_installer() + { + osx_dependency_installer + + info "Adding ethcore repository" + brew tap ethcore/ethcore git@github.com:ethcore/homebrew-ethcore.git + echo + + info "Updating brew" + brew update + echo + + info "Installing parity" + if [[ $isEth == true ]] + then + brew reinstall parity + else + brew install parity + brew linkapps parity + fi + echo + } + + function osx_dependency_installer() + { + if [[ $isGit == false ]]; + then + echo "Installing Git" + fi + + if [[ $isRuby == false ]]; + then + echo "Installing Ruby" + fi + + if [[ $isBrew == false ]]; + then + install_brew + fi + } + + function get_linux_dependencies() + { + find_apt + find_docker + } + + function find_apt() + { + APT_PATH=`which apt-get 2>/dev/null` + + if [[ -f $APT_PATH ]] + then + check "apt-get" + echo "$($APT_PATH -v)" + isApt=true + else + uncheck "apt-get is missing" + isApt=false + fi + } + + function find_docker() + { + DOCKER_PATH=`which docker 2>/dev/null` + + if [[ -f $DOCKER_PATH ]] + then + check "docker" + echo "$($DOCKER_PATH -v)" + isDocker=true + else + isDocker=false + fi + } + function linux_rocksdb_installer() + { + sudo add-apt-repository -y ppa:giskou/librocksdb + sudo apt-get -f -y install + sudo apt-get update + sudo apt-get install -y librocksdb + } + + function linux_installer() + { + info "Installing dependencies" + sudo apt-get update && sudo apt-get install -q -y git curl g++ wget + echo + + info "Installing rocksdb" + linux_rocksdb_installer + echo + + info "Installing parity" + file=/tmp/parity.deb + + + wget $PARITY_DEB_URL -qO $file + sudo dpkg -i $file + rm $file + } + + function install_netstats() + { + echo "install netstats" + + if [[ $isDocker == false ]] + then + info "installing docker" + curl -sSL https://get.docker.com/ | sh + fi + + dir=$HOME/.netstats + + secret=$(prompt_for_input "Please enter the netstats secret:") + instance_name=$(prompt_for_input "Please enter your instance name:") + contact_details=$(prompt_for_input "Please enter your contact details (optional):") + + + mkdir -p $dir + cat > $dir/app.json << EOL [ - { - "name" : "node-app", - "script" : "app.js", - "log_date_format" : "YYYY-MM-DD HH:mm Z", - "merge_logs" : false, - "watch" : false, - "max_restarts" : 10, - "exec_interpreter" : "node", - "exec_mode" : "fork_mode", - "env": - { - "NODE_ENV" : "production", - "RPC_HOST" : "localhost", - "RPC_PORT" : "8545", - "LISTENING_PORT" : "30303", - "INSTANCE_NAME" : "${instance_name}", - "CONTACT_DETAILS" : "${contact_details}", - "WS_SERVER" : "wss://rpc.ethstats.net", - "WS_SECRET" : "${secret}", - "VERBOSITY" : 2 - - } - } + { + "name" : "node-app", + "script" : "app.js", + "log_date_format" : "YYYY-MM-DD HH:mm Z", + "merge_logs" : false, + "watch" : false, + "max_restarts" : 10, + "exec_interpreter" : "node", + "exec_mode" : "fork_mode", + "env": + { + "NODE_ENV" : "production", + "RPC_HOST" : "localhost", + "RPC_PORT" : "8545", + "LISTENING_PORT" : "30303", + "INSTANCE_NAME" : "${instance_name}", + "CONTACT_DETAILS" : "${contact_details}", + "WS_SERVER" : "wss://rpc.ethstats.net", + "WS_SECRET" : "${secret}", + "VERBOSITY" : 2 + + } + } ] EOL - sudo docker rm --force netstats-client 2> /dev/null - sudo docker pull ethcore/netstats-client - sudo docker run -d --net=host --name netstats-client -v $dir/app.json:/home/ethnetintel/eth-net-intelligence-api/app.json ethcore/netstats-client - } + sudo docker rm --force netstats-client 2> /dev/null + sudo docker pull ethcore/netstats-client + sudo docker run -d --net=host --name netstats-client -v $dir/app.json:/home/ethnetintel/eth-net-intelligence-api/app.json ethcore/netstats-client + } - function install() - { - echo - head "Installing Parity build dependencies" + function install() + { + echo + head "Installing Parity build dependencies" - if [[ $OS_TYPE == "osx" ]] - then - osx_installer - elif [[ $OS_TYPE == "linux" ]] - then - linux_installer - fi - } + if [[ $OS_TYPE == "osx" ]] + then + osx_installer + elif [[ $OS_TYPE == "linux" ]] + then + linux_installer + fi + } - function verify_installation() - { - info "Verifying installation" - find_eth + function verify_installation() + { + info "Verifying installation" + find_eth - if [[ $isEth == false ]] - then - abortInstall - fi - } + if [[ $isEth == false ]] + then + abortInstall + fi + } - function abortInstall() - { - echo - error "Installation failed" - echo -e "$1" - echo - exit 0 - } + function abortInstall() + { + echo + error "Installation failed" + echo -e "$1" + echo + exit 0 + } - function finish() - { - echo - successHeading "Installation successful!" - # head "Next steps" - # info "Run ${cyan}\`\`${reset} to get started.${reset}" - echo - exit 0 - } + function finish() + { + echo + successHeading "Installation successful!" + # head "Next steps" + # info "Run ${cyan}\`\`${reset} to get started.${reset}" + echo + exit 0 + } - # Check dependencies - head "Checking OS dependencies" - detectOS + # Check dependencies + head "Checking OS dependencies" + detectOS - echo - head "In addition to the parity build dependencies, this script will install:" - echo "$INSTALL_FILES" - echo + echo + head "In addition to the parity build dependencies, this script will install:" + echo "$INSTALL_FILES" + echo - # Prompt user to continue or abort - if wait_for_user "${b}OK,${reset} let's go!" - then - echo "Installing..." - else - abortInstall "${red}==>${reset} Process stopped by user. To resume the install run the one-liner command again." - fi + # Prompt user to continue or abort + if wait_for_user "${b}OK,${reset} let's go!" + then + echo "Installing..." + else + abortInstall "${red}==>${reset} Process stopped by user. To resume the install run the one-liner command again." + fi - # Install dependencies and eth - install + # Install dependencies and eth + install - if [[ $OS_TYPE == "linux" ]] - then - echo "Netstats:" - head "Would you like to install and configure a netstats client?" - if wait_for_user "${b}OK,${reset} let's go!" - then - install_netstats - fi - fi + if [[ $OS_TYPE == "linux" ]] + then + echo "Netstats:" + head "Would you like to install and configure a netstats client?" + if wait_for_user "${b}OK,${reset} let's go!" + then + install_netstats + fi + fi - # Check installation - verify_installation + # Check installation + verify_installation - # Display goodby message - finish + # Display goodby message + finish } run_installer From f78b82ff0781c704686965a004fb97ddf4822a1e Mon Sep 17 00:00:00 2001 From: KKudryavtsev Date: Thu, 4 Feb 2016 15:57:26 +0000 Subject: [PATCH 03/22] replaced brew tap link with https; deb url from main repo --- install-parity.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install-parity.sh b/install-parity.sh index 58a7c6884..3217cc284 100755 --- a/install-parity.sh +++ b/install-parity.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash -#TODO: replace with the main repo url -PARITY_DEB_URL=https://github.com/jesuscript/scripts/raw/master/parity.deb + +PARITY_DEB_URL=https://github.com/ethcore/parity/releases/download/beta-0.9/parity_0.9.0-0_amd64.deb function run_installer() { @@ -325,7 +325,7 @@ function run_installer() osx_dependency_installer info "Adding ethcore repository" - brew tap ethcore/ethcore git@github.com:ethcore/homebrew-ethcore.git + brew tap ethcore/ethcore https://github.com/ethcore/homebrew-ethcore.git echo info "Updating brew" From de6cc186601e0c43ccdf7b1e05da1e574ec6347d Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 4 Feb 2016 18:43:05 +0100 Subject: [PATCH 04/22] get-deps no longer installs rust/multirust/rocksdb if it doesn't have to. Builds rocksdb only if necessary. --- install-deps.sh | 148 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 119 insertions(+), 29 deletions(-) diff --git a/install-deps.sh b/install-deps.sh index 4eedab25e..6ae6ed2e5 100755 --- a/install-deps.sh +++ b/install-deps.sh @@ -347,8 +347,31 @@ function run_installer() fi } + function linux_version() + { + source /etc/lsb-release + + if [[ $DISTRIB_ID == "Ubuntu" ]]; then + if [[ $DISTRIB_RELEASE == "14.04" ]]; then + check "Ubuntu-14.04" + isUbuntu1404=true + else + check "Ubuntu, but not 14.04" + isUbuntu1404=false + fi + else + check "Ubuntu not found" + isUbuntu1404=false + fi + } + function get_linux_dependencies() { + linux_version + + find_multirust + find_rocksdb + find_curl find_git find_make @@ -357,6 +380,47 @@ function run_installer() find_apt } + function find_rocksdb() + { + depCount=$((depCount+1)) + if [[ $(ldconfig -v 2>/dev/null | grep rocksdb | wc -l) == 1 ]]; then + depFound=$((depFound+1)) + check "apt-get" + echo "$($APT_PATH -v)" + isRocksDB=true + else + uncheck "librocksdb is missing" + isRocksDB=false + INSTALL_FILES+="${blue}${dim}==> librocksdb:${reset}\n" + fi + } + + function find_multirust() + { + depCount=$((depCount+2)) + MULTIRUST_PATH=`which multirust 2>/dev/null` + if [[ -f $MULTIRUST_PATH ]]; then + depFound=$((depFound+1)) + check "multirust" + isMultirust=true + if [[ $(multirust show-default 2>/dev/null | grep nightly | wc -l) == 4 ]]; then + depFound=$((depFound+1)) + check "rust nightly" + isMultirustNightly=true + else + uncheck "rust is not nightly" + isMultirustNightly=false + INSTALL_FILES+="${blue}${dim}==> multirust -> rust nightly:${reset}\n" + fi + else + uncheck "multirust is missing" + uncheck "rust nightly is missing" + isMultirust=false + isMultirustNightly=false + INSTALL_FILES+="${blue}${dim}==> multirust:${reset}\n" + fi + } + function find_apt() { depCount=$((depCount+1)) @@ -449,25 +513,37 @@ function run_installer() fi } + function ubuntu1404_rocksdb_installer() + { + sudo add-apt-repository -y ppa:giskou/librocksdb + sudo apt-get -f -y install + sudo apt-get update -qq + sudo apt-get install -y librocksdb + } + function linux_rocksdb_installer() { - oldpwd=`pwd` - cd /tmp - exe git clone --branch v4.1 --depth=1 https://github.com/facebook/rocksdb.git - cd rocksdb - exe make shared_lib - sudo cp -a librocksdb.so* /usr/lib - sudo ldconfig - cd /tmp - rm -rf /tmp/rocksdb - cd $oldpwd + if [[ $isUbuntu1404 ]]; then + ubuntu1404_rocksdb_installer + else + oldpwd=`pwd` + cd /tmp + exe git clone --branch v4.1 --depth=1 https://github.com/facebook/rocksdb.git + cd rocksdb + exe make shared_lib + sudo cp -a librocksdb.so* /usr/lib + sudo ldconfig + cd /tmp + rm -rf /tmp/rocksdb + cd $oldpwd + fi } function linux_installer() { if [[ $isGCC == false || $isGit == false || $isMake == false || $isCurl == false ]]; then info "Installing build dependencies..." - sudo apt-get update + sudo apt-get update -qq if [[ $isGit == false ]]; then sudo apt-get install -q -y git fi @@ -483,15 +559,24 @@ function run_installer() echo fi - info "Installing rocksdb..." - linux_rocksdb_installer - echo + if [[ $isRocksDB == false ]]; then + info "Installing rocksdb..." + linux_rocksdb_installer + echo + fi - info "Installing multirust..." - curl -sf https://raw.githubusercontent.com/brson/multirust/master/blastoff.sh | sudo sh -s -- --yes - sudo multirust update nightly - sudo multirust default nightly - echo + if [[ $isMultirust == false ]]; then + info "Installing multirust..." + curl -sf https://raw.githubusercontent.com/brson/multirust/master/blastoff.sh | sudo sh -s -- --yes + echo + fi + + if [[ $isMultirustNightly == false ]]; then + info "Installing rust nightly..." + sudo multirust update nightly + sudo multirust default nightly + echo + fi } function install() @@ -511,12 +596,19 @@ function run_installer() function verify_installation() { info "Verifying installation" -# find_eth -# if [[ $isEth == false ]] -# then -# abortInstall -# fi + if [[ $OS_TYPE == "linux" ]]; then + find_curl + find_git + find_make + find_gcc + find_rocksdb + find_multirust + + if [[ $isCurl == false || $isGit == false || $isMake == false || $isGCC == false || $isRocksDB == false || $isMultirustNightly == false ]]; then + abortInstall + fi + fi } function abortInstall() @@ -530,11 +622,9 @@ function run_installer() function finish() { -# echo -# successHeading "Installation successful!" -# head "Next steps" -# info "Run ${cyan}\`\`${reset} to get started.${reset}" -# echo + echo + successHeading "Installation successful!" + echo exit 0 } From 5202185bf86a565173e841d86131d7518ebdaba7 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 4 Feb 2016 18:52:33 +0100 Subject: [PATCH 05/22] Fix setup on docker 14.04 instances. --- install-deps.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install-deps.sh b/install-deps.sh index 6ae6ed2e5..77157c3e1 100755 --- a/install-deps.sh +++ b/install-deps.sh @@ -386,7 +386,6 @@ function run_installer() if [[ $(ldconfig -v 2>/dev/null | grep rocksdb | wc -l) == 1 ]]; then depFound=$((depFound+1)) check "apt-get" - echo "$($APT_PATH -v)" isRocksDB=true else uncheck "librocksdb is missing" @@ -431,7 +430,6 @@ function run_installer() then depFound=$((depFound+1)) check "apt-get" - echo "$($APT_PATH -v)" isApt=true else uncheck "apt-get is missing" @@ -499,7 +497,7 @@ function run_installer() function find_curl() { depCount=$((depCount+1)) - MAKE_PATH=`which curl 2>/dev/null` + CURL_PATH=`which curl 2>/dev/null` if [[ -f $CURL_PATH ]] then @@ -515,10 +513,12 @@ function run_installer() function ubuntu1404_rocksdb_installer() { - sudo add-apt-repository -y ppa:giskou/librocksdb + sudo apt-get update -qq + sudo apt-get install -qq -y software-properties-common + sudo apt-add-repository -y ppa:giskou/librocksdb sudo apt-get -f -y install sudo apt-get update -qq - sudo apt-get install -y librocksdb + sudo apt-get install -qq -y librocksdb } function linux_rocksdb_installer() From fcf9366eb89bf9ef10acd50d37f8f1060029099a Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 4 Feb 2016 21:07:52 +0300 Subject: [PATCH 06/22] local coverage for sync --- sync/cov.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 sync/cov.sh diff --git a/sync/cov.sh b/sync/cov.sh new file mode 100755 index 000000000..2f8c594ff --- /dev/null +++ b/sync/cov.sh @@ -0,0 +1,9 @@ +if ! type kcov > /dev/null; then + echo "Install kcov first (details inside this file). Aborting." + exit 1 +fi + +cargo test --no-run || exit $? +mkdir -p target/coverage +kcov --exclude-pattern ~/.multirust,rocksdb,secp256k1 --include-pattern src --verify target/coverage target/debug/ethsync* +xdg-open target/coverage/index.html From e27081fe668b3ad5f2c8274789d91cd08bf7ba2f Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 4 Feb 2016 21:09:32 +0300 Subject: [PATCH 07/22] filter out util/core --- sync/cov.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync/cov.sh b/sync/cov.sh index 2f8c594ff..c19dd5689 100755 --- a/sync/cov.sh +++ b/sync/cov.sh @@ -5,5 +5,5 @@ fi cargo test --no-run || exit $? mkdir -p target/coverage -kcov --exclude-pattern ~/.multirust,rocksdb,secp256k1 --include-pattern src --verify target/coverage target/debug/ethsync* +kcov --exclude-pattern ~/.multirust,rocksdb,secp256k1 --include-pattern sync/src --verify target/coverage target/debug/ethsync* xdg-open target/coverage/index.html From c0776b75b68500427d310d8407e09b61f34bfefe Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 4 Feb 2016 21:30:31 +0300 Subject: [PATCH 08/22] moving sources for proper test setup --- sync/src/chain.rs | 4 + sync/src/lib.rs | 4 +- sync/src/tests/chain.rs | 91 +++++++++++++++++ sync/src/{tests.rs => tests/helpers.rs} | 130 ++++-------------------- sync/src/tests/mod.rs | 2 + 5 files changed, 120 insertions(+), 111 deletions(-) create mode 100644 sync/src/tests/chain.rs rename sync/src/{tests.rs => tests/helpers.rs} (71%) create mode 100644 sync/src/tests/mod.rs diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 665508d92..40cbd496b 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -1013,3 +1013,7 @@ impl ChainSync { } } } + +#[cfg(test)] +mod tests { +} \ No newline at end of file diff --git a/sync/src/lib.rs b/sync/src/lib.rs index f3b43396c..1523a8a9f 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -109,6 +109,4 @@ impl NetworkProtocolHandler for EthSync { self.sync.write().unwrap().maintain_peers(&mut NetSyncIo::new(io, self.chain.deref())); self.sync.write().unwrap().maintain_sync(&mut NetSyncIo::new(io, self.chain.deref())); } -} - - +} \ No newline at end of file diff --git a/sync/src/tests/chain.rs b/sync/src/tests/chain.rs new file mode 100644 index 000000000..083a9bd33 --- /dev/null +++ b/sync/src/tests/chain.rs @@ -0,0 +1,91 @@ +use util::*; +use ethcore::client::{BlockChainClient}; +use io::SyncIo; +use chain::{SyncState}; +use super::helpers::*; + +#[test] +fn chain_two_peers() { + ::env_logger::init().ok(); + let mut net = TestNet::new(3); + net.peer_mut(1).chain.add_blocks(1000, false); + net.peer_mut(2).chain.add_blocks(1000, false); + net.sync(); + assert!(net.peer(0).chain.block_at(1000).is_some()); + assert_eq!(net.peer(0).chain.blocks.read().unwrap().deref(), net.peer(1).chain.blocks.read().unwrap().deref()); +} + +#[test] +fn chain_status_after_sync() { + ::env_logger::init().ok(); + let mut net = TestNet::new(3); + net.peer_mut(1).chain.add_blocks(1000, false); + net.peer_mut(2).chain.add_blocks(1000, false); + net.sync(); + let status = net.peer(0).sync.status(); + assert_eq!(status.state, SyncState::Idle); +} + +#[test] +fn chain_takes_few_steps() { + let mut net = TestNet::new(3); + net.peer_mut(1).chain.add_blocks(100, false); + net.peer_mut(2).chain.add_blocks(100, false); + let total_steps = net.sync(); + assert!(total_steps < 7); +} + +#[test] +fn chain_empty_blocks() { + ::env_logger::init().ok(); + let mut net = TestNet::new(3); + for n in 0..200 { + net.peer_mut(1).chain.add_blocks(5, n % 2 == 0); + net.peer_mut(2).chain.add_blocks(5, n % 2 == 0); + } + net.sync(); + assert!(net.peer(0).chain.block_at(1000).is_some()); + assert_eq!(net.peer(0).chain.blocks.read().unwrap().deref(), net.peer(1).chain.blocks.read().unwrap().deref()); +} + +#[test] +fn chain_forked() { + ::env_logger::init().ok(); + let mut net = TestNet::new(3); + net.peer_mut(0).chain.add_blocks(300, false); + net.peer_mut(1).chain.add_blocks(300, false); + net.peer_mut(2).chain.add_blocks(300, false); + net.peer_mut(0).chain.add_blocks(100, true); //fork + net.peer_mut(1).chain.add_blocks(200, false); + net.peer_mut(2).chain.add_blocks(200, false); + net.peer_mut(1).chain.add_blocks(100, false); //fork between 1 and 2 + net.peer_mut(2).chain.add_blocks(10, true); + // peer 1 has the best chain of 601 blocks + let peer1_chain = net.peer(1).chain.numbers.read().unwrap().clone(); + net.sync(); + assert_eq!(net.peer(0).chain.numbers.read().unwrap().deref(), &peer1_chain); + assert_eq!(net.peer(1).chain.numbers.read().unwrap().deref(), &peer1_chain); + assert_eq!(net.peer(2).chain.numbers.read().unwrap().deref(), &peer1_chain); +} + +#[test] +fn chain_restart() { + let mut net = TestNet::new(3); + net.peer_mut(1).chain.add_blocks(1000, false); + net.peer_mut(2).chain.add_blocks(1000, false); + + net.sync_steps(8); + + // make sure that sync has actually happened + assert!(net.peer(0).chain.chain_info().best_block_number > 100); + net.restart_peer(0); + + let status = net.peer(0).sync.status(); + assert_eq!(status.state, SyncState::NotSynced); +} + +#[test] +fn chain_status_empty() { + let net = TestNet::new(2); + assert_eq!(net.peer(0).sync.status().state, SyncState::NotSynced); +} \ No newline at end of file diff --git a/sync/src/tests.rs b/sync/src/tests/helpers.rs similarity index 71% rename from sync/src/tests.rs rename to sync/src/tests/helpers.rs index 88f19a8b6..7fdd695fb 100644 --- a/sync/src/tests.rs +++ b/sync/src/tests/helpers.rs @@ -4,14 +4,14 @@ use ethcore::block_queue::BlockQueueInfo; use ethcore::header::{Header as BlockHeader, BlockNumber}; use ethcore::error::*; use io::SyncIo; -use chain::{ChainSync, SyncState}; +use chain::{ChainSync}; -struct TestBlockChainClient { - blocks: RwLock>, - numbers: RwLock>, - genesis_hash: H256, - last_hash: RwLock, - difficulty: RwLock, +pub struct TestBlockChainClient { + pub blocks: RwLock>, + pub numbers: RwLock>, + pub genesis_hash: H256, + pub last_hash: RwLock, + pub difficulty: RwLock, } impl TestBlockChainClient { @@ -189,10 +189,10 @@ impl BlockChainClient for TestBlockChainClient { } } -struct TestIo<'p> { - chain: &'p mut TestBlockChainClient, - queue: &'p mut VecDeque, - sender: Option, +pub struct TestIo<'p> { + pub chain: &'p mut TestBlockChainClient, + pub queue: &'p mut VecDeque, + pub sender: Option, } impl<'p> TestIo<'p> { @@ -235,21 +235,21 @@ impl<'p> SyncIo for TestIo<'p> { } } -struct TestPacket { - data: Bytes, - packet_id: PacketId, - recipient: PeerId, +pub struct TestPacket { + pub data: Bytes, + pub packet_id: PacketId, + pub recipient: PeerId, } -struct TestPeer { - chain: TestBlockChainClient, - sync: ChainSync, - queue: VecDeque, +pub struct TestPeer { + pub chain: TestBlockChainClient, + pub sync: ChainSync, + pub queue: VecDeque, } -struct TestNet { - peers: Vec, - started: bool, +pub struct TestNet { + pub peers: Vec, + pub started: bool, } impl TestNet { @@ -329,89 +329,3 @@ impl TestNet { self.peers.iter().all(|p| p.queue.is_empty()) } } - -#[test] -fn chain_two_peers() { - ::env_logger::init().ok(); - let mut net = TestNet::new(3); - net.peer_mut(1).chain.add_blocks(1000, false); - net.peer_mut(2).chain.add_blocks(1000, false); - net.sync(); - assert!(net.peer(0).chain.block_at(1000).is_some()); - assert_eq!(net.peer(0).chain.blocks.read().unwrap().deref(), net.peer(1).chain.blocks.read().unwrap().deref()); -} - -#[test] -fn chain_status_after_sync() { - ::env_logger::init().ok(); - let mut net = TestNet::new(3); - net.peer_mut(1).chain.add_blocks(1000, false); - net.peer_mut(2).chain.add_blocks(1000, false); - net.sync(); - let status = net.peer(0).sync.status(); - assert_eq!(status.state, SyncState::Idle); -} - -#[test] -fn chain_takes_few_steps() { - let mut net = TestNet::new(3); - net.peer_mut(1).chain.add_blocks(100, false); - net.peer_mut(2).chain.add_blocks(100, false); - let total_steps = net.sync(); - assert!(total_steps < 7); -} - -#[test] -fn chain_empty_blocks() { - ::env_logger::init().ok(); - let mut net = TestNet::new(3); - for n in 0..200 { - net.peer_mut(1).chain.add_blocks(5, n % 2 == 0); - net.peer_mut(2).chain.add_blocks(5, n % 2 == 0); - } - net.sync(); - assert!(net.peer(0).chain.block_at(1000).is_some()); - assert_eq!(net.peer(0).chain.blocks.read().unwrap().deref(), net.peer(1).chain.blocks.read().unwrap().deref()); -} - -#[test] -fn chain_forked() { - ::env_logger::init().ok(); - let mut net = TestNet::new(3); - net.peer_mut(0).chain.add_blocks(300, false); - net.peer_mut(1).chain.add_blocks(300, false); - net.peer_mut(2).chain.add_blocks(300, false); - net.peer_mut(0).chain.add_blocks(100, true); //fork - net.peer_mut(1).chain.add_blocks(200, false); - net.peer_mut(2).chain.add_blocks(200, false); - net.peer_mut(1).chain.add_blocks(100, false); //fork between 1 and 2 - net.peer_mut(2).chain.add_blocks(10, true); - // peer 1 has the best chain of 601 blocks - let peer1_chain = net.peer(1).chain.numbers.read().unwrap().clone(); - net.sync(); - assert_eq!(net.peer(0).chain.numbers.read().unwrap().deref(), &peer1_chain); - assert_eq!(net.peer(1).chain.numbers.read().unwrap().deref(), &peer1_chain); - assert_eq!(net.peer(2).chain.numbers.read().unwrap().deref(), &peer1_chain); -} - -#[test] -fn chain_restart() { - let mut net = TestNet::new(3); - net.peer_mut(1).chain.add_blocks(1000, false); - net.peer_mut(2).chain.add_blocks(1000, false); - - net.sync_steps(8); - - // make sure that sync has actually happened - assert!(net.peer(0).chain.chain_info().best_block_number > 100); - net.restart_peer(0); - - let status = net.peer(0).sync.status(); - assert_eq!(status.state, SyncState::NotSynced); -} - -#[test] -fn chain_status_empty() { - let net = TestNet::new(2); - assert_eq!(net.peer(0).sync.status().state, SyncState::NotSynced); -} \ No newline at end of file diff --git a/sync/src/tests/mod.rs b/sync/src/tests/mod.rs new file mode 100644 index 000000000..a5fa44b04 --- /dev/null +++ b/sync/src/tests/mod.rs @@ -0,0 +1,2 @@ +pub mod helpers; +mod chain; \ No newline at end of file From ab131b134bc3bf96371154cd8017c5cdd8f43981 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 4 Feb 2016 22:03:14 +0300 Subject: [PATCH 09/22] first local chain test --- sync/src/chain.rs | 18 ++++++++++++++++++ sync/src/tests/chain.rs | 14 +++++++------- sync/src/tests/helpers.rs | 4 ++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 40cbd496b..b918c960d 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -1016,4 +1016,22 @@ impl ChainSync { #[cfg(test)] mod tests { + use tests::helpers::*; + use super::*; + use util::*; + + #[test] + fn return_receipts() { + let mut client = TestBlockChainClient::new(); + let mut queue:VecDeque = VecDeque::new(); + let mut io = TestIo::new(& mut client, & mut queue, None); + + let sync = ChainSync::new(); + let data = vec![0xc0]; + let rlp = UntrustedRlp::new(&data); + + let result = sync.return_receipts(& mut io, &rlp); + + assert!(result.is_ok()); + } } \ No newline at end of file diff --git a/sync/src/tests/chain.rs b/sync/src/tests/chain.rs index 083a9bd33..fcd9b6a7b 100644 --- a/sync/src/tests/chain.rs +++ b/sync/src/tests/chain.rs @@ -5,7 +5,7 @@ use chain::{SyncState}; use super::helpers::*; #[test] -fn chain_two_peers() { +fn two_peers() { ::env_logger::init().ok(); let mut net = TestNet::new(3); net.peer_mut(1).chain.add_blocks(1000, false); @@ -16,7 +16,7 @@ fn chain_two_peers() { } #[test] -fn chain_status_after_sync() { +fn status_after_sync() { ::env_logger::init().ok(); let mut net = TestNet::new(3); net.peer_mut(1).chain.add_blocks(1000, false); @@ -27,7 +27,7 @@ fn chain_status_after_sync() { } #[test] -fn chain_takes_few_steps() { +fn takes_few_steps() { let mut net = TestNet::new(3); net.peer_mut(1).chain.add_blocks(100, false); net.peer_mut(2).chain.add_blocks(100, false); @@ -36,7 +36,7 @@ fn chain_takes_few_steps() { } #[test] -fn chain_empty_blocks() { +fn empty_blocks() { ::env_logger::init().ok(); let mut net = TestNet::new(3); for n in 0..200 { @@ -49,7 +49,7 @@ fn chain_empty_blocks() { } #[test] -fn chain_forked() { +fn forked() { ::env_logger::init().ok(); let mut net = TestNet::new(3); net.peer_mut(0).chain.add_blocks(300, false); @@ -69,7 +69,7 @@ fn chain_forked() { } #[test] -fn chain_restart() { +fn restart() { let mut net = TestNet::new(3); net.peer_mut(1).chain.add_blocks(1000, false); net.peer_mut(2).chain.add_blocks(1000, false); @@ -85,7 +85,7 @@ fn chain_restart() { } #[test] -fn chain_status_empty() { +fn status_empty() { let net = TestNet::new(2); assert_eq!(net.peer(0).sync.status().state, SyncState::NotSynced); } \ No newline at end of file diff --git a/sync/src/tests/helpers.rs b/sync/src/tests/helpers.rs index 7fdd695fb..405d1e5c1 100644 --- a/sync/src/tests/helpers.rs +++ b/sync/src/tests/helpers.rs @@ -15,7 +15,7 @@ pub struct TestBlockChainClient { } impl TestBlockChainClient { - fn new() -> TestBlockChainClient { + pub fn new() -> TestBlockChainClient { let mut client = TestBlockChainClient { blocks: RwLock::new(HashMap::new()), @@ -196,7 +196,7 @@ pub struct TestIo<'p> { } impl<'p> TestIo<'p> { - fn new(chain: &'p mut TestBlockChainClient, queue: &'p mut VecDeque, sender: Option) -> TestIo<'p> { + pub fn new(chain: &'p mut TestBlockChainClient, queue: &'p mut VecDeque, sender: Option) -> TestIo<'p> { TestIo { chain: chain, queue: queue, From 993290bf01e2d3f7a1970e990a089e36fe1cd7da Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 4 Feb 2016 20:27:09 +0100 Subject: [PATCH 10/22] Additional features to make netstats install work. --- install-deps.sh | 107 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/install-deps.sh b/install-deps.sh index 77157c3e1..7d95bf9c9 100755 --- a/install-deps.sh +++ b/install-deps.sh @@ -105,7 +105,14 @@ function run_installer() done } - + function prompt_for_input() { + while : + do + read -p "$1 " imp + echo $imp + return + done + } function exe() { echo "\$ $@"; "$@" @@ -378,6 +385,7 @@ function run_installer() find_gcc find_apt + find_docker } function find_rocksdb() @@ -511,6 +519,23 @@ function run_installer() fi } + function find_docker() + { + depCount=$((depCount+1)) + DOCKER_PATH=`which docker 2>/dev/null` + + if [[ -f $DOCKER_PATH ]] + then + depFound=$((depFound+1)) + check "docker" + echo "$($DOCKER_PATH -v)" + isDocker=true + else + isDocker=false + uncheck "docker is missing" + fi + } + function ubuntu1404_rocksdb_installer() { sudo apt-get update -qq @@ -611,6 +636,72 @@ function run_installer() fi } + function build_parity() + { + info "Downloading Parity..." + git clone git@github.com:ethcore/parity + cd parity + + info "Building & testing Parity..." + cargo test --release -p ethcore-util + + info "Running consensus tests..." + cargo test --release --features ethcore/json-tests -p ethcore + + echo + info "Parity source code is in $(pwd)/parity" + info "Run a client with: ${b}cargo run --release${reset}" + } + + function install_netstats() + { + echo "Installing netstats" + + if [[ $isDocker == false ]]; then + info "Installing docker" + curl -sSL https://get.docker.com/ | sh + fi + + dir=$HOME/.netstats + + secret=$(prompt_for_input "Please enter the netstats secret:") + instance_name=$(prompt_for_input "Please enter your instance name:") + contact_details=$(prompt_for_input "Please enter your contact details (optional):") + + mkdir -p $dir + cat > $dir/app.json << EOL +[ + { + "name" : "node-app", + "script" : "app.js", + "log_date_format" : "YYYY-MM-DD HH:mm Z", + "merge_logs" : false, + "watch" : false, + "max_restarts" : 10, + "exec_interpreter" : "node", + "exec_mode" : "fork_mode", + "env": + { + "NODE_ENV" : "production", + "RPC_HOST" : "localhost", + "RPC_PORT" : "8545", + "LISTENING_PORT" : "30303", + "INSTANCE_NAME" : "${instance_name}", + "CONTACT_DETAILS" : "${contact_details}", + "WS_SERVER" : "wss://rpc.ethstats.net", + "WS_SECRET" : "${secret}", + "VERBOSITY" : 2 + + } + } +] +EOL + + sudo docker rm --force netstats-client 2> /dev/null + sudo docker pull ethcore/netstats-client + sudo docker run -d --net=host --name netstats-client -v $dir/app.json:/home/ethnetintel/eth-net-intelligence-api/app.json ethcore/netstats-client + } + function abortInstall() { echo @@ -648,6 +739,20 @@ function run_installer() # Check installation verify_installation + if [[ ! -e parity ]]; then + # Maybe install parity + if wait_for_user "${b}Build dependencies installed B-)!${reset} Would you like to download and build parity?"; then + # Do get parity. + build_parity + fi + fi + + if [[ $OS_TYPE == "linux" ]]; then + if wait_for_user "${b}Netstats:${reset} Would you like to install and configure a netstats client?"; then + install_netstats + fi + fi + # Display goodby message finish } From 84b83cda7787abae5e0865f97c62d5f7fa5eb00e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 4 Feb 2016 21:22:55 +0100 Subject: [PATCH 11/22] Deps install script also installs netstats properly. --- install-deps.sh | 52 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/install-deps.sh b/install-deps.sh index 7d95bf9c9..de1a6ebb7 100755 --- a/install-deps.sh +++ b/install-deps.sh @@ -657,19 +657,35 @@ function run_installer() { echo "Installing netstats" - if [[ $isDocker == false ]]; then - info "Installing docker" - curl -sSL https://get.docker.com/ | sh - fi - - dir=$HOME/.netstats - secret=$(prompt_for_input "Please enter the netstats secret:") instance_name=$(prompt_for_input "Please enter your instance name:") contact_details=$(prompt_for_input "Please enter your contact details (optional):") - mkdir -p $dir - cat > $dir/app.json << EOL + # install ethereum & install dependencies + sudo apt-get install -y -qq build-essential git unzip wget nodejs npm ntp cloud-utils + + # add node symlink if it doesn't exist + [[ ! -f /usr/bin/node ]] && sudo ln -s /usr/bin/nodejs /usr/bin/node + + # set up time update cronjob + sudo bash -c "cat > /etc/cron.hourly/ntpdate << EOF + #!/bin/sh + pm2 flush + sudo service ntp stop + sudo ntpdate -s ntp.ubuntu.com + sudo service ntp start + EOF" + + sudo chmod 755 /etc/cron.hourly/ntpdate + + [ ! -d "www" ] && git clone https://github.com/cubedro/eth-net-intelligence-api netstats + cd netstats + git pull + + sudo npm install + sudo npm install pm2 -g + + cat > app.json << EOL [ { "name" : "node-app", @@ -697,9 +713,8 @@ function run_installer() ] EOL - sudo docker rm --force netstats-client 2> /dev/null - sudo docker pull ethcore/netstats-client - sudo docker run -d --net=host --name netstats-client -v $dir/app.json:/home/ethnetintel/eth-net-intelligence-api/app.json ethcore/netstats-client + pm2 start app.json + cd .. } function abortInstall() @@ -719,13 +734,22 @@ EOL exit 0 } + + ####### Run the script + tput clear + echo + echo + echo " ${blue}∷ ${b}${green} WELCOME TO PARITY ${reset} ${blue}∷${reset}" + echo + echo + # Check dependencies head "Checking OS dependencies" detectOS if [[ $INSTALL_FILES != "" ]]; then echo - head "In addition to the parity build dependencies, this script will install:" + head "In addition to the Parity build dependencies, this script will install:" echo "$INSTALL_FILES" echo fi @@ -747,7 +771,7 @@ EOL fi fi - if [[ $OS_TYPE == "linux" ]]; then + if [[ $OS_TYPE == "linux" && $DISTRIB_ID == "Ubuntu" ]]; then if wait_for_user "${b}Netstats:${reset} Would you like to install and configure a netstats client?"; then install_netstats fi From 7e87546523d9ce73ef7ea029c6024b88413122a1 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 4 Feb 2016 21:35:46 +0100 Subject: [PATCH 12/22] Fix version of netstats to use. --- install-deps.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install-deps.sh b/install-deps.sh index de1a6ebb7..1e1ce9128 100755 --- a/install-deps.sh +++ b/install-deps.sh @@ -681,6 +681,7 @@ function run_installer() [ ! -d "www" ] && git clone https://github.com/cubedro/eth-net-intelligence-api netstats cd netstats git pull + git checkout 95d595258239a0fdf56b97dedcfb2be62f6170e6 sudo npm install sudo npm install pm2 -g From d80d8c792b7560feefe829a0fba6b2484cdc9223 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 4 Feb 2016 23:16:41 +0100 Subject: [PATCH 13/22] Fix for 15.10. --- install-deps.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-deps.sh b/install-deps.sh index 1e1ce9128..a831bb64f 100755 --- a/install-deps.sh +++ b/install-deps.sh @@ -548,7 +548,7 @@ function run_installer() function linux_rocksdb_installer() { - if [[ $isUbuntu1404 ]]; then + if [[ $isUbuntu1404 == true ]]; then ubuntu1404_rocksdb_installer else oldpwd=`pwd` From 98bd65daa7835bea8c3d43f6618a66438c57cb60 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 4 Feb 2016 23:18:13 +0100 Subject: [PATCH 14/22] Fix test building. --- install-deps.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install-deps.sh b/install-deps.sh index a831bb64f..5c42bcf2a 100755 --- a/install-deps.sh +++ b/install-deps.sh @@ -641,6 +641,8 @@ function run_installer() info "Downloading Parity..." git clone git@github.com:ethcore/parity cd parity + git submodule init + git submodule update info "Building & testing Parity..." cargo test --release -p ethcore-util From 8d7523a027bfa7273e8e80181342a05197a23971 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 5 Feb 2016 01:24:36 +0300 Subject: [PATCH 15/22] receipt tests --- sync/src/chain.rs | 111 +++++++++++++++++++++++++------------- sync/src/tests/helpers.rs | 13 ++++- 2 files changed, 87 insertions(+), 37 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index b918c960d..5a3856264 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -177,6 +177,7 @@ pub struct ChainSync { have_common_block: bool, } +type RlpResponseResult = Result, PacketDecodeError>; impl ChainSync { /// Create a new instance of syncing strategy. @@ -845,7 +846,7 @@ impl ChainSync { } /// Respond to GetBlockHeaders request - fn return_block_headers(&self, io: &mut SyncIo, r: &UntrustedRlp) -> Result<(), PacketDecodeError> { + fn return_block_headers(io: &SyncIo, r: &UntrustedRlp) -> RlpResponseResult { // Packet layout: // [ block: { P , B_32 }, maxHeaders: P, skip: P, reverse: P in { 0 , 1 } ] let max_headers: usize = try!(r.val_at(1)); @@ -892,18 +893,16 @@ impl ChainSync { } let mut rlp = RlpStream::new_list(count as usize); rlp.append_raw(&data, count as usize); - io.respond(BLOCK_HEADERS_PACKET, rlp.out()).unwrap_or_else(|e| - debug!(target: "sync", "Error sending headers: {:?}", e)); trace!(target: "sync", "-> GetBlockHeaders: returned {} entries", count); - Ok(()) + Ok(Some((BLOCK_HEADERS_PACKET, rlp))) } /// Respond to GetBlockBodies request - fn return_block_bodies(&self, io: &mut SyncIo, r: &UntrustedRlp) -> Result<(), PacketDecodeError> { + fn return_block_bodies(io: &SyncIo, r: &UntrustedRlp) -> RlpResponseResult { let mut count = r.item_count(); if count == 0 { debug!(target: "sync", "Empty GetBlockBodies request, ignoring."); - return Ok(()); + return Ok(None); } trace!(target: "sync", "-> GetBlockBodies: {} entries", count); count = min(count, MAX_BODIES_TO_SEND); @@ -917,18 +916,16 @@ impl ChainSync { } let mut rlp = RlpStream::new_list(added); rlp.append_raw(&data, added); - io.respond(BLOCK_BODIES_PACKET, rlp.out()).unwrap_or_else(|e| - debug!(target: "sync", "Error sending headers: {:?}", e)); trace!(target: "sync", "-> GetBlockBodies: returned {} entries", added); - Ok(()) + Ok(Some((BLOCK_BODIES_PACKET, rlp))) } /// Respond to GetNodeData request - fn return_node_data(&self, io: &mut SyncIo, r: &UntrustedRlp) -> Result<(), PacketDecodeError> { + fn return_node_data(io: &SyncIo, r: &UntrustedRlp) -> RlpResponseResult { let mut count = r.item_count(); if count == 0 { debug!(target: "sync", "Empty GetNodeData request, ignoring."); - return Ok(()); + return Ok(None); } count = min(count, MAX_NODE_DATA_TO_SEND); let mut added = 0usize; @@ -941,32 +938,43 @@ impl ChainSync { } let mut rlp = RlpStream::new_list(added); rlp.append_raw(&data, added); - io.respond(NODE_DATA_PACKET, rlp.out()).unwrap_or_else(|e| - debug!(target: "sync", "Error sending headers: {:?}", e)); - Ok(()) + Ok(Some((NODE_DATA_PACKET, rlp))) } - /// Respond to GetReceipts request - fn return_receipts(&self, io: &mut SyncIo, r: &UntrustedRlp) -> Result<(), PacketDecodeError> { - let mut count = r.item_count(); + fn return_receipts(io: &SyncIo, rlp: &UntrustedRlp) -> RlpResponseResult { + let mut count = rlp.item_count(); if count == 0 { debug!(target: "sync", "Empty GetReceipts request, ignoring."); - return Ok(()); + return Ok(None); } count = min(count, MAX_RECEIPTS_TO_SEND); let mut added = 0usize; let mut data = Bytes::new(); for i in 0..count { - if let Some(mut hdr) = io.chain().block_receipts(&try!(r.val_at::(i))) { + if let Some(mut hdr) = io.chain().block_receipts(&try!(rlp.val_at::(i))) { data.append(&mut hdr); added += 1; } } - let mut rlp = RlpStream::new_list(added); - rlp.append_raw(&data, added); - io.respond(RECEIPTS_PACKET, rlp.out()).unwrap_or_else(|e| - debug!(target: "sync", "Error sending headers: {:?}", e)); - Ok(()) + let mut rlp_result = RlpStream::new_list(added); + rlp_result.append_raw(&data, added); + Ok(Some((RECEIPTS_PACKET, rlp_result))) + } + + fn return_rlp(&self, io: &mut SyncIo, rlp: &UntrustedRlp, rlp_func: FRlp, error_func: FError) -> Result<(), PacketDecodeError> + where FRlp : Fn(&SyncIo, &UntrustedRlp) -> RlpResponseResult, + FError : FnOnce(UtilError) -> String + { + let response = rlp_func(io, rlp); + match response { + Err(e) => Err(e), + Ok(Some((packet_id, rlp_stream))) => { + io.respond(packet_id, rlp_stream.out()).unwrap_or_else( + |e| debug!(target: "sync", "{:?}", error_func(e))); + Ok(()) + } + _ => Ok(()) + } } /// Dispatch incoming requests and responses @@ -975,14 +983,26 @@ impl ChainSync { let result = match packet_id { STATUS_PACKET => self.on_peer_status(io, peer, &rlp), TRANSACTIONS_PACKET => self.on_peer_transactions(io, peer, &rlp), - GET_BLOCK_HEADERS_PACKET => self.return_block_headers(io, &rlp), BLOCK_HEADERS_PACKET => self.on_peer_block_headers(io, peer, &rlp), - GET_BLOCK_BODIES_PACKET => self.return_block_bodies(io, &rlp), BLOCK_BODIES_PACKET => self.on_peer_block_bodies(io, peer, &rlp), NEW_BLOCK_PACKET => self.on_peer_new_block(io, peer, &rlp), NEW_BLOCK_HASHES_PACKET => self.on_peer_new_hashes(io, peer, &rlp), - GET_NODE_DATA_PACKET => self.return_node_data(io, &rlp), - GET_RECEIPTS_PACKET => self.return_receipts(io, &rlp), + + GET_BLOCK_BODIES_PACKET => self.return_rlp(io, &rlp, + ChainSync::return_block_bodies, + |e| format!("Error sending block bodies: {:?}", e)), + + GET_BLOCK_HEADERS_PACKET => self.return_rlp(io, &rlp, + ChainSync::return_block_headers, + |e| format!("Error sending block headers: {:?}", e)), + + GET_RECEIPTS_PACKET => self.return_rlp(io, &rlp, + ChainSync::return_receipts, + |e| format!("Error sending receipts: {:?}", e)), + + GET_NODE_DATA_PACKET => self.return_rlp(io, &rlp, + ChainSync::return_node_data, + |e| format!("Error sending nodes: {:?}", e)), _ => { debug!(target: "sync", "Unknown packet {}", packet_id); Ok(()) @@ -1021,17 +1041,36 @@ mod tests { use util::*; #[test] - fn return_receipts() { + fn return_receipts_empty() { let mut client = TestBlockChainClient::new(); - let mut queue:VecDeque = VecDeque::new(); - let mut io = TestIo::new(& mut client, & mut queue, None); + let mut queue = VecDeque::new(); + let io = TestIo::new(&mut client, &mut queue, None); - let sync = ChainSync::new(); - let data = vec![0xc0]; - let rlp = UntrustedRlp::new(&data); - - let result = sync.return_receipts(& mut io, &rlp); + let result = ChainSync::return_receipts(&io, &UntrustedRlp::new(&[0xc0])); assert!(result.is_ok()); } + + #[test] + fn return_receipts() { + let mut client = TestBlockChainClient::new(); + let mut queue = VecDeque::new(); + let io = TestIo::new(&mut client, &mut queue, None); + + let mut receipt_list = RlpStream::new_list(4); + receipt_list.append(&H256::from("0000000000000000000000000000000000000000000000005555555555555555")); + receipt_list.append(&H256::from("ff00000000000000000000000000000000000000000000000000000000000000")); + receipt_list.append(&H256::from("fff0000000000000000000000000000000000000000000000000000000000000")); + receipt_list.append(&H256::from("aff0000000000000000000000000000000000000000000000000000000000000")); + + // it returns rlp ONLY for hashes started with "f" + let result = ChainSync::return_receipts(&io, &UntrustedRlp::new(&receipt_list.out())); + + assert!(result.is_ok()); + let rlp_result = result.unwrap(); + assert!(rlp_result.is_some()); + + // the length of two rlp-encoded receipts + assert_eq!(597, rlp_result.unwrap().1.out().len()); + } } \ No newline at end of file diff --git a/sync/src/tests/helpers.rs b/sync/src/tests/helpers.rs index 405d1e5c1..ce3560d63 100644 --- a/sync/src/tests/helpers.rs +++ b/sync/src/tests/helpers.rs @@ -5,6 +5,7 @@ use ethcore::header::{Header as BlockHeader, BlockNumber}; use ethcore::error::*; use io::SyncIo; use chain::{ChainSync}; +use ethcore::receipt::Receipt; pub struct TestBlockChainClient { pub blocks: RwLock>, @@ -120,7 +121,17 @@ impl BlockChainClient for TestBlockChainClient { None } - fn block_receipts(&self, _h: &H256) -> Option { + fn block_receipts(&self, hash: &H256) -> Option { + // starts with 'f' ? + if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") { + let receipt = Receipt::new( + H256::zero(), + U256::zero(), + vec![]); + let mut rlp = RlpStream::new(); + rlp.append(&receipt); + return Some(rlp.out()); + } None } From c12538b1237c3efede1e938daa6ed9dcdc25fbc4 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 5 Feb 2016 01:58:32 +0300 Subject: [PATCH 16/22] dispatch test as well --- sync/src/chain.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 5a3856264..62bb4b4de 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -1055,7 +1055,7 @@ mod tests { fn return_receipts() { let mut client = TestBlockChainClient::new(); let mut queue = VecDeque::new(); - let io = TestIo::new(&mut client, &mut queue, None); + let mut io = TestIo::new(&mut client, &mut queue, None); let mut receipt_list = RlpStream::new_list(4); receipt_list.append(&H256::from("0000000000000000000000000000000000000000000000005555555555555555")); @@ -1063,8 +1063,9 @@ mod tests { receipt_list.append(&H256::from("fff0000000000000000000000000000000000000000000000000000000000000")); receipt_list.append(&H256::from("aff0000000000000000000000000000000000000000000000000000000000000")); + let receipts_request = receipt_list.out(); // it returns rlp ONLY for hashes started with "f" - let result = ChainSync::return_receipts(&io, &UntrustedRlp::new(&receipt_list.out())); + let result = ChainSync::return_receipts(&io, &UntrustedRlp::new(&receipts_request.clone())); assert!(result.is_ok()); let rlp_result = result.unwrap(); @@ -1072,5 +1073,11 @@ mod tests { // the length of two rlp-encoded receipts assert_eq!(597, rlp_result.unwrap().1.out().len()); + + let mut sync = ChainSync::new(); + io.sender = Some(2usize); + sync.on_packet(&mut io, 1usize, super::GET_RECEIPTS_PACKET, &receipts_request); } + + } \ No newline at end of file From 51b41a70804913896c9a4bbfba6feaaa94842b49 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 5 Feb 2016 01:58:58 +0300 Subject: [PATCH 17/22] forgot root changes --- ethcore/src/lib.rs | 2 +- ethcore/src/receipt.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 3df01d898..540b5ea40 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -83,6 +83,7 @@ pub mod header; pub mod service; pub mod spec; pub mod views; +pub mod receipt; mod common; mod basic_types; @@ -98,7 +99,6 @@ mod state; mod account; mod action_params; mod transaction; -mod receipt; mod null_engine; mod builtin; mod extras; diff --git a/ethcore/src/receipt.rs b/ethcore/src/receipt.rs index 43f674aa9..3888a6abc 100644 --- a/ethcore/src/receipt.rs +++ b/ethcore/src/receipt.rs @@ -1,3 +1,5 @@ +//! Receipt + use util::*; use basic_types::LogBloom; use log_entry::LogEntry; From 0c90b75c67f618aa48c6cf426ee26672ba62fcc0 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 5 Feb 2016 02:01:29 +0300 Subject: [PATCH 18/22] excluded test code from coverage --- sync/cov.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync/cov.sh b/sync/cov.sh index c19dd5689..5e95542fa 100755 --- a/sync/cov.sh +++ b/sync/cov.sh @@ -5,5 +5,5 @@ fi cargo test --no-run || exit $? mkdir -p target/coverage -kcov --exclude-pattern ~/.multirust,rocksdb,secp256k1 --include-pattern sync/src --verify target/coverage target/debug/ethsync* +kcov --exclude-pattern ~/.multirust,rocksdb,secp256k1,sync/src/tests --include-pattern sync/src --verify target/coverage target/debug/ethsync* xdg-open target/coverage/index.html From b0cba757d6f6a71a5529e5a0656ac0a88c80e4ab Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 5 Feb 2016 02:57:51 +0300 Subject: [PATCH 19/22] test effort --- sync/src/chain.rs | 27 +++++++++++++++++++++++++++ sync/src/tests/helpers.rs | 9 ++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 62bb4b4de..869b19bf5 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -1077,7 +1077,34 @@ mod tests { let mut sync = ChainSync::new(); io.sender = Some(2usize); sync.on_packet(&mut io, 1usize, super::GET_RECEIPTS_PACKET, &receipts_request); + assert_eq!(1, io.queue.len()); } + #[test] + fn return_nodes() { + let mut client = TestBlockChainClient::new(); + let mut queue = VecDeque::new(); + let mut io = TestIo::new(&mut client, &mut queue, None); + let mut node_list = RlpStream::new_list(3); + node_list.append(&H256::from("0000000000000000000000000000000000000000000000005555555555555555")); + node_list.append(&H256::from("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa")); + node_list.append(&H256::from("aff0000000000000000000000000000000000000000000000000000000000000")); + + let node_request = node_list.out(); + // it returns rlp ONLY for hashes started with "f" + let result = ChainSync::return_node_data(&io, &UntrustedRlp::new(&node_request.clone())); + + assert!(result.is_ok()); + let rlp_result = result.unwrap(); + assert!(rlp_result.is_some()); + + // the length of one rlp-encoded hashe + assert_eq!(34, rlp_result.unwrap().1.out().len()); + + let mut sync = ChainSync::new(); + io.sender = Some(2usize); + sync.on_packet(&mut io, 1usize, super::GET_NODE_DATA_PACKET, &node_request); + assert_eq!(1, io.queue.len()); + } } \ No newline at end of file diff --git a/sync/src/tests/helpers.rs b/sync/src/tests/helpers.rs index ce3560d63..c4a4d80cb 100644 --- a/sync/src/tests/helpers.rs +++ b/sync/src/tests/helpers.rs @@ -117,7 +117,14 @@ impl BlockChainClient for TestBlockChainClient { }) } - fn state_data(&self, _h: &H256) -> Option { + // TODO: returns just hashes instead of node state rlp(?) + fn state_data(&self, hash: &H256) -> Option { + // starts with 'f' ? + if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") { + let mut rlp = RlpStream::new(); + rlp.append(&hash.clone()); + return Some(rlp.out()); + } None } From 410d6533e0c6f0f46343513cb7b014a71521dba0 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 5 Feb 2016 03:01:50 +0300 Subject: [PATCH 20/22] indents --- sync/src/chain.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sync/src/chain.rs b/sync/src/chain.rs index 869b19bf5..e143f20b1 100644 --- a/sync/src/chain.rs +++ b/sync/src/chain.rs @@ -997,12 +997,13 @@ impl ChainSync { |e| format!("Error sending block headers: {:?}", e)), GET_RECEIPTS_PACKET => self.return_rlp(io, &rlp, - ChainSync::return_receipts, - |e| format!("Error sending receipts: {:?}", e)), + ChainSync::return_receipts, + |e| format!("Error sending receipts: {:?}", e)), GET_NODE_DATA_PACKET => self.return_rlp(io, &rlp, - ChainSync::return_node_data, - |e| format!("Error sending nodes: {:?}", e)), + ChainSync::return_node_data, + |e| format!("Error sending nodes: {:?}", e)), + _ => { debug!(target: "sync", "Unknown packet {}", packet_id); Ok(()) From 0506a978e9adad5136f9d1a37b0f77fb25778aa1 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 5 Feb 2016 11:26:05 +0100 Subject: [PATCH 21/22] Remove docker. --- install-deps.sh | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/install-deps.sh b/install-deps.sh index 5c42bcf2a..bae8fc9a6 100755 --- a/install-deps.sh +++ b/install-deps.sh @@ -385,7 +385,6 @@ function run_installer() find_gcc find_apt - find_docker } function find_rocksdb() @@ -519,23 +518,6 @@ function run_installer() fi } - function find_docker() - { - depCount=$((depCount+1)) - DOCKER_PATH=`which docker 2>/dev/null` - - if [[ -f $DOCKER_PATH ]] - then - depFound=$((depFound+1)) - check "docker" - echo "$($DOCKER_PATH -v)" - isDocker=true - else - isDocker=false - uncheck "docker is missing" - fi - } - function ubuntu1404_rocksdb_installer() { sudo apt-get update -qq From cd24ffa723832e627c39add1cc9bff282e69a09b Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 5 Feb 2016 11:51:12 +0100 Subject: [PATCH 22/22] Additional info on parity build. --- install-deps.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/install-deps.sh b/install-deps.sh index bae8fc9a6..d03098c42 100755 --- a/install-deps.sh +++ b/install-deps.sh @@ -626,15 +626,23 @@ function run_installer() git submodule init git submodule update - info "Building & testing Parity..." - cargo test --release -p ethcore-util + info "Building..." + cargo build --release - info "Running consensus tests..." - cargo test --release --features ethcore/json-tests -p ethcore + cd .. echo - info "Parity source code is in $(pwd)/parity" - info "Run a client with: ${b}cargo run --release${reset}" + head "Parity is built!" + info "Parity source code is in ${b}$(pwd)/parity${reset}. From that path, you can:" + info "- Run a client & sync the chain with:" + info " ${b}cargo run --release${reset}" + info "- Run a JSONRPC-capable client (for use with netstats) with:" + info " ${b}cargo run --release -- -j --jsonrpc-url 127.0.0.1:8545${reset}" + info "- Run tests with:" + info " ${b}cargo test --release --features ethcore/json-tests -p ethcore${reset}" + info "- Install the client with:" + info " ${b}sudo cp target/release/parity /usr/bin${reset}" + echo } function install_netstats()