Merge branch 'sigint'

This commit is contained in:
Ștefan Talpalaru 2019-07-11 18:01:53 +02:00
commit 4a5154c694
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
5 changed files with 47 additions and 13 deletions

3
.gitignore vendored
View File

@ -9,3 +9,6 @@ build/
*.la *.la
*.exe *.exe
*.dll *.dll
/scripts/testnet*.sh

View File

@ -14,7 +14,7 @@ TOOLS := beacon_node validator_keygen bench_bls_sig_agggregation state_sim
TOOLS_DIRS := beacon_chain benchmarks research TOOLS_DIRS := beacon_chain benchmarks research
TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(TOOLS)) TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(TOOLS))
.PHONY: all sanity-checks deps nat-libs test $(TOOLS) clean_eth2_network_simulation_files eth2_network_simulation clean-testnet0 testnet0-nocleaning testnet0 clean-testnet1 testnet1-nocleaning testnet1 clean .PHONY: all sanity-checks deps nat-libs p2pd test $(TOOLS) clean_eth2_network_simulation_files eth2_network_simulation clean-testnet0 testnet0-nocleaning testnet0 clean-testnet1 testnet1-nocleaning testnet1 clean
all: | $(TOOLS) all: | $(TOOLS)
@ -34,6 +34,9 @@ build:
nat-libs: | deps nat-libs: | deps
+ $(MAKE) --silent -C ../../ nat-libs + $(MAKE) --silent -C ../../ nat-libs
p2pd: | deps
+ $(MAKE) --silent -C ../../ vendor/go/bin/p2pd
# Windows 10 with WSL enabled, but no distro installed, fails if "../../nimble.sh" is executed directly # Windows 10 with WSL enabled, but no distro installed, fails if "../../nimble.sh" is executed directly
# in a Makefile recipe but works when prefixing it with `bash`. No idea how the PATH is overridden. # in a Makefile recipe but works when prefixing it with `bash`. No idea how the PATH is overridden.
test: | build deps nat-libs test: | build deps nat-libs
@ -50,8 +53,8 @@ clean_eth2_network_simulation_files:
eth2_network_simulation: | beacon_node validator_keygen clean_eth2_network_simulation_files eth2_network_simulation: | beacon_node validator_keygen clean_eth2_network_simulation_files
SKIP_BUILDS=1 GIT_ROOT="$$PWD" BUILD_OUTPUTS_DIR="./build" tests/simulation/start.sh SKIP_BUILDS=1 GIT_ROOT="$$PWD" BUILD_OUTPUTS_DIR="./build" tests/simulation/start.sh
testnet0 testnet1: | build deps nat-libs testnet0 testnet1: | build deps nat-libs p2pd
../../env.sh scripts/build_testnet_node.sh $@ NIM_PARAMS="$(NIM_PARAMS)" ../../env.sh scripts/build_testnet_node.sh $@
clean-testnet0: clean-testnet0:
rm -rf ~/.cache/nimbus/BeaconNode/testnet0 rm -rf ~/.cache/nimbus/BeaconNode/testnet0

View File

@ -723,6 +723,15 @@ when isMainModule:
if config.logLevel != LogLevel.NONE: if config.logLevel != LogLevel.NONE:
setLogLevel(config.logLevel) setLogLevel(config.logLevel)
## Ctrl+C handling
proc controlCHandler() {.noconv.} =
when defined(windows):
# workaround for https://github.com/nim-lang/Nim/issues/4057
setupForeignThreadGc()
debug "Shutting down after having received SIGINT"
quit(1)
setControlCHook(controlCHandler)
case config.cmd case config.cmd
of createTestnet: of createTestnet:
var deposits: seq[Deposit] var deposits: seq[Deposit]

View File

@ -166,6 +166,8 @@ else:
template tcpEndPoint(address, port): auto = template tcpEndPoint(address, port): auto =
MultiAddress.init(address, Protocol.IPPROTO_TCP, port) MultiAddress.init(address, Protocol.IPPROTO_TCP, port)
var mainDaemon: DaemonAPI
proc createEth2Node*(conf: BeaconNodeConf): Future[Eth2Node] {.async.} = proc createEth2Node*(conf: BeaconNodeConf): Future[Eth2Node] {.async.} =
var var
(extIp, extTcpPort, extUdpPort) = setupNat(conf) (extIp, extTcpPort, extUdpPort) = setupNat(conf)
@ -174,13 +176,18 @@ else:
else: @[tcpEndPoint(extIp, extTcpPort)] else: @[tcpEndPoint(extIp, extTcpPort)]
keyFile = conf.ensureNetworkIdFile keyFile = conf.ensureNetworkIdFile
info "Starting LibP2P deamon", hostAddress, announcedAddresses, keyFile info "Starting the LibP2P daemon", hostAddress, announcedAddresses, keyFile
let daemon = await newDaemonApi({PSGossipSub}, mainDaemon = await newDaemonApi({PSGossipSub},
id = keyFile, id = keyFile,
hostAddresses = @[hostAddress], hostAddresses = @[hostAddress],
announcedAddresses = announcedAddresses) announcedAddresses = announcedAddresses)
return await Eth2Node.init(daemon) proc closeDaemon() {.noconv.} =
info "Shutting down the LibP2P daemon"
waitFor mainDaemon.close()
addQuitProc(closeDaemon)
return await Eth2Node.init(mainDaemon)
proc getPersistenBootstrapAddr*(conf: BeaconNodeConf, proc getPersistenBootstrapAddr*(conf: BeaconNodeConf,
ip: IpAddress, port: Port): BootstrapAddr = ip: IpAddress, port: Port): BootstrapAddr =

View File

@ -3,7 +3,7 @@
[ -z "$1" ] && { echo "Usage: `basename $0` testnetX"; exit 1; } [ -z "$1" ] && { echo "Usage: `basename $0` testnetX"; exit 1; }
set -eu set -e
cd $(dirname "$0") cd $(dirname "$0")
@ -12,11 +12,13 @@ source "$NETWORK_NAME.env"
cd .. cd ..
NIM_FLAGS="-d:release --lineTrace:on -d:chronicles_log_level=DEBUG -d:network_type=$NETWORK_TYPE -d:SECONDS_PER_SLOT=$SECONDS_PER_SLOT -d:SHARD_COUNT=$SHARD_COUNT -d:SLOTS_PER_EPOCH=$SLOTS_PER_EPOCH -d:DEFAULT_NETWORK=$NETWORK_NAME --hints:off --verbosity:0" # the NIM_PARAMS env var will be set in the Makefile, based on NIMFLAGS passed on the `make` command line
# (i.e.: make NIMFLAGS="--stackTrace:on" testnet1).
OUR_NIM_FLAGS="-d:release --lineTrace:on -d:chronicles_log_level=DEBUG -d:network_type=$NETWORK_TYPE -d:SECONDS_PER_SLOT=$SECONDS_PER_SLOT -d:SHARD_COUNT=$SHARD_COUNT -d:SLOTS_PER_EPOCH=$SLOTS_PER_EPOCH -d:DEFAULT_NETWORK=$NETWORK_NAME $NIM_PARAMS"
BEACON_NODE_BIN="build/${NETWORK_NAME}_node" BEACON_NODE_BIN="build/${NETWORK_NAME}_node"
CMD="nim c $NIM_FLAGS -o:$BEACON_NODE_BIN beacon_chain/beacon_node" CMD="nim c $OUR_NIM_FLAGS -o:$BEACON_NODE_BIN beacon_chain/beacon_node"
echo "$CMD" echo "$CMD"
$CMD $CMD
@ -24,10 +26,20 @@ if [ ! -d ~/.cache/nimbus/BeaconNode/${NETWORK_NAME}/validators ]; then
$BEACON_NODE_BIN --network=$NETWORK_NAME importValidator $BEACON_NODE_BIN --network=$NETWORK_NAME importValidator
fi fi
# simple wrapper script
BEACON_NODE_SCRIPT="scripts/${NETWORK_NAME}.sh"
cat > "$BEACON_NODE_SCRIPT" <<EOF
#!/bin/bash
cd \$(dirname "\$0")/..
../../env.sh $BEACON_NODE_BIN "\$@"
EOF
chmod 755 "$BEACON_NODE_SCRIPT"
echo echo
echo "Done! You're now ready to connect to $NETWORK_NAME by running:" echo "Done! You're now ready to connect to $NETWORK_NAME by running:"
echo echo
echo " $BEACON_NODE_BIN" echo " $BEACON_NODE_SCRIPT"
echo echo
echo "Database and configuration files will be placed in:" echo "Database and configuration files will be placed in:"
echo echo