MCPcopy Create free account
hub / github.com/ElementsProject/lightning / channel_set_state

Function channel_set_state

lightningd/channel.c:722–775  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

720}
721
722void channel_set_state(struct channel *channel,
723 enum channel_state old_state,
724 enum channel_state state,
725 enum state_change reason,
726 char *why)
727{
728 struct timeabs timestamp;
729
730 /* set closer, if known */
731 if (state > CHANNELD_NORMAL && channel->closer == NUM_SIDES) {
732 if (reason == REASON_LOCAL) channel->closer = LOCAL;
733 if (reason == REASON_USER) channel->closer = LOCAL;
734 if (reason == REASON_REMOTE) channel->closer = REMOTE;
735 if (reason == REASON_ONCHAIN) channel->closer = REMOTE;
736 }
737
738 /* use or update state_change_cause, if known */
739 if (reason != REASON_UNKNOWN)
740 channel->state_change_cause = reason;
741 else
742 reason = channel->state_change_cause;
743
744 log_info(channel->log, "State changed from %s to %s",
745 channel_state_name(channel), channel_state_str(state));
746 if (channel->state != old_state)
747 fatal("channel state %s should be %s",
748 channel_state_name(channel), channel_state_str(old_state));
749
750 channel->state = state;
751
752 /* TODO(cdecker) Selectively save updated fields to DB */
753 wallet_channel_save(channel->peer->ld->wallet, channel);
754
755 /* plugin notification channel_state_changed and DB entry */
756 if (state != old_state) { /* see issue #4029 */
757 timestamp = time_now();
758 wallet_state_change_add(channel->peer->ld->wallet,
759 channel->dbid,
760 &timestamp,
761 old_state,
762 state,
763 reason,
764 why);
765 notify_channel_state_changed(channel->peer->ld,
766 &channel->peer->id,
767 &channel->cid,
768 channel->scid,
769 &timestamp,
770 old_state,
771 state,
772 reason,
773 why);
774 }
775}
776
777const char *channel_change_state_reason_str(enum state_change reason)
778{

Callers 13

handle_channel_closedFunction · 0.85
handle_peer_tx_sigs_sentFunction · 0.85
handle_channel_lockedFunction · 0.85
handle_peer_tx_sigs_msgFunction · 0.85
channel_fail_permanentFunction · 0.85
onchaind_funding_spentFunction · 0.85
peer_closing_completeFunction · 0.85
json_closeFunction · 0.85
lockin_completeFunction · 0.85
peer_got_shutdownFunction · 0.85

Calls 8

log_infoClass · 0.85
time_nowFunction · 0.85
wallet_state_change_addFunction · 0.85
channel_state_nameFunction · 0.70
channel_state_strFunction · 0.70
fatalFunction · 0.70
wallet_channel_saveFunction · 0.50

Tested by

no test coverage detected