BOLT #2: * * A receiving node: * ... * - if `your_last_per_commitment_secret` does not match the expected values: * - SHOULD send an `error` and fail the channel. */
| 5518 | * - SHOULD send an `error` and fail the channel. |
| 5519 | */ |
| 5520 | static void check_current_dataloss_fields(struct peer *peer, |
| 5521 | u64 next_revocation_number, |
| 5522 | u64 next_commitment_number, |
| 5523 | const struct secret *last_local_per_commit_secret, |
| 5524 | /* NULL if option_static_remotekey */ |
| 5525 | const struct pubkey *remote_current_per_commitment_point) |
| 5526 | { |
| 5527 | struct secret old_commit_secret; |
| 5528 | |
| 5529 | /* By the time we're called, we've ensured this is a valid revocation |
| 5530 | * number. */ |
| 5531 | assert(next_revocation_number == peer->next_index[LOCAL] - 2 |
| 5532 | || next_revocation_number == peer->next_index[LOCAL] - 1); |
| 5533 | |
| 5534 | /* By the time we're called, we've ensured we're within 1 of |
| 5535 | * their commitment chain */ |
| 5536 | assert(next_commitment_number == peer->next_index[REMOTE] || |
| 5537 | next_commitment_number == peer->next_index[REMOTE] - 1); |
| 5538 | |
| 5539 | if (!last_local_per_commit_secret) |
| 5540 | return; |
| 5541 | |
| 5542 | /* BOLT #2: |
| 5543 | * - if `next_revocation_number` equals 0: |
| 5544 | * - MUST set `your_last_per_commitment_secret` to all zeroes |
| 5545 | */ |
| 5546 | |
| 5547 | status_debug("next_revocation_number = %"PRIu64, |
| 5548 | next_revocation_number); |
| 5549 | if (next_revocation_number == 0) |
| 5550 | memset(&old_commit_secret, 0, sizeof(old_commit_secret)); |
| 5551 | else { |
| 5552 | struct pubkey unused; |
| 5553 | revoke_commitment(next_revocation_number - 1, &old_commit_secret, &unused); |
| 5554 | } |
| 5555 | |
| 5556 | if (!secret_eq_consttime(&old_commit_secret, |
| 5557 | last_local_per_commit_secret)) |
| 5558 | peer_failed_err(peer->pps, |
| 5559 | &peer->channel_id, |
| 5560 | "bad reestablish: your_last_per_commitment_secret %"PRIu64 |
| 5561 | ": %s should be %s", |
| 5562 | next_revocation_number, |
| 5563 | fmt_secret(tmpctx, last_local_per_commit_secret), |
| 5564 | fmt_secret(tmpctx, &old_commit_secret)); |
| 5565 | |
| 5566 | if (!remote_current_per_commitment_point) { |
| 5567 | status_debug("option_static_remotekey: fields are correct"); |
| 5568 | return; |
| 5569 | } |
| 5570 | |
| 5571 | status_debug("Reestablish, comparing commitments. Remote's next local commitment number" |
| 5572 | " is %"PRIu64". Our next remote is %"PRIu64" with %"PRIu64 |
| 5573 | " revocations received", |
| 5574 | next_commitment_number, |
| 5575 | peer->next_index[REMOTE], |
| 5576 | peer->revocations_received); |
| 5577 |
no test coverage detected