Browse Source

Merge pull request #4817

c26649f Track modified size in TxMemPoolEntry so that we can correctly compute priority. (Alex Morcos)
0.10
Pieter Wuille 10 years ago
parent
commit
2ec82e94e6
No known key found for this signature in database
GPG Key ID: 8F653255C87992E0
  1. 12
      src/core.cpp
  2. 3
      src/core.h
  3. 4
      src/txmempool.cpp
  4. 1
      src/txmempool.h

12
src/core.cpp

@ -123,6 +123,14 @@ int64_t CTransaction::GetValueOut() const
} }
double CTransaction::ComputePriority(double dPriorityInputs, unsigned int nTxSize) const double CTransaction::ComputePriority(double dPriorityInputs, unsigned int nTxSize) const
{
nTxSize = CalculateModifiedSize(nTxSize);
if (nTxSize == 0) return 0.0;
return dPriorityInputs / nTxSize;
}
unsigned int CTransaction::CalculateModifiedSize(unsigned int nTxSize) const
{ {
// In order to avoid disincentivizing cleaning up the UTXO set we don't count // In order to avoid disincentivizing cleaning up the UTXO set we don't count
// the constant overhead for each txin and up to 110 bytes of scriptSig (which // the constant overhead for each txin and up to 110 bytes of scriptSig (which
@ -131,14 +139,14 @@ double CTransaction::ComputePriority(double dPriorityInputs, unsigned int nTxSiz
// risk encouraging people to create junk outputs to redeem later. // risk encouraging people to create junk outputs to redeem later.
if (nTxSize == 0) if (nTxSize == 0)
nTxSize = ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION); nTxSize = ::GetSerializeSize(*this, SER_NETWORK, PROTOCOL_VERSION);
BOOST_FOREACH(const CTxIn& txin, vin) BOOST_FOREACH(const CTxIn& txin, vin)
{ {
unsigned int offset = 41U + std::min(110U, (unsigned int)txin.scriptSig.size()); unsigned int offset = 41U + std::min(110U, (unsigned int)txin.scriptSig.size());
if (nTxSize > offset) if (nTxSize > offset)
nTxSize -= offset; nTxSize -= offset;
} }
if (nTxSize == 0) return 0.0; return nTxSize;
return dPriorityInputs / nTxSize;
} }
std::string CTransaction::ToString() const std::string CTransaction::ToString() const

3
src/core.h

@ -283,6 +283,9 @@ public:
// Compute priority, given priority of inputs and (optionally) tx size // Compute priority, given priority of inputs and (optionally) tx size
double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const; double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const;
// Compute modified tx size for priority calculation (optionally given tx size)
unsigned int CalculateModifiedSize(unsigned int nTxSize=0) const;
bool IsCoinBase() const bool IsCoinBase() const
{ {
return (vin.size() == 1 && vin[0].prevout.IsNull()); return (vin.size() == 1 && vin[0].prevout.IsNull());

4
src/txmempool.cpp

@ -23,6 +23,8 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, int64_t _nFee,
tx(_tx), nFee(_nFee), nTime(_nTime), dPriority(_dPriority), nHeight(_nHeight) tx(_tx), nFee(_nFee), nTime(_nTime), dPriority(_dPriority), nHeight(_nHeight)
{ {
nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
nModSize = tx.CalculateModifiedSize(nTxSize);
} }
CTxMemPoolEntry::CTxMemPoolEntry(const CTxMemPoolEntry& other) CTxMemPoolEntry::CTxMemPoolEntry(const CTxMemPoolEntry& other)
@ -34,7 +36,7 @@ double
CTxMemPoolEntry::GetPriority(unsigned int currentHeight) const CTxMemPoolEntry::GetPriority(unsigned int currentHeight) const
{ {
int64_t nValueIn = tx.GetValueOut()+nFee; int64_t nValueIn = tx.GetValueOut()+nFee;
double deltaPriority = ((double)(currentHeight-nHeight)*nValueIn)/nTxSize; double deltaPriority = ((double)(currentHeight-nHeight)*nValueIn)/nModSize;
double dResult = dPriority + deltaPriority; double dResult = dPriority + deltaPriority;
return dResult; return dResult;
} }

1
src/txmempool.h

@ -31,6 +31,7 @@ private:
CTransaction tx; CTransaction tx;
int64_t nFee; // Cached to avoid expensive parent-transaction lookups int64_t nFee; // Cached to avoid expensive parent-transaction lookups
size_t nTxSize; // ... and avoid recomputing tx size size_t nTxSize; // ... and avoid recomputing tx size
size_t nModSize; // ... and modified size for priority
int64_t nTime; // Local time when entering the mempool int64_t nTime; // Local time when entering the mempool
double dPriority; // Priority when entering the mempool double dPriority; // Priority when entering the mempool
unsigned int nHeight; // Chain height when entering the mempool unsigned int nHeight; // Chain height when entering the mempool

Loading…
Cancel
Save