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

Function check_future_dataloss_fields

channeld/channeld.c:5675–5724  ·  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

5673 * - SHOULD send an `error` to request the peer to fail the channel.
5674 */
5675static void check_future_dataloss_fields(struct peer *peer,
5676 u64 next_revocation_number,
5677 const struct secret *last_local_per_commit_secret)
5678{
5679 const u8 *msg;
5680 bool correct;
5681
5682 assert(next_revocation_number > peer->next_index[LOCAL] - 1);
5683
5684 if (next_revocation_number - 1 >= (1ULL << SHACHAIN_BITS)) {
5685 peer_failed_err(peer->pps,
5686 &peer->channel_id,
5687 "Invalid next_revocation_number value");
5688 }
5689
5690 msg = towire_hsmd_check_future_secret(NULL,
5691 next_revocation_number - 1,
5692 last_local_per_commit_secret);
5693 msg = hsm_req(tmpctx, take(msg));
5694 if (!fromwire_hsmd_check_future_secret_reply(msg, &correct))
5695 status_failed(STATUS_FAIL_HSM_IO,
5696 "Bad hsm_check_future_secret_reply: %s",
5697 tal_hex(tmpctx, msg));
5698
5699 if (!correct)
5700 peer_failed_err(peer->pps,
5701 &peer->channel_id,
5702 "bad future last_local_per_commit_secret: %"PRIu64
5703 " vs %"PRIu64,
5704 next_revocation_number,
5705 peer->next_index[LOCAL] - 1);
5706
5707 /* Oh shit, they really are from the future! */
5708 peer_billboard(true, "They have future commitment number %"PRIu64
5709 " vs our %"PRIu64". We must wait for them to close!",
5710 next_revocation_number,
5711 peer->next_index[LOCAL] - 1);
5712
5713 /* BOLT #2:
5714 * - MUST NOT broadcast its commitment transaction.
5715 * - SHOULD send an `error` to request the peer to fail the channel.
5716 */
5717 wire_sync_write(MASTER_FD,
5718 take(towire_channeld_fail_fallen_behind(NULL)));
5719
5720 sleep(1);
5721 /* We have to send them an error to trigger dropping to chain. */
5722 peer_failed_err(peer->pps, &peer->channel_id,
5723 "Awaiting unilateral close");
5724}
5725
5726/* BOLT #2:
5727 *

Callers 1

peer_reconnectFunction · 0.70

Calls 6

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

Tested by

no test coverage detected