| 1477 | } |
| 1478 | |
| 1479 | static bool |
| 1480 | wallet_update_channel_commit(struct lightningd *ld, |
| 1481 | struct channel *channel, |
| 1482 | struct channel_inflight *inflight, |
| 1483 | struct bitcoin_tx *remote_commit, |
| 1484 | struct bitcoin_signature *remote_commit_sig) |
| 1485 | { |
| 1486 | /*~ Only the candidate channel->funding names gets to be the |
| 1487 | * channel's commitment. Before promotion that is always the latest |
| 1488 | * attempt (wallet_update_channel moved channel->funding to it); after |
| 1489 | * promotion an attempt still completing belongs to its inflight only, |
| 1490 | * see wallet_add_inflight_attempt. */ |
| 1491 | if (bitcoin_outpoint_eq(&inflight->funding->outpoint, |
| 1492 | &channel->funding)) { |
| 1493 | channel_set_last_tx(channel, |
| 1494 | tal_steal(channel, remote_commit), |
| 1495 | remote_commit_sig); |
| 1496 | } else { |
| 1497 | log_info(channel->log, |
| 1498 | "Not updating channel commitment from RBF attempt %s:" |
| 1499 | " funding is %s", |
| 1500 | fmt_bitcoin_txid(tmpctx, |
| 1501 | &inflight->funding->outpoint.txid), |
| 1502 | fmt_bitcoin_txid(tmpctx, &channel->funding.txid)); |
| 1503 | } |
| 1504 | |
| 1505 | /* We can't call channel_set_state here: channel isn't in db, so |
| 1506 | * really this is a "channel creation" event. */ |
| 1507 | if (channel->state == DUALOPEND_OPEN_COMMIT_READY) { |
| 1508 | bool was_important; |
| 1509 | |
| 1510 | /* Does peer currently have an important channel? */ |
| 1511 | was_important = peer_any_channel(channel->peer, |
| 1512 | channel_important_filter, NULL, NULL); |
| 1513 | log_info(channel->log, "State changed from %s to %s", |
| 1514 | channel_state_name(channel), |
| 1515 | channel_state_str(DUALOPEND_OPEN_COMMITTED)); |
| 1516 | channel->state = DUALOPEND_OPEN_COMMITTED; |
| 1517 | notify_channel_state_changed(channel->peer->ld, |
| 1518 | &channel->peer->id, |
| 1519 | &channel->cid, |
| 1520 | channel->scid, |
| 1521 | clock_time(), |
| 1522 | DUALOPEND_OPEN_COMMIT_READY, |
| 1523 | DUALOPEND_OPEN_COMMITTED, |
| 1524 | REASON_REMOTE, |
| 1525 | "Commitment transaction committed"); |
| 1526 | tell_connectd_peer_importance(channel->peer, was_important); |
| 1527 | } |
| 1528 | |
| 1529 | /* Update in database */ |
| 1530 | wallet_channel_save(ld->wallet, channel); |
| 1531 | |
| 1532 | /* Set inflight data & update */ |
| 1533 | if (inflight->last_tx) { |
| 1534 | struct bitcoin_txid txid, inflight_txid; |
| 1535 | /* confirm they're the same tx! */ |
| 1536 | bitcoin_txid(remote_commit, &txid); |
no test coverage detected