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

Function update_node_psbt

plugins/spender/openchannel.c:251–321  ·  view source on GitHub ↗

After all of the changes have been applied to the parent psbt, * we update each node_psbt with the changes from every *other* peer. * * This updated node_psbt is the one that we should pass to * openchannel_update for the next round. * * We do update rounds until every peer returns "commitment_secured:true", * which will happen at the same round (as it requires us passing in * an identical

Source from the content-addressed store, hash-verified

249 * an identical PSBT as the previous round).
250 */
251static bool update_node_psbt(const tal_t *ctx,
252 const struct wally_psbt *parent_psbt,
253 struct wally_psbt **node_psbt)
254{
255 /* How to update this? We could do a comparison.
256 * More easily, we simply clone the parent and update
257 * the correct serial_ids for the node_psbt */
258 struct wally_psbt *clone;
259
260 tal_wally_start();
261 /* Only failure is alloc */
262 if (wally_psbt_clone_alloc(parent_psbt, 0, &clone) != WALLY_OK)
263 abort();
264 tal_wally_end_onto(ctx, clone, struct wally_psbt);
265
266 /* For every peer's input/output, flip the serial id
267 * on the clone. They should all be present. */
268 for (size_t i = 0; i < (*node_psbt)->num_inputs; i++) {
269 u64 serial_id;
270 int input_index;
271 if (!psbt_get_serial_id(&(*node_psbt)->inputs[i].unknowns,
272 &serial_id)) {
273 tal_wally_end(tal_free(clone));
274 return false;
275 }
276
277 /* We're the initiator here. If it's not the peer's
278 * input, skip it */
279 if (serial_id % 2 == TX_INITIATOR)
280 continue;
281 /* Down one, as that's where it'll be on the parent */
282 input_index = psbt_find_serial_input(clone, serial_id - 1);
283 /* Must exist */
284 assert(input_index != -1);
285 /* Update the cloned input serial to match the node's
286 * view */
287 psbt_input_set_serial_id(clone, &clone->inputs[input_index],
288 serial_id);
289
290 }
291
292 for (size_t i = 0; i < (*node_psbt)->num_outputs; i++) {
293 u64 serial_id;
294 int output_index;
295 if (!psbt_get_serial_id(&(*node_psbt)->outputs[i].unknowns,
296 &serial_id)) {
297 tal_wally_end(tal_free(clone));
298 return false;
299 }
300 /* We're the initiator here. If it's not the peer's
301 * output, skip it */
302 if (serial_id % 2 == TX_INITIATOR)
303 continue;
304
305 /* Down one, as that's where it'll be on the parent */
306 output_index = psbt_find_serial_output(clone,
307 serial_id - 1);
308 /* Must exist */

Callers 2

Calls 9

tal_wally_startFunction · 0.85
abortFunction · 0.85
psbt_get_serial_idFunction · 0.85
tal_wally_endFunction · 0.85
tal_freeFunction · 0.85
psbt_find_serial_inputFunction · 0.85
psbt_input_set_serial_idFunction · 0.85
psbt_find_serial_outputFunction · 0.85

Tested by

no test coverage detected