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

Function channel_record_open

lightningd/channel_control.c:1032–1086  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1030}
1031
1032void channel_record_open(struct channel *channel, u32 blockheight, bool record_push)
1033{
1034 struct chain_coin_mvt *mvt;
1035 struct amount_msat start_balance;
1036 bool is_pushed = !amount_msat_is_zero(channel->push);
1037 bool is_leased = channel->lease_expiry > 0;
1038
1039 /* If funds were pushed, add/sub them from the starting balance */
1040 if (channel->opener == LOCAL) {
1041 if (!amount_msat_add(&start_balance,
1042 channel->our_msat, channel->push))
1043 fatal("Unable to add push_msat (%s) + our_msat (%s)",
1044 fmt_amount_msat(tmpctx, channel->push),
1045 fmt_amount_msat(tmpctx, channel->our_msat));
1046 } else {
1047 if (!amount_msat_sub(&start_balance,
1048 channel->our_msat, channel->push))
1049 fatal("Unable to sub our_msat (%s) - push (%s)",
1050 fmt_amount_msat(tmpctx, channel->our_msat),
1051 fmt_amount_msat(tmpctx, channel->push));
1052 }
1053
1054 /* If it's not in a block yet, send a proposal */
1055 if (blockheight > 0)
1056 mvt = new_coin_channel_open(tmpctx,
1057 channel,
1058 &channel->funding,
1059 &channel->peer->id,
1060 blockheight,
1061 start_balance,
1062 channel->funding_sats,
1063 channel->opener == LOCAL,
1064 is_leased);
1065 else
1066 mvt = new_coin_channel_open_proposed(tmpctx,
1067 channel,
1068 &channel->funding,
1069 &channel->peer->id,
1070 start_balance,
1071 channel->funding_sats,
1072 channel->opener == LOCAL,
1073 is_leased);
1074
1075 wallet_save_chain_mvt(channel->peer->ld, mvt);
1076
1077 /* If we pushed sats, *now* record them */
1078 if (is_pushed && record_push)
1079 wallet_save_channel_mvt(channel->peer->ld,
1080 new_coin_channel_push(tmpctx, channel,
1081 channel->opener == REMOTE ? COIN_CREDIT : COIN_DEBIT,
1082 channel->push,
1083 is_leased
1084 ? mk_mvt_tags(MVT_LEASE_FEE)
1085 : mk_mvt_tags(MVT_PUSHED)));
1086}
1087
1088void lockin_has_completed(struct channel *channel, bool record_push)
1089{

Callers 3

handle_channel_lockedFunction · 0.85
onchaind_funding_spentFunction · 0.85
lockin_has_completedFunction · 0.85

Calls 10

amount_msat_is_zeroFunction · 0.85
amount_msat_addFunction · 0.85
amount_msat_subFunction · 0.85
new_coin_channel_openFunction · 0.85
wallet_save_chain_mvtFunction · 0.85
wallet_save_channel_mvtFunction · 0.85
new_coin_channel_pushFunction · 0.85
fatalFunction · 0.70
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected