| 1148 | } |
| 1149 | |
| 1150 | bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& message_start) |
| 1151 | { |
| 1152 | CDiskBlockPos hpos = pos; |
| 1153 | hpos.nPos -= 8; // Seek back 8 bytes for meta header |
| 1154 | CAutoFile filein(OpenBlockFile(hpos, true), SER_DISK, CLIENT_VERSION); |
| 1155 | if (filein.IsNull()) { |
| 1156 | return error("%s: OpenBlockFile failed for %s", __func__, pos.ToString()); |
| 1157 | } |
| 1158 | |
| 1159 | try { |
| 1160 | CMessageHeader::MessageStartChars blk_start; |
| 1161 | unsigned int blk_size; |
| 1162 | |
| 1163 | filein >> blk_start >> blk_size; |
| 1164 | |
| 1165 | if (memcmp(blk_start, message_start, CMessageHeader::MESSAGE_START_SIZE)) { |
| 1166 | return error("%s: Block magic mismatch for %s: %s versus expected %s", __func__, pos.ToString(), |
| 1167 | HexStr(blk_start, blk_start + CMessageHeader::MESSAGE_START_SIZE), |
| 1168 | HexStr(message_start, message_start + CMessageHeader::MESSAGE_START_SIZE)); |
| 1169 | } |
| 1170 | |
| 1171 | if (blk_size > MAX_SIZE) { |
| 1172 | return error("%s: Block data is larger than maximum deserialization size for %s: %s versus %s", __func__, pos.ToString(), |
| 1173 | blk_size, MAX_SIZE); |
| 1174 | } |
| 1175 | |
| 1176 | block.resize(blk_size); // Zeroing of memory is intentional here |
| 1177 | filein.read((char*)block.data(), blk_size); |
| 1178 | } catch(const std::exception& e) { |
| 1179 | return error("%s: Read from block file failed: %s for %s", __func__, e.what(), pos.ToString()); |
| 1180 | } |
| 1181 | |
| 1182 | return true; |
| 1183 | } |
| 1184 | |
| 1185 | bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const CBlockIndex* pindex, const CMessageHeader::MessageStartChars& message_start) |
| 1186 | { |
no test coverage detected