MCPcopy Create free account
hub / github.com/ElementsProject/elements / WriteBlock

Method WriteBlock

src/index/blockfilterindex.cpp:212–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

210}
211
212bool BlockFilterIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
213{
214 CBlockUndo block_undo;
215 uint256 prev_header;
216
217 if (pindex->nHeight > 0) {
218 if (!UndoReadFromDisk(block_undo, pindex)) {
219 return false;
220 }
221
222 std::pair<uint256, DBVal> read_out;
223 if (!m_db->Read(DBHeightKey(pindex->nHeight - 1), read_out)) {
224 return false;
225 }
226
227 uint256 expected_block_hash = pindex->pprev->GetBlockHash();
228 if (read_out.first != expected_block_hash) {
229 return error("%s: previous block header belongs to unexpected block %s; expected %s",
230 __func__, read_out.first.ToString(), expected_block_hash.ToString());
231 }
232
233 prev_header = read_out.second.header;
234 }
235
236 BlockFilter filter(m_filter_type, block, block_undo);
237
238 size_t bytes_written = WriteFilterToDisk(m_next_filter_pos, filter);
239 if (bytes_written == 0) return false;
240
241 std::pair<uint256, DBVal> value;
242 value.first = pindex->GetBlockHash();
243 value.second.hash = filter.GetHash();
244 value.second.header = filter.ComputeHeader(prev_header);
245 value.second.pos = m_next_filter_pos;
246
247 if (!m_db->Write(DBHeightKey(pindex->nHeight), value)) {
248 return false;
249 }
250
251 m_next_filter_pos.nPos += bytes_written;
252 return true;
253}
254
255static bool CopyHeightIndexToHashIndex(CDBIterator& db_it, CDBBatch& batch,
256 const std::string& index_name,

Callers

nothing calls this directly

Calls 9

UndoReadFromDiskFunction · 0.85
errorFunction · 0.85
ComputeHeaderMethod · 0.80
DBHeightKeyClass · 0.70
ReadMethod · 0.45
GetBlockHashMethod · 0.45
ToStringMethod · 0.45
GetHashMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected