diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2015-07-09 13:56:31 -0400 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2015-07-10 10:49:31 -0400 |
commit | 5098c47b2430ded299c21620527ebd0544fe51e2 (patch) | |
tree | 5423630dea9653802744ed2bb997797fc1b6ca96 /src/primitives | |
parent | 943b322d5d292707e193f3a9d8e971881540be23 (diff) |
Implement accurate memory accounting for mempool
Diffstat (limited to 'src/primitives')
-rw-r--r-- | src/primitives/transaction.cpp | 5 | ||||
-rw-r--r-- | src/primitives/transaction.h | 9 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 606dbea798..7ed2d45973 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -72,6 +72,11 @@ void CTransaction::UpdateHash() const *const_cast<uint256*>(&hash) = SerializeHash(*this); } +size_t CTransaction::DynamicMemoryUsage() const +{ + return memusage::RecursiveDynamicUsage(vin) + memusage::RecursiveDynamicUsage(vout); +} + CTransaction::CTransaction() : nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0) { } CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) { diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 6cfd93a9a1..77326c64b0 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -7,6 +7,7 @@ #define BITCOIN_PRIMITIVES_TRANSACTION_H #include "amount.h" +#include "memusage.h" #include "script/script.h" #include "serialize.h" #include "uint256.h" @@ -48,6 +49,8 @@ public: } std::string ToString() const; + + size_t DynamicMemoryUsage() const { return 0; } }; /** An input of a transaction. It contains the location of the previous @@ -96,6 +99,8 @@ public: } std::string ToString() const; + + size_t DynamicMemoryUsage() const { return scriptSig.DynamicMemoryUsage(); } }; /** An output of a transaction. It contains the public key that the next input @@ -166,6 +171,8 @@ public: } std::string ToString() const; + + size_t DynamicMemoryUsage() const { return scriptPubKey.DynamicMemoryUsage(); } }; struct CMutableTransaction; @@ -249,6 +256,8 @@ public: } std::string ToString() const; + + size_t DynamicMemoryUsage() const; }; /** A mutable version of CTransaction. */ |