From 6d0d8efb454fc8e166758fa7b29c264739d8cefc Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 13 May 2021 16:24:23 -0400 Subject: [PATCH] Store keysend preimage in PendingHTLCRouting. This will be used in upcoming commits to accept keysend payments. --- lightning/src/ln/channelmanager.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 52ac049ab..b351cccff 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -99,6 +99,7 @@ enum PendingHTLCRouting { Receive { payment_data: msgs::FinalOnionHopData, incoming_cltv_expiry: u32, // Used to track when we should expire pending HTLCs that go unclaimed + keysend_preimage: Option, }, } @@ -1433,10 +1434,10 @@ impl ChannelMana return_err!("Upstream node set CLTV to the wrong value", 18, &byte_utils::be32_to_array(msg.cltv_expiry)); } - let payment_data = match next_hop_data.format { - msgs::OnionHopDataFormat::Legacy { .. } => None, + let (payment_data, keysend_preimage) = match next_hop_data.format { + msgs::OnionHopDataFormat::Legacy { .. } => (None, None), msgs::OnionHopDataFormat::NonFinalNode { .. } => return_err!("Got non final data with an HMAC of 0", 0x4000 | 22, &[0;0]), - msgs::OnionHopDataFormat::FinalNode { payment_data, .. } => payment_data, + msgs::OnionHopDataFormat::FinalNode { payment_data, keysend_preimage } => (payment_data, keysend_preimage), }; if payment_data.is_none() { @@ -1452,6 +1453,7 @@ impl ChannelMana routing: PendingHTLCRouting::Receive { payment_data: payment_data.unwrap(), incoming_cltv_expiry: msg.cltv_expiry, + keysend_preimage, }, payment_hash: msg.payment_hash.clone(), incoming_shared_secret: shared_secret, @@ -2177,7 +2179,7 @@ impl ChannelMana for forward_info in pending_forwards.drain(..) { match forward_info { HTLCForwardInfo::AddHTLC { prev_short_channel_id, prev_htlc_id, forward_info: PendingHTLCInfo { - routing: PendingHTLCRouting::Receive { payment_data, incoming_cltv_expiry }, + routing: PendingHTLCRouting::Receive { payment_data, incoming_cltv_expiry, .. }, incoming_shared_secret, payment_hash, amt_to_forward, .. }, prev_funding_outpoint } => { let claimable_htlc = ClaimableHTLC { @@ -4326,6 +4328,7 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting, (1, Receive) => { (0, payment_data, required), (2, incoming_cltv_expiry, required), + (4, keysend_preimage, option) } ;); -- 2.39.5