22// Licensed under the Apache 2.0 License.
33#pragma once
44
5+ #include " ccf/crypto/sha256_hash.h"
56#include " ccf/ds/nonstd.h"
67#include " consensus/ledger_enclave_types.h"
8+ #include " crypto/openssl/hash.h"
9+ #include " ds/files.h"
710#include " time_bound_logger.h"
811
912#include < charconv>
@@ -263,6 +266,10 @@ namespace asynchost
263266
264267 static void on_snapshot_sync_and_rename (uv_work_t * req)
265268 {
269+ // don't init / deinit in sync
270+ #ifndef TEST_MODE_EXECUTE_SYNC_INLINE
271+ ccf::crypto::openssl_sha256_init ();
272+ #endif
266273 auto data = static_cast <AsyncSnapshotSyncAndRename*>(req->data );
267274
268275 {
@@ -280,6 +287,18 @@ namespace asynchost
280287
281288 const auto full_tmp_path = data->dir / data->tmp_file_name ;
282289 files::rename (full_tmp_path, full_committed_path);
290+
291+ // read and log the hash of the written snapshot
292+ auto raw = files::slurp (full_committed_path);
293+ LOG_INFO_FMT (
294+ " Written snapshot to {} (size: {} bytes, sha256: {} )" ,
295+ data->committed_file_name ,
296+ raw.size (),
297+ ccf::crypto::Sha256Hash (raw).hex_str ());
298+
299+ #ifndef TEST_MODE_EXECUTE_SYNC_INLINE
300+ ccf::crypto::openssl_sha256_shutdown ();
301+ #endif
283302 }
284303
285304 static void on_snapshot_sync_and_rename_complete (uv_work_t * req, int status)
@@ -380,6 +399,10 @@ namespace asynchost
380399#endif
381400 }
382401
402+ auto sha = ccf::crypto::Sha256Hash (*it->second .snapshot );
403+ LOG_INFO_FMT (
404+ " Writing snapshot to {} (sha256: {})" , full_snapshot_path, sha);
405+
383406 pending_snapshots.erase (it);
384407
385408 return ;
0 commit comments