disconnect notarisations

This commit is contained in:
Scott Sadler
2018-05-28 23:31:42 -03:00
parent 0ffacf04dc
commit 69c67b5117
4 changed files with 28 additions and 11 deletions

View File

@@ -201,7 +201,6 @@ bool ParseNotarisationOpReturn(const CTransaction &tx, NotarisationData &data)
/* /*
* Misc * Misc
*/ */
std::string EvalToStr(EvalCode c) std::string EvalToStr(EvalCode c)
{ {
FOREACH_EVAL(EVAL_GENERATE_STRING); FOREACH_EVAL(EVAL_GENERATE_STRING);

View File

@@ -2483,6 +2483,13 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
} }
} }
// Delete from notarisations cache
NotarisationsInBlock nibs;
if (GetBlockNotarisations(block.GetHash(), nibs)) {
pnotarisations->Erase(block.GetHash());
EraseBackNotarisations(nibs);
}
// set the old best anchor back // set the old best anchor back
view.PopAnchor(blockUndo.old_tree_root); view.PopAnchor(blockUndo.old_tree_root);
@@ -2502,6 +2509,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
return AbortNode(state, "Failed to write address unspent index"); return AbortNode(state, "Failed to write address unspent index");
} }
} }
return fClean; return fClean;
} }
@@ -2836,13 +2844,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION); pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
} }
// Record Notarisations // Record Notarisations
NotarisationsInBlock notarisations = GetNotarisationsInBlock(block, pindex->nHeight); NotarisationsInBlock notarisations = GetNotarisationsInBlock(block, pindex->nHeight);
pnotarisations->Write(block.GetHash(), notarisations); if (notarisations.size() > 0) {
WriteBackNotarisations(notarisations); // Very important to disconnect this pnotarisations->Write(block.GetHash(), notarisations);
// TODO: Disconnect? WriteBackNotarisations(notarisations);
}
view.PushAnchor(tree); view.PushAnchor(tree);
if (!fJustCheck) { if (!fJustCheck) {

View File

@@ -47,11 +47,21 @@ bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n)
/* /*
* Write an index of KMD notarisation id -> backnotarisation * Write an index of KMD notarisation id -> backnotarisation
*/ */
void WriteBackNotarisations(NotarisationsInBlock notarisations) void WriteBackNotarisations(const NotarisationsInBlock notarisations)
{ {
BOOST_FOREACH(Notarisation &n, notarisations) BOOST_FOREACH(const Notarisation &n, notarisations)
{ {
if (n.second.IsBackNotarisation) if (!n.second.txHash.IsNull())
pnotarisations->Write(n.second.txHash, n); pnotarisations->Write(n.second.txHash, n);
} }
} }
void EraseBackNotarisations(const NotarisationsInBlock notarisations)
{
BOOST_FOREACH(const Notarisation &n, notarisations)
{
if (!n.second.txHash.IsNull())
pnotarisations->Erase(n.second.txHash);
}
}

View File

@@ -21,6 +21,7 @@ typedef std::vector<Notarisation> NotarisationsInBlock;
NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight); NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight);
bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs); bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs);
bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n); bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n);
void WriteBackNotarisations(NotarisationsInBlock notarisations); void WriteBackNotarisations(const NotarisationsInBlock notarisations);
void EraseBackNotarisations(const NotarisationsInBlock notarisations);
#endif /* NOTARISATIONDB_H */ #endif /* NOTARISATIONDB_H */