diff --git a/Makefile b/Makefile index 2a33fa060..5dead2fb6 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,9 @@ build: nat-libs: | deps + $(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 # in a Makefile recipe but works when prefixing it with `bash`. No idea how the PATH is overridden. test: | build deps nat-libs @@ -50,7 +53,7 @@ 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 -testnet0 testnet1: | build deps nat-libs +testnet0 testnet1: | build deps nat-libs p2pd ../../env.sh scripts/build_testnet_node.sh $@ clean-testnet0: diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index 0a15ba535..90f65b9d1 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -723,6 +723,15 @@ when isMainModule: if config.logLevel != LogLevel.NONE: 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 of createTestnet: var deposits: seq[Deposit] diff --git a/beacon_chain/eth2_network.nim b/beacon_chain/eth2_network.nim index ee6d9d960..9d7cedb79 100644 --- a/beacon_chain/eth2_network.nim +++ b/beacon_chain/eth2_network.nim @@ -166,6 +166,8 @@ else: template tcpEndPoint(address, port): auto = MultiAddress.init(address, Protocol.IPPROTO_TCP, port) + var mainDaemon: DaemonAPI + proc createEth2Node*(conf: BeaconNodeConf): Future[Eth2Node] {.async.} = var (extIp, extTcpPort, extUdpPort) = setupNat(conf) @@ -174,13 +176,18 @@ else: else: @[tcpEndPoint(extIp, extTcpPort)] keyFile = conf.ensureNetworkIdFile - info "Starting LibP2P deamon", hostAddress, announcedAddresses, keyFile - let daemon = await newDaemonApi({PSGossipSub}, - id = keyFile, - hostAddresses = @[hostAddress], - announcedAddresses = announcedAddresses) + info "Starting the LibP2P daemon", hostAddress, announcedAddresses, keyFile + mainDaemon = await newDaemonApi({PSGossipSub}, + id = keyFile, + hostAddresses = @[hostAddress], + 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, ip: IpAddress, port: Port): BootstrapAddr = diff --git a/scripts/build_testnet_node.sh b/scripts/build_testnet_node.sh index a3b2a84c2..aca85b819 100755 --- a/scripts/build_testnet_node.sh +++ b/scripts/build_testnet_node.sh @@ -27,7 +27,7 @@ fi echo echo "Done! You're now ready to connect to $NETWORK_NAME by running:" echo -echo " $BEACON_NODE_BIN" +echo " ../../env.sh $BEACON_NODE_BIN" echo echo "Database and configuration files will be placed in:" echo