Skip to content

Commit b3f2b86

Browse files
Log digests of snapshots (#7300)
Co-authored-by: Amaury Chamayou <amaury@xargs.fr>
1 parent 6784c37 commit b3f2b86

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [5.0.23]
9+
10+
[5.0.23]: https://github.com/microsoft/CCF/releases/tag/5.0.23
11+
12+
### Added
13+
14+
- Logging of snapshot digests
15+
816
## [5.0.22]
917

1018
[5.0.22]: https://github.com/microsoft/CCF/releases/tag/5.0.22

src/host/main.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "ccf/version.h"
99
#include "config_schema.h"
1010
#include "configuration.h"
11+
#include "crypto/openssl/hash.h"
1112
#include "ds/cli_helper.h"
1213
#include "ds/files.h"
1314
#include "ds/non_blocking.h"
@@ -342,6 +343,8 @@ int main(int argc, char** argv)
342343
asynchost::ProcessLauncher process_launcher;
343344
process_launcher.register_message_handlers(bp.get_dispatcher());
344345

346+
ccf::crypto::openssl_sha256_init();
347+
345348
{
346349
// provide regular ticks to the enclave
347350
asynchost::Ticker ticker(config.tick_interval, writer_factory);
@@ -715,10 +718,13 @@ int main(int argc, char** argv)
715718
auto& [snapshot_dir, snapshot_file] = latest_committed_snapshot.value();
716719
startup_snapshot = files::slurp(snapshot_dir / snapshot_file);
717720

721+
auto sha = ccf::crypto::Sha256Hash(startup_snapshot);
722+
718723
LOG_INFO_FMT(
719-
"Found latest snapshot file: {} (size: {})",
724+
"Found latest snapshot file: {} (size: {}, sha256: {})",
720725
snapshot_dir / snapshot_file,
721-
startup_snapshot.size());
726+
startup_snapshot.size(),
727+
sha.hex_str());
722728
}
723729
else
724730
{
@@ -843,5 +849,7 @@ int main(int argc, char** argv)
843849
if (rc)
844850
LOG_FAIL_FMT("Failed to close uv loop cleanly: {}", uv_err_name(rc));
845851

852+
ccf::crypto::openssl_sha256_shutdown();
853+
846854
return rc;
847855
}

src/host/snapshots.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
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

Comments
 (0)