| 1295 | } |
| 1296 | |
| 1297 | static bool |
| 1298 | wallet_update_channel_commit(struct lightningd *ld, |
| 1299 | struct channel *channel, |
| 1300 | struct channel_inflight *inflight, |
| 1301 | struct bitcoin_tx *remote_commit, |
| 1302 | struct bitcoin_signature *remote_commit_sig) |
| 1303 | { |
| 1304 | channel_set_last_tx(channel, |
| 1305 | tal_steal(channel, remote_commit), |
| 1306 | remote_commit_sig); |
| 1307 | |
| 1308 | /* We can't call channel_set_state here: channel isn't in db, so |
| 1309 | * really this is a "channel creation" event. */ |
| 1310 | if (channel->state == DUALOPEND_OPEN_COMMIT_READY) { |
| 1311 | bool was_important; |
| 1312 | |
| 1313 | /* Does peer currently have an important channel? */ |
| 1314 | was_important = peer_any_channel(channel->peer, |
| 1315 | channel_important_filter, NULL, NULL); |
| 1316 | log_info(channel->log, "State changed from %s to %s", |
| 1317 | channel_state_name(channel), |
| 1318 | channel_state_str(DUALOPEND_OPEN_COMMITTED)); |
| 1319 | channel->state = DUALOPEND_OPEN_COMMITTED; |
| 1320 | notify_channel_state_changed(channel->peer->ld, |
| 1321 | &channel->peer->id, |
| 1322 | &channel->cid, |
| 1323 | channel->scid, |
| 1324 | clock_time(), |
| 1325 | DUALOPEND_OPEN_COMMIT_READY, |
| 1326 | DUALOPEND_OPEN_COMMITTED, |
| 1327 | REASON_REMOTE, |
| 1328 | "Commitment transaction committed"); |
| 1329 | tell_connectd_peer_importance(channel->peer, was_important); |
| 1330 | } |
| 1331 | |
| 1332 | /* Update in database */ |
| 1333 | wallet_channel_save(ld->wallet, channel); |
| 1334 | |
| 1335 | /* Set inflight data & update */ |
| 1336 | if (inflight->last_tx) { |
| 1337 | struct bitcoin_txid txid, inflight_txid; |
| 1338 | /* confirm they're the same tx! */ |
| 1339 | bitcoin_txid(remote_commit, &txid); |
| 1340 | bitcoin_txid(inflight->last_tx, &inflight_txid); |
| 1341 | if (!bitcoin_txid_eq(&txid, &inflight_txid)) { |
| 1342 | channel_fail_permanent(channel, |
| 1343 | REASON_LOCAL, |
| 1344 | "Invalid commitment txid." |
| 1345 | " expected (inflight's) %s, got %s", |
| 1346 | fmt_bitcoin_txid(tmpctx, &inflight_txid), |
| 1347 | fmt_bitcoin_txid(tmpctx, &txid)); |
| 1348 | } |
| 1349 | return false; |
| 1350 | } |
| 1351 | |
| 1352 | |
| 1353 | inflight_set_last_tx(inflight, remote_commit, *remote_commit_sig); |
| 1354 | wallet_inflight_save(ld->wallet, inflight); |
no test coverage detected