Changeset View
Changeset View
Standalone View
Standalone View
src/policy/fees.cpp
Show First 20 Lines • Show All 348 Lines • ▼ Show 20 Lines | CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate &_minRelayFee) | ||||
} | } | ||||
vfeelist.push_back(INF_FEERATE); | vfeelist.push_back(INF_FEERATE); | ||||
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 txhash = entry.GetTx().GetHash(); | ||||
if (mapMemPoolTxs.count(txid)) { | if (mapMemPoolTxs.count(txhash)) { | ||||
LogPrint("estimatefee", | LogPrint("estimatefee", | ||||
"Blockpolicy error mempool tx %s already being tracked\n", | "Blockpolicy error mempool tx %s already being tracked\n", | ||||
txid.ToString().c_str()); | txhash.ToString().c_str()); | ||||
return; | return; | ||||
} | } | ||||
if (txHeight != nBestSeenHeight) { | if (txHeight != nBestSeenHeight) { | ||||
// Ignore side chains and re-orgs; assuming they are random they don't | // Ignore side chains and re-orgs; assuming they are random they don't | ||||
// affect the estimate. We'll potentially double count transactions in | // affect the estimate. We'll potentially double count transactions in | ||||
// 1-block reorgs. Ignore txs if BlockPolicyEstimator is not in sync | // 1-block reorgs. Ignore txs if BlockPolicyEstimator is not in sync | ||||
// with chainActive.Tip(). It will be synced next time a block is | // with chainActive.Tip(). It will be synced next time a block is | ||||
// processed. | // processed. | ||||
return; | return; | ||||
} | } | ||||
// Only want to be updating estimates when our blockchain is synced, | // Only want to be updating estimates when our blockchain is synced, | ||||
// otherwise we'll miscalculate how many blocks its taking to get included. | // otherwise we'll miscalculate how many blocks its taking to get included. | ||||
if (!validFeeEstimate) { | if (!validFeeEstimate) { | ||||
untrackedTxs++; | untrackedTxs++; | ||||
return; | return; | ||||
} | } | ||||
trackedTxs++; | trackedTxs++; | ||||
// Feerates are stored and reported as BCC-per-kb: | // Feerates are stored and reported as BCC-per-kb: | ||||
CFeeRate feeRate(entry.GetFee(), entry.GetTxSize()); | CFeeRate feeRate(entry.GetFee(), entry.GetTxSize()); | ||||
mapMemPoolTxs[txid].blockHeight = txHeight; | mapMemPoolTxs[txhash].blockHeight = txHeight; | ||||
mapMemPoolTxs[txid].bucketIndex = | mapMemPoolTxs[txhash].bucketIndex = | ||||
feeStats.NewTx(txHeight, double(feeRate.GetFeePerK().GetSatoshis())); | feeStats.NewTx(txHeight, double(feeRate.GetFeePerK().GetSatoshis())); | ||||
} | } | ||||
bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, | bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, | ||||
const CTxMemPoolEntry *entry) { | const CTxMemPoolEntry *entry) { | ||||
if (!removeTx(entry->GetTx().GetId())) { | if (!removeTx(entry->GetTx().GetHash())) { | ||||
// This transaction wasn't being tracked for fee estimation | // This transaction wasn't being tracked for fee estimation | ||||
return false; | return false; | ||||
} | } | ||||
// How many blocks did it take for miners to include this transaction? | // How many blocks did it take for miners to include this transaction? | ||||
// blocksToConfirm is 1-based, so a transaction included in the earliest | // blocksToConfirm is 1-based, so a transaction included in the earliest | ||||
// possible block has confirmation count of 1 | // possible block has confirmation count of 1 | ||||
int blocksToConfirm = nBlockHeight - entry->GetHeight(); | int blocksToConfirm = nBlockHeight - entry->GetHeight(); | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |