| 46 | } |
| 47 | |
| 48 | std::optional<uint256> ReadSnapshotBaseBlockhash(fs::path chaindir) |
| 49 | { |
| 50 | if (!fs::exists(chaindir)) { |
| 51 | LogWarning("[snapshot] cannot read base blockhash: no chainstate dir " |
| 52 | "exists at path %s", fs::PathToString(chaindir)); |
| 53 | return std::nullopt; |
| 54 | } |
| 55 | const fs::path read_from = chaindir / node::SNAPSHOT_BLOCKHASH_FILENAME; |
| 56 | const std::string read_from_str = fs::PathToString(read_from); |
| 57 | |
| 58 | if (!fs::exists(read_from)) { |
| 59 | LogWarning("[snapshot] snapshot chainstate dir is malformed! no base blockhash file " |
| 60 | "exists at path %s. Try deleting %s and calling loadtxoutset again?", |
| 61 | fs::PathToString(chaindir), read_from_str); |
| 62 | return std::nullopt; |
| 63 | } |
| 64 | |
| 65 | uint256 base_blockhash; |
| 66 | FILE* file{fsbridge::fopen(read_from, "rb")}; |
| 67 | AutoFile afile{file}; |
| 68 | if (afile.IsNull()) { |
| 69 | LogWarning("[snapshot] failed to open base blockhash file for reading: %s", |
| 70 | read_from_str); |
| 71 | return std::nullopt; |
| 72 | } |
| 73 | afile >> base_blockhash; |
| 74 | |
| 75 | int64_t position = afile.tell(); |
| 76 | afile.seek(0, SEEK_END); |
| 77 | if (position != afile.tell()) { |
| 78 | LogWarning("[snapshot] unexpected trailing data in %s", read_from_str); |
| 79 | } |
| 80 | return base_blockhash; |
| 81 | } |
| 82 | |
| 83 | std::optional<fs::path> FindAssumeutxoChainstateDir(const fs::path& data_dir) |
| 84 | { |