log notarisations written to index
This commit is contained in:
28
src/main.cpp
28
src/main.cpp
@@ -2486,8 +2486,12 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
|
|||||||
// Delete from notarisations cache
|
// Delete from notarisations cache
|
||||||
NotarisationsInBlock nibs;
|
NotarisationsInBlock nibs;
|
||||||
if (GetBlockNotarisations(block.GetHash(), nibs)) {
|
if (GetBlockNotarisations(block.GetHash(), nibs)) {
|
||||||
pnotarisations->Erase(block.GetHash());
|
CLevelDBBatch batch;
|
||||||
EraseBackNotarisations(nibs);
|
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
|
// 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));
|
vPos.push_back(std::make_pair(tx.GetHash(), pos));
|
||||||
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
|
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);
|
view.PushAnchor(tree);
|
||||||
if (!fJustCheck) {
|
if (!fJustCheck) {
|
||||||
pindex->hashAnchorEnd = tree.root();
|
pindex->hashAnchorEnd = tree.root();
|
||||||
@@ -2920,6 +2917,17 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
|||||||
pindex->RaiseValidity(BLOCK_VALID_SCRIPTS);
|
pindex->RaiseValidity(BLOCK_VALID_SCRIPTS);
|
||||||
setDirtyBlockIndex.insert(pindex);
|
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 (fTxIndex)
|
||||||
if (!pblocktree->WriteTxIndex(vPos))
|
if (!pblocktree->WriteTxIndex(vPos))
|
||||||
|
|||||||
@@ -61,25 +61,24 @@ bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n)
|
|||||||
/*
|
/*
|
||||||
* Write an index of KMD notarisation id -> backnotarisation
|
* 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)
|
BOOST_FOREACH(const Notarisation &n, notarisations)
|
||||||
{
|
{
|
||||||
if (!n.second.txHash.IsNull())
|
if (!n.second.txHash.IsNull()) {
|
||||||
batch.Write(n.second.txHash, n);
|
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)
|
BOOST_FOREACH(const Notarisation &n, notarisations)
|
||||||
{
|
{
|
||||||
if (!n.second.txHash.IsNull())
|
if (!n.second.txHash.IsNull())
|
||||||
batch.Erase(n.second.txHash);
|
batch.Erase(n.second.txHash);
|
||||||
}
|
}
|
||||||
pnotarisations->WriteBatch(batch, true);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +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(const NotarisationsInBlock notarisations);
|
void WriteBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch);
|
||||||
void EraseBackNotarisations(const NotarisationsInBlock notarisations);
|
void EraseBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch);
|
||||||
|
|
||||||
#endif /* NOTARISATIONDB_H */
|
#endif /* NOTARISATIONDB_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user