aboutsummaryrefslogtreecommitdiff
path: root/src/index/base.h
diff options
context:
space:
mode:
authorJim Posen <jim.posen@gmail.com>2019-03-02 18:35:55 -0800
committerJim Posen <jim.posen@gmail.com>2019-04-06 12:03:21 -0700
commit4368384f1d267b011e03a805f934f5c47e2ca1b2 (patch)
tree19895592c19ffb3c2ceee7509cdda57988bf1a5f /src/index/base.h
parente439aeb30c0439001a781c5979aec41e1fc2aa50 (diff)
downloadbitcoin-4368384f1d267b011e03a805f934f5c47e2ca1b2.tar.xz
index: Allow atomic commits of index state to be extended.
Diffstat (limited to 'src/index/base.h')
-rw-r--r--src/index/base.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/index/base.h b/src/index/base.h
index 04ee6e6cc2..77e614a3af 100644
--- a/src/index/base.h
+++ b/src/index/base.h
@@ -32,7 +32,7 @@ protected:
bool ReadBestBlock(CBlockLocator& locator) const;
/// Write block locator of the chain that the txindex is in sync with.
- bool WriteBestBlock(const CBlockLocator& locator);
+ void WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator);
};
private:
@@ -54,8 +54,15 @@ private:
/// over and the sync thread exits.
void ThreadSync();
- /// Write the current chain block locator to the DB.
- bool WriteBestBlock(const CBlockIndex* block_index);
+ /// Write the current index state (eg. chain block locator and subclass-specific items) to disk.
+ ///
+ /// Recommendations for error handling:
+ /// If called on a successor of the previous committed best block in the index, the index can
+ /// continue processing without risk of corruption, though the index state will need to catch up
+ /// from further behind on reboot. If the new state is not a successor of the previous state (due
+ /// to a chain reorganization), the index must halt until Commit succeeds or else it could end up
+ /// getting corrupted.
+ bool Commit();
protected:
void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex,
@@ -69,6 +76,10 @@ protected:
/// Write update index entries for a newly connected block.
virtual bool WriteBlock(const CBlock& block, const CBlockIndex* pindex) { return true; }
+ /// Virtual method called internally by Commit that can be overridden to atomically
+ /// commit more index state.
+ virtual bool CommitInternal(CDBBatch& batch);
+
virtual DB& GetDB() const = 0;
/// Get the name of the index for display in logs.