log notarisations written to index

This commit is contained in:
Scott Sadler
2018-06-11 17:29:16 +02:00
parent 89cfc4272d
commit 846384769c
3 changed files with 26 additions and 19 deletions

View File

@@ -2486,8 +2486,12 @@ 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);
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
@@ -2844,14 +2848,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
vPos.push_back(std::make_pair(tx.GetHash(), pos));
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
}
// Record Notarisations
NotarisationsInBlock notarisations = GetNotarisationsInBlock(block, pindex->nHeight);
if (notarisations.size() > 0) {
pnotarisations->Write(block.GetHash(), notarisations);
WriteBackNotarisations(notarisations);
}
view.PushAnchor(tree);
if (!fJustCheck) {
pindex->hashAnchorEnd = tree.root();
@@ -2920,6 +2917,17 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
pindex->RaiseValidity(BLOCK_VALID_SCRIPTS);
setDirtyBlockIndex.insert(pindex);
}
// Record Notarisations
NotarisationsInBlock notarisations = GetNotarisationsInBlock(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 (!pblocktree->WriteTxIndex(vPos))

View File

@@ -61,25 +61,24 @@ bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n)
/*
* Write an index of KMD notarisation id -> backnotarisation
*/
void WriteBackNotarisations(const NotarisationsInBlock notarisations)
void WriteBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch)
{
CLevelDBBatch batch;
int wrote = 0;
BOOST_FOREACH(const Notarisation &n, notarisations)
{
if (!n.second.txHash.IsNull())
if (!n.second.txHash.IsNull()) {
batch.Write(n.second.txHash, n);
wrote++;
}
}
pnotarisations->WriteBatch(batch, true);
}
void EraseBackNotarisations(const NotarisationsInBlock notarisations)
void EraseBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch)
{
CLevelDBBatch batch;
BOOST_FOREACH(const Notarisation &n, notarisations)
{
if (!n.second.txHash.IsNull())
batch.Erase(n.second.txHash);
}
pnotarisations->WriteBatch(batch, true);
}

View File

@@ -21,7 +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(const NotarisationsInBlock notarisations);
void EraseBackNotarisations(const NotarisationsInBlock notarisations);
void WriteBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch);
void EraseBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch);
#endif /* NOTARISATIONDB_H */