a8566404be
c1235e3 Add RecursiveDynamicUsage overload for std::shared_ptr (Russell Yanofsky) 71f1903 Store disconnected block transactions outside mempool during reorg (Suhas Daftuar) 9decd64 [qa] Relax assumptions on mempool behavior during reorg (Suhas Daftuar) Tree-SHA512: c160ad853a5cd060d0307af7606a0c77907497ed7033c9599b95e73d83f68fdfcd4214bd8a83db1c5b7a58022722b9de1ed2e6ea2e02f38a7b6c717f079dd0c6
68 lines
2.3 KiB
C++
68 lines
2.3 KiB
C++
// Copyright (c) 2015 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_CORE_MEMUSAGE_H
|
|
#define BITCOIN_CORE_MEMUSAGE_H
|
|
|
|
#include "primitives/transaction.h"
|
|
#include "primitives/block.h"
|
|
#include "memusage.h"
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CScript& script) {
|
|
return memusage::DynamicUsage(*static_cast<const CScriptBase*>(&script));
|
|
}
|
|
|
|
static inline size_t RecursiveDynamicUsage(const COutPoint& out) {
|
|
return 0;
|
|
}
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CTxIn& in) {
|
|
return RecursiveDynamicUsage(in.scriptSig) + RecursiveDynamicUsage(in.prevout);
|
|
}
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CTxOut& out) {
|
|
return RecursiveDynamicUsage(out.scriptPubKey);
|
|
}
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CTransaction& tx) {
|
|
size_t mem = memusage::DynamicUsage(tx.vin) + memusage::DynamicUsage(tx.vout);
|
|
for (std::vector<CTxIn>::const_iterator it = tx.vin.begin(); it != tx.vin.end(); it++) {
|
|
mem += RecursiveDynamicUsage(*it);
|
|
}
|
|
for (std::vector<CTxOut>::const_iterator it = tx.vout.begin(); it != tx.vout.end(); it++) {
|
|
mem += RecursiveDynamicUsage(*it);
|
|
}
|
|
return mem;
|
|
}
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CMutableTransaction& tx) {
|
|
size_t mem = memusage::DynamicUsage(tx.vin) + memusage::DynamicUsage(tx.vout);
|
|
for (std::vector<CTxIn>::const_iterator it = tx.vin.begin(); it != tx.vin.end(); it++) {
|
|
mem += RecursiveDynamicUsage(*it);
|
|
}
|
|
for (std::vector<CTxOut>::const_iterator it = tx.vout.begin(); it != tx.vout.end(); it++) {
|
|
mem += RecursiveDynamicUsage(*it);
|
|
}
|
|
return mem;
|
|
}
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CBlock& block) {
|
|
size_t mem = memusage::DynamicUsage(block.vtx);
|
|
for (const auto& tx : block.vtx) {
|
|
mem += memusage::DynamicUsage(tx) + RecursiveDynamicUsage(*tx);
|
|
}
|
|
return mem;
|
|
}
|
|
|
|
static inline size_t RecursiveDynamicUsage(const CBlockLocator& locator) {
|
|
return memusage::DynamicUsage(locator.vHave);
|
|
}
|
|
|
|
template<typename X>
|
|
static inline size_t RecursiveDynamicUsage(const std::shared_ptr<X>& p) {
|
|
return p ? memusage::DynamicUsage(p) + RecursiveDynamicUsage(*p) : 0;
|
|
}
|
|
|
|
#endif // BITCOIN_CORE_MEMUSAGE_H
|