| 453 | } |
| 454 | |
| 455 | static u8 *sign_and_timestamp_update(const tal_t *ctx, |
| 456 | struct daemon *daemon, |
| 457 | const struct chan *chan, |
| 458 | int direction, |
| 459 | u8 *unsigned_update TAKES) |
| 460 | { |
| 461 | u8 *msg, *update; |
| 462 | be32 timestamp; |
| 463 | const u32 *prev_timestamp; |
| 464 | const struct half_chan *hc = &chan->half[direction]; |
| 465 | |
| 466 | if (is_halfchan_defined(hc)) |
| 467 | prev_timestamp = &hc->bcast.timestamp; |
| 468 | else |
| 469 | prev_timestamp = NULL; |
| 470 | |
| 471 | /* Get an appropriate timestamp */ |
| 472 | timestamp = cpu_to_be32(timestamp_for_update(daemon, |
| 473 | prev_timestamp, |
| 474 | is_disabled(unsigned_update))); |
| 475 | memcpy(timestamp_access(unsigned_update), ×tamp, sizeof(timestamp)); |
| 476 | |
| 477 | /* Note that we treat the hsmd as synchronous. This is simple (no |
| 478 | * callback hell)!, but may need to change to async if we ever want |
| 479 | * remote HSMs */ |
| 480 | if (!wire_sync_write(HSM_FD, |
| 481 | towire_hsmd_cupdate_sig_req(tmpctx, unsigned_update))) { |
| 482 | status_failed(STATUS_FAIL_HSM_IO, "Writing cupdate_sig_req: %s", |
| 483 | strerror(errno)); |
| 484 | } |
| 485 | |
| 486 | msg = wire_sync_read(tmpctx, HSM_FD); |
| 487 | if (!msg || !fromwire_hsmd_cupdate_sig_reply(ctx, msg, &update)) { |
| 488 | status_failed(STATUS_FAIL_HSM_IO, |
| 489 | "Reading cupdate_sig_req: %s", |
| 490 | strerror(errno)); |
| 491 | } |
| 492 | |
| 493 | if (taken(unsigned_update)) |
| 494 | tal_free(unsigned_update); |
| 495 | |
| 496 | /* Tell lightningd about this immediately (even if we're not actually |
| 497 | * applying it now). We choose not to send info about private |
| 498 | * channels, even in errors. */ |
| 499 | if (is_chan_public(chan)) { |
| 500 | msg = towire_gossipd_got_local_channel_update(NULL, &chan->scid, |
| 501 | update); |
| 502 | daemon_conn_send(daemon->master, take(msg)); |
| 503 | } |
| 504 | |
| 505 | return update; |
| 506 | } |
| 507 | |
| 508 | static u8 *create_unsigned_update(const tal_t *ctx, |
| 509 | const struct short_channel_id *scid, |
no test coverage detected