Skip to content

Commit 9a8a8ad

Browse files
committed
Use int64_t type for transaction sizes consistently
This change gets rid of 8 casts.
1 parent fa4314f commit 9a8a8ad

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/txmempool.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
8686
bool spends_coinbase, int64_t sigops_cost, LockPoints lp)
8787
: tx{tx},
8888
nFee{fee},
89-
nTxWeight(GetTransactionWeight(*tx)),
89+
nTxWeight{GetTransactionWeight(*tx)},
9090
nUsageSize{RecursiveDynamicUsage(tx)},
9191
nTime{time},
9292
entryHeight{entry_height},
@@ -111,7 +111,7 @@ void CTxMemPoolEntry::UpdateLockPoints(const LockPoints& lp)
111111
lockPoints = lp;
112112
}
113113

114-
size_t CTxMemPoolEntry::GetTxSize() const
114+
int64_t CTxMemPoolEntry::GetTxSize() const
115115
{
116116
return GetVirtualTransactionSize(nTxWeight, sigOpCost);
117117
}
@@ -150,12 +150,12 @@ void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendan
150150
int64_t modifyCount = 0;
151151
for (const CTxMemPoolEntry& descendant : descendants) {
152152
if (!setExclude.count(descendant.GetTx().GetHash())) {
153-
modifySize += int64_t(descendant.GetTxSize());
153+
modifySize += descendant.GetTxSize();
154154
modifyFee += descendant.GetModifiedFee();
155155
modifyCount++;
156156
cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant));
157157
// Update ancestor state for each descendant
158-
mapTx.modify(mapTx.iterator_to(descendant), update_ancestor_state{int64_t(updateIt->GetTxSize()), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost()});
158+
mapTx.modify(mapTx.iterator_to(descendant), update_ancestor_state{updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost()});
159159
}
160160
}
161161
mapTx.modify(updateIt, update_descendant_state(modifySize, modifyFee, modifyCount));
@@ -342,7 +342,7 @@ void CTxMemPool::UpdateAncestorsOf(bool add, txiter it, setEntries &setAncestors
342342
UpdateChild(mapTx.iterator_to(parent), it, add);
343343
}
344344
const int64_t updateCount = (add ? 1 : -1);
345-
const int64_t updateSize{updateCount * int64_t(it->GetTxSize())};
345+
const int64_t updateSize{updateCount * it->GetTxSize()};
346346
const CAmount updateFee = updateCount * it->GetModifiedFee();
347347
for (txiter ancestorIt : setAncestors) {
348348
mapTx.modify(ancestorIt, update_descendant_state(updateSize, updateFee, updateCount));
@@ -356,7 +356,7 @@ void CTxMemPool::UpdateEntryForAncestors(txiter it, const setEntries &setAncesto
356356
CAmount updateFee = 0;
357357
int64_t updateSigOpsCost = 0;
358358
for (txiter ancestorIt : setAncestors) {
359-
updateSize += int64_t(ancestorIt->GetTxSize());
359+
updateSize += ancestorIt->GetTxSize();
360360
updateFee += ancestorIt->GetModifiedFee();
361361
updateSigOpsCost += ancestorIt->GetSigOpCost();
362362
}
@@ -433,17 +433,17 @@ void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove, b
433433

434434
void CTxMemPoolEntry::UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
435435
{
436-
nSizeWithDescendants += uint64_t(modifySize);
437-
assert(int64_t(nSizeWithDescendants) > 0);
436+
nSizeWithDescendants += modifySize;
437+
assert(nSizeWithDescendants > 0);
438438
nModFeesWithDescendants += modifyFee;
439439
nCountWithDescendants += uint64_t(modifyCount);
440440
assert(int64_t(nCountWithDescendants) > 0);
441441
}
442442

443443
void CTxMemPoolEntry::UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps)
444444
{
445-
nSizeWithAncestors += uint64_t(modifySize);
446-
assert(int64_t(nSizeWithAncestors) > 0);
445+
nSizeWithAncestors += modifySize;
446+
assert(nSizeWithAncestors > 0);
447447
nModFeesWithAncestors += modifyFee;
448448
nCountWithAncestors += uint64_t(modifyCount);
449449
assert(int64_t(nCountWithAncestors) > 0);
@@ -764,7 +764,7 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
764764
std::string dummy;
765765
CalculateMemPoolAncestors(*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy);
766766
uint64_t nCountCheck = setAncestors.size() + 1;
767-
uint64_t nSizeCheck = it->GetTxSize();
767+
int64_t nSizeCheck{it->GetTxSize()};
768768
CAmount nFeesCheck = it->GetModifiedFee();
769769
int64_t nSigOpCheck = it->GetSigOpCost();
770770

@@ -785,7 +785,7 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
785785
// Check children against mapNextTx
786786
CTxMemPoolEntry::Children setChildrenCheck;
787787
auto iter = mapNextTx.lower_bound(COutPoint(it->GetTx().GetHash(), 0));
788-
uint64_t child_sizes = 0;
788+
int64_t child_sizes{0};
789789
for (; iter != mapNextTx.end() && iter->first->hash == it->GetTx().GetHash(); ++iter) {
790790
txiter childit = mapTx.find(iter->second->GetHash());
791791
assert(childit != mapTx.end()); // mapNextTx points to in-mempool transactions

src/txmempool.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class CTxMemPoolEntry
9595
mutable Parents m_parents;
9696
mutable Children m_children;
9797
const CAmount nFee; //!< Cached to avoid expensive parent-transaction lookups
98-
const size_t nTxWeight; //!< ... and avoid recomputing tx weight (also used for GetTxSize())
98+
const int64_t nTxWeight; //!< ... and avoid recomputing tx weight (also used for GetTxSize())
9999
const size_t nUsageSize; //!< ... and total memory usage
100100
const int64_t nTime; //!< Local time when entering the mempool
101101
const unsigned int entryHeight; //!< Chain height when entering the mempool
@@ -108,12 +108,12 @@ class CTxMemPoolEntry
108108
// mempool; if we remove this transaction we must remove all of these
109109
// descendants as well.
110110
uint64_t nCountWithDescendants{1}; //!< number of descendant transactions
111-
uint64_t nSizeWithDescendants; //!< ... and size
111+
int64_t nSizeWithDescendants; //!< ... and size
112112
CAmount nModFeesWithDescendants; //!< ... and total fees (all including us)
113113

114114
// Analogous statistics for ancestor transactions
115115
uint64_t nCountWithAncestors{1};
116-
uint64_t nSizeWithAncestors;
116+
int64_t nSizeWithAncestors;
117117
CAmount nModFeesWithAncestors;
118118
int64_t nSigOpCostWithAncestors;
119119

@@ -126,8 +126,8 @@ class CTxMemPoolEntry
126126
const CTransaction& GetTx() const { return *this->tx; }
127127
CTransactionRef GetSharedTx() const { return this->tx; }
128128
const CAmount& GetFee() const { return nFee; }
129-
size_t GetTxSize() const;
130-
size_t GetTxWeight() const { return nTxWeight; }
129+
int64_t GetTxSize() const;
130+
int64_t GetTxWeight() const { return nTxWeight; }
131131
std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
132132
unsigned int GetHeight() const { return entryHeight; }
133133
int64_t GetSigOpCost() const { return sigOpCost; }
@@ -146,13 +146,13 @@ class CTxMemPoolEntry
146146
void UpdateLockPoints(const LockPoints& lp);
147147

148148
uint64_t GetCountWithDescendants() const { return nCountWithDescendants; }
149-
uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }
149+
int64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }
150150
CAmount GetModFeesWithDescendants() const { return nModFeesWithDescendants; }
151151

152152
bool GetSpendsCoinbase() const { return spendsCoinbase; }
153153

154154
uint64_t GetCountWithAncestors() const { return nCountWithAncestors; }
155-
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
155+
int64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
156156
CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
157157
int64_t GetSigOpCostWithAncestors() const { return nSigOpCostWithAncestors; }
158158

@@ -345,7 +345,7 @@ struct TxMempoolInfo
345345
CAmount fee;
346346

347347
/** Virtual size of the transaction. */
348-
size_t vsize;
348+
int64_t vsize;
349349

350350
/** The fee delta. */
351351
int64_t nFeeDelta;

0 commit comments

Comments
 (0)