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

Function peer_got_revoke

lightningd/peer_htlcs.c:2595–2737  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2593 struct commitment_revocation_payload *);
2594
2595void peer_got_revoke(struct channel *channel, const u8 *msg)
2596{
2597 u64 revokenum;
2598 struct secret per_commitment_secret;
2599 struct pubkey next_per_commitment_point;
2600 struct changed_htlc *changed;
2601 enum onion_wire *badonions;
2602 u8 **failmsgs;
2603 size_t i;
2604 struct lightningd *ld = channel->peer->ld;
2605 struct fee_states *fee_states;
2606 struct height_states *blockheight_states;
2607 struct penalty_base *pbase;
2608 struct commitment_revocation_payload *payload;
2609 struct bitcoin_tx *penalty_tx;
2610
2611 if (!fromwire_channeld_got_revoke(msg, msg,
2612 &revokenum, &per_commitment_secret,
2613 &next_per_commitment_point,
2614 &fee_states,
2615 &blockheight_states,
2616 &changed,
2617 &pbase,
2618 &penalty_tx)
2619 || !fee_states_valid(fee_states, channel->opener)
2620 || !height_states_valid(blockheight_states, channel->opener)) {
2621 channel_internal_error(channel, "bad fromwire_channeld_got_revoke %s",
2622 tal_hex(channel, msg));
2623 return;
2624 }
2625
2626 log_debug(channel->log,
2627 "got revoke %"PRIu64": %zu changed",
2628 revokenum, tal_count(changed));
2629
2630 /* Save any immediate failures for after we reply. */
2631 badonions = tal_arrz(msg, enum onion_wire, tal_count(changed));
2632 failmsgs = tal_arrz(msg, u8 *, tal_count(changed));
2633 for (i = 0; i < tal_count(changed); i++) {
2634 /* BOLT #2:
2635 * A node:
2636 * - until an incoming HTLC has been irrevocably committed:
2637 * - MUST NOT offer the corresponding outgoing HTLC
2638 * (`update_add_htlc`) in response to that incoming HTLC.
2639 */
2640 /* If we're doing final accept, we need to forward */
2641 if (changed[i].newstate == RCVD_ADD_ACK_REVOCATION) {
2642 peer_accepted_htlc(failmsgs,
2643 channel, changed[i].id, false,
2644 &badonions[i], &failmsgs[i]);
2645 } else {
2646 if (!changed_htlc(channel, &changed[i])) {
2647 channel_internal_error(channel,
2648 "got_revoke: update failed");
2649 return;
2650 }
2651 }
2652 }

Callers 1

channel_msgFunction · 0.85

Calls 15

fee_states_validFunction · 0.85
height_states_validFunction · 0.85
tal_hexFunction · 0.85
peer_accepted_htlcFunction · 0.85
revocations_receivedFunction · 0.85
wallet_shachain_add_hashFunction · 0.85
shachain_indexFunction · 0.85
fmt_secretFunction · 0.85
tal_freeFunction · 0.85
update_per_commit_pointFunction · 0.85

Tested by

no test coverage detected