Browse Source

StructuredLogger propagated as a const reference

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
ba81493976
  1. 1
      libdevcore/StructuredLogger.h
  2. 33
      libethereum/BlockChain.cpp
  3. 8
      libethereum/BlockChain.h
  4. 8
      libethereum/Client.cpp
  5. 7
      libethereum/Client.h
  6. 6
      libethereum/EthereumHost.cpp
  7. 3
      libethereum/EthereumHost.h
  8. 8
      libp2p/Host.cpp
  9. 7
      libp2p/Host.h
  10. 2
      libwebthree/WebThree.cpp
  11. 2
      libwebthree/WebThree.h

1
libdevcore/StructuredLogger.h

@ -35,6 +35,7 @@ namespace dev
class StructuredLogger class StructuredLogger
{ {
public: public:
StructuredLogger(): m_enabled(false) {}
StructuredLogger(bool _enabled): m_enabled(_enabled) {} StructuredLogger(bool _enabled): m_enabled(_enabled) {}
void logStarting(std::string const& _clientImpl, const char* _ethVersion); void logStarting(std::string const& _clientImpl, const char* _ethVersion);

33
libethereum/BlockChain.cpp

@ -25,7 +25,6 @@
#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>
@ -153,7 +152,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, StructuredLogger const& _logger)
{ {
_bq.tick(*this); _bq.tick(*this);
@ -188,7 +187,7 @@ 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, StructuredLogger const& _logger) noexcept
{ {
try try
{ {
@ -201,7 +200,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, StructuredLogger const& _logger)
{ {
// 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;
@ -318,13 +317,12 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db, StructuredLo
} }
#endif #endif
if (_logger) _logger.logChainReceivedNewBlock(
_logger->logChainReceivedNewBlock( bi.headerHash(WithoutNonce).abridged(),
bi.headerHash(WithoutNonce).abridged(), bi.nonce.abridged(),
bi.nonce.abridged(), currentHash().abridged(),
currentHash().abridged(), "", // TODO: remote id ??
"", // TODO: remote id ?? bi.parentHash.abridged());
bi.parentHash.abridged());
// cnote << "Parent " << bi.parentHash << " has " << details(bi.parentHash).children.size() << " children."; // cnote << "Parent " << bi.parentHash << " has " << details(bi.parentHash).children.size() << " children.";
h256s ret; h256s ret;
@ -339,13 +337,12 @@ 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);
if (_logger) _logger.logChainNewHead(
_logger->logChainNewHead( bi.headerHash(WithoutNonce).abridged(),
bi.headerHash(WithoutNonce).abridged(), bi.nonce.abridged(),
bi.nonce.abridged(), currentHash().abridged(),
currentHash().abridged(), bi.parentHash.abridged()
bi.parentHash.abridged() );
);
} }
else else
{ {

8
libethereum/BlockChain.h

@ -32,6 +32,7 @@
#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"
@ -40,7 +41,6 @@ namespace ldb = leveldb;
namespace dev namespace dev
{ {
class StructuredLogger;
class OverlayDB; class OverlayDB;
namespace eth namespace eth
@ -80,15 +80,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, StructuredLogger const& _logger);
/// 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 = nullptr) noexcept; h256s attemptImport(bytes const& _block, OverlayDB const& _stateDB, StructuredLogger const& _logger = StructuredLogger()) 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 = nullptr); h256s import(bytes const& _block, OverlayDB const& _stateDB, StructuredLogger const& _logger = StructuredLogger());
/// 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;

8
libethereum/Client.cpp

@ -25,7 +25,6 @@
#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"
@ -61,7 +60,7 @@ 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, StructuredLogger const* _structuredLogger): 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),
@ -70,7 +69,7 @@ Client::Client(p2p::Host* _extNet, std::string const& _dbPath, bool _forceClean,
m_postMine(Address(), m_stateDB), m_postMine(Address(), m_stateDB),
m_structuredLogger(_structuredLogger) m_structuredLogger(_structuredLogger)
{ {
m_host = _extNet->registerCapability(new EthereumHost(m_bc, m_tq, m_bq, _networkId, _structuredLogger)); m_host = _extNet->registerCapability(new EthereumHost(m_bc, m_tq, m_bq, _networkId));
if (_miners > -1) if (_miners > -1)
setMiningThreads(_miners); setMiningThreads(_miners);
@ -418,8 +417,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));
if (m_structuredLogger) m_structuredLogger.logTransactionReceived(t.sha3().abridged(), t.sender().abridged());
m_structuredLogger->logTransactionReceived(t.sha3().abridged(), t.sender().abridged());
cnote << "New transaction " << t; cnote << "New transaction " << t;
m_tq.attemptImport(t.rlp()); m_tq.attemptImport(t.rlp());
} }

7
libethereum/Client.h

@ -32,6 +32,7 @@
#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"
@ -45,8 +46,6 @@
namespace dev namespace dev
{ {
class StructuredLogger;
namespace eth namespace eth
{ {
@ -170,7 +169,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 = nullptr); u256 _networkId = 0, int _miners = -1, StructuredLogger const& _structuredLogger = StructuredLogger());
/// Destructor. /// Destructor.
virtual ~Client(); virtual ~Client();
@ -368,7 +367,7 @@ 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; StructuredLogger const& m_structuredLogger;
mutable std::chrono::system_clock::time_point m_lastGarbageCollection; mutable std::chrono::system_clock::time_point m_lastGarbageCollection;
}; };

6
libethereum/EthereumHost.cpp

@ -38,15 +38,13 @@ using namespace dev;
using namespace dev::eth; using namespace dev::eth;
using namespace p2p; using namespace p2p;
EthereumHost::EthereumHost(BlockChain const& _ch, TransactionQueue& _tq, BlockQueue& _bq, EthereumHost::EthereumHost(BlockChain const& _ch, TransactionQueue& _tq, BlockQueue& _bq, u256 _networkId):
u256 _networkId, bool _structuredLogging):
HostCapability<EthereumPeer>(), HostCapability<EthereumPeer>(),
Worker ("ethsync"), Worker ("ethsync"),
m_chain (_ch), m_chain (_ch),
m_tq (_tq), m_tq (_tq),
m_bq (_bq), m_bq (_bq),
m_networkId (_networkId), m_networkId (_networkId)
m_structuredLogging (_structuredLogging)
{ {
m_latestBlockSent = _ch.currentHash(); m_latestBlockSent = _ch.currentHash();
} }

3
libethereum/EthereumHost.h

@ -59,7 +59,7 @@ class EthereumHost: public p2p::HostCapability<EthereumPeer>, Worker
public: public:
/// Start server, but don't listen. /// Start server, but don't listen.
EthereumHost(BlockChain const& _ch, TransactionQueue& _tq, BlockQueue& _bq, u256 _networkId, bool _structuredLogging); EthereumHost(BlockChain const& _ch, TransactionQueue& _tq, BlockQueue& _bq, u256 _networkId);
/// Will block on network process events. /// Will block on network process events.
virtual ~EthereumHost(); virtual ~EthereumHost();
@ -111,7 +111,6 @@ private:
u256 m_networkId; u256 m_networkId;
EthereumPeer* m_syncer = nullptr; // TODO: switch to weak_ptr EthereumPeer* m_syncer = nullptr; // TODO: switch to weak_ptr
bool m_structuredLogging;
DownloadMan m_man; DownloadMan m_man;

8
libp2p/Host.cpp

@ -27,7 +27,6 @@
#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"
@ -46,7 +45,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, StructuredLogger const& _structuredLogger):
Worker("p2p", 0), Worker("p2p", 0),
m_restoreNetwork(_restoreNetwork.toBytes()), m_restoreNetwork(_restoreNetwork.toBytes()),
m_clientVersion(_clientVersion), m_clientVersion(_clientVersion),
@ -477,9 +476,8 @@ void Host::connect(std::shared_ptr<Peer> const& _p)
_p->m_lastConnected = std::chrono::system_clock::now(); _p->m_lastConnected = std::chrono::system_clock::now();
_p->m_failedAttempts = 0; _p->m_failedAttempts = 0;
if (m_structuredLogger) m_structuredLogger.logP2PConnected(_p->id.abridged(), _p->peerEndpoint(), _p->m_lastConnected,
m_structuredLogger->logP2PConnected(_p->id.abridged(), _p->peerEndpoint(), _p->m_lastConnected, 0);// TODO: num_connections
0);// TODO: num_connections
auto ps = make_shared<Session>(this, std::move(*s), _p); auto ps = make_shared<Session>(this, std::move(*s), _p);
ps->start(); ps->start();

7
libp2p/Host.h

@ -33,6 +33,7 @@
#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"
@ -45,8 +46,6 @@ namespace bi = ba::ip;
namespace dev namespace dev
{ {
class StructuredLogger;
namespace p2p namespace p2p
{ {
@ -88,7 +87,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 = nullptr); bytesConstRef _restoreNetwork = bytesConstRef(), StructuredLogger const& _structuredLogger = StructuredLogger());
/// Will block on network process events. /// Will block on network process events.
virtual ~Host(); virtual ~Host();
@ -235,7 +234,7 @@ 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; StructuredLogger const& m_structuredLogger;
bool m_accepting = false; bool m_accepting = false;
}; };

2
libwebthree/WebThree.cpp

@ -37,7 +37,7 @@ 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, StructuredLogger const& _structuredLogger):
m_clientVersion(_clientVersion), m_clientVersion(_clientVersion),
m_net(_clientVersion, _n, _network, _structuredLogger) m_net(_clientVersion, _n, _network, _structuredLogger)
{ {

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 = nullptr); bytesConstRef _network = bytesConstRef(), int _miners = -1, StructuredLogger const& _structuredLogger = StructuredLogger());
/// Destructor. /// Destructor.
~WebThreeDirect(); ~WebThreeDirect();

Loading…
Cancel
Save