| 1951 | } |
| 1952 | |
| 1953 | void peer_sending_commitsig(struct channel *channel, const u8 *msg) |
| 1954 | { |
| 1955 | u64 commitnum; |
| 1956 | struct fee_states *fee_states; |
| 1957 | struct height_states *blockheight_states; |
| 1958 | struct changed_htlc *changed_htlcs; |
| 1959 | size_t i, maxid = 0, num_local_added = 0; |
| 1960 | struct bitcoin_signature commit_sig; |
| 1961 | struct bitcoin_signature *htlc_sigs; |
| 1962 | struct lightningd *ld = channel->peer->ld; |
| 1963 | struct penalty_base *pbase; |
| 1964 | |
| 1965 | if (!fromwire_channeld_sending_commitsig(msg, msg, |
| 1966 | &commitnum, |
| 1967 | &pbase, |
| 1968 | &fee_states, |
| 1969 | &blockheight_states, |
| 1970 | &changed_htlcs, |
| 1971 | &commit_sig, &htlc_sigs) |
| 1972 | || !fee_states_valid(fee_states, channel->opener) |
| 1973 | || !height_states_valid(blockheight_states, channel->opener)) { |
| 1974 | channel_internal_error(channel, "bad channel_sending_commitsig %s", |
| 1975 | tal_hex(channel, msg)); |
| 1976 | return; |
| 1977 | } |
| 1978 | |
| 1979 | for (i = 0; i < tal_count(changed_htlcs); i++) { |
| 1980 | if (!changed_htlc(channel, changed_htlcs + i)) { |
| 1981 | channel_internal_error(channel, |
| 1982 | "channel_sending_commitsig: update failed"); |
| 1983 | return; |
| 1984 | } |
| 1985 | |
| 1986 | /* While we're here, sanity check added ones are in |
| 1987 | * ascending order. */ |
| 1988 | if (changed_htlcs[i].newstate == SENT_ADD_COMMIT) { |
| 1989 | num_local_added++; |
| 1990 | if (changed_htlcs[i].id > maxid) |
| 1991 | maxid = changed_htlcs[i].id; |
| 1992 | } |
| 1993 | } |
| 1994 | |
| 1995 | if (num_local_added != 0) { |
| 1996 | if (maxid != channel->next_htlc_id + num_local_added - 1) { |
| 1997 | channel_internal_error(channel, |
| 1998 | "channel_sending_commitsig:" |
| 1999 | " Added %"PRIu64", maxid now %"PRIu64 |
| 2000 | " from %"PRIu64, |
| 2001 | num_local_added, maxid, channel->next_htlc_id); |
| 2002 | return; |
| 2003 | } |
| 2004 | channel->next_htlc_id += num_local_added; |
| 2005 | } |
| 2006 | |
| 2007 | /* FIXME: We could detect if this changed, and adjust bounds and write |
| 2008 | * it to db iff it has. */ |
| 2009 | tal_free(channel->fee_states); |
| 2010 | channel->fee_states = tal_steal(channel, fee_states); |
no test coverage detected