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

Function create_anchor_details

lightningd/anchorspend.c:120–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120struct anchor_details *create_anchor_details(const tal_t *ctx,
121 struct channel *channel,
122 const struct bitcoin_tx *tx)
123{
124 struct lightningd *ld = channel->peer->ld;
125 const struct htlc_in *hin;
126 struct htlc_in_map_iter ini;
127 const struct htlc_out *hout;
128 struct htlc_out_map_iter outi;
129 struct anchor_details *adet = tal(ctx, struct anchor_details);
130 struct local_anchor_info *infos, local_anchor;
131 struct deadline_value v;
132 u32 final_deadline;
133
134 /* If we don't have an anchor, we can't do anything. */
135 if (!channel_type_has_anchors(channel->type))
136 return tal_free(adet);
137
138 if (!hsm_capable(ld, WIRE_HSMD_SIGN_ANCHORSPEND)) {
139 log_broken(ld->log, "hsm not capable of signing anchorspends!");
140 return tal_free(adet);
141 }
142
143 adet->anchor_wscript
144 = bitcoin_wscript_anchor(adet, &channel->local_funding_pubkey);
145 adet->anchors = tal_arr(adet, struct one_anchor, 0);
146
147 /* Look for any remote commitment tx anchors we might use */
148 infos = wallet_get_local_anchors(tmpctx,
149 channel->peer->ld->wallet,
150 channel->dbid);
151 for (size_t i = 0; i < tal_count(infos); i++)
152 add_one_anchor(adet, &infos[i], REMOTE);
153
154 /* Now append our own, if we have one. */
155 if (find_anchor_output(channel, tx, adet->anchor_wscript,
156 &local_anchor.anchor_point)) {
157 local_anchor.commitment_weight = bitcoin_tx_weight(tx);
158 local_anchor.commitment_fee = bitcoin_tx_compute_fee(tx);
159 add_one_anchor(adet, &local_anchor, LOCAL);
160 }
161
162 log_debug(channel->log, "We have %zu anchor points to use",
163 tal_count(adet->anchors));
164
165 /* This happens in several cases:
166 * 1. Mutual close tx.
167 * 2. There's no to-us output and no HTLCs */
168 if (tal_count(adet->anchors) == 0) {
169 return tal_free(adet);
170 }
171
172 adet->vals = tal_arr(adet, struct deadline_value, 0);
173
174 /* OK, what's it worth, at each deadline?
175 * We care about incoming HTLCs where we have the preimage, and
176 * outgoing HTLCs. */
177 for (hin = htlc_in_map_first(ld->htlcs_in, &ini);

Callers 1

sign_and_send_lastFunction · 0.70

Calls 10

channel_type_has_anchorsFunction · 0.85
tal_freeFunction · 0.85
bitcoin_wscript_anchorFunction · 0.85
wallet_get_local_anchorsFunction · 0.85
add_one_anchorFunction · 0.85
find_anchor_outputFunction · 0.85
bitcoin_tx_weightFunction · 0.85
bitcoin_tx_compute_feeFunction · 0.85
merge_deadlinesFunction · 0.85
hsm_capableFunction · 0.70

Tested by

no test coverage detected