Skip to content

Commit

Permalink
common: make json_add_timeabs full precision & renamed json_add_time
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ShahanaFarooqui authored and rustyrussell committed Sep 21, 2023
1 parent d745323 commit 3f95597
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions common/json_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion common/json_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" */
Expand Down
4 changes: 2 additions & 2 deletions lightningd/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lightningd/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lightningd/test/run-log-pruning.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
6 changes: 3 additions & 3 deletions lightningd/test/run-log_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down

0 comments on commit 3f95597

Please sign in to comment.