move disconnect notarisations from DisconnectBlock to DisconnectTip
This commit is contained in:
@@ -75,8 +75,8 @@ int ScanNotarisationsFromHeight(int nHeight, const IsTarget f, Notarisation &fou
|
|||||||
|
|
||||||
for (int h=nHeight; h<limit; h++) {
|
for (int h=nHeight; h<limit; h++) {
|
||||||
NotarisationsInBlock notarisations;
|
NotarisationsInBlock notarisations;
|
||||||
uint256 blockHash = *chainActive[h]->phashBlock;
|
|
||||||
if (!GetBlockNotarisations(blockHash, notarisations))
|
if (!GetBlockNotarisations(*chainActive[h]->phashBlock, notarisations))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
BOOST_FOREACH(found, notarisations) {
|
BOOST_FOREACH(found, notarisations) {
|
||||||
|
|||||||
54
src/main.cpp
54
src/main.cpp
@@ -2349,6 +2349,37 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, const CO
|
|||||||
return fClean;
|
return fClean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ConnectNotarisations(const CBlock &block, int height)
|
||||||
|
{
|
||||||
|
// Record Notarisations
|
||||||
|
NotarisationsInBlock notarisations = ScanBlockNotarisations(block, height);
|
||||||
|
if (notarisations.size() > 0) {
|
||||||
|
CLevelDBBatch batch;
|
||||||
|
batch.Write(block.GetHash(), notarisations);
|
||||||
|
WriteBackNotarisations(notarisations, batch);
|
||||||
|
pnotarisations->WriteBatch(batch, true);
|
||||||
|
LogPrintf("ConnectBlock: wrote %i block notarisations in block: %s\n",
|
||||||
|
notarisations.size(), block.GetHash().GetHex().data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DisconnectNotarisations(const CBlock &block)
|
||||||
|
{
|
||||||
|
// Delete from notarisations cache
|
||||||
|
NotarisationsInBlock nibs;
|
||||||
|
if (GetBlockNotarisations(block.GetHash(), nibs)) {
|
||||||
|
CLevelDBBatch batch;
|
||||||
|
batch.Erase(block.GetHash());
|
||||||
|
EraseBackNotarisations(nibs, batch);
|
||||||
|
pnotarisations->WriteBatch(batch, true);
|
||||||
|
LogPrintf("DisconnectTip: deleted %i block notarisations in block: %s\n",
|
||||||
|
nibs.size(), block.GetHash().GetHex().data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool* pfClean)
|
bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool* pfClean)
|
||||||
{
|
{
|
||||||
assert(pindex->GetBlockHash() == view.GetBestBlock());
|
assert(pindex->GetBlockHash() == view.GetBestBlock());
|
||||||
@@ -2483,17 +2514,6 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete from notarisations cache
|
|
||||||
NotarisationsInBlock nibs;
|
|
||||||
if (GetBlockNotarisations(block.GetHash(), nibs)) {
|
|
||||||
CLevelDBBatch batch;
|
|
||||||
batch.Erase(block.GetHash());
|
|
||||||
EraseBackNotarisations(nibs, batch);
|
|
||||||
pnotarisations->WriteBatch(batch, true);
|
|
||||||
LogPrintf("ConnectBlock: Deleted %i block notarisations in block: %s\n",
|
|
||||||
nibs.size(), block.GetHash().GetHex().data());
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the old best anchor back
|
// set the old best anchor back
|
||||||
view.PopAnchor(blockUndo.old_tree_root);
|
view.PopAnchor(blockUndo.old_tree_root);
|
||||||
|
|
||||||
@@ -2918,16 +2938,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|||||||
setDirtyBlockIndex.insert(pindex);
|
setDirtyBlockIndex.insert(pindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record Notarisations
|
ConnectNotarisations(block, pindex->nHeight);
|
||||||
NotarisationsInBlock notarisations = ScanBlockNotarisations(block, pindex->nHeight);
|
|
||||||
if (notarisations.size() > 0) {
|
|
||||||
CLevelDBBatch batch;
|
|
||||||
batch.Write(block.GetHash(), notarisations);
|
|
||||||
WriteBackNotarisations(notarisations, batch);
|
|
||||||
pnotarisations->WriteBatch(batch, true);
|
|
||||||
LogPrintf("ConnectBlock: wrote %i block notarisations in block: %s\n",
|
|
||||||
notarisations.size(), block.GetHash().GetHex().data());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fTxIndex)
|
if (fTxIndex)
|
||||||
if (!pblocktree->WriteTxIndex(vPos))
|
if (!pblocktree->WriteTxIndex(vPos))
|
||||||
@@ -3165,6 +3176,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
|
|||||||
if (!DisconnectBlock(block, state, pindexDelete, view))
|
if (!DisconnectBlock(block, state, pindexDelete, view))
|
||||||
return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
|
return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
|
||||||
assert(view.Flush());
|
assert(view.Flush());
|
||||||
|
DisconnectNotarisations(block);
|
||||||
}
|
}
|
||||||
LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
|
LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
|
||||||
uint256 anchorAfterDisconnect = pcoinsTip->GetBestAnchor();
|
uint256 anchorAfterDisconnect = pcoinsTip->GetBestAnchor();
|
||||||
|
|||||||
Reference in New Issue
Block a user