Browse Source

move disconnect notarisations from DisconnectBlock to DisconnectTip

pull/4/head
Scott Sadler 6 years ago
parent
commit
84964112be
  1. 4
      src/crosschain.cpp
  2. 54
      src/main.cpp

4
src/crosschain.cpp

@ -75,8 +75,8 @@ int ScanNotarisationsFromHeight(int nHeight, const IsTarget f, Notarisation &fou
for (int h=nHeight; h<limit; h++) {
NotarisationsInBlock notarisations;
uint256 blockHash = *chainActive[h]->phashBlock;
if (!GetBlockNotarisations(blockHash, notarisations))
if (!GetBlockNotarisations(*chainActive[h]->phashBlock, notarisations))
continue;
BOOST_FOREACH(found, notarisations) {

54
src/main.cpp

@ -2349,6 +2349,37 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, const CO
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)
{
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
view.PopAnchor(blockUndo.old_tree_root);
@ -2918,16 +2938,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
setDirtyBlockIndex.insert(pindex);
}
// Record Notarisations
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());
}
ConnectNotarisations(block, pindex->nHeight);
if (fTxIndex)
if (!pblocktree->WriteTxIndex(vPos))
@ -3165,6 +3176,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
if (!DisconnectBlock(block, state, pindexDelete, view))
return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
assert(view.Flush());
DisconnectNotarisations(block);
}
LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
uint256 anchorAfterDisconnect = pcoinsTip->GetBestAnchor();

Loading…
Cancel
Save