From c98081438fac84d2e80deae28f92a74d47f3dbb8 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 10 Aug 2015 23:49:46 +0200 Subject: [PATCH 1/3] Fix an error in a type resolution SOL test This will also fix the build. --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index ba5a5a60f..3daabc85e 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1906,7 +1906,7 @@ BOOST_AUTO_TEST_CASE(reference_compare_operators) )"; BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode1), TypeError); char const* sourceCode2 = R"( - contract test { struct s {uint a;}; s x; s y; function() { x == y; } } + contract test { struct s {uint a;} s x; s y; function() { x == y; } } )"; BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode2), TypeError); } From 9d0204f8962d2cc02d977754d67b28e5ceb90fcc Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 10 Aug 2015 14:39:04 +0200 Subject: [PATCH 2/3] Add a JS console command for exiting the client The function is web3.admin.eth.exit() --- eth/main.cpp | 22 +++++++++------------ libethereum/Client.cpp | 6 ++++++ libethereum/Client.h | 5 +++++ libjsqrc/admin.js | 5 +++++ libweb3jsonrpc/WebThreeStubServerBase.cpp | 8 ++++++++ libweb3jsonrpc/WebThreeStubServerBase.h | 1 + libweb3jsonrpc/abstractwebthreestubserver.h | 6 ++++++ libweb3jsonrpc/spec.json | 1 + test/libweb3jsonrpc/webthreestubclient.h | 10 ++++++++++ 9 files changed, 51 insertions(+), 13 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index 8b41c73e1..988e2c885 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -219,8 +219,6 @@ string pretty(h160 _a, dev::eth::State const& _st) return ns; } -bool g_exit = false; - inline bool isPrime(unsigned _number) { if (((!(_number & 1)) && _number != 2 ) || (_number < 2) || (_number % 3 == 0 && _number != 3)) @@ -231,11 +229,6 @@ inline bool isPrime(unsigned _number) return true; } -void sighandler(int) -{ - g_exit = true; -} - enum class NodeMode { PeerServer, @@ -1028,9 +1021,9 @@ int main(int argc, char** argv) if (!remoteHost.empty()) web3.addNode(p2p::NodeId(), remoteHost + ":" + toString(remotePort)); - signal(SIGABRT, &sighandler); - signal(SIGTERM, &sighandler); - signal(SIGINT, &sighandler); + signal(SIGABRT, &Client::exitHandler); + signal(SIGTERM, &Client::exitHandler); + signal(SIGINT, &Client::exitHandler); if (c) { @@ -1044,17 +1037,20 @@ int main(int argc, char** argv) shared_ptr rpcServer = make_shared(*console.connector(), web3, make_shared([&](){ return web3.ethereum(); }, getAccountPassword, keyManager), vector(), keyManager, *gasPricer); string sessionKey = rpcServer->newSession(SessionPermissions{{Privilege::Admin}}); console.eval("web3.admin.setSessionKey('" + sessionKey + "')"); - while (console.readExpression()) + while (!Client::shouldExit()) + { + console.readExpression(); stopMiningAfterXBlocks(c, n, mining); + } rpcServer->StopListening(); #endif } else - while (!g_exit) + while (!Client::shouldExit()) stopMiningAfterXBlocks(c, n, mining); } else - while (!g_exit) + while (!Client::shouldExit()) this_thread::sleep_for(chrono::milliseconds(1000)); #if ETH_JSONRPC diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 4a46c16ea..aed6f60d6 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -67,6 +67,12 @@ const char* ClientTrace::name() { return EthTeal "⧫" EthGray " ◎"; } const char* ClientDetail::name() { return EthTeal "⧫" EthCoal " ●"; } #endif +bool Client::s_shouldExit = false; +void Client::exitHandler(int) +{ + s_shouldExit = true; +} + static const Addresses c_canaries = { Address("4bb7e8ae99b645c2b7860b8f3a2328aae28bd80a"), // gav diff --git a/libethereum/Client.h b/libethereum/Client.h index 3c8d08b23..4c5afc652 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -121,6 +121,8 @@ public: BlockQueue const& blockQueue() const { return m_bq; } /// Get the block queue. OverlayDB const& stateDB() const { return m_stateDB; } + /// Handles a request to exit the client with a specific signal + static void exitHandler(int signal); /// Freeze worker thread and sync some of the block queue. std::tuple syncQueue(unsigned _max = 1); @@ -144,6 +146,8 @@ public: /// Enable/disable precomputing of the DAG for next epoch void setShouldPrecomputeDAG(bool _precompute); + /// Check to see if we should exit + static bool shouldExit() { return s_shouldExit; } /// Check to see if we'd mine on an apparently bad chain. bool mineOnBadChain() const { return m_mineOnBadChain; } /// Set true if you want to mine even when the canary says you're on the wrong chain. @@ -324,6 +328,7 @@ protected: bool m_forceMining = false; ///< Mine even when there are no transactions pending? bool m_mineOnBadChain = false; ///< Mine even when the canary says it's a bad chain. bool m_paranoia = false; ///< Should we be paranoid about our state? + static bool s_shouldExit; ///< Exit requested? mutable std::chrono::system_clock::time_point m_lastGarbageCollection; ///< When did we last both doing GC on the watches? diff --git a/libjsqrc/admin.js b/libjsqrc/admin.js index 61a13af14..3aaebdee3 100644 --- a/libjsqrc/admin.js +++ b/libjsqrc/admin.js @@ -35,6 +35,11 @@ web3._extend({ call: 'admin_eth_blockQueueStatus', inputFormatter: [getSessionKey], params: 1 + }), new web3._extend.Method({ + name: 'eth.exit', + call: 'admin_eth_exit', + inputFormatter: [getSessionKey], + params: 1 }), new web3._extend.Method({ name: 'net.nodeInfo', call: 'admin_net_nodeInfo', diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 3f4f56bb4..193a795a6 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -23,6 +23,7 @@ #include "WebThreeStubServerBase.h" +#include // Make sure boost/asio.hpp is included before windows.h. #include @@ -575,6 +576,13 @@ Json::Value WebThreeStubServerBase::admin_net_nodeInfo(const string& _session) return ret; } +bool WebThreeStubServerBase::admin_eth_exit(string const& _session) +{ + ADMIN; + Client::exitHandler(SIGTERM); + return true; +} + bool WebThreeStubServerBase::admin_eth_setMining(bool _on, std::string const& _session) { ADMIN; diff --git a/libweb3jsonrpc/WebThreeStubServerBase.h b/libweb3jsonrpc/WebThreeStubServerBase.h index 98eff9b6e..fabb9dde1 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.h +++ b/libweb3jsonrpc/WebThreeStubServerBase.h @@ -167,6 +167,7 @@ public: virtual Json::Value admin_net_peers(std::string const& _session); virtual Json::Value admin_net_nodeInfo(std::string const& _session); + virtual bool admin_eth_exit(std::string const& _session); virtual bool admin_eth_setMining(bool _on, std::string const& _session); virtual Json::Value admin_eth_blockQueueStatus(std::string const& _session) { (void)_session; return Json::Value(); } virtual bool admin_eth_setAskPrice(std::string const& _wei, std::string const& _session) { (void)_wei; (void)_session; return false; } diff --git a/libweb3jsonrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h index be047c08a..6ae546931 100644 --- a/libweb3jsonrpc/abstractwebthreestubserver.h +++ b/libweb3jsonrpc/abstractwebthreestubserver.h @@ -85,6 +85,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerbindAndAddMethod(jsonrpc::Procedure("admin_net_peers", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::admin_net_peersI); this->bindAndAddMethod(jsonrpc::Procedure("admin_eth_blockQueueStatus", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::admin_eth_blockQueueStatusI); this->bindAndAddMethod(jsonrpc::Procedure("admin_net_nodeInfo", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::admin_net_nodeInfoI); + this->bindAndAddMethod(jsonrpc::Procedure("admin_eth_exit", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::admin_eth_exitI); this->bindAndAddMethod(jsonrpc::Procedure("admin_eth_setAskPrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::admin_eth_setAskPriceI); this->bindAndAddMethod(jsonrpc::Procedure("admin_eth_setBidPrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::admin_eth_setBidPriceI); this->bindAndAddMethod(jsonrpc::Procedure("admin_eth_setReferencePrice", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::admin_eth_setReferencePriceI); @@ -412,6 +413,10 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServeradmin_net_nodeInfo(request[0u].asString()); } + inline virtual void admin_eth_exitI(const Json::Value &request, Json::Value &response) + { + response = this->admin_eth_exit(request[0u].asString()); + } inline virtual void admin_eth_setAskPriceI(const Json::Value &request, Json::Value &response) { response = this->admin_eth_setAskPrice(request[0u].asString(), request[1u].asString()); @@ -549,6 +554,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerCallMethod("admin_eth_exit",p); + if (result.isBool()) + return result.asBool(); + else + throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); + } bool admin_eth_setAskPrice(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) { Json::Value p; From fe15d3e0c82d79476ec5032641c10e6ae36a6081 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 10 Aug 2015 22:37:47 +0200 Subject: [PATCH 3/3] Remove quit functionality from readConsole Is now superseded by web3.admin.eth.exit() --- libjsconsole/JSConsole.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libjsconsole/JSConsole.h b/libjsconsole/JSConsole.h index 393f7080f..da045a6f8 100644 --- a/libjsconsole/JSConsole.h +++ b/libjsconsole/JSConsole.h @@ -41,7 +41,7 @@ public: JSConsole(): m_engine(Engine()), m_printer(Printer(m_engine)) {} ~JSConsole() {} - bool readExpression() const + void readExpression() const { std::string cmd = ""; g_logPost = [](std::string const& a, char const*) @@ -83,9 +83,6 @@ public: } } while (openBrackets > 0); - if (cmd == "quit") - return false; - if (!isEmpty) { #if ETH_READLINE @@ -95,7 +92,6 @@ public: std::string result = m_printer.prettyPrint(value).cstr(); std::cout << result << std::endl; } - return true; } void eval(std::string const& _expression) { m_engine.eval(_expression.c_str()); }