mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
Allow untrimming headers when needed
This commit is contained in:
parent
4259278ff5
commit
c28c5ce619
5 changed files with 40 additions and 0 deletions
|
|
@ -2573,6 +2573,11 @@ bool CChainState::FlushStateToDisk(
|
|||
{
|
||||
LOG_TIME_MILLIS_WITH_CATEGORY("write block index to disk", BCLog::BENCH);
|
||||
|
||||
if (node::fTrimHeaders) {
|
||||
for (std::set<CBlockIndex*>::iterator it = setTrimmableBlockIndex.begin(); it != setTrimmableBlockIndex.end(); it++) {
|
||||
(*it)->untrim();
|
||||
}
|
||||
}
|
||||
if (!m_blockman.WriteBlockIndexDB()) {
|
||||
return AbortNode(state, "Failed to write to block index database");
|
||||
}
|
||||
|
|
@ -2709,6 +2714,17 @@ static void UpdateTipLog(
|
|||
!warning_messages.empty() ? strprintf(" warning='%s'", warning_messages) : "");
|
||||
}
|
||||
|
||||
void ForceUntrimHeader(const CBlockIndex *pindex_)
|
||||
{
|
||||
assert(pindex_);
|
||||
if (!pindex_->trimmed()) {
|
||||
return;
|
||||
}
|
||||
AssertLockHeld(cs_main);
|
||||
CBlockIndex *pindex=const_cast<CBlockIndex*>(pindex_);
|
||||
pindex->untrim();
|
||||
}
|
||||
|
||||
void CChainState::UpdateTip(const CBlockIndex* pindexNew)
|
||||
{
|
||||
AssertLockHeld(::cs_main);
|
||||
|
|
@ -2754,11 +2770,13 @@ void CChainState::UpdateTip(const CBlockIndex* pindexNew)
|
|||
}
|
||||
UpdateTipLog(coins_tip, pindexNew, m_params, __func__, "", warning_messages.original);
|
||||
|
||||
ForceUntrimHeader(pindexNew);
|
||||
// Do some logging if dynafed parameters changed.
|
||||
if (pindexNew->pprev && !pindexNew->dynafed_params().IsNull()) {
|
||||
int height = pindexNew->nHeight;
|
||||
uint256 hash = pindexNew->GetBlockHash();
|
||||
uint256 root = pindexNew->dynafed_params().m_current.CalculateRoot();
|
||||
ForceUntrimHeader(pindexNew->pprev);
|
||||
if (pindexNew->pprev->dynafed_params().IsNull()) {
|
||||
LogPrintf("Dynafed activated in block %d:%s: %s\n", height, hash.GetHex(), root.GetHex());
|
||||
} else if (root != pindexNew->pprev->dynafed_params().m_current.CalculateRoot()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue