From 3f95597a5e05fe9b38968d13a0f6e84b752fe8ea Mon Sep 17 00:00:00 2001 From: ShahanaFarooqui Date: Thu, 14 Sep 2023 12:10:43 +0930 Subject: [PATCH] common: make json_add_timeabs full precision & renamed json_add_time json_add_timeabs only printed in milliseconds and json_add_time outputs a string which is weird Changelog-Changed: JSON-RPC time fields now have full nanosecond precision (i.e. 9 decimals not 3): `listfowards` `received_time` `resolved_time` `listpays`/`listsendpays` `created_at`. --- common/json_stream.c | 6 +++--- common/json_stream.h | 2 +- lightningd/log.c | 4 ++-- lightningd/notification.c | 2 +- lightningd/test/run-log-pruning.c | 6 +++--- lightningd/test/run-log_filter.c | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/common/json_stream.c b/common/json_stream.c index 7ef3750dd..1abfaed28 100644 --- a/common/json_stream.c +++ b/common/json_stream.c @@ -370,11 +370,11 @@ void json_add_timeabs(struct json_stream *result, const char *fieldname, struct timeabs t) { json_add_primitive_fmt(result, fieldname, - "%" PRIu64 ".%03" PRIu64, - (u64)t.ts.tv_sec, (u64)t.ts.tv_nsec / 1000000); + "%" PRIu64 ".%09" PRIu64, + (u64)t.ts.tv_sec, (u64)t.ts.tv_nsec); } -void json_add_time(struct json_stream *result, const char *fieldname, +void json_add_timestr(struct json_stream *result, const char *fieldname, struct timespec ts) { char timebuf[100]; diff --git a/common/json_stream.h b/common/json_stream.h index bc68569ca..4b37aee83 100644 --- a/common/json_stream.h +++ b/common/json_stream.h @@ -255,7 +255,7 @@ void json_add_timeabs(struct json_stream *result, const char *fieldname, struct timeabs t); /* used in log.c and notification.c*/ -void json_add_time(struct json_stream *result, const char *fieldname, +void json_add_timestr(struct json_stream *result, const char *fieldname, struct timespec ts); /* Add ISO_8601 timestamp string, i.e. "2019-09-07T15:50+01:00" */ diff --git a/lightningd/log.c b/lightningd/log.c index 4c9b6b9be..2afd0a373 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -1087,7 +1087,7 @@ static void log_to_json(unsigned int skipped, : level == LOG_IO_IN ? "IO_IN" : level == LOG_IO_OUT ? "IO_OUT" : "UNKNOWN"); - json_add_time(info->response, "time", diff.ts); + json_add_timestr(info->response, "time", diff.ts); if (node_id) json_add_node_id(info->response, "node_id", node_id); json_add_string(info->response, "source", prefix); @@ -1148,7 +1148,7 @@ static struct command_result *json_getlog(struct command *cmd, response = json_stream_success(cmd); /* Suppress logging for this stream, to not bloat io logs */ json_stream_log_suppress_for_cmd(response, cmd); - json_add_time(response, "created_at", log_book->init_time.ts); + json_add_timestr(response, "created_at", log_book->init_time.ts); json_add_num(response, "bytes_used", (unsigned int)log_book->mem_used); json_add_num(response, "bytes_max", (unsigned int)log_book->max_mem); json_add_log(response, log_book, NULL, *minlevel); diff --git a/lightningd/notification.c b/lightningd/notification.c index edb00ed87..8012477d1 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -136,7 +136,7 @@ static void warning_notification_serialize(struct json_stream *stream, : "warn"); /* unsuaul/broken event is rare, plugin pay more attentions on * the absolute time, like when channels failed. */ - json_add_time(stream, "time", l->time.ts); + json_add_timestr(stream, "time", l->time.ts); json_add_timeiso(stream, "timestamp", &l->time); json_add_string(stream, "source", l->prefix->prefix); json_add_string(stream, "log", l->log); diff --git a/lightningd/test/run-log-pruning.c b/lightningd/test/run-log-pruning.c index 2e03ed27d..d3a6fe6ec 100644 --- a/lightningd/test/run-log-pruning.c +++ b/lightningd/test/run-log-pruning.c @@ -51,10 +51,10 @@ void json_add_string(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED, const char *str TAKES UNNEEDED) { fprintf(stderr, "json_add_string called!\n"); abort(); } -/* Generated stub for json_add_time */ -void json_add_time(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, +/* Generated stub for json_add_timestr */ +void json_add_timestr(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, struct timespec ts UNNEEDED) -{ fprintf(stderr, "json_add_time called!\n"); abort(); } +{ fprintf(stderr, "json_add_timestr called!\n"); abort(); } /* Generated stub for json_array_end */ void json_array_end(struct json_stream *js UNNEEDED) { fprintf(stderr, "json_array_end called!\n"); abort(); } diff --git a/lightningd/test/run-log_filter.c b/lightningd/test/run-log_filter.c index be53d73a0..acc101685 100644 --- a/lightningd/test/run-log_filter.c +++ b/lightningd/test/run-log_filter.c @@ -55,10 +55,10 @@ void json_add_string(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED, const char *str TAKES UNNEEDED) { fprintf(stderr, "json_add_string called!\n"); abort(); } -/* Generated stub for json_add_time */ -void json_add_time(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, +/* Generated stub for json_add_timestr */ +void json_add_timestr(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, struct timespec ts UNNEEDED) -{ fprintf(stderr, "json_add_time called!\n"); abort(); } +{ fprintf(stderr, "json_add_timestr called!\n"); abort(); } /* Generated stub for json_array_end */ void json_array_end(struct json_stream *js UNNEEDED) { fprintf(stderr, "json_array_end called!\n"); abort(); }