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