This commit is contained in:
Calin Culianu 2020-01-05 02:16:02 +02:00
parent 89cd5e8901
commit 0f25722fb0
No known key found for this signature in database
GPG key ID: 21810A542031C02C
5 changed files with 82 additions and 0 deletions

View file

@ -139,6 +139,20 @@ void Controller::startup()
conns += connect(bitcoindmgr.get(), &BitcoinDMgr::allConnectionsLost, this, [this]{ stopTimer(mempoolLogTimer);});
}
{
// set up periodid refresh of mempool fee histogram
constexpr const char *feeHistogramTimer = "feeHistogramTimer";
constexpr int feeHistogramTimerInterval = 10 * 1000;//500 * 1000; // 500 seconds
conns += connect(this, &Controller::upToDate, this, [this] {
callOnTimerSoon(feeHistogramTimerInterval, feeHistogramTimer, [this]{
refreshMempoolHistogram();
return true;
}, false, Qt::TimerType::VeryCoarseTimer);
});
// disable the timer if synchronizing and restart it later when up-to-date
conns += connect(this, &Controller::synchronizing, this, [this]{ stopTimer(feeHistogramTimer); });
}
start(); // start our thread
}
@ -1172,6 +1186,23 @@ void Controller::process_DoUndoAndRetry()
}
}
void Controller::refreshMempoolHistogram() const
{
const auto t0 = Util::getTimeMicros();
Mempool::FeeHistogramVec hist;
{
auto [mempool, lock] = storage->mempool();
auto histtmp = mempool.calcCompactFeeHistogram();
hist.swap(histtmp);
}
const auto elapsed = Util::getTimeMicros() - t0;
Debug() << "Histogram: " << Util::Stringify(hist, [](const auto &val) {
auto & [feeRate, cumSize] = val;
return QString("(%1, %2)").arg(feeRate).arg(cumSize);
});
Debug() << "Refreshed mempool fee histogram in " << QString::number(elapsed/1e3, 'f', 4) << " msec";
}
// -- CtlTask
CtlTask::CtlTask(Controller *ctl, const QString &name)
: QObject(nullptr), ctl(ctl)