From ed2c73d0231cef3ce9d722ea10ac8ede8e965c53 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 23 Apr 2015 14:40:42 +0200 Subject: [PATCH 1/6] json output for the commandline compiler. --- solc/CommandLineInterface.cpp | 101 ++++++++++++++++++++++++++++++---- solc/CommandLineInterface.h | 1 + 2 files changed, 90 insertions(+), 12 deletions(-) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 182015709..2d8720371 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -27,6 +27,7 @@ #include #include +#include #include "BuildInfo.h" #include @@ -50,6 +51,7 @@ namespace dev namespace solidity { + // LTODO: Maybe some argument class pairing names with // extensions and other attributes would be a better choice here? static string const g_argAbiStr = "json-abi"; @@ -64,6 +66,18 @@ static string const g_argNatspecDevStr = "natspec-dev"; static string const g_argNatspecUserStr = "natspec-user"; static string const g_argAddStandard = "add-std"; +/// Possible arguments to for --combined-json +static set const g_combinedJsonArgs{ + "binary", + "opcodes", + "json-abi", + "sol-abi", + "asm", + "ast", + "natspec-user", + "natspec-dev" +}; + static void version() { cout << "solc, the solidity compiler commandline interface " << dev::Version << endl @@ -72,24 +86,24 @@ static void version() exit(0); } -static inline bool argToStdout(po::variables_map const& _args, string const& _name) +static inline bool humanTargetedStdout(po::variables_map const& _args, string const& _name) { return _args.count(_name) && _args[_name].as() != OutputType::FILE; } -static bool needStdout(po::variables_map const& _args) +static bool needsHumanTargetedStdout(po::variables_map const& _args) { return - argToStdout(_args, g_argAbiStr) || - argToStdout(_args, g_argSolAbiStr) || - argToStdout(_args, g_argNatspecUserStr) || - argToStdout(_args, g_argAstJson) || - argToStdout(_args, g_argNatspecDevStr) || - argToStdout(_args, g_argAsmStr) || - argToStdout(_args, g_argAsmJsonStr) || - argToStdout(_args, g_argOpcodesStr) || - argToStdout(_args, g_argBinaryStr); + humanTargetedStdout(_args, g_argAbiStr) || + humanTargetedStdout(_args, g_argSolAbiStr) || + humanTargetedStdout(_args, g_argNatspecUserStr) || + humanTargetedStdout(_args, g_argAstJson) || + humanTargetedStdout(_args, g_argNatspecDevStr) || + humanTargetedStdout(_args, g_argAsmStr) || + humanTargetedStdout(_args, g_argAsmJsonStr) || + humanTargetedStdout(_args, g_argOpcodesStr) || + humanTargetedStdout(_args, g_argBinaryStr); } static inline bool outputToFile(OutputType type) @@ -220,6 +234,11 @@ bool CommandLineInterface::parseArguments(int argc, char** argv) ("optimize", po::value()->default_value(false), "Optimize bytecode for size") ("add-std", po::value()->default_value(false), "Add standard contracts") ("input-file", po::value>(), "input file") + ( + "combined-json", + po::value()->value_name(boost::join(g_combinedJsonArgs, ",")), + "Output a single json document containing the specified information, can be combined." + ) (g_argAstStr.c_str(), po::value()->value_name("stdout|file|both"), "Request to output the AST of the contract.") (g_argAstJson.c_str(), po::value()->value_name("stdout|file|both"), @@ -255,6 +274,16 @@ bool CommandLineInterface::parseArguments(int argc, char** argv) cout << _exception.what() << endl; return false; } + if (m_args.count("combined-json")) + { + vector requests; + for (string const& item: boost::split(requests, m_args["combined-json"].as(), boost::is_any_of(","))) + if (!g_combinedJsonArgs.count(item)) + { + cout << "Invalid option to --combined-json: " << item << endl; + return false; + } + } po::notify(m_args); if (m_args.count("help")) @@ -350,6 +379,52 @@ bool CommandLineInterface::processInput() return true; } +void CommandLineInterface::handleCombinedJSON() +{ + Json::Value output(Json::objectValue); + + set requests; + boost::split(requests, m_args["combined-json"].as(), boost::is_any_of(",")); + vector contracts = m_compiler->getContractNames(); + + if (!contracts.empty()) + output["contracts"] = Json::Value(Json::objectValue); + for (string const& contractName: contracts) + { + Json::Value contractData(Json::objectValue); + if (requests.count("sol-abi")) + contractData["sol-abi"] = m_compiler->getSolidityInterface(contractName); + if (requests.count("json-abi")) + contractData["json-abi"] = m_compiler->getInterface(contractName); + if (requests.count("binary")) + contractData["binary"] = toHex(m_compiler->getBytecode(contractName)); + if (requests.count("opcodes")) + contractData["opcodes"] = eth::disassemble(m_compiler->getBytecode(contractName)); + if (requests.count("asm")) + { + ostringstream unused; + contractData["asm"] = m_compiler->streamAssembly(unused, contractName, m_sourceCodes, true); + } + if (requests.count("natspec-dev")) + contractData["natspec-dev"] = m_compiler->getMetadata(contractName, DocumentationType::NatspecDev); + if (requests.count("natspec-user")) + contractData["natspec-user"] = m_compiler->getMetadata(contractName, DocumentationType::NatspecUser); + output["contracts"][contractName] = contractData; + } + + if (requests.count("ast")) + { + output["sources"] = Json::Value(Json::objectValue); + for (auto const& sourceCode: m_sourceCodes) + { + ASTJsonConverter converter(m_compiler->getAST(sourceCode.first)); + output["sources"][sourceCode.first] = Json::Value(Json::objectValue); + output["sources"][sourceCode.first]["AST"] = converter.json(); + } + } + cout << Json::FastWriter().write(output) << endl; +} + void CommandLineInterface::handleAst(string const& _argStr) { string title; @@ -408,6 +483,8 @@ void CommandLineInterface::handleAst(string const& _argStr) void CommandLineInterface::actOnInput() { + handleCombinedJSON(); + // do we need AST output? handleAst(g_argAstStr); handleAst(g_argAstJson); @@ -415,7 +492,7 @@ void CommandLineInterface::actOnInput() vector contracts = m_compiler->getContractNames(); for (string const& contract: contracts) { - if (needStdout(m_args)) + if (needsHumanTargetedStdout(m_args)) cout << endl << "======= " << contract << " =======" << endl; // do we need EVM assembly? diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h index 79029f9d1..459f17d3e 100644 --- a/solc/CommandLineInterface.h +++ b/solc/CommandLineInterface.h @@ -53,6 +53,7 @@ public: void actOnInput(); private: + void handleCombinedJSON(); void handleAst(std::string const& _argStr); void handleBinary(std::string const& _contract); void handleOpcode(std::string const& _contract); From 323662c6f3c941c9af9718eaa748e02b764a6dd6 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 23 Apr 2015 15:47:54 +0200 Subject: [PATCH 2/6] Removed extra blank line. --- solc/CommandLineInterface.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 2d8720371..5e4c901f3 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -51,7 +51,6 @@ namespace dev namespace solidity { - // LTODO: Maybe some argument class pairing names with // extensions and other attributes would be a better choice here? static string const g_argAbiStr = "json-abi"; From 87770dad0b0a10d1b626bba56f4a3a63b5dd6bcb Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 23 Apr 2015 17:55:40 +0200 Subject: [PATCH 3/6] More logging stuff. Fixes #1680 --- alethzero/NatspecHandler.cpp | 2 +- eth/main.cpp | 2 +- libdevcore/Log.h | 14 +++++----- libdevcore/Worker.cpp | 23 +++++++++++----- libethereum/BlockChain.cpp | 6 ++--- libethereum/Client.cpp | 32 +++++++++++++---------- libethereum/ClientBase.cpp | 4 +-- libethereum/EthereumHost.cpp | 2 +- libethereum/EthereumPeer.cpp | 14 +++++----- libethereum/State.cpp | 26 +++++++++--------- libethereum/State.h | 2 +- libethereum/TransactionQueue.cpp | 2 +- libp2p/Host.cpp | 16 ++++++------ libp2p/Network.cpp | 2 +- libp2p/NodeTable.cpp | 8 +++--- libp2p/Session.cpp | 6 ++--- libweb3jsonrpc/WebThreeStubServerBase.cpp | 6 ++--- test/libdevcrypto/trie.cpp | 6 ++--- test/libwhisper/whisperTopic.cpp | 10 +++---- 19 files changed, 100 insertions(+), 83 deletions(-) diff --git a/alethzero/NatspecHandler.cpp b/alethzero/NatspecHandler.cpp index ffab6db58..a7cad6853 100644 --- a/alethzero/NatspecHandler.cpp +++ b/alethzero/NatspecHandler.cpp @@ -58,7 +58,7 @@ string NatspecHandler::retrieve(dev::h256 const& _contractHash) const { string ret; m_db->Get(m_readOptions, _contractHash.ref(), &ret); - cdebug << "Looking up NatSpec: " << _contractHash.abridged() << ret; + cdebug << "Looking up NatSpec: " << _contractHash << ret; return ret; } diff --git a/eth/main.cpp b/eth/main.cpp index 2d79f4954..9cc1b6e22 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -517,7 +517,7 @@ int main(int argc, char** argv) bool bootstrap = false; /// Mining params - unsigned mining = ~(unsigned)0; + unsigned mining = 0; bool forceMining = false; KeyPair sigKey = KeyPair::create(); Secret sessionSecret; diff --git a/libdevcore/Log.h b/libdevcore/Log.h index 71c2b3450..f63bf26c2 100644 --- a/libdevcore/Log.h +++ b/libdevcore/Log.h @@ -86,11 +86,12 @@ struct WarnChannel: public LogChannel { static const char* name(); static const struct NoteChannel: public LogChannel { static const char* name(); }; struct DebugChannel: public LogChannel { static const char* name(); static const int verbosity = 0; }; -enum LogTag +enum class LogTag { None, - url, - error + Url, + Error, + Special }; class LogOutputStreamBase @@ -102,12 +103,13 @@ public: { switch (m_logTag) { - case url: m_sstr << EthNavyUnder; break; - case error: m_sstr << EthRedBold; break; + case LogTag::Url: m_sstr << EthNavyUnder; break; + case LogTag::Error: m_sstr << EthRedBold; break; + case LogTag::Special: m_sstr << EthWhiteBold; break; default:; } m_sstr << _t << EthReset; - m_logTag = None; + m_logTag = LogTag::None; } void append(unsigned long _t) { m_sstr << EthBlue << _t << EthReset; } diff --git a/libdevcore/Worker.cpp b/libdevcore/Worker.cpp index 7fe320420..a68c18958 100644 --- a/libdevcore/Worker.cpp +++ b/libdevcore/Worker.cpp @@ -29,18 +29,25 @@ using namespace dev; void Worker::startWorking() { -// cnote << "startWorking for thread" << m_name; + cnote << "startWorking for thread" << m_name; Guard l(x_work); - m_state = WorkerState::Starting; - if (!m_work) + if (m_work) { + WorkerState ex = WorkerState::Stopped; + m_state.compare_exchange_strong(ex, WorkerState::Starting); + } + else + { + m_state = WorkerState::Starting; m_work.reset(new thread([&]() { setThreadName(m_name.c_str()); + cnote << "Thread begins"; while (m_state != WorkerState::Killing) { WorkerState ex = WorkerState::Starting; - m_state.compare_exchange_strong(ex, WorkerState::Started); + bool ok = m_state.compare_exchange_strong(ex, WorkerState::Started); + cnote << "Trying to set Started: Thread was" << (unsigned)ex << "; " << ok; startedWorking(); cnote << "Entering work loop..."; @@ -52,22 +59,25 @@ void Worker::startWorking() // m_state.compare_exchange_strong(ex, WorkerState::Stopped); ex = m_state.exchange(WorkerState::Stopped); - if (ex == WorkerState::Killing) + cnote << "State: Stopped: Thread was" << (unsigned)ex; + if (ex == WorkerState::Killing || ex == WorkerState::Starting) m_state.exchange(ex); + cnote << "Waiting until not Stopped..."; while (m_state == WorkerState::Stopped) this_thread::sleep_for(chrono::milliseconds(20)); } })); cnote << "Spawning" << m_name; } + cnote << "Waiting until Started..."; while (m_state != WorkerState::Started) this_thread::sleep_for(chrono::microseconds(20)); } void Worker::stopWorking() { -// cnote << "stopWorking for thread" << m_name; + cnote << "stopWorking for thread" << m_name; ETH_GUARDED(x_work) if (m_work) { @@ -75,6 +85,7 @@ void Worker::stopWorking() WorkerState ex = WorkerState::Started; m_state.compare_exchange_strong(ex, WorkerState::Stopping); + cnote << "Waiting until Stopped..."; while (m_state != WorkerState::Stopped) this_thread::sleep_for(chrono::microseconds(20)); } diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index fbc92a863..f9c21752d 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -320,14 +320,14 @@ tuple BlockChain::sync(BlockQueue& _bq, OverlayDB const& _st } catch (dev::eth::UnknownParent) { - cwarn << "ODD: Import queue contains block with unknown parent." << error << boost::current_exception_diagnostic_information(); + cwarn << "ODD: Import queue contains block with unknown parent." << LogTag::Error << boost::current_exception_diagnostic_information(); // NOTE: don't reimport since the queue should guarantee everything in the right order. // Can't continue - chain bad. badBlocks.push_back(BlockInfo::headerHash(block)); } catch (Exception const& _e) { - cnote << "Exception while importing block. Someone (Jeff? That you?) seems to be giving us dodgy blocks!" << error << diagnostic_information(_e); + cnote << "Exception while importing block. Someone (Jeff? That you?) seems to be giving us dodgy blocks!" << LogTag::Error << diagnostic_information(_e); // NOTE: don't reimport since the queue should guarantee everything in the right order. // Can't continue - chain bad. badBlocks.push_back(BlockInfo::headerHash(block)); @@ -611,7 +611,7 @@ ImportRoute BlockChain::import(bytes const& _block, OverlayDB const& _db, Import m_extrasDB->Put(m_writeOptions, ldb::Slice("best"), ldb::Slice((char const*)&(bi.hash()), 32)); } - clog(BlockChainNote) << " Imported and best" << td << " (#" << bi.number << "). Has" << (details(bi.parentHash).children.size() - 1) << "siblings. Route:" << toString(route); + clog(BlockChainNote) << " Imported and best" << td << " (#" << bi.number << "). Has" << (details(bi.parentHash).children.size() - 1) << "siblings. Route:" << route; noteCanonChanged(); StructuredLogger::chainNewHead( diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 408f8ebca..675999a13 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -291,24 +291,23 @@ void Client::clearPending() noteChanged(changeds); } -template -static string filtersToString(T const& _fs) +template +static S& filtersStreamOut(S& _out, T const& _fs) { - stringstream ret; - ret << "{"; + _out << "{"; unsigned i = 0; for (h256 const& f: _fs) { - ret << (i++ ? ", " : ""); + _out << (i++ ? ", " : ""); if (f == PendingChangedFilter) - ret << url << "pending"; + _out << LogTag::Special << "pending"; else if (f == ChainChangedFilter) - ret << url << "chain"; + _out << LogTag::Special << "chain"; else - ret << f; + _out << f; } - ret << "}"; - return ret.str(); + _out << "}"; + return _out; } void Client::appendFromNewPending(TransactionReceipt const& _receipt, h256Set& io_changed, h256 _transactionHash) @@ -572,16 +571,21 @@ void Client::noteChanged(h256Set const& _filters) { Guard l(x_filtersWatches); if (_filters.size()) - cnote << "noteChanged(" << filtersToString(_filters) << ")"; + filtersStreamOut(cnote << "noteChanged:", _filters); // accrue all changes left in each filter into the watches. for (auto& w: m_watches) if (_filters.count(w.second.id)) { - cwatch << "!!!" << w.first << (m_filters.count(w.second.id) ? w.second.id.abridged() : w.second.id == PendingChangedFilter ? "pending" : w.second.id == ChainChangedFilter ? "chain" : "???"); - if (m_filters.count(w.second.id)) // Normal filtering watch + if (m_filters.count(w.second.id)) + { + cwatch << "!!!" << w.first << w.second.id.abridged(); w.second.changes += m_filters.at(w.second.id).changes; - else // Special ('pending'/'latest') watch + } + else + { + cwatch << "!!!" << w.first << LogTag::Special << (w.second.id == PendingChangedFilter ? "pending" : w.second.id == ChainChangedFilter ? "chain" : "???"); w.second.changes.push_back(LocalisedLogEntry(SpecialLogEntry, 0)); + } } // clear the filters now. for (auto& i: m_filters) diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 6092879b9..ac1b09ab0 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -226,7 +226,7 @@ unsigned ClientBase::installWatch(LogFilter const& _f, Reaping _r) Guard l(x_filtersWatches); if (!m_filters.count(h)) { - cwatch << "FFF" << _f << h.abridged(); + cwatch << "FFF" << _f << h; m_filters.insert(make_pair(h, _f)); } } @@ -240,7 +240,7 @@ unsigned ClientBase::installWatch(h256 _h, Reaping _r) Guard l(x_filtersWatches); ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0; m_watches[ret] = ClientWatch(_h, _r); - cwatch << "+++" << ret << _h.abridged(); + cwatch << "+++" << ret << _h; } #if INITIAL_STATE_AS_CHANGES auto ch = logs(ret); diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index fde2ae745..c98dd7642 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -61,7 +61,7 @@ bool EthereumHost::ensureInitialised() { // First time - just initialise. m_latestBlockSent = m_chain.currentHash(); - clog(NetNote) << "Initialising: latest=" << m_latestBlockSent.abridged(); + clog(NetNote) << "Initialising: latest=" << m_latestBlockSent; for (auto const& i: m_tq.transactions()) m_transactionsSent.insert(i.first); diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index d730771a0..f3edaf8ea 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -134,7 +134,7 @@ void EthereumPeer::transition(Asking _a, bool _force) clog(NetWarn) << "Bad state: asking for Hashes yet not syncing!"; if (shouldGrabBlocks()) { - clog(NetNote) << "Difficulty of hashchain HIGHER. Grabbing" << m_syncingNeededBlocks.size() << "blocks [latest now" << m_syncingLatestHash.abridged() << ", was" << host()->m_latestBlockSent.abridged() << "]"; + clog(NetNote) << "Difficulty of hashchain HIGHER. Grabbing" << m_syncingNeededBlocks.size() << "blocks [latest now" << m_syncingLatestHash << ", was" << host()->m_latestBlockSent << "]"; host()->m_man.resetToChain(m_syncingNeededBlocks); // host()->m_latestBlockSent = m_syncingLatestHash; @@ -253,7 +253,7 @@ bool EthereumPeer::shouldGrabBlocks() const if (m_syncingNeededBlocks.empty()) return false; - clog(NetNote) << "Should grab blocks? " << td << "vs" << ctd << ";" << m_syncingNeededBlocks.size() << " blocks, ends" << m_syncingNeededBlocks.back().abridged(); + clog(NetNote) << "Should grab blocks? " << td << "vs" << ctd << ";" << m_syncingNeededBlocks.size() << " blocks, ends" << m_syncingNeededBlocks.back(); if (td < ctd || (td == ctd && host()->m_chain.currentHash() == lh)) return false; @@ -280,7 +280,7 @@ void EthereumPeer::attemptSync() unsigned n = host()->m_chain.number(); u256 td = host()->m_chain.details().totalDifficulty; - clog(NetAllDetail) << "Attempt chain-grab? Latest:" << c.abridged() << ", number:" << n << ", TD:" << td << " versus " << m_totalDifficulty; + clog(NetAllDetail) << "Attempt chain-grab? Latest:" << c << ", number:" << n << ", TD:" << td << " versus " << m_totalDifficulty; if (td >= m_totalDifficulty) { clog(NetAllDetail) << "No. Our chain is better."; @@ -310,7 +310,7 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r) m_latestHash = _r[3].toHash(); auto genesisHash = _r[4].toHash(); - clog(NetMessageSummary) << "Status:" << m_protocolVersion << "/" << m_networkId << "/" << genesisHash.abridged() << ", TD:" << m_totalDifficulty << "=" << m_latestHash.abridged(); + clog(NetMessageSummary) << "Status:" << m_protocolVersion << "/" << m_networkId << "/" << genesisHash << ", TD:" << m_totalDifficulty << "=" << m_latestHash; if (genesisHash != host()->m_chain.genesisHash()) disable("Invalid genesis hash"); @@ -358,7 +358,7 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r) { h256 later = _r[0].toHash(); unsigned limit = _r[1].toInt(); - clog(NetMessageSummary) << "GetBlockHashes (" << limit << "entries," << later.abridged() << ")"; + clog(NetMessageSummary) << "GetBlockHashes (" << limit << "entries," << later << ")"; unsigned c = min(host()->m_chain.number(later), limit); @@ -413,7 +413,7 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r) knowns++; m_syncingLastReceivedHash = h; } - clog(NetMessageSummary) << knowns << "knowns," << unknowns << "unknowns; now at" << m_syncingLastReceivedHash.abridged(); + clog(NetMessageSummary) << knowns << "knowns," << unknowns << "unknowns; now at" << m_syncingLastReceivedHash; // run through - ask for more. transition(Asking::Hashes); break; @@ -526,7 +526,7 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r) case NewBlockPacket: { auto h = BlockInfo::headerHash(_r[0].data()); - clog(NetMessageSummary) << "NewBlock: " << h.abridged(); + clog(NetMessageSummary) << "NewBlock: " << h; if (_r.itemCount() != 2) disable("NewBlock without 2 data fields."); diff --git a/libethereum/State.cpp b/libethereum/State.cpp index ea2834cc1..d5a54985e 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -329,7 +329,7 @@ bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi, Impor if (m_db.lookup(bi.stateRoot).empty()) { - cwarn << "Unable to sync to" << bi.hash().abridged() << "; state root" << bi.stateRoot.abridged() << "not found in database."; + cwarn << "Unable to sync to" << bi.hash() << "; state root" << bi.stateRoot << "not found in database."; cwarn << "Database corrupt: contains block without stateRoot:" << bi; cwarn << "Bailing."; exit(-1); @@ -500,7 +500,7 @@ pair State::sync(BlockChain const& _bc, TransactionQu else if (i.second.gasPrice() < _gp.ask(*this) * 9 / 10) { // less than 90% of our ask price for gas. drop. - cnote << i.first.abridged() << "Dropping El Cheapo transaction (<90% of ask price)"; + cnote << i.first << "Dropping El Cheapo transaction (<90% of ask price)"; _tq.drop(i.first); } } @@ -512,13 +512,13 @@ pair State::sync(BlockChain const& _bc, TransactionQu if (req > got) { // too old - cnote << i.first.abridged() << "Dropping old transaction (nonce too low)"; + cnote << i.first << "Dropping old transaction (nonce too low)"; _tq.drop(i.first); } else if (got > req + 5) { // too new - cnote << i.first.abridged() << "Dropping new transaction (> 5 nonces ahead)"; + cnote << i.first << "Dropping new transaction (> 5 nonces ahead)"; _tq.drop(i.first); } else @@ -529,7 +529,7 @@ pair State::sync(BlockChain const& _bc, TransactionQu bigint const& got = *boost::get_error_info(e); if (got > m_currentBlock.gasLimit) { - cnote << i.first.abridged() << "Dropping over-gassy transaction (gas > block's gas limit)"; + cnote << i.first << "Dropping over-gassy transaction (gas > block's gas limit)"; _tq.drop(i.first); } else @@ -538,14 +538,14 @@ pair State::sync(BlockChain const& _bc, TransactionQu catch (Exception const& _e) { // Something else went wrong - drop it. - cnote << i.first.abridged() << "Dropping invalid transaction:" << diagnostic_information(_e); + cnote << i.first << "Dropping invalid transaction:" << diagnostic_information(_e); _tq.drop(i.first); } catch (std::exception const&) { // Something else went wrong - drop it. _tq.drop(i.first); - cnote << i.first.abridged() << "Transaction caused low-level exception :("; + cnote << i.first << "Transaction caused low-level exception :("; } } if (chrono::steady_clock::now() > deadline) @@ -709,15 +709,15 @@ void State::cleanup(bool _fullCommit) paranoia("immediately before database commit", true); // Commit the new trie to disk. - clog(StateTrace) << "Committing to disk: stateRoot" << m_currentBlock.stateRoot.abridged() << "=" << rootHash().abridged() << "=" << toHex(asBytes(m_db.lookup(rootHash()))); + clog(StateTrace) << "Committing to disk: stateRoot" << m_currentBlock.stateRoot << "=" << rootHash() << "=" << toHex(asBytes(m_db.lookup(rootHash()))); m_db.commit(); - clog(StateTrace) << "Committed: stateRoot" << m_currentBlock.stateRoot.abridged() << "=" << rootHash().abridged() << "=" << toHex(asBytes(m_db.lookup(rootHash()))); + clog(StateTrace) << "Committed: stateRoot" << m_currentBlock.stateRoot << "=" << rootHash() << "=" << toHex(asBytes(m_db.lookup(rootHash()))); paranoia("immediately after database commit", true); m_previousBlock = m_currentBlock; m_currentBlock.populateFromParent(m_previousBlock); - clog(StateTrace) << "finalising enactment. current -> previous, hash is" << m_previousBlock.hash().abridged(); + clog(StateTrace) << "finalising enactment. current -> previous, hash is" << m_previousBlock.hash(); } else m_db.rollback(); @@ -789,7 +789,7 @@ void State::commitToMine(BlockChain const& _bc) { uncommitToMine(); -// cnote << "Committing to mine on block" << m_previousBlock.hash.abridged(); +// cnote << "Committing to mine on block" << m_previousBlock.hash; #if ETH_PARANOIA && 0 commit(); cnote << "Pre-reward stateRoot:" << m_state.root(); @@ -866,7 +866,7 @@ void State::commitToMine(BlockChain const& _bc) // Commit any and all changes to the trie that are in the cache, then update the state root accordingly. commit(); -// cnote << "Post-reward stateRoot:" << m_state.root().abridged(); +// cnote << "Post-reward stateRoot:" << m_state.root(); // cnote << m_state; // cnote << *this; @@ -890,7 +890,7 @@ void State::completeMine() ret.appendRaw(m_currentUncles); ret.swapOut(m_currentBytes); m_currentBlock.noteDirty(); - cnote << "Mined " << m_currentBlock.hash().abridged() << "(parent: " << m_currentBlock.parentHash.abridged() << ")"; + cnote << "Mined " << m_currentBlock.hash() << "(parent: " << m_currentBlock.parentHash << ")"; StructuredLogger::minedNewBlock( m_currentBlock.hash().abridged(), m_currentBlock.nonce.abridged(), diff --git a/libethereum/State.h b/libethereum/State.h index 85ca30649..d02521c7a 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -174,7 +174,7 @@ public: PoW::assignResult(_result, m_currentBlock); - cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce).abridged() << m_currentBlock.nonce.abridged() << m_currentBlock.difficulty << PoW::verify(m_currentBlock); + cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce) << m_currentBlock.nonce << m_currentBlock.difficulty << PoW::verify(m_currentBlock); completeMine(); diff --git a/libethereum/TransactionQueue.cpp b/libethereum/TransactionQueue.cpp index a4eb5cee8..40eec1ac5 100644 --- a/libethereum/TransactionQueue.cpp +++ b/libethereum/TransactionQueue.cpp @@ -57,7 +57,7 @@ ImportResult TransactionQueue::import(bytesConstRef _transactionRLP, ImportCallb m_known.insert(h); if (_cb) m_callbacks[h] = _cb; - ctxq << "Queued vaguely legit-looking transaction" << h.abridged(); + ctxq << "Queued vaguely legit-looking transaction" << h; m_onReady(); } catch (Exception const& _e) diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index fff718295..b7a3a929a 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -204,7 +204,7 @@ void Host::startPeerSession(Public const& _id, RLP const& _rlp, RLPXFrameIO* _io stringstream capslog; for (auto cap: caps) capslog << "(" << cap.first << "," << dec << cap.second << ")"; - clog(NetMessageSummary) << "Hello: " << clientVersion << "V[" << protocolVersion << "]" << _id.abridged() << showbase << capslog.str() << dec << listenPort; + clog(NetMessageSummary) << "Hello: " << clientVersion << "V[" << protocolVersion << "]" << _id << showbase << capslog.str() << dec << listenPort; // create session so disconnects are managed auto ps = make_shared(this, _io, p, PeerSessionInfo({_id, clientVersion, _endpoint.address().to_string(), listenPort, chrono::steady_clock::duration(), _rlp[2].toSet(), 0, map()})); @@ -221,7 +221,7 @@ void Host::startPeerSession(Public const& _id, RLP const& _rlp, RLPXFrameIO* _io if(s->isConnected()) { // Already connected. - clog(NetWarn) << "Session already exists for peer with id" << _id.abridged(); + clog(NetWarn) << "Session already exists for peer with id" << _id; ps->disconnect(DuplicatePeer); return; } @@ -238,7 +238,7 @@ void Host::startPeerSession(Public const& _id, RLP const& _rlp, RLPXFrameIO* _io m_sessions[_id] = ps; } - clog(NetNote) << "p2p.host.peer.register" << _id.abridged(); + clog(NetNote) << "p2p.host.peer.register" << _id; StructuredLogger::p2pConnected(_id.abridged(), ps->m_peer->endpoint, ps->m_peer->m_lastConnected, clientVersion, peerCount()); } @@ -466,7 +466,7 @@ void Host::connect(std::shared_ptr const& _p) } bi::tcp::endpoint ep(_p->endpoint); - clog(NetConnect) << "Attempting connection to node" << _p->id.abridged() << "@" << ep << "from" << id().abridged(); + clog(NetConnect) << "Attempting connection to node" << _p->id << "@" << ep << "from" << id(); auto socket = make_shared(new bi::tcp::socket(m_ioService)); socket->ref().async_connect(ep, [=](boost::system::error_code const& ec) { @@ -475,13 +475,13 @@ void Host::connect(std::shared_ptr const& _p) if (ec) { - clog(NetConnect) << "Connection refused to node" << _p->id.abridged() << "@" << ep << "(" << ec.message() << ")"; + clog(NetConnect) << "Connection refused to node" << _p->id << "@" << ep << "(" << ec.message() << ")"; // Manually set error (session not present) _p->m_lastDisconnect = TCPError; } else { - clog(NetConnect) << "Connecting to" << _p->id.abridged() << "@" << ep; + clog(NetConnect) << "Connecting to" << _p->id << "@" << ep; auto handshake = make_shared(this, socket, _p->id); { Guard l(x_connecting); @@ -619,14 +619,14 @@ void Host::startedWorking() runAcceptor(); } else - clog(NetNote) << "p2p.start.notice id:" << id().abridged() << "TCP Listen port is invalid or unavailable."; + clog(NetNote) << "p2p.start.notice id:" << id() << "TCP Listen port is invalid or unavailable."; shared_ptr nodeTable(new NodeTable(m_ioService, m_alias, NodeIPEndpoint(bi::address::from_string(listenAddress()), listenPort(), listenPort()))); nodeTable->setEventHandler(new HostNodeTableHandler(*this)); m_nodeTable = nodeTable; restoreNetwork(&m_restoreNetwork); - clog(NetNote) << "p2p.started id:" << id().abridged(); + clog(NetNote) << "p2p.started id:" << id(); run(boost::system::error_code()); } diff --git a/libp2p/Network.cpp b/libp2p/Network.cpp index 1c780c5e9..de054a178 100644 --- a/libp2p/Network.cpp +++ b/libp2p/Network.cpp @@ -228,7 +228,7 @@ bi::tcp::endpoint Network::resolveHost(string const& _addr) bi::tcp::resolver r(s_resolverIoService); auto it = r.resolve({split[0], toString(port)}, ec); if (ec) - clog(NetWarn) << "Error resolving host address..." << url << _addr << ":" << error << ec.message(); + clog(NetWarn) << "Error resolving host address..." << LogTag::Url << _addr << ":" << LogTag::Error << ec.message(); else ep = *it; } diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 4f81e42b9..e324b8f86 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -87,7 +87,7 @@ shared_ptr NodeTable::addNode(Node const& _node) // we handle when tcp endpoint is 0 below if (_node.endpoint.address.to_string() == "0.0.0.0") { - clog(NodeTableWarn) << "addNode Failed. Invalid UDP address" << url << "0.0.0.0" << "for" << _node.id; + clog(NodeTableWarn) << "addNode Failed. Invalid UDP address" << LogTag::Url << "0.0.0.0" << "for" << _node.id; return move(shared_ptr()); } @@ -326,7 +326,7 @@ void NodeTable::noteActiveNode(Public const& _pubk, bi::udp::endpoint const& _en shared_ptr node = nodeEntry(_pubk); if (!!node && !node->pending) { - clog(NodeTableConnect) << "Noting active node:" << _pubk.abridged() << _endpoint.address().to_string() << ":" << _endpoint.port(); + clog(NodeTableConnect) << "Noting active node:" << _pubk << _endpoint.address().to_string() << ":" << _endpoint.port(); node->endpoint.address = _endpoint.address(); node->endpoint.udpPort = _endpoint.port(); @@ -381,7 +381,7 @@ void NodeTable::dropNode(shared_ptr _n) } // notify host - clog(NodeTableUpdate) << "p2p.nodes.drop " << _n->id.abridged(); + clog(NodeTableUpdate) << "p2p.nodes.drop " << _n->id; if (m_nodeEventHandler) m_nodeEventHandler->appendEvent(_n->id, NodeEntryDropped); } @@ -464,7 +464,7 @@ void NodeTable::onReceived(UDPSocketFace*, bi::udp::endpoint const& _from, bytes return; // unsolicited pong; don't note node as active } - clog(NodeTableConnect) << "PONG from " << nodeid.abridged() << _from; + clog(NodeTableConnect) << "PONG from " << nodeid << _from; break; } diff --git a/libp2p/Session.cpp b/libp2p/Session.cpp index 363953a20..8f395158b 100644 --- a/libp2p/Session.cpp +++ b/libp2p/Session.cpp @@ -138,7 +138,7 @@ void Session::serviceNodesRequest() auto rs = randomSelection(peers, 10); for (auto const& i: rs) { - clog(NetTriviaDetail) << "Sending peer " << i.id.abridged() << i.endpoint; + clog(NetTriviaDetail) << "Sending peer " << i.id << i.endpoint; if (i.endpoint.address.is_v4()) s.appendList(3) << bytesConstRef(i.endpoint.address.to_v4().to_bytes().data(), 4) << i.endpoint.tcpPort << i.id; else// if (i.second.address().is_v6()) - assumed @@ -215,7 +215,7 @@ bool Session::interpret(PacketType _t, RLP const& _r) auto ep = bi::tcp::endpoint(peerAddress, _r[i][1].toInt()); NodeId id = _r[i][2].toHash(); - clog(NetAllDetail) << "Checking: " << ep << "(" << id.abridged() << ")"; + clog(NetAllDetail) << "Checking: " << ep << "(" << id << ")"; if (!isPublicAddress(peerAddress)) goto CONTINUE; // Private address. Ignore. @@ -238,7 +238,7 @@ bool Session::interpret(PacketType _t, RLP const& _r) // OK passed all our checks. Assume it's good. addRating(1000); m_server->addNode(id, NodeIPEndpoint(ep.address(), ep.port(), ep.port())); - clog(NetTriviaDetail) << "New peer: " << ep << "(" << id .abridged()<< ")"; + clog(NetTriviaDetail) << "New peer: " << ep << "(" << id << ")"; CONTINUE:; LAMEPEER:; } diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 212f3728b..7b124a6f2 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -848,7 +848,7 @@ bool WebThreeStubServerBase::shh_post(Json::Value const& _json) Secret from; if (m.from() && m_ids.count(m.from())) { - cwarn << "Silently signing message from identity" << m.from().abridged() << ": User validation hook goes here."; + cwarn << "Silently signing message from identity" << m.from() << ": User validation hook goes here."; // TODO: insert validification hook here. from = m_ids[m.from()]; } @@ -940,7 +940,7 @@ Json::Value WebThreeStubServerBase::shh_getFilterChanges(string const& _filterId shh::Message m; if (pub) { - cwarn << "Silently decrypting message from identity" << pub.abridged() << ": User validation hook goes here."; + cwarn << "Silently decrypting message from identity" << pub << ": User validation hook goes here."; m = e.open(face()->fullTopic(id), m_ids[pub]); } else @@ -973,7 +973,7 @@ Json::Value WebThreeStubServerBase::shh_getMessages(string const& _filterId) shh::Message m; if (pub) { - cwarn << "Silently decrypting message from identity" << pub.abridged() << ": User validation hook goes here."; + cwarn << "Silently decrypting message from identity" << pub << ": User validation hook goes here."; m = e.open(face()->fullTopic(id), m_ids[pub]); } else diff --git a/test/libdevcrypto/trie.cpp b/test/libdevcrypto/trie.cpp index 0e7125624..3b3fa1dd2 100644 --- a/test/libdevcrypto/trie.cpp +++ b/test/libdevcrypto/trie.cpp @@ -522,17 +522,17 @@ BOOST_AUTO_TEST_CASE(trieStess) cwarn << "Good:" << d2.root(); // for (auto i: dm2.get()) -// cwarn << i.first.abridged() << ": " << RLP(i.second); +// cwarn << i.first << ": " << RLP(i.second); d2.debugStructure(cerr); cwarn << "Broken:" << d.root(); // Leaves an extension -> extension (3c1... -> 742...) // for (auto i: dm.get()) -// cwarn << i.first.abridged() << ": " << RLP(i.second); +// cwarn << i.first << ": " << RLP(i.second); d.debugStructure(cerr); d2.insert(k, v); cwarn << "Pres:" << d2.root(); // for (auto i: dm2.get()) -// cwarn << i.first.abridged() << ": " << RLP(i.second); +// cwarn << i.first << ": " << RLP(i.second); d2.debugStructure(cerr); g_logVerbosity = 99; d2.remove(k); diff --git a/test/libwhisper/whisperTopic.cpp b/test/libwhisper/whisperTopic.cpp index 0ea681b67..3caed5c56 100644 --- a/test/libwhisper/whisperTopic.cpp +++ b/test/libwhisper/whisperTopic.cpp @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(topic) if (received.count(last)) continue; received.insert(last); - cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt(); + cnote << "New message from:" << msg.from() << RLP(msg.payload()).toInt(); result += last; } this_thread::sleep_for(chrono::milliseconds(50)); @@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE(forwarding) { Message msg = whost1->envelope(i).open(whost1->fullTopic(w)); unsigned last = RLP(msg.payload()).toInt(); - cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt(); + cnote << "New message from:" << msg.from() << RLP(msg.payload()).toInt(); result = last; } this_thread::sleep_for(chrono::milliseconds(50)); @@ -175,7 +175,7 @@ BOOST_AUTO_TEST_CASE(forwarding) for (auto i: whost2->checkWatch(w)) { Message msg = whost2->envelope(i).open(whost2->fullTopic(w)); - cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt(); + cnote << "New message from:" << msg.from() << RLP(msg.payload()).toInt(); } this_thread::sleep_for(chrono::milliseconds(50)); } @@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) for (auto i: whost1->checkWatch(w)) { Message msg = whost1->envelope(i).open(whost1->fullTopic(w)); - cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt(); + cnote << "New message from:" << msg.from() << RLP(msg.payload()).toInt(); } this_thread::sleep_for(chrono::milliseconds(50)); } @@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) { Message msg = wh->envelope(i).open(wh->fullTopic(w)); unsigned last = RLP(msg.payload()).toInt(); - cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt(); + cnote << "New message from:" << msg.from() << RLP(msg.payload()).toInt(); result = last; } this_thread::sleep_for(chrono::milliseconds(50)); From 39a52ae219dd1a3f94e8bc1e6a51b54913f2a1ca Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 23 Apr 2015 18:23:12 +0200 Subject: [PATCH 4/6] Fix killBlockchain. --- libethereum/Client.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 675999a13..9c8905036 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -237,9 +237,6 @@ void Client::doneWorking() void Client::killChain() { - WriteGuard l(x_postMine); - WriteGuard l2(x_preMine); - bool wasMining = isMining(); if (wasMining) stopMining(); @@ -248,18 +245,21 @@ void Client::killChain() m_tq.clear(); m_bq.clear(); m_farm.stop(); - m_preMine = State(); - m_postMine = State(); -// ETH_WRITE_GUARDED(x_stateDB) // no point doing this yet since we can't control where else it's open yet. { + WriteGuard l(x_postMine); + WriteGuard l2(x_preMine); + + m_preMine = State(); + m_postMine = State(); + m_stateDB = OverlayDB(); m_stateDB = State::openDB(Defaults::dbPath(), WithExisting::Kill); - } - m_bc.reopen(Defaults::dbPath(), WithExisting::Kill); + m_bc.reopen(Defaults::dbPath(), WithExisting::Kill); - m_preMine = State(m_stateDB); - m_postMine = State(m_stateDB); + m_preMine = State(m_stateDB, BaseState::CanonGenesis); + m_postMine = State(m_stateDB); + } if (auto h = m_host.lock()) h->reset(); From 792b878315bddc15a925613d047e195926c740b4 Mon Sep 17 00:00:00 2001 From: Ryan Casey Date: Thu, 23 Apr 2015 09:42:01 -0700 Subject: [PATCH 5/6] Direct more mundane failures to cerr as well. --- solc/CommandLineInterface.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 5e4c901f3..0cc1ab259 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -270,7 +270,7 @@ bool CommandLineInterface::parseArguments(int argc, char** argv) } catch (po::error const& _exception) { - cout << _exception.what() << endl; + cerr << _exception.what() << endl; return false; } if (m_args.count("combined-json")) @@ -279,7 +279,7 @@ bool CommandLineInterface::parseArguments(int argc, char** argv) for (string const& item: boost::split(requests, m_args["combined-json"].as(), boost::is_any_of(","))) if (!g_combinedJsonArgs.count(item)) { - cout << "Invalid option to --combined-json: " << item << endl; + cerr << "Invalid option to --combined-json: " << item << endl; return false; } } @@ -317,13 +317,13 @@ bool CommandLineInterface::processInput() auto path = boost::filesystem::path(infile); if (!boost::filesystem::exists(path)) { - cout << "Skipping non existant input file \"" << infile << "\"" << endl; + cerr << "Skipping non existant input file \"" << infile << "\"" << endl; continue; } if (!boost::filesystem::is_regular_file(path)) { - cout << "\"" << infile << "\" is not a valid file. Skipping" << endl; + cerr << "\"" << infile << "\" is not a valid file. Skipping" << endl; continue; } From 8c153eceb38b639040795599b16c80209cc840fa Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 23 Apr 2015 19:08:36 +0200 Subject: [PATCH 6/6] Update --format-prefix documentation. --- abi/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abi/main.cpp b/abi/main.cpp index e7382c761..27c5eea1b 100644 --- a/abi/main.cpp +++ b/abi/main.cpp @@ -43,7 +43,7 @@ void help() << " -h,--help Print this help message and exit." << endl << " -V,--version Show the version and exit." << endl << "Input options:" << endl - << " -f,--format-prefix Require all input formats to be prefixed e.g. 0x for hex, . for decimal, @ for binary." << endl + << " -f,--format-prefix Require all input formats to be prefixed e.g. 0x for hex, + for decimal, ' for binary." << endl << " -F,--no-format-prefix Require no input format to be prefixed." << endl << " -t,--typing Require all arguments to be typed e.g. b32: (bytes32), u64: (uint64), b[]: (byte[]), i: (int256)." << endl << " -T,--no-typing Require no arguments to be typed." << endl