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

Function WriteSnapshotBaseBlockhash

src/node/utxo_snapshot.cpp:22–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20namespace node {
21
22bool WriteSnapshotBaseBlockhash(Chainstate& snapshot_chainstate)
23{
24 AssertLockHeld(::cs_main);
25 assert(snapshot_chainstate.m_from_snapshot_blockhash);
26
27 const std::optional<fs::path> chaindir = snapshot_chainstate.StoragePath();
28 assert(chaindir); // Sanity check that chainstate isn't in-memory.
29 const fs::path write_to = *chaindir / node::SNAPSHOT_BLOCKHASH_FILENAME;
30
31 FILE* file{fsbridge::fopen(write_to, "wb")};
32 AutoFile afile{file};
33 if (afile.IsNull()) {
34 LogError("[snapshot] failed to open base blockhash file for writing: %s",
35 fs::PathToString(write_to));
36 return false;
37 }
38 afile << *snapshot_chainstate.m_from_snapshot_blockhash;
39
40 if (afile.fclose() != 0) {
41 LogError("[snapshot] failed to close base blockhash file %s after writing",
42 fs::PathToString(write_to));
43 return false;
44 }
45 return true;
46}
47
48std::optional<uint256> ReadSnapshotBaseBlockhash(fs::path chaindir)
49{

Callers 1

validation.cppFile · 0.85

Calls 5

fopenFunction · 0.85
PathToStringFunction · 0.85
StoragePathMethod · 0.80
fcloseMethod · 0.80
IsNullMethod · 0.45

Tested by

no test coverage detected