|
3 | 3 | #include <ccan/bitops/bitops.h> |
4 | 4 | #include <ccan/ccan/cast/cast.h> |
5 | 5 | #include <ccan/tal/str/str.h> |
6 | | -#include <ccan/time/time.h> |
| 6 | +#include <common/clock_time.h> |
7 | 7 | #include <common/coin_mvt.h> |
8 | 8 | #include <common/node_id.h> |
9 | 9 | #include <common/utils.h> |
@@ -155,6 +155,12 @@ static enum mvt_tag mvt_tag_in_db(enum mvt_tag mvt_tag) |
155 | 155 | abort(); |
156 | 156 | } |
157 | 157 |
|
| 158 | +/* This puts the coin movements in order */ |
| 159 | +u64 coinmvt_current_time(void) |
| 160 | +{ |
| 161 | + return clock_time_progresses().ts.tv_sec; |
| 162 | +} |
| 163 | + |
158 | 164 | const char *mvt_tag_str(enum mvt_tag tag) |
159 | 165 | { |
160 | 166 | assert((unsigned)tag < NUM_MVT_TAGS); |
@@ -338,7 +344,7 @@ static struct chain_coin_mvt *new_chain_coin_mvt_sat(const tal_t *ctx, |
338 | 344 | assert(ok); |
339 | 345 |
|
340 | 346 | return new_chain_coin_mvt(ctx, channel, account_name, |
341 | | - time_now().ts.tv_sec, tx_txid, |
| 347 | + coinmvt_current_time(), tx_txid, |
342 | 348 | outpoint, payment_hash, |
343 | 349 | blockheight, tags, direction, amt_msat, |
344 | 350 | /* All amounts that are sat are |
@@ -393,7 +399,7 @@ struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx, |
393 | 399 | tags = mk_mvt_tags(MVT_CHANNEL_CLOSE); |
394 | 400 |
|
395 | 401 | mvt = new_chain_coin_mvt(ctx, channel, alt_account, |
396 | | - time_now().ts.tv_sec, txid, |
| 402 | + coinmvt_current_time(), txid, |
397 | 403 | out, NULL, blockheight, |
398 | 404 | tags, |
399 | 405 | COIN_DEBIT, amount, |
@@ -421,7 +427,7 @@ struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx, |
421 | 427 | if (is_leased) |
422 | 428 | mvt_tag_set(&tags, MVT_LEASED); |
423 | 429 |
|
424 | | - mvt = new_chain_coin_mvt(ctx, channel, NULL, time_now().ts.tv_sec, |
| 430 | + mvt = new_chain_coin_mvt(ctx, channel, NULL, coinmvt_current_time(), |
425 | 431 | NULL, out, NULL, 0, |
426 | 432 | tags, |
427 | 433 | COIN_CREDIT, amount, output_val, 0); |
@@ -474,7 +480,7 @@ struct chain_coin_mvt *new_coin_channel_open(const tal_t *ctx, |
474 | 480 | bool is_leased) |
475 | 481 | { |
476 | 482 | return new_coin_channel_open_general(ctx, channel, NULL, |
477 | | - time_now().ts.tv_sec, |
| 483 | + coinmvt_current_time(), |
478 | 484 | out, peer_id, blockheight, |
479 | 485 | amount, output_val, is_opener, is_leased); |
480 | 486 | } |
@@ -516,7 +522,7 @@ struct chain_coin_mvt *new_coin_external_spend(const tal_t *ctx, |
516 | 522 | struct mvt_tags tags) |
517 | 523 | { |
518 | 524 | return new_chain_coin_mvt(ctx, NULL, ACCOUNT_NAME_EXTERNAL, |
519 | | - time_now().ts.tv_sec, txid, |
| 525 | + coinmvt_current_time(), txid, |
520 | 526 | outpoint, NULL, blockheight, |
521 | 527 | tags, |
522 | 528 | COIN_CREDIT, AMOUNT_MSAT(0), amount, 0); |
@@ -584,7 +590,7 @@ struct channel_coin_mvt *new_coin_channel_push(const tal_t *ctx, |
584 | 590 | struct mvt_tags tags) |
585 | 591 | { |
586 | 592 | return new_coin_channel_push_general(ctx, channel, NULL, |
587 | | - time_now().ts.tv_sec, |
| 593 | + coinmvt_current_time(), |
588 | 594 | direction, amount, tags); |
589 | 595 | } |
590 | 596 |
|
@@ -731,6 +737,10 @@ void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_m |
731 | 737 | } else |
732 | 738 | mvt->peer_id = NULL; |
733 | 739 | mvt->timestamp = fromwire_u64(cursor, max); |
| 740 | + |
| 741 | + /* Align onchaind's timestamps with ours if we're deterministic */ |
| 742 | + if (clock_time_overridden()) |
| 743 | + mvt->timestamp = coinmvt_current_time(); |
734 | 744 | } |
735 | 745 |
|
736 | 746 | struct mvt_tags mk_mvt_tags_(enum mvt_tag tag, ...) |
|
0 commit comments