Skip to content

Commit 67dba4d

Browse files
JBetzMixa84
andcommitted
Use nFees for amounts and nFeeValue for value (ElementsProject#16)
Co-authored-by: Mihailo Milenkovic <[email protected]>
1 parent a0b2819 commit 67dba4d

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

src/node/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
305305
nBlockWeight += iter->GetTxWeight();
306306
++nBlockTx;
307307
nBlockSigOpsCost += iter->GetSigOpCost();
308-
feeMap[iter->GetFeeAsset()] += iter->GetFeeAmount();
308+
feeMap[iter->GetFeeAsset()] += iter->GetFee();
309309
inBlock.insert(iter);
310310

311311
bool fPrintPriority = gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY);

src/txmempool.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ struct update_fee_delta
6868
int64_t feeDelta;
6969
};
7070

71-
struct update_fee
71+
struct update_fee_value
7272
{
73-
explicit update_fee(int64_t _fee) : fee(_fee) { }
73+
explicit update_fee_value(int64_t _feeValue) : feeValue(_feeValue) { }
7474

75-
void operator() (CTxMemPoolEntry &e) { e.UpdateFee(fee); }
75+
void operator() (CTxMemPoolEntry &e) { e.UpdateFeeValue(feeValue); }
7676

7777
private:
78-
int64_t fee;
78+
int64_t feeValue;
7979
};
8080

8181
bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
@@ -95,14 +95,14 @@ bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp)
9595
return true;
9696
}
9797

98-
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee, CAsset feeAsset, CAmount feeAmount,
98+
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee, CAsset feeAsset, CAmount feeValue,
9999
int64_t time, unsigned int entry_height,
100100
bool spends_coinbase, int64_t sigops_cost, LockPoints lp,
101101
const std::set<std::pair<uint256, COutPoint>>& _setPeginsSpent)
102102
: tx{tx},
103103
nFee{fee},
104104
nFeeAsset{feeAsset},
105-
nFeeAmount{feeAmount},
105+
nFeeValue{feeValue},
106106
nTxWeight(GetTransactionWeight(*tx)),
107107
nUsageSize{RecursiveDynamicUsage(tx)},
108108
nTime{time},
@@ -111,9 +111,9 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee, CAsset
111111
sigOpCost{sigops_cost},
112112
lockPoints{lp},
113113
nSizeWithDescendants{GetTxSize()},
114-
nModFeesWithDescendants{nFee},
114+
nModFeesWithDescendants{nFeeValue},
115115
nSizeWithAncestors{GetTxSize()},
116-
nModFeesWithAncestors{nFee},
116+
nModFeesWithAncestors{nFeeValue},
117117
nSigOpCostWithAncestors{sigOpCost},
118118
setPeginsSpent(_setPeginsSpent) {}
119119

@@ -124,11 +124,11 @@ void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
124124
feeDelta = newFeeDelta;
125125
}
126126

127-
void CTxMemPoolEntry::UpdateFee(const CAmount newFee)
127+
void CTxMemPoolEntry::UpdateFeeValue(const CAmount newFeeValue)
128128
{
129-
nModFeesWithDescendants += newFee - nFee;
130-
nModFeesWithAncestors += newFee - nFee;
131-
nFee = newFee;
129+
nModFeesWithDescendants += newFeeValue - nFeeValue;
130+
nModFeesWithAncestors += newFeeValue - nFeeValue;
131+
nFeeValue = newFeeValue;
132132
}
133133

134134
void CTxMemPoolEntry::UpdateLockPoints(const LockPoints& lp)
@@ -1078,25 +1078,25 @@ void CTxMemPool::RecomputeFees()
10781078
ExchangeRateMap exchangeRateMap = ExchangeRateMap::GetInstance();
10791079
for (CTxMemPoolEntry tx : mapTx) {
10801080
txiter it = mapTx.find(tx.GetTx().GetHash());
1081-
CAmount newFee = exchangeRateMap.CalculateExchangeValue(tx.GetFeeAmount(), tx.GetFeeAsset());
1082-
CAmount feeDelta = newFee - tx.GetFee();
1083-
if (feeDelta != 0) {
1084-
mapTx.modify(it, update_fee(newFee));
1081+
CAmount newFeeValue = exchangeRateMap.CalculateExchangeValue(tx.GetFee(), tx.GetFeeAsset());
1082+
CAmount feeValueDelta = newFeeValue - tx.GetFeeValue();
1083+
if (feeValueDelta != 0) {
1084+
mapTx.modify(it, update_fee_value(newFeeValue));
10851085

10861086
// Now update all ancestors' modified fees with descendants
10871087
setEntries setAncestors;
10881088
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
10891089
std::string dummy;
10901090
CalculateMemPoolAncestors(tx, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false);
10911091
for (txiter ancestorIt : setAncestors) {
1092-
mapTx.modify(ancestorIt, update_descendant_state(0, feeDelta, 0));
1092+
mapTx.modify(ancestorIt, update_descendant_state(0, feeValueDelta, 0));
10931093
}
10941094
// Now update all descendants' modified fees with ancestors
10951095
setEntries setDescendants;
10961096
CalculateDescendants(it, setDescendants);
10971097
setDescendants.erase(it);
10981098
for (txiter descendantIt : setDescendants) {
1099-
mapTx.modify(descendantIt, update_ancestor_state(0, feeDelta, 0, 0));
1099+
mapTx.modify(descendantIt, update_ancestor_state(0, feeValueDelta, 0, 0));
11001100
}
11011101
++nTransactionsUpdated;
11021102
}

src/txmempool.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ class CTxMemPoolEntry
9595
const CTransactionRef tx;
9696
mutable Parents m_parents;
9797
mutable Children m_children;
98-
CAmount nFee; //!< Value in reference unit, computed using configured exchange rates. It is not a `const` because it needs to be updated whenever exchange rates change.
98+
const CAmount nFee; //!< Cached to avoid expensive parent-transaction lookups
9999
const CAsset nFeeAsset; //!< ELEMENTS: The asset used for fee payment. Always equal to policyAsset unless con_any_asset_fees is enabled.
100-
const CAmount nFeeAmount; //!< ELEMENTS: The amount of nFeeAsset used for fee payment. Always equal to nFee unless con_any_asset_fees is enabled.
100+
CAmount nFeeValue; //!< ELEMENTS: Value in reference unit, computed using configured exchange rates. It is not a `const` because it needs to be updated whenever exchange rates change.
101101
const size_t nTxWeight; //!< ... and avoid recomputing tx weight (also used for GetTxSize())
102102
const size_t nUsageSize; //!< ... and total memory usage
103103
const int64_t nTime; //!< Local time when entering the mempool
@@ -121,7 +121,7 @@ class CTxMemPoolEntry
121121
int64_t nSigOpCostWithAncestors;
122122

123123
public:
124-
CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee, const CAsset feeAsset, const CAmount feeAmount,
124+
CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee, const CAsset feeAsset, const CAmount feeValue,
125125
int64_t time, unsigned int entry_height,
126126
bool spends_coinbase,
127127
int64_t sigops_cost, LockPoints lp,
@@ -131,7 +131,7 @@ class CTxMemPoolEntry
131131
CTransactionRef GetSharedTx() const { return this->tx; }
132132
const CAmount& GetFee() const { return nFee; }
133133
const CAsset& GetFeeAsset() const { return nFeeAsset; }
134-
const CAmount& GetFeeAmount() const { return nFeeAmount; }
134+
const CAmount& GetFeeValue() const { return nFeeValue; }
135135
size_t GetTxSize() const;
136136
size_t GetTxWeight() const { return nTxWeight; }
137137
std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
@@ -148,8 +148,8 @@ class CTxMemPoolEntry
148148
// Updates the fee delta used for mining priority score, and the
149149
// modified fees with descendants.
150150
void UpdateFeeDelta(int64_t feeDelta);
151-
// Updates the base fee and the modified fees with ancestors and descendants.
152-
void UpdateFee(const CAmount fee);
151+
// Updates the fee value and the modified fees with ancestors and descendants.
152+
void UpdateFeeValue(const CAmount fee);
153153
// Update the LockPoints after a reorg
154154
void UpdateLockPoints(const LockPoints& lp);
155155

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,8 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
915915
}
916916
}
917917

918-
CAmount currentFeeValuation = ExchangeRateMap::GetInstance().CalculateExchangeValue(ws.m_base_fees, feeAsset);
919-
entry.reset(new CTxMemPoolEntry(ptx, currentFeeValuation, feeAsset, ws.m_base_fees, nAcceptTime, m_active_chainstate.m_chain.Height(),
918+
CAmount currentFeeValue = ExchangeRateMap::GetInstance().CalculateExchangeValue(ws.m_base_fees, feeAsset);
919+
entry.reset(new CTxMemPoolEntry(ptx, ws.m_base_fees, feeAsset, currentFeeValue, nAcceptTime, m_active_chainstate.m_chain.Height(),
920920
fSpendsCoinbase, nSigOpsCost, lp, setPeginsSpent));
921921
ws.m_vsize = entry->GetTxSize();
922922

0 commit comments

Comments
 (0)