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

Method WriteUndoDataForBlock

src/node/blockstorage.cpp:725–753  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

723}
724
725bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams)
726{
727 AssertLockHeld(::cs_main);
728 // Write undo information to disk
729 if (pindex->GetUndoPos().IsNull()) {
730 FlatFilePos _pos;
731 if (!FindUndoPos(state, pindex->nFile, _pos, ::GetSerializeSize(blockundo, CLIENT_VERSION) + 40)) {
732 return error("ConnectBlock(): FindUndoPos failed");
733 }
734 if (!UndoWriteToDisk(blockundo, _pos, pindex->pprev->GetBlockHash(), chainparams.MessageStart())) {
735 return AbortNode(state, "Failed to write undo data");
736 }
737 // rev files are written in block height order, whereas blk files are written as blocks come in (often out of order)
738 // we want to flush the rev (undo) file once we've written the last block, which is indicated by the last height
739 // in the block file info as below; note that this does not catch the case where the undo writes are keeping up
740 // with the block writes (usually when a synced up node is getting newly mined blocks) -- this case is caught in
741 // the FindBlockPos function
742 if (_pos.nFile < m_last_blockfile && static_cast<uint32_t>(pindex->nHeight) == m_blockfile_info[_pos.nFile].nHeightLast) {
743 FlushUndoFile(_pos.nFile, true);
744 }
745
746 // update nUndoPos in block index
747 pindex->nUndoPos = _pos.nPos;
748 pindex->nStatus |= BLOCK_HAVE_UNDO;
749 m_dirty_blockindex.insert(pindex);
750 }
751
752 return true;
753}
754
755bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, const Consensus::Params& consensusParams)
756{

Callers 1

ConnectBlockMethod · 0.80

Calls 7

GetSerializeSizeFunction · 0.85
errorFunction · 0.85
UndoWriteToDiskFunction · 0.85
AbortNodeFunction · 0.50
IsNullMethod · 0.45
GetBlockHashMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected