Changeset View
Changeset View
Standalone View
Standalone View
src/policy/fees.cpp
Show First 20 Lines • Show All 320 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
// This function is called from CTxMemPool::removeUnchecked to ensure txs | // This function is called from CTxMemPool::removeUnchecked to ensure txs | ||||
// removed from the mempool for any reason are no longer tracked. Txs that were | // removed from the mempool for any reason are no longer tracked. Txs that were | ||||
// part of a block have already been removed in processBlockTx to ensure they | // part of a block have already been removed in processBlockTx to ensure they | ||||
// are never double tracked, but it is of no harm to try to remove them again. | // are never double tracked, but it is of no harm to try to remove them again. | ||||
bool CBlockPolicyEstimator::removeTx(uint256 hash) { | bool CBlockPolicyEstimator::removeTx(uint256 hash) { | ||||
std::map<uint256, TxStatsInfo>::iterator pos = mapMemPoolTxs.find(hash); | std::map<uint256, TxStatsInfo>::iterator pos = mapMemPoolTxs.find(hash); | ||||
if (pos != mapMemPoolTxs.end()) { | if (pos == mapMemPoolTxs.end()) { | ||||
return false; | |||||
} | |||||
feeStats.removeTx(pos->second.blockHeight, nBestSeenHeight, | feeStats.removeTx(pos->second.blockHeight, nBestSeenHeight, | ||||
pos->second.bucketIndex); | pos->second.bucketIndex); | ||||
mapMemPoolTxs.erase(hash); | mapMemPoolTxs.erase(hash); | ||||
return true; | return true; | ||||
} else { | |||||
return false; | |||||
} | |||||
} | } | ||||
CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate &_minRelayFee) | CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate &_minRelayFee) | ||||
: nBestSeenHeight(0), trackedTxs(0), untrackedTxs(0) { | : nBestSeenHeight(0), trackedTxs(0), untrackedTxs(0) { | ||||
static_assert(MIN_FEERATE > 0, "Min feerate must be nonzero"); | static_assert(MIN_FEERATE > Amount(0), "Min feerate must be nonzero"); | ||||
minTrackedFee = _minRelayFee < CFeeRate(Amount(int64_t(MIN_FEERATE))) | CFeeRate minFeeRate(MIN_FEERATE); | ||||
? CFeeRate(Amount(int64_t(MIN_FEERATE))) | minTrackedFee = _minRelayFee < minFeeRate ? minFeeRate : _minRelayFee; | ||||
: _minRelayFee; | |||||
std::vector<double> vfeelist; | std::vector<double> vfeelist; | ||||
for (Amount bucketBoundary = minTrackedFee.GetFeePerK(); | for (double bucketBoundary = minTrackedFee.GetFeePerK().GetSatoshis(); | ||||
bucketBoundary <= MAX_FEERATE; | bucketBoundary <= double(MAX_FEERATE.GetSatoshis()); | ||||
bucketBoundary += bucketBoundary / FEE_SPACING_FRACTION) { | bucketBoundary *= FEE_SPACING) { | ||||
vfeelist.push_back(double(bucketBoundary.GetSatoshis())); | vfeelist.push_back(bucketBoundary); | ||||
} | } | ||||
vfeelist.push_back(double(INF_FEERATE.GetSatoshis())); | vfeelist.push_back(double(INF_FEERATE.GetSatoshis())); | ||||
feeStats.Initialize(vfeelist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY); | feeStats.Initialize(vfeelist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY); | ||||
} | } | ||||
void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry &entry, | void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry &entry, | ||||
bool validFeeEstimate) { | bool validFeeEstimate) { | ||||
uint32_t txHeight = entry.GetHeight(); | uint32_t txHeight = entry.GetHeight(); | ||||
uint256 txid = entry.GetTx().GetId(); | uint256 txid = entry.GetTx().GetId(); | ||||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | if (nFileVersion < 139900) { | ||||
priStats.Read(filein); | priStats.Read(filein); | ||||
} | } | ||||
} | } | ||||
FeeFilterRounder::FeeFilterRounder(const CFeeRate &minIncrementalFee) { | FeeFilterRounder::FeeFilterRounder(const CFeeRate &minIncrementalFee) { | ||||
Amount minFeeLimit = | Amount minFeeLimit = | ||||
std::max(Amount(1), minIncrementalFee.GetFeePerK() / 2); | std::max(Amount(1), minIncrementalFee.GetFeePerK() / 2); | ||||
feeset.insert(Amount(0)); | feeset.insert(Amount(0)); | ||||
for (Amount bucketBoundary = minFeeLimit; bucketBoundary <= MAX_FEERATE; | for (double bucketBoundary = minFeeLimit.GetSatoshis(); | ||||
bucketBoundary += bucketBoundary / FEE_SPACING_FRACTION) { | bucketBoundary <= double(MAX_FEERATE.GetSatoshis()); | ||||
feeset.insert(bucketBoundary); | bucketBoundary *= FEE_SPACING) { | ||||
feeset.insert(Amount(int64_t(bucketBoundary))); | |||||
} | } | ||||
} | } | ||||
Amount FeeFilterRounder::round(const Amount currentMinFee) { | Amount FeeFilterRounder::round(const Amount currentMinFee) { | ||||
std::set<Amount>::iterator it = feeset.lower_bound(currentMinFee); | auto it = feeset.lower_bound(currentMinFee); | ||||
if ((it != feeset.begin() && insecure_rand.rand32() % 3 != 0) || | if ((it != feeset.begin() && insecure_rand.rand32() % 3 != 0) || | ||||
it == feeset.end()) { | it == feeset.end()) { | ||||
it--; | it--; | ||||
} | } | ||||
return *it; | return *it; | ||||
} | } |