Changeset View
Changeset View
Standalone View
Standalone View
src/index/coinstatsindex.cpp
Show First 20 Lines • Show All 242 Lines • ▼ Show 20 Lines | bool CoinStatsIndex::WriteBlock(const CBlock &block, | ||||
value.second.total_unspendables_scripts = m_total_unspendables_scripts; | value.second.total_unspendables_scripts = m_total_unspendables_scripts; | ||||
value.second.total_unspendables_unclaimed_rewards = | value.second.total_unspendables_unclaimed_rewards = | ||||
m_total_unspendables_unclaimed_rewards; | m_total_unspendables_unclaimed_rewards; | ||||
uint256 out; | uint256 out; | ||||
m_muhash.Finalize(out); | m_muhash.Finalize(out); | ||||
value.second.muhash = out; | value.second.muhash = out; | ||||
CDBBatch batch(*m_db); | // Intentionally do not update DB_MUHASH here so it stays in sync with | ||||
batch.Write(DBHeightKey(pindex->nHeight), value); | // DB_BEST_BLOCK, and the index is not corrupted if there is an unclean | ||||
batch.Write(DB_MUHASH, m_muhash); | // shutdown. | ||||
return m_db->WriteBatch(batch); | return m_db->Write(DBHeightKey(pindex->nHeight), value); | ||||
} | } | ||||
static bool CopyHeightIndexToHashIndex(CDBIterator &db_it, CDBBatch &batch, | static bool CopyHeightIndexToHashIndex(CDBIterator &db_it, CDBBatch &batch, | ||||
const std::string &index_name, | const std::string &index_name, | ||||
int start_height, int stop_height) { | int start_height, int stop_height) { | ||||
DBHeightKey key{start_height}; | DBHeightKey key{start_height}; | ||||
db_it.Seek(key); | db_it.Seek(key); | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | if (pindex) { | ||||
m_total_unspendables_scripts = entry.total_unspendables_scripts; | m_total_unspendables_scripts = entry.total_unspendables_scripts; | ||||
m_total_unspendables_unclaimed_rewards = | m_total_unspendables_unclaimed_rewards = | ||||
entry.total_unspendables_unclaimed_rewards; | entry.total_unspendables_unclaimed_rewards; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool CoinStatsIndex::CommitInternal(CDBBatch &batch) { | |||||
// DB_MUHASH should always be committed in a batch together with | |||||
// DB_BEST_BLOCK to prevent an inconsistent state of the DB. | |||||
batch.Write(DB_MUHASH, m_muhash); | |||||
return BaseIndex::CommitInternal(batch); | |||||
} | |||||
// Reverse a single block as part of a reorg | // Reverse a single block as part of a reorg | ||||
bool CoinStatsIndex::ReverseBlock(const CBlock &block, | bool CoinStatsIndex::ReverseBlock(const CBlock &block, | ||||
const CBlockIndex *pindex) { | const CBlockIndex *pindex) { | ||||
CBlockUndo block_undo; | CBlockUndo block_undo; | ||||
std::pair<BlockHash, DBVal> read_out; | std::pair<BlockHash, DBVal> read_out; | ||||
const Amount block_subsidy{ | const Amount block_subsidy{ | ||||
GetBlockSubsidy(pindex->nHeight, Params().GetConsensus())}; | GetBlockSubsidy(pindex->nHeight, Params().GetConsensus())}; | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | Assert(m_total_unspendables_genesis_block == | ||||
read_out.second.total_unspendables_genesis_block); | read_out.second.total_unspendables_genesis_block); | ||||
Assert(m_total_unspendables_bip30 == | Assert(m_total_unspendables_bip30 == | ||||
read_out.second.total_unspendables_bip30); | read_out.second.total_unspendables_bip30); | ||||
Assert(m_total_unspendables_scripts == | Assert(m_total_unspendables_scripts == | ||||
read_out.second.total_unspendables_scripts); | read_out.second.total_unspendables_scripts); | ||||
Assert(m_total_unspendables_unclaimed_rewards == | Assert(m_total_unspendables_unclaimed_rewards == | ||||
read_out.second.total_unspendables_unclaimed_rewards); | read_out.second.total_unspendables_unclaimed_rewards); | ||||
return m_db->Write(DB_MUHASH, m_muhash); | return true; | ||||
} | } |