| 143 | } |
| 144 | |
| 145 | static void try_update_blockheight(struct lightningd *ld, |
| 146 | struct channel *channel) |
| 147 | { |
| 148 | u32 blockheight = get_block_height(ld->topology); |
| 149 | u8 *msg; |
| 150 | |
| 151 | /* We don't update the blockheight for non-leased chans */ |
| 152 | if (channel->lease_expiry == 0) |
| 153 | return; |
| 154 | |
| 155 | log_debug(channel->log, "attempting update blockheight %s", |
| 156 | fmt_channel_id(tmpctx, &channel->cid)); |
| 157 | |
| 158 | if (!topology_synced(ld->topology)) { |
| 159 | log_debug(channel->log, "chain not synced," |
| 160 | " not updating blockheight"); |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | /* If they're offline, check that we're not too far behind anyway */ |
| 165 | if (!channel->owner) { |
| 166 | if (channel->opener == REMOTE) { |
| 167 | u32 peer_height |
| 168 | = get_blockheight(channel->blockheight_states, |
| 169 | channel->opener, REMOTE); |
| 170 | |
| 171 | /* Lease no longer active, we don't (really) care */ |
| 172 | if (peer_height >= channel->lease_expiry) |
| 173 | return; |
| 174 | |
| 175 | assert(peer_height + 1008 > peer_height); |
| 176 | if (peer_height + 1008 < blockheight) |
| 177 | channel_fail_permanent(channel, |
| 178 | REASON_PROTOCOL, |
| 179 | "Offline peer is too" |
| 180 | " far behind," |
| 181 | " terminating leased" |
| 182 | " channel. Our current" |
| 183 | " %u, theirs %u", |
| 184 | blockheight, |
| 185 | peer_height); |
| 186 | } |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | /* If we're not opened/locked in yet, don't send update */ |
| 191 | if (!channel_state_can_add_htlc(channel->state)) |
| 192 | return; |
| 193 | |
| 194 | log_debug(ld->log, "update_blockheight: height = %u", blockheight); |
| 195 | |
| 196 | msg = towire_channeld_blockheight(NULL, blockheight); |
| 197 | subd_send_msg(channel->owner, take(msg)); |
| 198 | } |
| 199 | |
| 200 | void notify_feerate_change(struct lightningd *ld) |
| 201 | { |
no test coverage detected