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

Function ReadSnapshotBaseBlockhash

src/node/utxo_snapshot.cpp:48–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48std::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
83std::optional<fs::path> FindAssumeutxoChainstateDir(const fs::path& data_dir)
84{

Callers 2

SetupSnapshotMethod · 0.85

Calls 6

existsFunction · 0.85
PathToStringFunction · 0.85
fopenFunction · 0.85
tellMethod · 0.80
IsNullMethod · 0.45
seekMethod · 0.45

Tested by 1

SetupSnapshotMethod · 0.68