Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit d53d787

Browse files
committed
entangled/ciri/consensus: snapshot - add logging
1 parent 4439624 commit d53d787

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

ciri/consensus/snapshot/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ cc_library(
8080
"//common:errors",
8181
"//common/model:transaction",
8282
"//utils:files",
83+
"//utils:logger_helper",
8384
"//utils:macros",
8485
"//utils/containers/hash:hash_uint64_t_map",
8586
],

ciri/consensus/snapshot/snapshot_metadata.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@
1010
#include <stdlib.h>
1111
#include "common/model/transaction.h"
1212
#include "utils/files.h"
13+
#include "utils/logger_helper.h"
1314
#include "utils/macros.h"
1415

16+
#define SNAPSHOT_METADATA_LOGGER_ID "snapshot_metadata"
17+
18+
static logger_id_t logger_id;
19+
1520
retcode_t iota_snapshot_metadata_init(snapshot_metadata_t *const snapshot_metadata, flex_trit_t const *const hash,
1621
uint64_t index, uint64_t timestamp, hash_to_uint64_t_map_t solid_entry_points) {
1722
memcpy(snapshot_metadata->hash, hash, FLEX_TRIT_SIZE_243);
1823
snapshot_metadata->index = index;
1924
snapshot_metadata->timestamp = timestamp;
2025
snapshot_metadata->solid_entry_points = NULL;
2126
hash_to_uint64_t_map_copy(&solid_entry_points, &snapshot_metadata->solid_entry_points);
27+
logger_id = logger_helper_enable(SNAPSHOT_METADATA_LOGGER_ID, LOGGER_DEBUG, true);
2228
return RC_OK;
2329
}
2430

@@ -30,6 +36,7 @@ void iota_snapshot_metadata_reset(snapshot_metadata_t *const snapshot_metadata)
3036

3137
retcode_t iota_snapshot_metadata_destroy(snapshot_metadata_t *const snapshot_metadata) {
3238
hash_to_uint64_t_map_free(&snapshot_metadata->solid_entry_points);
39+
logger_helper_release(logger_id);
3340
return RC_OK;
3441
}
3542

@@ -146,9 +153,15 @@ retcode_t iota_snapshot_metadata_read_from_file(snapshot_metadata_t *const snaps
146153
retcode_t ret = RC_OK;
147154
char *buffer = NULL;
148155

149-
ERR_BIND_GOTO(iota_utils_read_file_into_buffer(metadata_file, &buffer), ret, cleanup);
156+
if ((ret = iota_utils_read_file_into_buffer(metadata_file, &buffer)) != RC_OK) {
157+
log_error(logger_id, "Failed reading metadata file\n");
158+
goto cleanup;
159+
}
150160
if (buffer) {
151-
ERR_BIND_GOTO(iota_snapshot_metadata_deserialize_str(buffer, snapshot_metadata), ret, cleanup);
161+
if ((ret = iota_snapshot_metadata_deserialize_str(buffer, snapshot_metadata)) != RC_OK) {
162+
log_error(logger_id, "Failed deserializing metadata file\n");
163+
goto cleanup;
164+
}
152165
}
153166

154167
cleanup:

0 commit comments

Comments
 (0)