mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
kernel: Add progress method to notifications
This commit is part of the libbitcoinkernel project and seeks to remove the ChainstateManager's and, more generally, the kernel library's dependency on interface_ui with options methods in this and the following few commits. By removing interface_ui from the kernel library, its dependency on boost is reduced to just boost::multi_index.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <hash.h>
|
||||
#include <kernel/chainparams.h>
|
||||
#include <kernel/mempool_entry.h>
|
||||
#include <kernel/notifications_interface.h>
|
||||
#include <logging.h>
|
||||
#include <logging/timer.h>
|
||||
#include <node/blockstorage.h>
|
||||
@@ -72,6 +73,7 @@ using kernel::CCoinsStats;
|
||||
using kernel::CoinStatsHashType;
|
||||
using kernel::ComputeUTXOStats;
|
||||
using kernel::LoadMempool;
|
||||
using kernel::Notifications;
|
||||
|
||||
using fsbridge::FopenFn;
|
||||
using node::BlockManager;
|
||||
@@ -4145,14 +4147,15 @@ bool Chainstate::LoadChainTip()
|
||||
return true;
|
||||
}
|
||||
|
||||
CVerifyDB::CVerifyDB()
|
||||
CVerifyDB::CVerifyDB(Notifications& notifications)
|
||||
: m_notifications{notifications}
|
||||
{
|
||||
uiInterface.ShowProgress(_("Verifying blocks…").translated, 0, false);
|
||||
m_notifications.progress(_("Verifying blocks…"), 0, false);
|
||||
}
|
||||
|
||||
CVerifyDB::~CVerifyDB()
|
||||
{
|
||||
uiInterface.ShowProgress("", 100, false);
|
||||
m_notifications.progress(bilingual_str{}, 100, false);
|
||||
}
|
||||
|
||||
VerifyDBResult CVerifyDB::VerifyDB(
|
||||
@@ -4192,7 +4195,7 @@ VerifyDBResult CVerifyDB::VerifyDB(
|
||||
LogPrintf("Verification progress: %d%%\n", percentageDone);
|
||||
reportDone = percentageDone / 10;
|
||||
}
|
||||
uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false);
|
||||
m_notifications.progress(_("Verifying blocks…"), percentageDone, false);
|
||||
if (pindex->nHeight <= chainstate.m_chain.Height() - nCheckDepth) {
|
||||
break;
|
||||
}
|
||||
@@ -4268,7 +4271,7 @@ VerifyDBResult CVerifyDB::VerifyDB(
|
||||
LogPrintf("Verification progress: %d%%\n", percentageDone);
|
||||
reportDone = percentageDone / 10;
|
||||
}
|
||||
uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false);
|
||||
m_notifications.progress(_("Verifying blocks…"), percentageDone, false);
|
||||
pindex = chainstate.m_chain.Next(pindex);
|
||||
CBlock block;
|
||||
if (!chainstate.m_blockman.ReadBlockFromDisk(block, *pindex)) {
|
||||
@@ -4327,7 +4330,7 @@ bool Chainstate::ReplayBlocks()
|
||||
if (hashHeads.empty()) return true; // We're already in a consistent state.
|
||||
if (hashHeads.size() != 2) return error("ReplayBlocks(): unknown inconsistent state");
|
||||
|
||||
uiInterface.ShowProgress(_("Replaying blocks…").translated, 0, false);
|
||||
m_chainman.GetNotifications().progress(_("Replaying blocks…"), 0, false);
|
||||
LogPrintf("Replaying blocks\n");
|
||||
|
||||
const CBlockIndex* pindexOld = nullptr; // Old tip during the interrupted flush.
|
||||
@@ -4374,13 +4377,13 @@ bool Chainstate::ReplayBlocks()
|
||||
const CBlockIndex& pindex{*Assert(pindexNew->GetAncestor(nHeight))};
|
||||
|
||||
LogPrintf("Rolling forward %s (%i)\n", pindex.GetBlockHash().ToString(), nHeight);
|
||||
uiInterface.ShowProgress(_("Replaying blocks…").translated, (int) ((nHeight - nForkHeight) * 100.0 / (pindexNew->nHeight - nForkHeight)) , false);
|
||||
m_chainman.GetNotifications().progress(_("Replaying blocks…"), (int)((nHeight - nForkHeight) * 100.0 / (pindexNew->nHeight - nForkHeight)), false);
|
||||
if (!RollforwardBlock(&pindex, cache)) return false;
|
||||
}
|
||||
|
||||
cache.SetBestBlock(pindexNew->GetBlockHash());
|
||||
cache.Flush();
|
||||
uiInterface.ShowProgress("", 100, false);
|
||||
m_chainman.GetNotifications().progress(bilingual_str{}, 100, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user