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

Function ReadRawBlockFromDisk

src/node/blockstorage.cpp:801–834  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

799}
800
801bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos, const CMessageHeader::MessageStartChars& message_start)
802{
803 FlatFilePos hpos = pos;
804 hpos.nPos -= 8; // Seek back 8 bytes for meta header
805 CAutoFile filein(OpenBlockFile(hpos, true), SER_DISK, CLIENT_VERSION);
806 if (filein.IsNull()) {
807 return error("%s: OpenBlockFile failed for %s", __func__, pos.ToString());
808 }
809
810 try {
811 CMessageHeader::MessageStartChars blk_start;
812 unsigned int blk_size;
813
814 filein >> blk_start >> blk_size;
815
816 if (memcmp(blk_start, message_start, CMessageHeader::MESSAGE_START_SIZE)) {
817 return error("%s: Block magic mismatch for %s: %s versus expected %s", __func__, pos.ToString(),
818 HexStr(blk_start),
819 HexStr(message_start));
820 }
821
822 if (blk_size > MAX_SIZE) {
823 return error("%s: Block data is larger than maximum deserialization size for %s: %s versus %s", __func__, pos.ToString(),
824 blk_size, MAX_SIZE);
825 }
826
827 block.resize(blk_size); // Zeroing of memory is intentional here
828 filein.read(MakeWritableByteSpan(block));
829 } catch (const std::exception& e) {
830 return error("%s: Read from block file failed: %s for %s", __func__, e.what(), pos.ToString());
831 }
832
833 return true;
834}
835
836/** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
837FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp)

Callers 1

ProcessGetBlockDataMethod · 0.85

Calls 8

OpenBlockFileFunction · 0.85
errorFunction · 0.85
MakeWritableByteSpanFunction · 0.85
HexStrFunction · 0.50
IsNullMethod · 0.45
ToStringMethod · 0.45
resizeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected