diff --git a/bin/start.sh b/bin/start.sh index dc7d901674dca8e5c4f9738961de2ba2ca3e9820..6714fc46198ce88d14e2ca1343df5b84f91a2dc2 100755 --- a/bin/start.sh +++ b/bin/start.sh @@ -60,6 +60,7 @@ function getsyncmode echo echo '***' echo + # (re)configure parameters (you never know if they changed) flexargs="$( accountlist) $( getminer ) $( getsyncmode )" set -x geth \ diff --git a/bin/syncmode.sh b/bin/syncmode.sh new file mode 100755 index 0000000000000000000000000000000000000000..009d260899f968f030e86c503a46ec7bc4c8d9bf --- /dev/null +++ b/bin/syncmode.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# Robert Martin-Legene <robert@nic.ar> + +if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi +source ${BFAHOME}/bin/libbfa.sh || exit 1 + +defaultmode="fast" + +echo "Available synchronization modes:" +echo " full : verify all blocks and all transactions since genesis (most secure)" +echo " fast : verify all blocks but not all transactions (faster than full, but less certain)" +echo " light: Makes this node into a light node which downloads almost" +echo " nothing, but relies on fast and full nodes in the network" +echo " to answer it's requests. This is the fastest and uses least" +echo " local resources, but outsources all trust to another node." +echo "Default mode is fast, because for many, it is a healthy compromise" +echo "between speed and paranoia. You can change the setting, according to" +echo "your needs." + +function modefilter +{ + case "$mode" in + "full"|"fast"|"light") + ;; + *) + echo "Unsupported mode." + mode="" + return + ;; + esac + true +} + +bfaconfig node +mode=$( cat ${BFANODEDIR}/syncmode 2>/dev/null || true ) +mode=${mode:-${defaultmode}} +orgmode=$mode +modefilter +echo "Your current mode is set to ${mode}" +killed=0 +mode= + +echo +while [ -z "${mode}" ] +do + read -p "Which mode do you wish? : " mode + modefilter +done +echo $mode > ${BFANODEDIR}/syncmode +if [ "$orgmode" = "fast" -a "$mode" = "full" ] +then + echo "You increased your paranoia level. The proper thing to do now," + echo "would be to delete your version of what you synchronized with" + echo "fast mode, and revalidate everything in the entire blockchain." + echo "This probably takes quite a long time and also requires downloading" + echo "all blocks from the entire blockchain again." + REPLY= + while [ "$REPLY" != "y" -a "$REPLY" != "n" ] + do + read -p "Do you wish to delete all downloaded blocks and resynchronize? [yn]: " + REPLY=${REPLY,,} + done + if [ "$REPLY" = "y" ] + then + if [ -r "${BFANODEDIR}/geth.pid" ] + then + local pid=$( cat ${BFANODEDIR}/geth.pid ) + kill -0 $pid 2>/dev/null && + echo "Killing running geth." && + killed=1 + while ! kill $pid 2>/dev/null + do + sleep 1 + done + fi + rm -fr ${BFANODEDIR}/geth/chainstate ${BFANODEDIR}/geth/lightchainstate + geth --cache 0 --datadir ${BFANODEDIR} init ${BFAHOME}/src/genesis.json + test $killed -eq 1 && + echo && + echo "The startup.sh should restart your geth shortly." + fi +fi