From 09754063e0605429680f4c58a85967777ad87cc1 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Fri, 19 Jan 2018 09:58:21 -0500 Subject: Correct mempool mapTx comment --- src/txmempool.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/txmempool.h b/src/txmempool.h index d6f8e7094b..d25d9c50bb 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -379,8 +379,9 @@ public: * * mapTx is a boost::multi_index that sorts the mempool on 4 criteria: * - transaction hash - * - feerate [we use max(feerate of tx, feerate of tx with all descendants)] + * - descendant feerate [we use max(feerate of tx, feerate of tx with all descendants)] * - time in mempool + * - ancestor feerate [we use min(feerate of tx, feerate of tx with all unconfirmed ancestors)] * * Note: the term "descendant" refers to in-mempool transactions that depend on * this one, while "ancestor" refers to in-mempool transactions that a given -- cgit v1.2.3 From e868b22917aee4c888f843bd86a2bf8ea29530eb Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Fri, 19 Jan 2018 10:38:58 -0500 Subject: fee estimator: avoid sorting mempool on shutdown --- src/init.cpp | 2 +- src/policy/fees.cpp | 13 +++++++------ src/policy/fees.h | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/init.cpp b/src/init.cpp index b48802637b..564b2b3328 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -205,7 +205,7 @@ void Shutdown() if (fFeeEstimatesInitialized) { - ::feeEstimator.FlushUnconfirmed(::mempool); + ::feeEstimator.FlushUnconfirmed(); fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; CAutoFile est_fileout(fsbridge::fopen(est_path, "wb"), SER_DISK, CLIENT_VERSION); if (!est_fileout.IsNull()) diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 9142f3706d..79b450e3e6 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -981,16 +981,17 @@ bool CBlockPolicyEstimator::Read(CAutoFile& filein) return true; } -void CBlockPolicyEstimator::FlushUnconfirmed(CTxMemPool& pool) { +void CBlockPolicyEstimator::FlushUnconfirmed() { int64_t startclear = GetTimeMicros(); - std::vector txids; - pool.queryHashes(txids); LOCK(cs_feeEstimator); - for (auto& txid : txids) { - removeTx(txid, false); + size_t num_entries = mapMemPoolTxs.size(); + // Remove every entry in mapMemPoolTxs + while (!mapMemPoolTxs.empty()) { + auto mi = mapMemPoolTxs.begin(); + removeTx(mi->first, false); // this calls erase() on mapMemPoolTxs } int64_t endclear = GetTimeMicros(); - LogPrint(BCLog::ESTIMATEFEE, "Recorded %u unconfirmed txs from mempool in %gs\n",txids.size(), (endclear - startclear)*0.000001); + LogPrint(BCLog::ESTIMATEFEE, "Recorded %u unconfirmed txs from mempool in %gs\n", num_entries, (endclear - startclear)*0.000001); } FeeFilterRounder::FeeFilterRounder(const CFeeRate& minIncrementalFee) diff --git a/src/policy/fees.h b/src/policy/fees.h index 96a842b7a1..5f69e989c1 100644 --- a/src/policy/fees.h +++ b/src/policy/fees.h @@ -223,7 +223,7 @@ public: bool Read(CAutoFile& filein); /** Empty mempool transactions on shutdown to record failure to confirm for txs still in mempool */ - void FlushUnconfirmed(CTxMemPool& pool); + void FlushUnconfirmed(); /** Calculation of highest target that estimates are tracked for */ unsigned int HighestTargetTracked(FeeEstimateHorizon horizon) const; -- cgit v1.2.3 From 669c9433cfbc6bc25243fcdb550009b2d4180cc9 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Fri, 19 Jan 2018 10:53:55 -0500 Subject: Avoid leaking prioritization information when relaying transactions --- src/txmempool.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/txmempool.h b/src/txmempool.h index d25d9c50bb..c6a1bf08ce 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -241,15 +241,18 @@ public: /** \class CompareTxMemPoolEntryByScore * - * Sort by score of entry ((fee+delta)/size) in descending order + * Sort by feerate of entry (fee/size) in descending order + * This is only used for transaction relay, so we use GetFee() + * instead of GetModifiedFee() to avoid leaking prioritization + * information via the sort order. */ class CompareTxMemPoolEntryByScore { public: bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const { - double f1 = (double)a.GetModifiedFee() * b.GetTxSize(); - double f2 = (double)b.GetModifiedFee() * a.GetTxSize(); + double f1 = (double)a.GetFee() * b.GetTxSize(); + double f2 = (double)b.GetFee() * a.GetTxSize(); if (f1 == f2) { return b.GetTx().GetHash() < a.GetTx().GetHash(); } -- cgit v1.2.3