Hello I can real-time monitor max fee of all P2WSH output transactions in Bitcoin core. It is printed in console. I will add it to next version of modified bitcoin core.
After a block is mined the max fee in mempool is usually small, probably 15-30 sat/byte
But later some expensive transaction arrives and bumps it to like 150 sat/byte, sometimes up to 220 sat/byte
Then a block is mined.
Here is a patch:
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index 68f47d5cc..4ca668a15 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -332,6 +332,8 @@ CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator) :
// accepting transactions becomes O(N^2) where N is the number
// of transactions in the pool
nCheckFrequency = 0;
+
+ maxP2WSHFee.clear();
}
bool CTxMemPool::isSpent(const COutPoint& outpoint) const
@@ -399,6 +401,21 @@ void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAnces
totalTxSize += entry.GetTxSize();
if (minerPolicyEstimator) {minerPolicyEstimator->processTransaction(entry, validFeeEstimate);}
+ // check if it's P2WSH
+ for (unsigned int i = 0; i < tx.vout.size(); i++) {
+ CTxOut out = tx.vout[i];
+ CScript scriptPubKey = out.scriptPubKey;
+ if (scriptPubKey.IsPayToWitnessScriptHash()) {
+ CFeeRate P2WSHFee = CFeeRate(entry.GetFee(), entry.GetTxSize()); // entry.GetTxSize();
+ uint64_t feerate = (((uint64_t)P2WSHFee.GetFeePerK()) << 32 | (((base_blob<256>)tx.GetHash()).GetUint64(0) >> 32));
+ this->maxP2WSHFee.insert(feerate);
+ feerate = *(this->maxP2WSHFee.rbegin());
+ //::maxP2WSHFee = feerate >> 32;
+ printf("MAX FEE IN POOL: %lu\n", feerate >> 32);
+ break;
+ }
+ }
+
vTxHashes.emplace_back(tx.GetWitnessHash(), newit);
newit->vTxHashesIdx = vTxHashes.size() - 1;
}
@@ -553,8 +572,25 @@ void CTxMemPool::removeForBlock(const std::vector& vtx, unsigne
for (const auto& tx : vtx)
{
uint256 hash = tx->GetHash();
-
indexed_transaction_set::iterator i = mapTx.find(hash);
+
+
+ // check if it's P2WSH
+ for (unsigned int ii = 0; ii < tx->vout.size(); ii++) {
+ CTxOut out = tx->vout[ii];
+ CScript scriptPubKey = out.scriptPubKey;
+ if (scriptPubKey.IsPayToWitnessScriptHash()) {
+ CFeeRate P2WSHFee = CFeeRate((i)->GetFee(), (i)->GetTxSize()); // entry.GetTxSize();
+ uint64_t feerate = (((uint64_t)P2WSHFee.GetFeePerK()) << 32 | (((base_blob<256>)tx->GetHash()).GetUint64(0) >> 32));
+ this->maxP2WSHFee.erase(feerate);
+ feerate = *(this->maxP2WSHFee.rbegin());
+ //::maxP2WSHFee = feerate >> 32;
+ printf("MAX FEE IN POOL: %lu\n", feerate >> 32);
+ break;
+ }
+ }
+
+
if (i != mapTx.end())
entries.push_back(&*i);
}
@@ -586,6 +624,7 @@ void CTxMemPool::_clear()
blockSinceLastRollingFeeBump = false;
rollingMinimumFeeRate = 0;
++nTransactionsUpdated;
+ maxP2WSHFee.clear();
}
void CTxMemPool::clear()
diff --git a/src/txmempool.h b/src/txmempool.h
index f7afaec8f..6fe7cff47 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -457,6 +457,8 @@ private:
public:
+ std::set maxP2WSHFee;
+
static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; // public only for testing
typedef boost::multi_index_container<