| 20 | namespace node { |
| 21 | |
| 22 | bool 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 | |
| 48 | std::optional<uint256> ReadSnapshotBaseBlockhash(fs::path chaindir) |
| 49 | { |
no test coverage detected