From 1bdc4914f5d12d46891d09ba1c51c51fe24fe3a0 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 31 Oct 2012 15:48:17 -0700 Subject: [PATCH 01/10] Add InstanceCounter. --- newcoin.vcxproj | 1 + src/InstanceCounter.cpp | 15 ++++++++ src/InstanceCounter.h | 76 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 src/InstanceCounter.cpp create mode 100644 src/InstanceCounter.h diff --git a/newcoin.vcxproj b/newcoin.vcxproj index a2dd3bbb6a..3109a074aa 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -112,6 +112,7 @@ + diff --git a/src/InstanceCounter.cpp b/src/InstanceCounter.cpp new file mode 100644 index 0000000000..5640102820 --- /dev/null +++ b/src/InstanceCounter.cpp @@ -0,0 +1,15 @@ +#include "InstanceCounter.h" + +InstanceType* InstanceType::sHeadInstance = NULL; + +std::vector InstanceType::getInstanceCounts(int min) +{ + std::vector ret; + for (InstanceType* i = sHeadInstance; i != NULL; i = i->mNextInstance) + { + int c = i->getCount(); + if (c >= min) + ret.push_back(InstanceCount(i->getName(), c)); + } + return ret; +} diff --git a/src/InstanceCounter.h b/src/InstanceCounter.h new file mode 100644 index 0000000000..62c8b91ba6 --- /dev/null +++ b/src/InstanceCounter.h @@ -0,0 +1,76 @@ +#ifndef INSTANCE_COUNTER__H +#define INSTANCE_COUNTER__H + +#include +#include + +#include + +#define DEFINE_INSTANCE(x) \ + extern InstanceType IT_##x; \ + class Instance_##x : private Instance \ + { \ + protected: \ + Instance_##x() : Instance(IT_##x) { ; } \ + } + +#define DECLARE_INSTANCE(x) \ + InstanceType IT_##x(#x); + +#define IS_INSTANCE(x) Instance_##x + +class InstanceType +{ +protected: + int mInstances; + std::string mName; + boost::mutex mLock; + + InstanceType* mNextInstance; + static InstanceType* sHeadInstance; + +public: + typedef std::pair InstanceCount; + + InstanceType(const char *n) : mInstances(0), mName(n) + { + mNextInstance = sHeadInstance; + sHeadInstance = this; + } + + void addInstance() + { + mLock.lock(); + ++mInstances; + mLock.unlock(); + } + void decInstance() + { + mLock.lock(); + --mInstances; + mLock.unlock(); + } + int getCount() + { + boost::mutex::scoped_lock(mLock); + return mInstances; + } + const std::string& getName() + { + return mName; + } + + static std::vector getInstanceCounts(int min = 1); +}; + +class Instance +{ +protected: + InstanceType& mType; + +public: + Instance(InstanceType& t) : mType(t) { mType.addInstance(); } + ~Instance() { mType.decInstance(); } +}; + +#endif From ce9dc18adea2dd5080c7a4d0b4446f24fcce74d1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 31 Oct 2012 15:48:38 -0700 Subject: [PATCH 02/10] Add get_counts RPC function. --- src/RPCHandler.cpp | 42 +++++++++++++++++++++++++++++------------- src/RPCHandler.h | 8 +++++++- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/RPCHandler.cpp b/src/RPCHandler.cpp index 2b8fe72257..36fcfdffd3 100644 --- a/src/RPCHandler.cpp +++ b/src/RPCHandler.cpp @@ -7,6 +7,7 @@ #include "RippleAddress.h" #include "AccountState.h" #include "NicknameState.h" +#include "InstanceCounter.h" #include "Pathfinder.h" #include @@ -75,7 +76,7 @@ Json::Value RPCHandler::rpcError(int iError) for (i=NUMBER(errorInfoA); i-- && errorInfoA[i].iError != iError;) ; - Json::Value jsonResult = Json::Value(Json::objectValue); + Json::Value jsonResult(Json::objectValue); jsonResult["error"] = i >= 0 ? errorInfoA[i].pToken : lexical_cast_i(iError); jsonResult["error_message"] = i >= 0 ? errorInfoA[i].pMessage : lexical_cast_i(iError); @@ -2420,37 +2421,38 @@ Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& param bool mAdminRequired; unsigned int iOptions; } commandsA[] = { - { "accept_ledger", &RPCHandler::doAcceptLedger, 0, 0, true }, - { "account_domain_set", &RPCHandler::doAccountDomainSet, 2, 3, false, optCurrent }, + { "accept_ledger", &RPCHandler::doAcceptLedger, 0, 0, true }, + { "account_domain_set", &RPCHandler::doAccountDomainSet, 2, 3, false, optCurrent }, { "account_email_set", &RPCHandler::doAccountEmailSet, 2, 3, false, optCurrent }, { "account_info", &RPCHandler::doAccountInfo, 1, 2, false, optCurrent }, { "account_message_set", &RPCHandler::doAccountMessageSet, 3, 3, false, optCurrent }, { "account_publish_set", &RPCHandler::doAccountPublishSet, 4, 4, false, optCurrent }, { "account_rate_set", &RPCHandler::doAccountRateSet, 3, 3, false, optCurrent }, { "account_tx", &RPCHandler::doAccountTransactions, 2, 3, false, optNetwork }, - { "account_wallet_set", &RPCHandler::doAccountWalletSet, 2, 3, false, optCurrent }, + { "account_wallet_set", &RPCHandler::doAccountWalletSet, 2, 3, false, optCurrent }, { "connect", &RPCHandler::doConnect, 1, 2, true }, { "data_delete", &RPCHandler::doDataDelete, 1, 1, true }, { "data_fetch", &RPCHandler::doDataFetch, 1, 1, true }, { "data_store", &RPCHandler::doDataStore, 2, 2, true }, + { "get_counts", &RPCHandler::doGetCounts, 0, 1, true }, { "ledger", &RPCHandler::doLedger, 0, 2, false, optNetwork }, - { "log_level", &RPCHandler::doLogLevel, 0, 2, true }, + { "log_level", &RPCHandler::doLogLevel, 0, 2, true }, { "logrotate", &RPCHandler::doLogRotate, 0, 0, true }, - { "nickname_info", &RPCHandler::doNicknameInfo, 1, 1, false, optCurrent }, + { "nickname_info", &RPCHandler::doNicknameInfo, 1, 1, false, optCurrent }, { "nickname_set", &RPCHandler::doNicknameSet, 2, 3, false, optCurrent }, { "offer_create", &RPCHandler::doOfferCreate, 9, 10, false, optCurrent }, { "offer_cancel", &RPCHandler::doOfferCancel, 3, 3, false, optCurrent }, { "owner_info", &RPCHandler::doOwnerInfo, 1, 2, false, optCurrent }, - { "password_fund", &RPCHandler::doPasswordFund, 2, 3, false, optCurrent }, + { "password_fund", &RPCHandler::doPasswordFund, 2, 3, false, optCurrent }, { "password_set", &RPCHandler::doPasswordSet, 2, 3, false, optNetwork }, { "peers", &RPCHandler::doPeers, 0, 0, true }, { "profile", &RPCHandler::doProfile, 1, 9, false, optCurrent }, { "ripple", &RPCHandler::doRipple, 9, -1, false, optCurrent|optClosed }, { "ripple_lines_get", &RPCHandler::doRippleLinesGet, 1, 2, false, optCurrent }, { "ripple_line_set", &RPCHandler::doRippleLineSet, 4, 7, false, optCurrent }, - { "send", &RPCHandler::doSend, 3, 9, false, optCurrent }, + { "send", &RPCHandler::doSend, 3, 9, false, optCurrent }, { "server_info", &RPCHandler::doServerInfo, 0, 0, true }, - { "stop", &RPCHandler::doStop, 0, 0, true }, + { "stop", &RPCHandler::doStop, 0, 0, true }, { "tx", &RPCHandler::doTx, 1, 1, true }, { "tx_history", &RPCHandler::doTxHistory, 1, 1, false, }, @@ -2459,16 +2461,16 @@ Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& param { "unl_list", &RPCHandler::doUnlList, 0, 0, true }, { "unl_load", &RPCHandler::doUnlLoad, 0, 0, true }, { "unl_network", &RPCHandler::doUnlNetwork, 0, 0, true }, - { "unl_reset", &RPCHandler::doUnlReset, 0, 0, true }, - { "unl_score", &RPCHandler::doUnlScore, 0, 0, true }, + { "unl_reset", &RPCHandler::doUnlReset, 0, 0, true }, + { "unl_score", &RPCHandler::doUnlScore, 0, 0, true }, - { "validation_create", &RPCHandler::doValidationCreate, 0, 1, false }, + { "validation_create", &RPCHandler::doValidationCreate, 0, 1, false }, { "validation_seed", &RPCHandler::doValidationSeed, 0, 1, false }, { "wallet_accounts", &RPCHandler::doWalletAccounts, 1, 1, false, optCurrent }, { "wallet_add", &RPCHandler::doWalletAdd, 3, 5, false, optCurrent }, { "wallet_claim", &RPCHandler::doWalletClaim, 2, 4, false, optNetwork }, - { "wallet_create", &RPCHandler::doWalletCreate, 3, 4, false, optCurrent }, + { "wallet_create", &RPCHandler::doWalletCreate, 3, 4, false, optCurrent }, { "wallet_propose", &RPCHandler::doWalletPropose, 0, 1, false, }, { "wallet_seed", &RPCHandler::doWalletSeed, 0, 1, false, }, @@ -2603,6 +2605,20 @@ Json::Value RPCHandler::doLogin(const Json::Value& params) } } +Json::Value RPCHandler::doGetCounts(const Json::Value& params) +{ + int minCount = 1; + if (params.size() > 0) + minCount = params[0u].asInt(); + + std::vector count = InstanceType::getInstanceCounts(minCount); + + Json::Value ret(Json::objectValue); + BOOST_FOREACH(InstanceType::InstanceCount& it, count) + ret[it.first] = it.second; + return ret; +} + Json::Value RPCHandler::doLogLevel(const Json::Value& params) { if (params.size() == 0) diff --git a/src/RPCHandler.h b/src/RPCHandler.h index 4dfd7f80b5..c001e7dffa 100644 --- a/src/RPCHandler.h +++ b/src/RPCHandler.h @@ -1,3 +1,6 @@ +#ifndef RPCHANDLER__H +#define RPCHANDLER__H + // used by the RPCServer or WSDoor to carry out these RPC commands class NetworkOPs; @@ -37,6 +40,7 @@ class RPCHandler Json::Value doDataDelete(const Json::Value& params); Json::Value doDataFetch(const Json::Value& params); Json::Value doDataStore(const Json::Value& params); + Json::Value doGetCounts(const Json::Value& params); Json::Value doLedger(const Json::Value& params); Json::Value doLogRotate(const Json::Value& params); Json::Value doNicknameInfo(const Json::Value& params); @@ -156,4 +160,6 @@ public: Json::Value doCommand(const std::string& command, Json::Value& params,int role); Json::Value rpcError(int iError); -}; \ No newline at end of file +}; + +#endif From cd93bd0de3ac7914021c61b0c02d813396a74d3d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 31 Oct 2012 15:49:47 -0700 Subject: [PATCH 03/10] Make sure TaggedCaches get sweeped. --- src/Application.cpp | 13 ++++++++++++- src/Application.h | 3 +++ src/HashedObject.h | 1 + src/LedgerHistory.h | 1 + src/TaggedCache.h | 4 ++-- src/TransactionMaster.h | 1 + 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 7c459fc129..8ec0b2bf3a 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -42,11 +42,13 @@ Application::Application() : mNetOps(mIOService, &mMasterLedger), mTempNodeCache(16384, 90), mHashedObjectStore(16384, 300), mSNTPClient(mAuxService), mRpcDB(NULL), mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL), - mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL) + mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL), mSweepTimer(mAuxService) { RAND_bytes(mNonce256.begin(), mNonce256.size()); RAND_bytes(reinterpret_cast(&mNonceST), sizeof(mNonceST)); mJobQueue.setThreadCount(); + mSweepTimer.expires_from_now(boost::posix_time::seconds(60)); + mSweepTimer.async_wait(boost::bind(&Application::sweep, this)); } extern const char *RpcDBInit[], *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[], *NetNodeDBInit[]; @@ -183,6 +185,15 @@ void Application::run() std::cout << "Done." << std::endl; } +void Application::sweep() +{ + mMasterTransaction.sweep(); + mHashedObjectStore.sweep(); + mMasterLedger.sweep(); + mSweepTimer.expires_from_now(boost::posix_time::seconds(60)); + mSweepTimer.async_wait(boost::bind(&Application::sweep, this)); +} + Application::~Application() { delete mTxnDB; diff --git a/src/Application.h b/src/Application.h index ebb078492d..8193408327 100644 --- a/src/Application.h +++ b/src/Application.h @@ -66,6 +66,8 @@ class Application uint256 mNonce256; std::size_t mNonceST; + boost::asio::deadline_timer mSweepTimer; + std::map mPeerMap; boost::recursive_mutex mPeerMapLock; @@ -110,6 +112,7 @@ public: void run(); void stop(); + void sweep(); }; extern Application* theApp; diff --git a/src/HashedObject.h b/src/HashedObject.h index 5178af0896..a3fb8cbe0b 100644 --- a/src/HashedObject.h +++ b/src/HashedObject.h @@ -61,6 +61,7 @@ public: void bulkWrite(); void waitWrite(); + void sweep() { mCache.sweep(); } }; #endif diff --git a/src/LedgerHistory.h b/src/LedgerHistory.h index ed58f4fc98..51ecaf7143 100644 --- a/src/LedgerHistory.h +++ b/src/LedgerHistory.h @@ -18,6 +18,7 @@ public: Ledger::pointer getLedgerBySeq(uint32 index); Ledger::pointer getLedgerByHash(const uint256& hash); Ledger::pointer canonicalizeLedger(Ledger::pointer, bool cache); + void sweep() { mLedgersByHash.sweep(); } }; #endif diff --git a/src/TaggedCache.h b/src/TaggedCache.h index ece2b36631..a6c56efa42 100644 --- a/src/TaggedCache.h +++ b/src/TaggedCache.h @@ -96,7 +96,7 @@ template void TaggedCache::sweep typename boost::unordered_map::iterator cit = mCache.begin(); while (cit != mCache.end()) { - if (cit->second->second.first < target) + if (cit->second.first < target) mCache.erase(cit++); else ++cit; @@ -106,7 +106,7 @@ template void TaggedCache::sweep typename boost::unordered_map::iterator mit = mMap.begin(); while (mit != mMap.end()) { - if (mit->second->expired()) + if (mit->second.expired()) mMap.erase(mit++); else ++mit; diff --git a/src/TransactionMaster.h b/src/TransactionMaster.h index 19fd8b64da..138c05c9c0 100644 --- a/src/TransactionMaster.h +++ b/src/TransactionMaster.h @@ -20,6 +20,7 @@ public: // return value: true = we had the transaction already bool canonicalize(Transaction::pointer& txn, bool maybeNew); + void sweep(void) { mCache.sweep(); } }; #endif From f0eb8e79430cf7770ab701614692a6c4261b92a5 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 31 Oct 2012 15:50:14 -0700 Subject: [PATCH 04/10] Add instance counts to core classes. --- src/Ledger.cpp | 1 + src/Ledger.h | 5 ++++- src/LedgerMaster.h | 2 ++ src/Peer.cpp | 1 + src/Peer.h | 5 ++++- src/SHAMap.cpp | 4 ++++ src/SHAMap.h | 13 +++++++++---- 7 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Ledger.cpp b/src/Ledger.cpp index 1b6775232f..69807417e9 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -20,6 +20,7 @@ #include "Log.h" SETUP_LOG(); +DECLARE_INSTANCE(Ledger); Ledger::Ledger(const RippleAddress& masterID, uint64 startAmount) : mTotCoins(startAmount), mLedgerSeq(1), mCloseTime(0), mParentCloseTime(0), mCloseResolution(LEDGER_TIME_ACCURACY), mCloseFlags(0), diff --git a/src/Ledger.h b/src/Ledger.h index 1074ec9fbf..c033c59c4d 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -18,6 +18,7 @@ #include "types.h" #include "BitcoinUtil.h" #include "SHAMap.h" +#include "InstanceCounter.h" enum LedgerStateParms { @@ -38,7 +39,9 @@ enum LedgerStateParms #define LEDGER_JSON_DUMP_STATE 0x20000000 #define LEDGER_JSON_FULL 0x40000000 -class Ledger : public boost::enable_shared_from_this +DEFINE_INSTANCE(Ledger); + +class Ledger : public boost::enable_shared_from_this, public IS_INSTANCE(Ledger) { // The basic Ledger structure, can be opened, closed, or synching friend class TransactionEngine; public: diff --git a/src/LedgerMaster.h b/src/LedgerMaster.h index 967026fed3..e3270710e5 100644 --- a/src/LedgerMaster.h +++ b/src/LedgerMaster.h @@ -91,6 +91,8 @@ public: void setLedgerRangePresent(uint32 minV, uint32 maxV) { mCompleteLedgers.setRange(minV, maxV); } bool addHeldTransaction(const Transaction::pointer& trans); + + void sweep(void) { mLedgerHistory.sweep(); } }; #endif diff --git a/src/Peer.cpp b/src/Peer.cpp index 609bf90e50..491991c23f 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -16,6 +16,7 @@ #include "Log.h" SETUP_LOG(); +DECLARE_INSTANCE(Peer); // Don't try to run past receiving nonsense from a peer #define TRUST_NETWORK diff --git a/src/Peer.h b/src/Peer.h index 76b11d092c..cc3a525c5b 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -11,6 +11,7 @@ #include "PackedMessage.h" #include "Ledger.h" #include "Transaction.h" +#include "InstanceCounter.h" enum PeerPunish { @@ -21,7 +22,9 @@ enum PeerPunish typedef std::pair ipPort; -class Peer : public boost::enable_shared_from_this +DEFINE_INSTANCE(Peer); + +class Peer : public boost::enable_shared_from_this, public IS_INSTANCE(Peer) { public: typedef boost::shared_ptr pointer; diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index b7a775778a..e3de616d28 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -17,6 +17,10 @@ SETUP_LOG(); +DECLARE_INSTANCE(SHAMap); +DECLARE_INSTANCE(SHAMapItem); +DECLARE_INSTANCE(SHAMapTreeNode); + std::size_t hash_value(const SHAMapNode& mn) { std::size_t seed = theApp->getNonceST(); diff --git a/src/SHAMap.h b/src/SHAMap.h index 107d3d8b65..6acadf6679 100644 --- a/src/SHAMap.h +++ b/src/SHAMap.h @@ -14,6 +14,11 @@ #include "ScopedLock.h" #include "Serializer.h" #include "HashedObject.h" +#include "InstanceCounter.h" + +DEFINE_INSTANCE(SHAMap); +DEFINE_INSTANCE(SHAMapItem); +DEFINE_INSTANCE(SHAMapTreeNode); class SHAMap; @@ -31,7 +36,7 @@ private: public: - static const int rootDepth=0; + static const int rootDepth = 0; SHAMapNode() : mDepth(0) { ; } SHAMapNode(int depth, const uint256& hash); @@ -77,7 +82,7 @@ extern std::size_t hash_value(const SHAMapNode& mn); inline std::ostream& operator<<(std::ostream& out, const SHAMapNode& node) { return out << node.getString(); } -class SHAMapItem +class SHAMapItem : public IS_INSTANCE(SHAMapItem) { // an item stored in a SHAMap public: typedef boost::shared_ptr pointer; @@ -135,7 +140,7 @@ enum SHAMapType smtFREE =3, // A tree not part of a ledger }; -class SHAMapTreeNode : public SHAMapNode +class SHAMapTreeNode : public SHAMapNode, public IS_INSTANCE(SHAMapTreeNode) { friend class SHAMap; @@ -276,7 +281,7 @@ public: extern std::ostream& operator<<(std::ostream&, const SHAMapMissingNode&); -class SHAMap +class SHAMap : public IS_INSTANCE(SHAMap) { public: typedef boost::shared_ptr pointer; From 9743b7cafae3ac562f5a100f1a6735ca8740f1dd Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 31 Oct 2012 15:55:14 -0700 Subject: [PATCH 05/10] Add 'getTrackSize' --- src/TaggedCache.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/TaggedCache.h b/src/TaggedCache.h index a6c56efa42..fe7e03d242 100644 --- a/src/TaggedCache.h +++ b/src/TaggedCache.h @@ -44,6 +44,7 @@ public: int getTargetAge() const; int getCacheSize(); + int getTrackSize(); int getSweepAge(); void setTargetSize(int size); @@ -78,6 +79,12 @@ template int TaggedCache::getCac return mCache.size(); } +template int TaggedCache::getTrackSize() +{ + boost::recursive_mutex::scoped_lock sl(mLock); + return mMap.size(); +} + template void TaggedCache::sweep() { boost::recursive_mutex::scoped_lock sl(mLock); From a37c5d6314f3b1a0a97892c562bc623f187d6d64 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 31 Oct 2012 16:01:59 -0700 Subject: [PATCH 06/10] Sweep the temp node cache. --- src/Application.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Application.cpp b/src/Application.cpp index 8ec0b2bf3a..758fae4ae6 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -190,6 +190,7 @@ void Application::sweep() mMasterTransaction.sweep(); mHashedObjectStore.sweep(); mMasterLedger.sweep(); + mTempNodeCache.sweep(); mSweepTimer.expires_from_now(boost::posix_time::seconds(60)); mSweepTimer.async_wait(boost::bind(&Application::sweep, this)); } From ca65e5ad8f1e6395c64f19f7cfea267d24f55bf3 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 31 Oct 2012 16:02:21 -0700 Subject: [PATCH 07/10] Add transactions to the tracked class list. --- src/Transaction.cpp | 2 ++ src/Transaction.h | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Transaction.cpp b/src/Transaction.cpp index 2fca627427..c4dbd435c9 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -13,6 +13,8 @@ #include "SerializedTransaction.h" #include "Log.h" +DECLARE_INSTANCE(Transaction); + Transaction::Transaction(SerializedTransaction::ref sit, bool bValidate) : mInLedger(0), mStatus(INVALID), mResult(temUNCERTAIN), mTransaction(sit) { diff --git a/src/Transaction.h b/src/Transaction.h index 8d14654e29..ea049b5279 100644 --- a/src/Transaction.h +++ b/src/Transaction.h @@ -21,6 +21,7 @@ #include "SHAMap.h" #include "SerializedTransaction.h" #include "TransactionErr.h" +#include "InstanceCounter.h" class Database; @@ -37,8 +38,10 @@ enum TransStatus INCOMPLETE = 8 // needs more signatures }; +DEFINE_INSTANCE(Transaction); + // This class is for constructing and examining transactions. Transactions are static so manipulation functions are unnecessary. -class Transaction : public boost::enable_shared_from_this +class Transaction : public boost::enable_shared_from_this, private IS_INSTANCE(Transaction) { public: typedef boost::shared_ptr pointer; From 7fa7a5e2cca6892ccb757468143582067bb2bcee Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 31 Oct 2012 16:02:38 -0700 Subject: [PATCH 08/10] Add hashed objects to the tracked class list. --- src/HashedObject.cpp | 1 + src/HashedObject.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/HashedObject.cpp b/src/HashedObject.cpp index 997be4c23d..bff9c34c66 100644 --- a/src/HashedObject.cpp +++ b/src/HashedObject.cpp @@ -9,6 +9,7 @@ #include "Log.h" SETUP_LOG(); +DECLARE_INSTANCE(HashedObject); HashedObjectStore::HashedObjectStore(int cacheSize, int cacheAge) : mCache(cacheSize, cacheAge), mWritePending(false) diff --git a/src/HashedObject.h b/src/HashedObject.h index a3fb8cbe0b..7f31912542 100644 --- a/src/HashedObject.h +++ b/src/HashedObject.h @@ -10,6 +10,9 @@ #include "uint256.h" #include "ScopedLock.h" #include "TaggedCache.h" +#include "InstanceCounter.h" + +DEFINE_INSTANCE(HashedObject); enum HashedObjectType { @@ -20,7 +23,7 @@ enum HashedObjectType hotTRANSACTION_NODE = 4 }; -class HashedObject +class HashedObject : private IS_INSTANCE(HashedObject) { public: typedef boost::shared_ptr pointer; From 9098c3f73965b7a0e85f861fba6b07118fae2f9c Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 31 Oct 2012 16:09:22 -0700 Subject: [PATCH 09/10] Make the compiler happy. --- src/InstanceCounter.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/InstanceCounter.h b/src/InstanceCounter.h index 62c8b91ba6..ffb3665f55 100644 --- a/src/InstanceCounter.h +++ b/src/InstanceCounter.h @@ -6,15 +6,19 @@ #include -#define DEFINE_INSTANCE(x) \ - extern InstanceType IT_##x; \ - class Instance_##x : private Instance \ - { \ - protected: \ - Instance_##x() : Instance(IT_##x) { ; } \ +#define DEFINE_INSTANCE(x) \ + extern InstanceType IT_##x; \ + class Instance_##x : private Instance \ + { \ + protected: \ + Instance_##x() : Instance(IT_##x) { ; } \ + Instance_##x(const Instance_##x &) : \ + Instance(IT_##x) { ; } \ + Instance_##x& operator=(const Instance_##x&) \ + { return *this; } \ } -#define DECLARE_INSTANCE(x) \ +#define DECLARE_INSTANCE(x) \ InstanceType IT_##x(#x); #define IS_INSTANCE(x) Instance_##x From 8e4b11b668d2560ae6d236bdfee3a5b97679921c Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 31 Oct 2012 16:11:59 -0700 Subject: [PATCH 10/10] Add more counted types. --- src/SerializedLedger.cpp | 2 ++ src/SerializedLedger.h | 5 ++++- src/SerializedObject.cpp | 2 ++ src/SerializedObject.h | 8 ++++++-- src/SerializedTransaction.cpp | 2 ++ src/SerializedTransaction.h | 5 ++++- src/SerializedTypes.cpp | 1 + src/SerializedTypes.h | 6 ++++-- 8 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/SerializedLedger.cpp b/src/SerializedLedger.cpp index 359a93fa58..00a3539878 100644 --- a/src/SerializedLedger.cpp +++ b/src/SerializedLedger.cpp @@ -5,6 +5,8 @@ #include "Ledger.h" #include "Log.h" +DECLARE_INSTANCE(SerializedLedgerEntry) + SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint256& index) : STObject(sfLedgerEntry), mIndex(index) { diff --git a/src/SerializedLedger.h b/src/SerializedLedger.h index c02126db15..7bbdfaf992 100644 --- a/src/SerializedLedger.h +++ b/src/SerializedLedger.h @@ -4,8 +4,11 @@ #include "SerializedObject.h" #include "LedgerFormats.h" #include "RippleAddress.h" +#include "InstanceCounter.h" -class SerializedLedgerEntry : public STObject +DEFINE_INSTANCE(SerializedLedgerEntry); + +class SerializedLedgerEntry : public STObject, private IS_INSTANCE(SerializedLedgerEntry) { public: typedef boost::shared_ptr pointer; diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index 1477a23937..7b6a51f946 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -14,6 +14,8 @@ #include "SerializedTransaction.h" SETUP_LOG(); +DECLARE_INSTANCE(SerializedObject); +DECLARE_INSTANCE(SerializedArray); std::auto_ptr STObject::makeDefaultObject(SerializedTypeID id, SField::ref name) { diff --git a/src/SerializedObject.h b/src/SerializedObject.h index 00c89ed1eb..d0d3ce6afe 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -8,6 +8,10 @@ #include "../json/value.h" #include "SerializedTypes.h" +#include "InstanceCounter.h" + +DEFINE_INSTANCE(SerializedObject); +DEFINE_INSTANCE(SerializedArray); // Serializable object/array types @@ -22,7 +26,7 @@ public: SOElement(SField::ref fi, SOE_Flags fl) : e_field(fi), flags(fl) { ; } }; -class STObject : public SerializedType +class STObject : public SerializedType, private IS_INSTANCE(SerializedObject) { protected: boost::ptr_vector mData; @@ -175,7 +179,7 @@ namespace boost -class STArray : public SerializedType +class STArray : public SerializedType, private IS_INSTANCE(SerializedArray) { public: typedef std::vector vector; diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp index d6b7a02916..bdc26d77eb 100644 --- a/src/SerializedTransaction.cpp +++ b/src/SerializedTransaction.cpp @@ -8,6 +8,8 @@ #include "Log.h" #include "HashPrefixes.h" +DECLARE_INSTANCE(SerializedTransaction); + SerializedTransaction::SerializedTransaction(TransactionType type) : STObject(sfTransaction), mType(type) { mFormat = TransactionFormat::getTxnFormat(type); diff --git a/src/SerializedTransaction.h b/src/SerializedTransaction.h index 185ca6cdac..50d974db09 100644 --- a/src/SerializedTransaction.h +++ b/src/SerializedTransaction.h @@ -9,6 +9,7 @@ #include "SerializedObject.h" #include "TransactionFormats.h" #include "RippleAddress.h" +#include "InstanceCounter.h" #define TXN_SQL_NEW 'N' #define TXN_SQL_CONFLICT 'C' @@ -17,7 +18,9 @@ #define TXN_SQL_INCLUDED 'I' #define TXN_SQL_UNKNOWN 'U' -class SerializedTransaction : public STObject +DEFINE_INSTANCE(SerializedTransaction); + +class SerializedTransaction : public STObject, private IS_INSTANCE(SerializedTransaction) { public: typedef boost::shared_ptr pointer; diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index 55fc7039b1..5fc0ebbe3f 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -14,6 +14,7 @@ #include "TransactionErr.h" SETUP_LOG(); +DECLARE_INSTANCE(SerializedEntry); STAmount saZero(CURRENCY_ONE, ACCOUNT_ONE, 0); STAmount saOne(CURRENCY_ONE, ACCOUNT_ONE, 1); diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 62f7347c85..6e1267448f 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -9,7 +9,7 @@ #include "uint256.h" #include "Serializer.h" #include "FieldNames.h" - +#include "InstanceCounter.h" enum PathFlags { @@ -30,7 +30,9 @@ enum PathFlags #define ACCOUNT_XNS uint160(0) #define ACCOUNT_ONE uint160(1) // Used as a place holder -class SerializedType +DEFINE_INSTANCE(SerializedEntry); + +class SerializedType : private IS_INSTANCE(SerializedEntry) { protected: SField::ptr fName;