MCPcopy Create free account
hub / github.com/ElementsProject/lightning / check_future_dataloss_fields

Function check_future_dataloss_fields

channeld/channeld.c:5468–5511  ·  view source on GitHub ↗

BOLT #2: * * A receiving node: * - MUST ignore `my_current_per_commitment_point`, but MAY require it to be * a valid point. * - if `next_revocation_number` is greater than expected above, AND * `your_last_per_commitment_secret` is correct for that * `next_revocation_number` minus 1: * - MUST NOT broadcast its commitment transaction. * - SHOULD send an `error` to

Source from the content-addressed store, hash-verified

5466 * - SHOULD send an `error` to request the peer to fail the channel.
5467 */
5468static void check_future_dataloss_fields(struct peer *peer,
5469 u64 next_revocation_number,
5470 const struct secret *last_local_per_commit_secret)
5471{
5472 const u8 *msg;
5473 bool correct;
5474
5475 assert(next_revocation_number > peer->next_index[LOCAL] - 1);
5476
5477 msg = towire_hsmd_check_future_secret(NULL,
5478 next_revocation_number - 1,
5479 last_local_per_commit_secret);
5480 msg = hsm_req(tmpctx, take(msg));
5481 if (!fromwire_hsmd_check_future_secret_reply(msg, &correct))
5482 status_failed(STATUS_FAIL_HSM_IO,
5483 "Bad hsm_check_future_secret_reply: %s",
5484 tal_hex(tmpctx, msg));
5485
5486 if (!correct)
5487 peer_failed_err(peer->pps,
5488 &peer->channel_id,
5489 "bad future last_local_per_commit_secret: %"PRIu64
5490 " vs %"PRIu64,
5491 next_revocation_number,
5492 peer->next_index[LOCAL] - 1);
5493
5494 /* Oh shit, they really are from the future! */
5495 peer_billboard(true, "They have future commitment number %"PRIu64
5496 " vs our %"PRIu64". We must wait for them to close!",
5497 next_revocation_number,
5498 peer->next_index[LOCAL] - 1);
5499
5500 /* BOLT #2:
5501 * - MUST NOT broadcast its commitment transaction.
5502 * - SHOULD send an `error` to request the peer to fail the channel.
5503 */
5504 wire_sync_write(MASTER_FD,
5505 take(towire_channeld_fail_fallen_behind(NULL)));
5506
5507 sleep(1);
5508 /* We have to send them an error to trigger dropping to chain. */
5509 peer_failed_err(peer->pps, &peer->channel_id,
5510 "Awaiting unilateral close");
5511}
5512
5513/* BOLT #2:
5514 *

Callers 1

peer_reconnectFunction · 0.70

Calls 6

hsm_reqFunction · 0.85
tal_hexFunction · 0.85
status_failedFunction · 0.50
peer_failed_errFunction · 0.50
peer_billboardFunction · 0.50
wire_sync_writeFunction · 0.50

Tested by

no test coverage detected