| 128 | } |
| 129 | |
| 130 | void channel_record_open(struct channel *channel, u32 blockheight, bool record_push) |
| 131 | { |
| 132 | struct chain_coin_mvt *mvt; |
| 133 | struct amount_msat start_balance; |
| 134 | bool is_pushed = !amount_msat_zero(channel->push); |
| 135 | bool is_leased = channel->lease_expiry > 0; |
| 136 | |
| 137 | /* If funds were pushed, add/sub them from the starting balance */ |
| 138 | if (channel->opener == LOCAL) { |
| 139 | if (!amount_msat_add(&start_balance, |
| 140 | channel->our_msat, channel->push)) |
| 141 | fatal("Unable to add push_msat (%s) + our_msat (%s)", |
| 142 | type_to_string(tmpctx, struct amount_msat, |
| 143 | &channel->push), |
| 144 | type_to_string(tmpctx, struct amount_msat, |
| 145 | &channel->our_msat)); |
| 146 | } else { |
| 147 | if (!amount_msat_sub(&start_balance, |
| 148 | channel->our_msat, channel->push)) |
| 149 | fatal("Unable to sub our_msat (%s) - push (%s)", |
| 150 | type_to_string(tmpctx, struct amount_msat, |
| 151 | &channel->our_msat), |
| 152 | type_to_string(tmpctx, struct amount_msat, |
| 153 | &channel->push)); |
| 154 | } |
| 155 | |
| 156 | /* If it's not in a block yet, send a proposal */ |
| 157 | if (blockheight > 0) |
| 158 | mvt = new_coin_channel_open(tmpctx, |
| 159 | &channel->cid, |
| 160 | &channel->funding, |
| 161 | &channel->peer->id, |
| 162 | blockheight, |
| 163 | start_balance, |
| 164 | channel->funding_sats, |
| 165 | channel->opener == LOCAL, |
| 166 | is_leased); |
| 167 | else |
| 168 | mvt = new_coin_channel_open_proposed(tmpctx, |
| 169 | &channel->cid, |
| 170 | &channel->funding, |
| 171 | &channel->peer->id, |
| 172 | start_balance, |
| 173 | channel->funding_sats, |
| 174 | channel->opener == LOCAL, |
| 175 | is_leased); |
| 176 | |
| 177 | notify_chain_mvt(channel->peer->ld, mvt); |
| 178 | |
| 179 | /* If we pushed sats, *now* record them */ |
| 180 | if (is_pushed && record_push) |
| 181 | notify_channel_mvt(channel->peer->ld, |
| 182 | new_coin_channel_push(tmpctx, &channel->cid, |
| 183 | channel->push, |
| 184 | is_leased ? LEASE_FEE : PUSHED, |
| 185 | channel->opener == REMOTE)); |
| 186 | } |
| 187 |
no test coverage detected