@@ -111,24 +111,27 @@ CoinStatsIndex::CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain, size_t
111111 m_db = std::make_unique<CoinStatsIndex::DB>(path / " db" , n_cache_size, f_memory, f_wipe);
112112}
113113
114- bool CoinStatsIndex::WriteBlock (const CBlock & block, const CBlockIndex* pindex )
114+ bool CoinStatsIndex::CustomAppend (const interfaces::BlockInfo & block)
115115{
116116 CBlockUndo block_undo;
117- const CAmount block_subsidy{GetBlockSubsidy (pindex-> nHeight , Params ().GetConsensus ())};
117+ const CAmount block_subsidy{GetBlockSubsidy (block. height , Params ().GetConsensus ())};
118118 m_total_subsidy += block_subsidy;
119119
120120 // Ignore genesis block
121- if (pindex->nHeight > 0 ) {
121+ if (block.height > 0 ) {
122+ // pindex variable gives indexing code access to node internals. It
123+ // will be removed in upcoming commit
124+ const CBlockIndex* pindex = WITH_LOCK (cs_main, return m_chainstate->m_blockman .LookupBlockIndex (block.hash ));
122125 if (!UndoReadFromDisk (block_undo, pindex)) {
123126 return false ;
124127 }
125128
126129 std::pair<uint256, DBVal> read_out;
127- if (!m_db->Read (DBHeightKey (pindex-> nHeight - 1 ), read_out)) {
130+ if (!m_db->Read (DBHeightKey (block. height - 1 ), read_out)) {
128131 return false ;
129132 }
130133
131- uint256 expected_block_hash{pindex-> pprev -> GetBlockHash ( )};
134+ uint256 expected_block_hash{* Assert (block. prev_hash )};
132135 if (read_out.first != expected_block_hash) {
133136 LogPrintf (" WARNING: previous block header belongs to unexpected block %s; expected %s\n " ,
134137 read_out.first .ToString (), expected_block_hash.ToString ());
@@ -140,12 +143,13 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
140143 }
141144
142145 // TODO: Deduplicate BIP30 related code
143- bool is_bip30_block{(pindex-> nHeight == 91722 && pindex-> GetBlockHash () == uint256S (" 0x00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e" )) ||
144- (pindex-> nHeight == 91812 && pindex-> GetBlockHash () == uint256S (" 0x00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f" ))};
146+ bool is_bip30_block{(block. height == 91722 && block. hash == uint256S (" 0x00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e" )) ||
147+ (block. height == 91812 && block. hash == uint256S (" 0x00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f" ))};
145148
146149 // Add the new utxos created from the block
147- for (size_t i = 0 ; i < block.vtx .size (); ++i) {
148- const auto & tx{block.vtx .at (i)};
150+ assert (block.data );
151+ for (size_t i = 0 ; i < block.data ->vtx .size (); ++i) {
152+ const auto & tx{block.data ->vtx .at (i)};
149153
150154 // Skip duplicate txid coinbase transactions (BIP30).
151155 if (is_bip30_block && tx->IsCoinBase ()) {
@@ -156,7 +160,7 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
156160
157161 for (uint32_t j = 0 ; j < tx->vout .size (); ++j) {
158162 const CTxOut& out{tx->vout [j]};
159- Coin coin{out, pindex-> nHeight , tx->IsCoinBase ()};
163+ Coin coin{out, block. height , tx->IsCoinBase ()};
160164 COutPoint outpoint{tx->GetHash (), j};
161165
162166 // Skip unspendable coins
@@ -212,7 +216,7 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
212216 m_total_unspendables_unclaimed_rewards += unclaimed_rewards;
213217
214218 std::pair<uint256, DBVal> value;
215- value.first = pindex-> GetBlockHash () ;
219+ value.first = block. hash ;
216220 value.second .transaction_output_count = m_transaction_output_count;
217221 value.second .bogo_size = m_bogo_size;
218222 value.second .total_amount = m_total_amount;
@@ -232,7 +236,7 @@ bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
232236
233237 // Intentionally do not update DB_MUHASH here so it stays in sync with
234238 // DB_BEST_BLOCK, and the index is not corrupted if there is an unclean shutdown.
235- return m_db->Write (DBHeightKey (pindex-> nHeight ), value);
239+ return m_db->Write (DBHeightKey (block. height ), value);
236240}
237241
238242static bool CopyHeightIndexToHashIndex (CDBIterator& db_it, CDBBatch& batch,
0 commit comments