Browse Source

StructuredLogger becomes a global singleton class

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
623d640fb5
  1. 9
      eth/main.cpp
  2. 16
      libdevcore/StructuredLogger.cpp
  3. 41
      libdevcore/StructuredLogger.h
  4. 15
      libethereum/BlockChain.cpp
  5. 7
      libethereum/BlockChain.h
  6. 13
      libethereum/Client.cpp
  7. 4
      libethereum/Client.h
  8. 5
      libethereum/Miner.cpp
  9. 4
      libethereum/Miner.h
  10. 17
      libethereum/State.cpp
  11. 4
      libethereum/State.h
  12. 8
      libp2p/Host.cpp
  13. 4
      libp2p/Host.h
  14. 7
      libp2p/Session.cpp
  15. 6
      libwebthree/WebThree.cpp
  16. 2
      libwebthree/WebThree.h

9
eth/main.cpp

@ -359,7 +359,7 @@ int main(int argc, char** argv)
cout << credits(); cout << credits();
StructuredLogger structuredLogger(structuredLogging, structuredLoggingFormat); StructLog.initialize(structuredLogging, structuredLoggingFormat);
VMFactory::setKind(jit ? VMKind::JIT : VMKind::Interpreter); VMFactory::setKind(jit ? VMKind::JIT : VMKind::Interpreter);
NetworkPreferences netPrefs(listenPort, publicIP, upnp, useLocal); NetworkPreferences netPrefs(listenPort, publicIP, upnp, useLocal);
auto nodesState = contents((dbPath.size() ? dbPath : getDataDir()) + "/network.rlp"); auto nodesState = contents((dbPath.size() ? dbPath : getDataDir()) + "/network.rlp");
@ -371,12 +371,11 @@ int main(int argc, char** argv)
mode == NodeMode::Full ? set<string>{"eth", "shh"} : set<string>(), mode == NodeMode::Full ? set<string>{"eth", "shh"} : set<string>(),
netPrefs, netPrefs,
&nodesState, &nodesState,
miners, miners
structuredLogger
); );
web3.setIdealPeerCount(peers); web3.setIdealPeerCount(peers);
eth::Client* c = mode == NodeMode::Full ? web3.ethereum() : nullptr; eth::Client* c = mode == NodeMode::Full ? web3.ethereum() : nullptr;
structuredLogger.logStarting(clientImplString, dev::Version); StructLog.starting(clientImplString, dev::Version);
if (c) if (c)
{ {
c->setForceMining(forceMining); c->setForceMining(forceMining);
@ -910,7 +909,7 @@ int main(int argc, char** argv)
while (!g_exit) while (!g_exit)
this_thread::sleep_for(chrono::milliseconds(1000)); this_thread::sleep_for(chrono::milliseconds(1000));
structuredLogger.logStopping(clientImplString, dev::Version); StructLog.stopping(clientImplString, dev::Version);
auto netData = web3.saveNetwork(); auto netData = web3.saveNetwork();
if (!netData.empty()) if (!netData.empty())
writeFile((dbPath.size() ? dbPath : getDataDir()) + "/network.rlp", netData); writeFile((dbPath.size() ? dbPath : getDataDir()) + "/network.rlp", netData);

16
libdevcore/StructuredLogger.cpp

@ -54,7 +54,7 @@ void StructuredLogger::outputJson(Json::Value const& _value, std::string const&
cout << event << endl << flush; cout << event << endl << flush;
} }
void StructuredLogger::logStarting(string const& _clientImpl, const char* _ethVersion) const void StructuredLogger::starting(string const& _clientImpl, const char* _ethVersion) const
{ {
if (m_enabled) if (m_enabled)
{ {
@ -67,7 +67,7 @@ void StructuredLogger::logStarting(string const& _clientImpl, const char* _ethVe
} }
} }
void StructuredLogger::logStopping(string const& _clientImpl, const char* _ethVersion) const void StructuredLogger::stopping(string const& _clientImpl, const char* _ethVersion) const
{ {
if (m_enabled) if (m_enabled)
{ {
@ -80,7 +80,7 @@ void StructuredLogger::logStopping(string const& _clientImpl, const char* _ethVe
} }
} }
void StructuredLogger::logP2PConnected(string const& _id, bi::tcp::endpoint const& _addr, void StructuredLogger::p2pConnected(string const& _id, bi::tcp::endpoint const& _addr,
chrono::system_clock::time_point const& _ts, string const& _remoteVersion, unsigned int _numConnections) const chrono::system_clock::time_point const& _ts, string const& _remoteVersion, unsigned int _numConnections) const
{ {
if (m_enabled) if (m_enabled)
@ -98,7 +98,7 @@ void StructuredLogger::logP2PConnected(string const& _id, bi::tcp::endpoint cons
} }
} }
void StructuredLogger::logP2PDisconnected(string const& _id, bi::tcp::endpoint const& _addr, unsigned int _numConnections) const void StructuredLogger::p2pDisconnected(string const& _id, bi::tcp::endpoint const& _addr, unsigned int _numConnections) const
{ {
if (m_enabled) if (m_enabled)
{ {
@ -114,7 +114,7 @@ void StructuredLogger::logP2PDisconnected(string const& _id, bi::tcp::endpoint c
} }
} }
void StructuredLogger::logMinedNewBlock(string const& _hash, string const& _blockNumber, void StructuredLogger::minedNewBlock(string const& _hash, string const& _blockNumber,
string const& _chainHeadHash, string const& _prevHash) const string const& _chainHeadHash, string const& _prevHash) const
{ {
if (m_enabled) if (m_enabled)
@ -130,7 +130,7 @@ void StructuredLogger::logMinedNewBlock(string const& _hash, string const& _bloc
} }
} }
void StructuredLogger::logChainReceivedNewBlock(string const& _hash, string const& _blockNumber, void StructuredLogger::chainReceivedNewBlock(string const& _hash, string const& _blockNumber,
string const& _chainHeadHash, string const& _remoteID, string const& _prevHash) const string const& _chainHeadHash, string const& _remoteID, string const& _prevHash) const
{ {
if (m_enabled) if (m_enabled)
@ -147,7 +147,7 @@ void StructuredLogger::logChainReceivedNewBlock(string const& _hash, string cons
} }
} }
void StructuredLogger::logChainNewHead(string const& _hash, string const& _blockNumber, void StructuredLogger::chainNewHead(string const& _hash, string const& _blockNumber,
string const& _chainHeadHash, string const& _prevHash) const string const& _chainHeadHash, string const& _prevHash) const
{ {
if (m_enabled) if (m_enabled)
@ -163,7 +163,7 @@ void StructuredLogger::logChainNewHead(string const& _hash, string const& _block
} }
} }
void StructuredLogger::logTransactionReceived(string const& _hash, string const& _remoteId) const void StructuredLogger::transactionReceived(string const& _hash, string const& _remoteId) const
{ {
if (m_enabled) if (m_enabled)
{ {

41
libdevcore/StructuredLogger.h

@ -38,31 +38,42 @@ namespace dev
class StructuredLogger class StructuredLogger
{ {
public: public:
/// Default constructor, logging off
StructuredLogger(): m_enabled(false){}
/** /**
* Initializes a structured logger object * Initializes the structured logger object
* @param _enabled Whether logging is on or off * @param _enabled Whether logging is on or off
* @param _timeFormat A time format string as described here: * @param _timeFormat A time format string as described here:
* http://en.cppreference.com/w/cpp/chrono/c/strftime * http://en.cppreference.com/w/cpp/chrono/c/strftime
* with which to display timestamps * with which to display timestamps
*/ */
StructuredLogger(bool _enabled, std::string const& _timeFormat): void initialize(bool _enabled, std::string const& _timeFormat)
m_enabled(_enabled), m_timeFormat(_timeFormat) {} {
m_enabled = _enabled;
m_timeFormat = _timeFormat;
}
void logStarting(std::string const& _clientImpl, const char* _ethVersion) const; static StructuredLogger& get()
void logStopping(std::string const& _clientImpl, const char* _ethVersion) const; {
void logP2PConnected(std::string const& _id, bi::tcp::endpoint const& _addr, static StructuredLogger instance;
return instance;
}
void starting(std::string const& _clientImpl, const char* _ethVersion) const;
void stopping(std::string const& _clientImpl, const char* _ethVersion) const;
void p2pConnected(std::string const& _id, bi::tcp::endpoint const& _addr,
std::chrono::system_clock::time_point const& _ts, std::string const& _remoteVersion, unsigned int _numConnections) const; std::chrono::system_clock::time_point const& _ts, std::string const& _remoteVersion, unsigned int _numConnections) const;
void logP2PDisconnected(std::string const& _id, bi::tcp::endpoint const& _addr, unsigned int _numConnections) const; void p2pDisconnected(std::string const& _id, bi::tcp::endpoint const& _addr, unsigned int _numConnections) const;
void logMinedNewBlock(std::string const& _hash, std::string const& _blockNumber, void minedNewBlock(std::string const& _hash, std::string const& _blockNumber,
std::string const& _chainHeadHash, std::string const& _prevHash) const; std::string const& _chainHeadHash, std::string const& _prevHash) const;
void logChainReceivedNewBlock(std::string const& _hash, std::string const& _blockNumber, std::string const& _chainHeadHash, void chainReceivedNewBlock(std::string const& _hash, std::string const& _blockNumber, std::string const& _chainHeadHash,
std::string const& _remoteID, std::string const& _prevHash) const; std::string const& _remoteID, std::string const& _prevHash) const;
void logChainNewHead(std::string const& _hash, std::string const& _blockNumber, std::string const& _chainHeadHash, void chainNewHead(std::string const& _hash, std::string const& _blockNumber, std::string const& _chainHeadHash,
std::string const& _prevHash) const; std::string const& _prevHash) const;
void logTransactionReceived(std::string const& _hash, std::string const& _remoteId) const; void transactionReceived(std::string const& _hash, std::string const& _remoteId) const;
private: private:
// Singleton class, no copying
StructuredLogger() {}
StructuredLogger(StructuredLogger const&) = delete;
void operator=(StructuredLogger const&) = delete;
/// @returns a string representation of a timepoint /// @returns a string representation of a timepoint
std::string timePointToString(std::chrono::system_clock::time_point const& _ts) const; std::string timePointToString(std::chrono::system_clock::time_point const& _ts) const;
void outputJson(Json::Value const& _value, std::string const& _name) const; void outputJson(Json::Value const& _value, std::string const& _name) const;
@ -71,4 +82,8 @@ private:
std::string m_timeFormat = "%Y-%m-%dT%H:%M:%S"; std::string m_timeFormat = "%Y-%m-%dT%H:%M:%S";
}; };
/// Convenience macro to get the singleton instance
/// Calling the logging functions becomes as simple as: StructLog.transactionReceived(...)
#define StructLog StructuredLogger::get()
} }

15
libethereum/BlockChain.cpp

@ -25,6 +25,7 @@
#include <test/JsonSpiritHeaders.h> #include <test/JsonSpiritHeaders.h>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/RLP.h> #include <libdevcore/RLP.h>
#include <libdevcore/StructuredLogger.h>
#include <libdevcrypto/FileSystem.h> #include <libdevcrypto/FileSystem.h>
#include <libethcore/Exceptions.h> #include <libethcore/Exceptions.h>
#include <libethcore/ProofOfWork.h> #include <libethcore/ProofOfWork.h>
@ -152,7 +153,7 @@ inline string toString(h256s const& _bs)
return out.str(); return out.str();
} }
h256s BlockChain::sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max, StructuredLogger const& _logger) h256s BlockChain::sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max)
{ {
_bq.tick(*this); _bq.tick(*this);
@ -164,7 +165,7 @@ h256s BlockChain::sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max
{ {
try try
{ {
for (auto h: import(block, _stateDB, _logger)) for (auto h: import(block, _stateDB))
if (!_max--) if (!_max--)
break; break;
else else
@ -187,11 +188,11 @@ h256s BlockChain::sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max
return ret; return ret;
} }
h256s BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB, StructuredLogger const& _logger) noexcept h256s BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB) noexcept
{ {
try try
{ {
return import(_block, _stateDB, _logger); return import(_block, _stateDB);
} }
catch (...) catch (...)
{ {
@ -200,7 +201,7 @@ h256s BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB,
} }
} }
h256s BlockChain::import(bytes const& _block, OverlayDB const& _db, StructuredLogger const& _logger) h256s BlockChain::import(bytes const& _block, OverlayDB const& _db)
{ {
// VERIFY: populates from the block and checks the block is internally coherent. // VERIFY: populates from the block and checks the block is internally coherent.
BlockInfo bi; BlockInfo bi;
@ -317,7 +318,7 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db, StructuredLo
} }
#endif #endif
_logger.logChainReceivedNewBlock( StructLog.chainReceivedNewBlock(
bi.headerHash(WithoutNonce).abridged(), bi.headerHash(WithoutNonce).abridged(),
bi.nonce.abridged(), bi.nonce.abridged(),
currentHash().abridged(), currentHash().abridged(),
@ -337,7 +338,7 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db, StructuredLo
} }
m_extrasDB->Put(m_writeOptions, ldb::Slice("best"), ldb::Slice((char const*)&newHash, 32)); m_extrasDB->Put(m_writeOptions, ldb::Slice("best"), ldb::Slice((char const*)&newHash, 32));
clog(BlockChainNote) << " Imported and best" << td << ". Has" << (details(bi.parentHash).children.size() - 1) << "siblings. Route:" << toString(ret); clog(BlockChainNote) << " Imported and best" << td << ". Has" << (details(bi.parentHash).children.size() - 1) << "siblings. Route:" << toString(ret);
_logger.logChainNewHead( StructLog.chainNewHead(
bi.headerHash(WithoutNonce).abridged(), bi.headerHash(WithoutNonce).abridged(),
bi.nonce.abridged(), bi.nonce.abridged(),
currentHash().abridged(), currentHash().abridged(),

7
libethereum/BlockChain.h

@ -32,7 +32,6 @@
#include <libethcore/CommonEth.h> #include <libethcore/CommonEth.h>
#include <libethcore/BlockInfo.h> #include <libethcore/BlockInfo.h>
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
#include <libdevcore/StructuredLogger.h>
#include "BlockDetails.h" #include "BlockDetails.h"
#include "Account.h" #include "Account.h"
#include "BlockQueue.h" #include "BlockQueue.h"
@ -80,15 +79,15 @@ public:
void process(); void process();
/// Sync the chain with any incoming blocks. All blocks should, if processed in order /// Sync the chain with any incoming blocks. All blocks should, if processed in order
h256s sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max, StructuredLogger const& _logger); h256s sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max);
/// Attempt to import the given block directly into the CanonBlockChain and sync with the state DB. /// Attempt to import the given block directly into the CanonBlockChain and sync with the state DB.
/// @returns the block hashes of any blocks that came into/went out of the canonical block chain. /// @returns the block hashes of any blocks that came into/went out of the canonical block chain.
h256s attemptImport(bytes const& _block, OverlayDB const& _stateDB, StructuredLogger const& _logger = StructuredLogger()) noexcept; h256s attemptImport(bytes const& _block, OverlayDB const& _stateDB) noexcept;
/// Import block into disk-backed DB /// Import block into disk-backed DB
/// @returns the block hashes of any blocks that came into/went out of the canonical block chain. /// @returns the block hashes of any blocks that came into/went out of the canonical block chain.
h256s import(bytes const& _block, OverlayDB const& _stateDB, StructuredLogger const& _logger = StructuredLogger()); h256s import(bytes const& _block, OverlayDB const& _stateDB);
/// Returns true if the given block is known (though not necessarily a part of the canon chain). /// Returns true if the given block is known (though not necessarily a part of the canon chain).
bool isKnown(h256 _hash) const; bool isKnown(h256 _hash) const;

13
libethereum/Client.cpp

@ -25,6 +25,7 @@
#include <thread> #include <thread>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <libdevcore/Log.h> #include <libdevcore/Log.h>
#include <libdevcore/StructuredLogger.h>
#include <libp2p/Host.h> #include <libp2p/Host.h>
#include "Defaults.h" #include "Defaults.h"
#include "Executive.h" #include "Executive.h"
@ -59,15 +60,13 @@ void VersionChecker::setOk()
} }
} }
Client::Client(p2p::Host* _extNet, std::string const& _dbPath, bool _forceClean, Client::Client(p2p::Host* _extNet, std::string const& _dbPath, bool _forceClean, u256 _networkId, int _miners):
u256 _networkId, int _miners, StructuredLogger const& _structuredLogger):
Worker("eth"), Worker("eth"),
m_vc(_dbPath), m_vc(_dbPath),
m_bc(_dbPath, !m_vc.ok() || _forceClean), m_bc(_dbPath, !m_vc.ok() || _forceClean),
m_stateDB(State::openDB(_dbPath, !m_vc.ok() || _forceClean)), m_stateDB(State::openDB(_dbPath, !m_vc.ok() || _forceClean)),
m_preMine(Address(), m_stateDB), m_preMine(Address(), m_stateDB),
m_postMine(Address(), m_stateDB), m_postMine(Address(), m_stateDB)
m_structuredLogger(_structuredLogger)
{ {
m_host = _extNet->registerCapability(new EthereumHost(m_bc, m_tq, m_bq, _networkId)); m_host = _extNet->registerCapability(new EthereumHost(m_bc, m_tq, m_bq, _networkId));
@ -417,7 +416,7 @@ void Client::transact(Secret _secret, u256 _value, Address _dest, bytes const& _
} }
Transaction t(_value, _gasPrice, _gas, _dest, _data, n, _secret); Transaction t(_value, _gasPrice, _gas, _dest, _data, n, _secret);
// cdebug << "Nonce at " << toAddress(_secret) << " pre:" << m_preMine.transactionsFrom(toAddress(_secret)) << " post:" << m_postMine.transactionsFrom(toAddress(_secret)); // cdebug << "Nonce at " << toAddress(_secret) << " pre:" << m_preMine.transactionsFrom(toAddress(_secret)) << " post:" << m_postMine.transactionsFrom(toAddress(_secret));
m_structuredLogger.logTransactionReceived(t.sha3().abridged(), t.sender().abridged()); StructLog.transactionReceived(t.sha3().abridged(), t.sender().abridged());
cnote << "New transaction " << t; cnote << "New transaction " << t;
m_tq.attemptImport(t.rlp()); m_tq.attemptImport(t.rlp());
} }
@ -523,7 +522,7 @@ void Client::doWork()
h256s hs; h256s hs;
{ {
WriteGuard l(x_stateDB); WriteGuard l(x_stateDB);
hs = m_bc.attemptImport(m.blockData(), m_stateDB, m_structuredLogger); hs = m_bc.attemptImport(m.blockData(), m_stateDB);
} }
if (hs.size()) if (hs.size())
{ {
@ -558,7 +557,7 @@ void Client::doWork()
cwork << "BQ ==> CHAIN ==> STATE"; cwork << "BQ ==> CHAIN ==> STATE";
OverlayDB db = m_stateDB; OverlayDB db = m_stateDB;
x_stateDB.unlock(); x_stateDB.unlock();
h256s newBlocks = m_bc.sync(m_bq, db, 100, m_structuredLogger); // TODO: remove transactions from m_tq nicely rather than relying on out of date nonce later on. h256s newBlocks = m_bc.sync(m_bq, db, 100); // TODO: remove transactions from m_tq nicely rather than relying on out of date nonce later on.
if (newBlocks.size()) if (newBlocks.size())
{ {
for (auto i: newBlocks) for (auto i: newBlocks)

4
libethereum/Client.h

@ -32,7 +32,6 @@
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
#include <libdevcore/Worker.h> #include <libdevcore/Worker.h>
#include <libdevcore/StructuredLogger.h>
#include <libevm/FeeStructure.h> #include <libevm/FeeStructure.h>
#include <libp2p/Common.h> #include <libp2p/Common.h>
#include "CanonBlockChain.h" #include "CanonBlockChain.h"
@ -169,7 +168,7 @@ class Client: public MinerHost, public Interface, Worker
public: public:
/// New-style Constructor. /// New-style Constructor.
explicit Client(p2p::Host* _host, std::string const& _dbPath = std::string(), bool _forceClean = false, explicit Client(p2p::Host* _host, std::string const& _dbPath = std::string(), bool _forceClean = false,
u256 _networkId = 0, int _miners = -1, StructuredLogger const& _structuredLogger = StructuredLogger()); u256 _networkId = 0, int _miners = -1);
/// Destructor. /// Destructor.
virtual ~Client(); virtual ~Client();
@ -367,7 +366,6 @@ private:
std::map<h256, InstalledFilter> m_filters; std::map<h256, InstalledFilter> m_filters;
std::map<unsigned, ClientWatch> m_watches; std::map<unsigned, ClientWatch> m_watches;
StructuredLogger const& m_structuredLogger;
mutable std::chrono::system_clock::time_point m_lastGarbageCollection; mutable std::chrono::system_clock::time_point m_lastGarbageCollection;
}; };

5
libethereum/Miner.cpp

@ -36,10 +36,9 @@ LocalMiner::LocalMiner(MinerHost* _host, unsigned _id):
{ {
} }
void LocalMiner::setup(MinerHost* _host, unsigned _id, StructuredLogger const* _structuredLogger) void LocalMiner::setup(MinerHost* _host, unsigned _id)
{ {
m_host = _host; m_host = _host;
m_structuredLogger = _structuredLogger;
setName("miner-" + toString(_id)); setName("miner-" + toString(_id));
} }
@ -80,7 +79,7 @@ void LocalMiner::doWork()
} }
if (mineInfo.completed) if (mineInfo.completed)
{ {
m_mineState.completeMine(m_structuredLogger); m_mineState.completeMine();
m_host->onComplete(); m_host->onComplete();
m_miningStatus = Mined; m_miningStatus = Mined;
} }

4
libethereum/Miner.h

@ -33,7 +33,6 @@
namespace dev namespace dev
{ {
class StructuredLogger;
namespace eth namespace eth
{ {
@ -106,7 +105,7 @@ public:
~LocalMiner() { stop(); } ~LocalMiner() { stop(); }
/// Setup its basics. /// Setup its basics.
void setup(MinerHost* _host, unsigned _id = 0, StructuredLogger const* _structuredLogger = nullptr); void setup(MinerHost* _host, unsigned _id = 0);
/// Start mining. /// Start mining.
void start() { startWorking(); } void start() { startWorking(); }
@ -145,7 +144,6 @@ private:
mutable std::mutex x_mineInfo; ///< Lock for the mining progress & history. mutable std::mutex x_mineInfo; ///< Lock for the mining progress & history.
MineProgress m_mineProgress; ///< What's our progress? MineProgress m_mineProgress; ///< What's our progress?
std::list<MineInfo> m_mineHistory; ///< What the history of our mining? std::list<MineInfo> m_mineHistory; ///< What the history of our mining?
StructuredLogger const* m_structuredLogger;
}; };
} }

17
libethereum/State.cpp

@ -802,12 +802,12 @@ bool State::completeMine(h256 const& _nonce)
m_currentBlock.nonce = _nonce; m_currentBlock.nonce = _nonce;
cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce).abridged() << m_currentBlock.nonce.abridged() << m_currentBlock.difficulty << ProofOfWork::verify(m_currentBlock.headerHash(WithoutNonce), m_currentBlock.nonce, m_currentBlock.difficulty); cnote << "Completed" << m_currentBlock.headerHash(WithoutNonce).abridged() << m_currentBlock.nonce.abridged() << m_currentBlock.difficulty << ProofOfWork::verify(m_currentBlock.headerHash(WithoutNonce), m_currentBlock.nonce, m_currentBlock.difficulty);
completeMine(nullptr); completeMine();
return true; return true;
} }
void State::completeMine(StructuredLogger const* _structuredLogger) void State::completeMine()
{ {
cdebug << "Completing mine!"; cdebug << "Completing mine!";
// Got it! // Got it!
@ -821,13 +821,12 @@ void State::completeMine(StructuredLogger const* _structuredLogger)
ret.swapOut(m_currentBytes); ret.swapOut(m_currentBytes);
m_currentBlock.hash = sha3(RLP(m_currentBytes)[0].data()); m_currentBlock.hash = sha3(RLP(m_currentBytes)[0].data());
cnote << "Mined " << m_currentBlock.hash.abridged() << "(parent: " << m_currentBlock.parentHash.abridged() << ")"; cnote << "Mined " << m_currentBlock.hash.abridged() << "(parent: " << m_currentBlock.parentHash.abridged() << ")";
if (_structuredLogger) StructLog.minedNewBlock(
_structuredLogger->logMinedNewBlock( m_currentBlock.hash.abridged(),
m_currentBlock.hash.abridged(), m_currentBlock.nonce.abridged(),
m_currentBlock.nonce.abridged(), "", //TODO: chain head hash here ??
"", //TODO: chain head hash here ?? m_currentBlock.parentHash.abridged()
m_currentBlock.parentHash.abridged() );
);
// Quickly reset the transactions. // Quickly reset the transactions.
// TODO: Leave this in a better state than this limbo, or at least record that it's in limbo. // TODO: Leave this in a better state than this limbo, or at least record that it's in limbo.

4
libethereum/State.h

@ -41,8 +41,6 @@
namespace dev namespace dev
{ {
class StructuredLogger;
namespace test { class ImportTest; } namespace test { class ImportTest; }
namespace eth namespace eth
@ -141,7 +139,7 @@ public:
* // unlock * // unlock
* @endcode * @endcode
*/ */
void completeMine(StructuredLogger const* _structuredLogger = nullptr); void completeMine();
/// Get the complete current block, including valid nonce. /// Get the complete current block, including valid nonce.
/// Only valid after mine() returns true. /// Only valid after mine() returns true.

8
libp2p/Host.cpp

@ -27,6 +27,7 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libdevcore/StructuredLogger.h>
#include <libethcore/Exceptions.h> #include <libethcore/Exceptions.h>
#include <libdevcrypto/FileSystem.h> #include <libdevcrypto/FileSystem.h>
#include "Session.h" #include "Session.h"
@ -45,7 +46,7 @@ void HostNodeTableHandler::processEvent(NodeId const& _n, NodeTableEventType con
m_host.onNodeTableEvent(_n, _e); m_host.onNodeTableEvent(_n, _e);
} }
Host::Host(std::string const& _clientVersion, NetworkPreferences const& _n, bytesConstRef _restoreNetwork, StructuredLogger const& _structuredLogger): Host::Host(std::string const& _clientVersion, NetworkPreferences const& _n, bytesConstRef _restoreNetwork):
Worker("p2p", 0), Worker("p2p", 0),
m_restoreNetwork(_restoreNetwork.toBytes()), m_restoreNetwork(_restoreNetwork.toBytes()),
m_clientVersion(_clientVersion), m_clientVersion(_clientVersion),
@ -54,8 +55,7 @@ Host::Host(std::string const& _clientVersion, NetworkPreferences const& _n, byte
m_ioService(2), m_ioService(2),
m_tcp4Acceptor(m_ioService), m_tcp4Acceptor(m_ioService),
m_alias(networkAlias(_restoreNetwork)), m_alias(networkAlias(_restoreNetwork)),
m_lastPing(chrono::steady_clock::time_point::min()), m_lastPing(chrono::steady_clock::time_point::min())
m_structuredLogger(_structuredLogger)
{ {
for (auto address: m_ifAddresses) for (auto address: m_ifAddresses)
if (address.is_v4()) if (address.is_v4())
@ -159,7 +159,7 @@ void Host::registerPeer(std::shared_ptr<Session> _s, CapDescs const& _caps)
{ {
{ {
clog(NetNote) << "p2p.host.peer.register" << _s->m_peer->id.abridged(); clog(NetNote) << "p2p.host.peer.register" << _s->m_peer->id.abridged();
m_structuredLogger.logP2PConnected( StructLog.p2pConnected(
_s->m_peer->id.abridged(), _s->m_peer->peerEndpoint(), _s->m_peer->id.abridged(), _s->m_peer->peerEndpoint(),
_s->m_peer->m_lastConnected, _s->m_peer->m_lastConnected,
_s->m_info.clientVersion, _s->m_info.clientVersion,

4
libp2p/Host.h

@ -33,7 +33,6 @@
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
#include <libdevcore/Worker.h> #include <libdevcore/Worker.h>
#include <libdevcore/RangeMask.h> #include <libdevcore/RangeMask.h>
#include <libdevcore/StructuredLogger.h>
#include <libdevcrypto/Common.h> #include <libdevcrypto/Common.h>
#include "NodeTable.h" #include "NodeTable.h"
#include "HostCapability.h" #include "HostCapability.h"
@ -87,7 +86,7 @@ class Host: public Worker
public: public:
/// Start server, listening for connections on the given port. /// Start server, listening for connections on the given port.
Host(std::string const& _clientVersion, NetworkPreferences const& _n = NetworkPreferences(), Host(std::string const& _clientVersion, NetworkPreferences const& _n = NetworkPreferences(),
bytesConstRef _restoreNetwork = bytesConstRef(), StructuredLogger const& _structuredLogger = StructuredLogger()); bytesConstRef _restoreNetwork = bytesConstRef());
/// Will block on network process events. /// Will block on network process events.
virtual ~Host(); virtual ~Host();
@ -234,7 +233,6 @@ private:
std::map<CapDesc, std::shared_ptr<HostCapabilityFace>> m_capabilities; ///< Each of the capabilities we support. std::map<CapDesc, std::shared_ptr<HostCapabilityFace>> m_capabilities; ///< Each of the capabilities we support.
std::chrono::steady_clock::time_point m_lastPing; ///< Time we sent the last ping to all peers. std::chrono::steady_clock::time_point m_lastPing; ///< Time we sent the last ping to all peers.
StructuredLogger const& m_structuredLogger;
bool m_accepting = false; bool m_accepting = false;
}; };

7
libp2p/Session.cpp

@ -24,6 +24,7 @@
#include <chrono> #include <chrono>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h> #include <libdevcore/CommonIO.h>
#include <libdevcore/StructuredLogger.h>
#include <libethcore/Exceptions.h> #include <libethcore/Exceptions.h>
#include "Host.h" #include "Host.h"
#include "Capability.h" #include "Capability.h"
@ -467,8 +468,10 @@ void Session::drop(DisconnectReason _reason)
void Session::disconnect(DisconnectReason _reason) void Session::disconnect(DisconnectReason _reason)
{ {
clogS(NetConnect) << "Disconnecting (our reason:" << reasonOf(_reason) << ")"; clogS(NetConnect) << "Disconnecting (our reason:" << reasonOf(_reason) << ")";
m_server->m_structuredLogger.logP2PDisconnected(m_info.id.abridged(), m_peer->peerEndpoint(), StructLog.p2pDisconnected(
0);// TODO: num connections m_info.id.abridged(),
m_peer->peerEndpoint(),
0);// TODO: num connections
if (m_socket.is_open()) if (m_socket.is_open())
{ {
RLPStream s; RLPStream s;

6
libwebthree/WebThree.cpp

@ -37,14 +37,14 @@ using namespace dev::shh;
WebThreeDirect::WebThreeDirect(std::string const& _clientVersion, std::string const& _dbPath, bool _forceClean, WebThreeDirect::WebThreeDirect(std::string const& _clientVersion, std::string const& _dbPath, bool _forceClean,
std::set<std::string> const& _interfaces, NetworkPreferences const& _n, std::set<std::string> const& _interfaces, NetworkPreferences const& _n,
bytesConstRef _network, int _miners, StructuredLogger const& _structuredLogger): bytesConstRef _network, int _miners):
m_clientVersion(_clientVersion), m_clientVersion(_clientVersion),
m_net(_clientVersion, _n, _network, _structuredLogger) m_net(_clientVersion, _n, _network)
{ {
if (_dbPath.size()) if (_dbPath.size())
Defaults::setDBPath(_dbPath); Defaults::setDBPath(_dbPath);
if (_interfaces.count("eth")) if (_interfaces.count("eth"))
m_ethereum.reset(new eth::Client(&m_net, _dbPath, _forceClean, 0, _miners, _structuredLogger)); m_ethereum.reset(new eth::Client(&m_net, _dbPath, _forceClean, 0, _miners));
if (_interfaces.count("shh")) if (_interfaces.count("shh"))
m_whisper = m_net.registerCapability<WhisperHost>(new WhisperHost); m_whisper = m_net.registerCapability<WhisperHost>(new WhisperHost);

2
libwebthree/WebThree.h

@ -106,7 +106,7 @@ public:
WebThreeDirect(std::string const& _clientVersion, std::string const& _dbPath, bool _forceClean = false, WebThreeDirect(std::string const& _clientVersion, std::string const& _dbPath, bool _forceClean = false,
std::set<std::string> const& _interfaces = {"eth", "shh"}, std::set<std::string> const& _interfaces = {"eth", "shh"},
p2p::NetworkPreferences const& _n = p2p::NetworkPreferences(), p2p::NetworkPreferences const& _n = p2p::NetworkPreferences(),
bytesConstRef _network = bytesConstRef(), int _miners = -1, StructuredLogger const& _structuredLogger = StructuredLogger()); bytesConstRef _network = bytesConstRef(), int _miners = -1);
/// Destructor. /// Destructor.
~WebThreeDirect(); ~WebThreeDirect();

Loading…
Cancel
Save