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
{
public:
StructuredLogger(): m_enabled(false) {}
StructuredLogger(bool _enabled): m_enabled(_enabled) {}
void logStarting(std::string const& _clientImpl, const char* _ethVersion);

33
libethereum/BlockChain.cpp

@ -25,7 +25,6 @@
#include <test/JsonSpiritHeaders.h>
#include <libdevcore/Common.h>
#include <libdevcore/RLP.h>
#include <libdevcore/StructuredLogger.h>
#include <libdevcrypto/FileSystem.h>
#include <libethcore/Exceptions.h>
#include <libethcore/ProofOfWork.h>
@ -153,7 +152,7 @@ inline string toString(h256s const& _bs)
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);
@ -188,7 +187,7 @@ h256s BlockChain::sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max
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
{
@ -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.
BlockInfo bi;
@ -318,13 +317,12 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db, StructuredLo
}
#endif
if (_logger)
_logger->logChainReceivedNewBlock(
bi.headerHash(WithoutNonce).abridged(),
bi.nonce.abridged(),
currentHash().abridged(),
"", // TODO: remote id ??
bi.parentHash.abridged());
_logger.logChainReceivedNewBlock(
bi.headerHash(WithoutNonce).abridged(),
bi.nonce.abridged(),
currentHash().abridged(),
"", // TODO: remote id ??
bi.parentHash.abridged());
// cnote << "Parent " << bi.parentHash << " has " << details(bi.parentHash).children.size() << " children.";
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));
clog(BlockChainNote) << " Imported and best" << td << ". Has" << (details(bi.parentHash).children.size() - 1) << "siblings. Route:" << toString(ret);
if (_logger)
_logger->logChainNewHead(
bi.headerHash(WithoutNonce).abridged(),
bi.nonce.abridged(),
currentHash().abridged(),
bi.parentHash.abridged()
);
_logger.logChainNewHead(
bi.headerHash(WithoutNonce).abridged(),
bi.nonce.abridged(),
currentHash().abridged(),
bi.parentHash.abridged()
);
}
else
{

8
libethereum/BlockChain.h

@ -32,6 +32,7 @@
#include <libethcore/CommonEth.h>
#include <libethcore/BlockInfo.h>
#include <libdevcore/Guards.h>
#include <libdevcore/StructuredLogger.h>
#include "BlockDetails.h"
#include "Account.h"
#include "BlockQueue.h"
@ -40,7 +41,6 @@ namespace ldb = leveldb;
namespace dev
{
class StructuredLogger;
class OverlayDB;
namespace eth
@ -80,15 +80,15 @@ public:
void process();
/// 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.
/// @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
/// @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).
bool isKnown(h256 _hash) const;

8
libethereum/Client.cpp

@ -25,7 +25,6 @@
#include <thread>
#include <boost/filesystem.hpp>
#include <libdevcore/Log.h>
#include <libdevcore/StructuredLogger.h>
#include <libp2p/Host.h>
#include "Defaults.h"
#include "Executive.h"
@ -61,7 +60,7 @@ void VersionChecker::setOk()
}
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"),
m_vc(_dbPath),
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_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)
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);
// 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;
m_tq.attemptImport(t.rlp());
}

7
libethereum/Client.h

@ -32,6 +32,7 @@
#include <libdevcore/CommonIO.h>
#include <libdevcore/Guards.h>
#include <libdevcore/Worker.h>
#include <libdevcore/StructuredLogger.h>
#include <libevm/FeeStructure.h>
#include <libp2p/Common.h>
#include "CanonBlockChain.h"
@ -45,8 +46,6 @@
namespace dev
{
class StructuredLogger;
namespace eth
{
@ -170,7 +169,7 @@ class Client: public MinerHost, public Interface, Worker
public:
/// New-style Constructor.
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.
virtual ~Client();
@ -368,7 +367,7 @@ private:
std::map<h256, InstalledFilter> m_filters;
std::map<unsigned, ClientWatch> m_watches;
StructuredLogger const* m_structuredLogger;
StructuredLogger const& m_structuredLogger;
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 p2p;
EthereumHost::EthereumHost(BlockChain const& _ch, TransactionQueue& _tq, BlockQueue& _bq,
u256 _networkId, bool _structuredLogging):
EthereumHost::EthereumHost(BlockChain const& _ch, TransactionQueue& _tq, BlockQueue& _bq, u256 _networkId):
HostCapability<EthereumPeer>(),
Worker ("ethsync"),
m_chain (_ch),
m_tq (_tq),
m_bq (_bq),
m_networkId (_networkId),
m_structuredLogging (_structuredLogging)
m_networkId (_networkId)
{
m_latestBlockSent = _ch.currentHash();
}

3
libethereum/EthereumHost.h

@ -59,7 +59,7 @@ class EthereumHost: public p2p::HostCapability<EthereumPeer>, Worker
public:
/// 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.
virtual ~EthereumHost();
@ -111,7 +111,6 @@ private:
u256 m_networkId;
EthereumPeer* m_syncer = nullptr; // TODO: switch to weak_ptr
bool m_structuredLogging;
DownloadMan m_man;

8
libp2p/Host.cpp

@ -27,7 +27,6 @@
#include <boost/algorithm/string.hpp>
#include <libdevcore/Common.h>
#include <libdevcore/CommonIO.h>
#include <libdevcore/StructuredLogger.h>
#include <libethcore/Exceptions.h>
#include <libdevcrypto/FileSystem.h>
#include "Session.h"
@ -46,7 +45,7 @@ void HostNodeTableHandler::processEvent(NodeId const& _n, NodeTableEventType con
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),
m_restoreNetwork(_restoreNetwork.toBytes()),
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_failedAttempts = 0;
if (m_structuredLogger)
m_structuredLogger->logP2PConnected(_p->id.abridged(), _p->peerEndpoint(), _p->m_lastConnected,
0);// TODO: num_connections
m_structuredLogger.logP2PConnected(_p->id.abridged(), _p->peerEndpoint(), _p->m_lastConnected,
0);// TODO: num_connections
auto ps = make_shared<Session>(this, std::move(*s), _p);
ps->start();

7
libp2p/Host.h

@ -33,6 +33,7 @@
#include <libdevcore/Guards.h>
#include <libdevcore/Worker.h>
#include <libdevcore/RangeMask.h>
#include <libdevcore/StructuredLogger.h>
#include <libdevcrypto/Common.h>
#include "NodeTable.h"
#include "HostCapability.h"
@ -45,8 +46,6 @@ namespace bi = ba::ip;
namespace dev
{
class StructuredLogger;
namespace p2p
{
@ -88,7 +87,7 @@ class Host: public Worker
public:
/// Start server, listening for connections on the given port.
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.
virtual ~Host();
@ -235,7 +234,7 @@ private:
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.
StructuredLogger const* m_structuredLogger;
StructuredLogger const& m_structuredLogger;
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,
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_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,
std::set<std::string> const& _interfaces = {"eth", "shh"},
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.
~WebThreeDirect();

Loading…
Cancel
Save