| 799 | } |
| 800 | |
| 801 | bool 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 */ |
| 837 | FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp) |
no test coverage detected