From 69c67b5117cad7bf52ca3189727419e67f965f7b Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Mon, 28 May 2018 23:31:42 -0300 Subject: [PATCH] disconnect notarisations --- src/cc/eval.cpp | 1 - src/main.cpp | 19 +++++++++++++------ src/notarisationdb.cpp | 16 +++++++++++++--- src/notarisationdb.h | 3 ++- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 2c966f192..25550d1e2 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -201,7 +201,6 @@ bool ParseNotarisationOpReturn(const CTransaction &tx, NotarisationData &data) /* * Misc */ - std::string EvalToStr(EvalCode c) { FOREACH_EVAL(EVAL_GENERATE_STRING); diff --git a/src/main.cpp b/src/main.cpp index a3bd0f515..2e73f2af0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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) { diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index 42a3ae41f..18b9da685 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -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); + } +} diff --git a/src/notarisationdb.h b/src/notarisationdb.h index 0e3d48c00..27f979784 100644 --- a/src/notarisationdb.h +++ b/src/notarisationdb.h @@ -21,6 +21,7 @@ typedef std::vector 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 */