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
*/
std::string EvalToStr(EvalCode c)
{
FOREACH_EVAL(EVAL_GENERATE_STRING);

View File

@@ -2482,7 +2482,14 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
RemoveImportTombstone(tx, view);
}
}
// Delete from notarisations cache
NotarisationsInBlock nibs;
if (GetBlockNotarisations(block.GetHash(), nibs)) {
pnotarisations->Erase(block.GetHash());
EraseBackNotarisations(nibs);
}
// set the old best anchor back
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 fClean;
}
@@ -2836,13 +2844,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
}
// Record Notarisations
NotarisationsInBlock notarisations = GetNotarisationsInBlock(block, pindex->nHeight);
pnotarisations->Write(block.GetHash(), notarisations);
WriteBackNotarisations(notarisations); // Very important to disconnect this
// TODO: Disconnect?
if (notarisations.size() > 0) {
pnotarisations->Write(block.GetHash(), notarisations);
WriteBackNotarisations(notarisations);
}
view.PushAnchor(tree);
if (!fJustCheck) {

View File

@@ -47,11 +47,21 @@ bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n)
/*
* 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);
}
}
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);
bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs);
bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n);
void WriteBackNotarisations(NotarisationsInBlock notarisations);
void WriteBackNotarisations(const NotarisationsInBlock notarisations);
void EraseBackNotarisations(const NotarisationsInBlock notarisations);
#endif /* NOTARISATIONDB_H */