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

Function check_current_dataloss_fields

channeld/channeld.c:2571–2671  ·  view source on GitHub ↗

BOLT #2: * * A receiving node: * - if `option_static_remotekey` applies to the commitment transaction: * ... * - if `your_last_per_commitment_secret` does not match the expected values: * - SHOULD send an `error` and fail the channel. * - otherwise, if it supports `option_data_loss_protect`: *... * - otherwise (`your_last_per_commitment_secret` or * `my_current_per_commitme

Source from the content-addressed store, hash-verified

2569 * - SHOULD send an `error` and fail the channel.
2570 */
2571static void check_current_dataloss_fields(struct peer *peer,
2572 u64 next_revocation_number,
2573 u64 next_commitment_number,
2574 const struct secret *last_local_per_commit_secret,
2575 /* NULL if option_static_remotekey */
2576 const struct pubkey *remote_current_per_commitment_point)
2577{
2578 struct secret old_commit_secret;
2579
2580 /* By the time we're called, we've ensured this is a valid revocation
2581 * number. */
2582 assert(next_revocation_number == peer->next_index[LOCAL] - 2
2583 || next_revocation_number == peer->next_index[LOCAL] - 1);
2584
2585 /* By the time we're called, we've ensured we're within 1 of
2586 * their commitment chain */
2587 assert(next_commitment_number == peer->next_index[REMOTE] ||
2588 next_commitment_number == peer->next_index[REMOTE] - 1);
2589
2590 if (!last_local_per_commit_secret)
2591 return;
2592
2593 /* BOLT #2:
2594 * - if `next_revocation_number` equals 0:
2595 * - MUST set `your_last_per_commitment_secret` to all zeroes
2596 */
2597
2598 status_debug("next_revocation_number = %"PRIu64,
2599 next_revocation_number);
2600 if (next_revocation_number == 0)
2601 memset(&old_commit_secret, 0, sizeof(old_commit_secret));
2602 else {
2603 struct pubkey unused;
2604 /* This gets previous revocation number, since asking for
2605 * commitment point N gives secret for N-2 */
2606 get_per_commitment_point(next_revocation_number+1,
2607 &unused, &old_commit_secret);
2608 }
2609
2610 if (!secret_eq_consttime(&old_commit_secret,
2611 last_local_per_commit_secret))
2612 peer_failed_err(peer->pps,
2613 &peer->channel_id,
2614 "bad reestablish: your_last_per_commitment_secret %"PRIu64
2615 ": %s should be %s",
2616 next_revocation_number,
2617 type_to_string(tmpctx, struct secret,
2618 last_local_per_commit_secret),
2619 type_to_string(tmpctx, struct secret,
2620 &old_commit_secret));
2621
2622 if (!remote_current_per_commitment_point) {
2623 status_debug("option_static_remotekey: fields are correct");
2624 return;
2625 }
2626
2627 status_debug("Reestablish, comparing commitments. Remote's next local commitment number"
2628 " is %"PRIu64". Our next remote is %"PRIu64" with %"PRIu64

Callers 1

peer_reconnectFunction · 0.85

Calls 5

get_per_commitment_pointFunction · 0.85
secret_eq_consttimeFunction · 0.85
peer_failed_errFunction · 0.85
peer_failed_warnFunction · 0.85
type_to_stringClass · 0.50

Tested by

no test coverage detected