| 723 | } |
| 724 | |
| 725 | bool 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 | |
| 755 | bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, const Consensus::Params& consensusParams) |
| 756 | { |
no test coverage detected