MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ReadBlockUndo

Method ReadBlockUndo

src/node/blockstorage.cpp:715–748  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

713}
714
715bool BlockManager::ReadBlockUndo(CBlockUndo& blockundo, const CBlockIndex& index) const
716{
717 const FlatFilePos pos{WITH_LOCK(::cs_main, return index.GetUndoPos())};
718
719 // Open history file to read
720 AutoFile file{OpenUndoFile(pos, true)};
721 if (file.IsNull()) {
722 LogError("OpenUndoFile failed for %s while reading block undo", pos.ToString());
723 return false;
724 }
725 BufferedReader filein{std::move(file)};
726
727 try {
728 // Read block
729 HashVerifier verifier{filein}; // Use HashVerifier, as reserializing may lose data, c.f. commit d3424243
730
731 verifier << index.pprev->GetBlockHash();
732 verifier >> blockundo;
733
734 uint256 hashChecksum;
735 filein >> hashChecksum;
736
737 // Verify checksum
738 if (hashChecksum != verifier.GetHash()) {
739 LogError("Checksum mismatch at %s while reading block undo", pos.ToString());
740 return false;
741 }
742 } catch (const std::exception& e) {
743 LogError("Deserialize or I/O error - %s at %s while reading block undo", e.what(), pos.ToString());
744 return false;
745 }
746
747 return true;
748}
749
750bool BlockManager::FlushUndoFile(int block_file, bool finalize)
751{

Callers 10

rest_spent_txoutsFunction · 0.80
DisconnectBlockMethod · 0.80
VerifyDBMethod · 0.80
ComputeFilterFunction · 0.80
ProcessBlockMethod · 0.80
RewindMethod · 0.80
getrawtransactionFunction · 0.80
blockToJSONFunction · 0.80
GetUndoCheckedFunction · 0.80

Calls 5

IsNullMethod · 0.45
ToStringMethod · 0.45
GetBlockHashMethod · 0.45
GetHashMethod · 0.45
whatMethod · 0.45

Tested by 1

ComputeFilterFunction · 0.64