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

Function check_future_dataloss_fields

channeld/channeld.c:2508–2556  ·  view source on GitHub ↗

BOLT #2: * * A receiving node: * - if `option_static_remotekey` applies to the commitment transaction: * - if `next_revocation_number` is greater than expected above, AND * `your_last_per_commitment_secret` is correct for that * `next_revocation_number` minus 1: *... * - otherwise, if it supports `option_data_loss_protect`: * - if `next_revocation_number` is greater than exp

Source from the content-addressed store, hash-verified

2506 * `next_revocation_number` minus 1:
2507 */
2508static void check_future_dataloss_fields(struct peer *peer,
2509 u64 next_revocation_number,
2510 const struct secret *last_local_per_commit_secret,
2511 /* This is NULL if option_static_remotekey */
2512 const struct pubkey *remote_current_per_commitment_point)
2513{
2514 const u8 *msg;
2515 bool correct;
2516
2517 assert(next_revocation_number > peer->next_index[LOCAL] - 1);
2518
2519 msg = towire_hsmd_check_future_secret(NULL,
2520 next_revocation_number - 1,
2521 last_local_per_commit_secret);
2522 msg = hsm_req(tmpctx, take(msg));
2523 if (!fromwire_hsmd_check_future_secret_reply(msg, &correct))
2524 status_failed(STATUS_FAIL_HSM_IO,
2525 "Bad hsm_check_future_secret_reply: %s",
2526 tal_hex(tmpctx, msg));
2527
2528 if (!correct)
2529 peer_failed_err(peer->pps,
2530 &peer->channel_id,
2531 "bad future last_local_per_commit_secret: %"PRIu64
2532 " vs %"PRIu64,
2533 next_revocation_number,
2534 peer->next_index[LOCAL] - 1);
2535
2536 /* Oh shit, they really are from the future! */
2537 peer_billboard(true, "They have future commitment number %"PRIu64
2538 " vs our %"PRIu64". We must wait for them to close!",
2539 next_revocation_number,
2540 peer->next_index[LOCAL] - 1);
2541
2542 /* BOLT #2:
2543 * - MUST NOT broadcast its commitment transaction.
2544 * - SHOULD send an `error` to request the peer to fail the channel.
2545 * - SHOULD store `my_current_per_commitment_point` to
2546 * retrieve funds should the sending node broadcast its
2547 * commitment transaction on-chain.
2548 */
2549 wire_sync_write(MASTER_FD,
2550 take(towire_channeld_fail_fallen_behind(NULL,
2551 remote_current_per_commitment_point)));
2552
2553 /* We have to send them an error to trigger dropping to chain. */
2554 peer_failed_err(peer->pps, &peer->channel_id,
2555 "Awaiting unilateral close");
2556}
2557
2558/* BOLT #2:
2559 *

Callers 1

peer_reconnectFunction · 0.70

Calls 6

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

Tested by

no test coverage detected