| 1944 | } |
| 1945 | |
| 1946 | static void send_reestablish(struct peer *peer, |
| 1947 | const struct channel_id *cid, |
| 1948 | const struct shachain *their_shachain, |
| 1949 | u64 local_next_index) |
| 1950 | { |
| 1951 | u8 *msg; |
| 1952 | struct secret last_remote_per_commit_secret; |
| 1953 | u64 num_revocations; |
| 1954 | |
| 1955 | /* BOLT #2: |
| 1956 | * - if `next_revocation_number` equals 0: |
| 1957 | * - MUST set `your_last_per_commitment_secret` to all zeroes |
| 1958 | * - otherwise: |
| 1959 | * - MUST set `your_last_per_commitment_secret` to the last |
| 1960 | * `per_commitment_secret` it received |
| 1961 | */ |
| 1962 | num_revocations = revocations_received(their_shachain); |
| 1963 | if (num_revocations == 0) |
| 1964 | memset(&last_remote_per_commit_secret, 0, |
| 1965 | sizeof(last_remote_per_commit_secret)); |
| 1966 | else if (!shachain_get_secret(their_shachain, |
| 1967 | num_revocations-1, |
| 1968 | &last_remote_per_commit_secret)) { |
| 1969 | log_peer_broken(peer->ld->log, &peer->id, |
| 1970 | "%s: cannot get shachain secret %"PRIu64" to send reestablish", |
| 1971 | fmt_channel_id(tmpctx, cid), num_revocations-1); |
| 1972 | return; |
| 1973 | } |
| 1974 | |
| 1975 | /* BOLT #2: |
| 1976 | * The sending node: |
| 1977 | * - MUST set `next_commitment_number` to the commitment number of the |
| 1978 | * next `commitment_signed` it expects to receive. |
| 1979 | * - MUST set `next_revocation_number` to the commitment number of the |
| 1980 | * next `revoke_and_ack` message it expects to receive. |
| 1981 | * - MUST set `my_current_per_commitment_point` to a valid point. |
| 1982 | * - if `next_revocation_number` equals 0: |
| 1983 | * - MUST set `your_last_per_commitment_secret` to all zeroes |
| 1984 | * - otherwise: |
| 1985 | * - MUST set `your_last_per_commitment_secret` to the last `per_commitment_secret` it received |
| 1986 | */ |
| 1987 | msg = towire_channel_reestablish(tmpctx, cid, |
| 1988 | local_next_index, |
| 1989 | num_revocations, |
| 1990 | &last_remote_per_commit_secret, |
| 1991 | /* Any valid point works, since static_remotekey */ |
| 1992 | &peer->ld->our_pubkey, |
| 1993 | /* No upgrade for you, since we're closed! */ |
| 1994 | NULL); |
| 1995 | subd_send_msg(peer->ld->connectd, |
| 1996 | take(towire_connectd_peer_send_msg(NULL, &peer->id, |
| 1997 | peer->connectd_counter, |
| 1998 | msg))); |
| 1999 | } |
| 2000 | |
| 2001 | /* connectd tells us a peer has a message and we've not already attached |
| 2002 | * a subd. Normally this is a race, but it happens for real when opening |
no test coverage detected