@@ -4430,7 +4430,24 @@ where
4430
4430
onion_utils::Hop::Receive(next_hop_data) => {
4431
4431
// OUR PAYMENT!
4432
4432
let current_height: u32 = self.best_block.read().unwrap().height;
4433
- match create_recv_pending_htlc_info(next_hop_data, shared_secret, msg.payment_hash,
4433
+ match create_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive(next_hop_data), shared_secret, msg.payment_hash,
4434
+ msg.amount_msat, msg.cltv_expiry, None, allow_underpay, msg.skimmed_fee_msat,
4435
+ current_height)
4436
+ {
4437
+ Ok(info) => {
4438
+ // Note that we could obviously respond immediately with an update_fulfill_htlc
4439
+ // message, however that would leak that we are the recipient of this payment, so
4440
+ // instead we stay symmetric with the forwarding case, only responding (after a
4441
+ // delay) once they've send us a commitment_signed!
4442
+ PendingHTLCStatus::Forward(info)
4443
+ },
4444
+ Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
4445
+ }
4446
+ },
4447
+ onion_utils::Hop::BlindedReceive(next_hop_data) => {
4448
+ // OUR PAYMENT!
4449
+ let current_height: u32 = self.best_block.read().unwrap().height;
4450
+ match create_recv_pending_htlc_info(msgs::InboundOnionPayload::BlindedReceive(next_hop_data), shared_secret, msg.payment_hash,
4434
4451
msg.amount_msat, msg.cltv_expiry, None, allow_underpay, msg.skimmed_fee_msat,
4435
4452
current_height)
4436
4453
{
@@ -4445,7 +4462,14 @@ where
4445
4462
}
4446
4463
},
4447
4464
onion_utils::Hop::Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => {
4448
- match create_fwd_pending_htlc_info(msg, next_hop_data, next_hop_hmac,
4465
+ match create_fwd_pending_htlc_info(msg, msgs::InboundOnionPayload::Forward(next_hop_data), next_hop_hmac,
4466
+ new_packet_bytes, shared_secret, next_packet_pubkey_opt) {
4467
+ Ok(info) => PendingHTLCStatus::Forward(info),
4468
+ Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
4469
+ }
4470
+ },
4471
+ onion_utils::Hop::BlindedForward { next_hop_data, next_hop_hmac, new_packet_bytes } => {
4472
+ match create_fwd_pending_htlc_info(msg, msgs::InboundOnionPayload::BlindedForward(next_hop_data), next_hop_hmac,
4449
4473
new_packet_bytes, shared_secret, next_packet_pubkey_opt) {
4450
4474
Ok(info) => PendingHTLCStatus::Forward(info),
4451
4475
Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data)
@@ -5860,22 +5884,22 @@ where
5860
5884
failed_payment!(err_msg, err_code, Vec::new(), Some(phantom_shared_secret));
5861
5885
},
5862
5886
};
5863
- match next_hop {
5864
- onion_utils::Hop::Receive(hop_data) => {
5865
- let current_height: u32 = self.best_block.read().unwrap().height;
5866
- match create_recv_pending_htlc_info(hop_data,
5867
- incoming_shared_secret, payment_hash, outgoing_amt_msat,
5868
- outgoing_cltv_value, Some(phantom_shared_secret), false, None,
5869
- current_height)
5870
- {
5871
- Ok(info) => phantom_receives.push((
5872
- prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
5873
- prev_channel_id, prev_user_channel_id, vec![(info, prev_htlc_id)]
5874
- )),
5875
- Err(InboundHTLCErr { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret))
5876
- }
5877
- } ,
5878
- _ => panic!(),
5887
+ let inbound_onion_payload = match next_hop {
5888
+ onion_utils::Hop::Receive(hop_data) => msgs::InboundOnionPayload::Receive(hop_data),
5889
+ onion_utils::Hop::BlindedReceive(hop_data) => msgs::InboundOnionPayload::BlindedReceive(hop_data),
5890
+ _ => panic!()
5891
+ };
5892
+ let current_height: u32 = self.best_block.read().unwrap().height;
5893
+ match create_recv_pending_htlc_info(inbound_onion_payload,
5894
+ incoming_shared_secret, payment_hash, outgoing_amt_msat,
5895
+ outgoing_cltv_value, Some(phantom_shared_secret), false, None,
5896
+ current_height)
5897
+ {
5898
+ Ok(info) => phantom_receives.push((
5899
+ prev_short_channel_id, prev_counterparty_node_id, prev_funding_outpoint,
5900
+ prev_channel_id, prev_user_channel_id, vec![(info, prev_htlc_id)]
5901
+ )) ,
5902
+ Err(InboundHTLCErr { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret))
5879
5903
}
5880
5904
} else {
5881
5905
fail_forward!(format!("Unknown short channel id {} for forward HTLC", short_chan_id), 0x4000 | 10, Vec::new(), None);
@@ -15570,16 +15594,17 @@ mod tests {
15570
15594
let node = create_network(1, &node_cfg, &node_chanmgr);
15571
15595
let sender_intended_amt_msat = 100;
15572
15596
let extra_fee_msat = 10;
15573
- let hop_data = msgs::InboundOnionPayload::Receive {
15597
+ let hop_data = msgs::InboundOnionPayload::Receive(msgs::InboundOnionReceivePayload {
15574
15598
sender_intended_htlc_amt_msat: 100,
15575
15599
cltv_expiry_height: 42,
15576
15600
payment_metadata: None,
15577
15601
keysend_preimage: None,
15578
15602
payment_data: Some(msgs::FinalOnionHopData {
15579
- payment_secret: PaymentSecret([0; 32]), total_msat: sender_intended_amt_msat,
15603
+ payment_secret: PaymentSecret([0; 32]),
15604
+ total_msat: sender_intended_amt_msat,
15580
15605
}),
15581
15606
custom_tlvs: Vec::new(),
15582
- };
15607
+ }) ;
15583
15608
// Check that if the amount we received + the penultimate hop extra fee is less than the sender
15584
15609
// intended amount, we fail the payment.
15585
15610
let current_height: u32 = node[0].node.best_block.read().unwrap().height;
@@ -15592,16 +15617,17 @@ mod tests {
15592
15617
} else { panic!(); }
15593
15618
15594
15619
// If amt_received + extra_fee is equal to the sender intended amount, we're fine.
15595
- let hop_data = msgs::InboundOnionPayload::Receive { // This is the same payload as above, InboundOnionPayload doesn't implement Clone
15620
+ let hop_data = msgs::InboundOnionPayload::Receive(msgs::InboundOnionReceivePayload { // This is the same payload as above, InboundOnionPayload doesn't implement Clone
15596
15621
sender_intended_htlc_amt_msat: 100,
15597
15622
cltv_expiry_height: 42,
15598
15623
payment_metadata: None,
15599
15624
keysend_preimage: None,
15600
15625
payment_data: Some(msgs::FinalOnionHopData {
15601
- payment_secret: PaymentSecret([0; 32]), total_msat: sender_intended_amt_msat,
15626
+ payment_secret: PaymentSecret([0; 32]),
15627
+ total_msat: sender_intended_amt_msat,
15602
15628
}),
15603
15629
custom_tlvs: Vec::new(),
15604
- };
15630
+ }) ;
15605
15631
let current_height: u32 = node[0].node.best_block.read().unwrap().height;
15606
15632
assert!(create_recv_pending_htlc_info(hop_data, [0; 32], PaymentHash([0; 32]),
15607
15633
sender_intended_amt_msat - extra_fee_msat, 42, None, true, Some(extra_fee_msat),
@@ -15616,16 +15642,17 @@ mod tests {
15616
15642
let node = create_network(1, &node_cfg, &node_chanmgr);
15617
15643
15618
15644
let current_height: u32 = node[0].node.best_block.read().unwrap().height;
15619
- let result = create_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive {
15645
+ let result = create_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive(msgs::InboundOnionReceivePayload {
15620
15646
sender_intended_htlc_amt_msat: 100,
15621
15647
cltv_expiry_height: 22,
15622
15648
payment_metadata: None,
15623
15649
keysend_preimage: None,
15624
15650
payment_data: Some(msgs::FinalOnionHopData {
15625
- payment_secret: PaymentSecret([0; 32]), total_msat: 100,
15651
+ payment_secret: PaymentSecret([0; 32]),
15652
+ total_msat: 100,
15626
15653
}),
15627
15654
custom_tlvs: Vec::new(),
15628
- }, [0; 32], PaymentHash([0; 32]), 100, 23, None, true, None, current_height);
15655
+ }) , [0; 32], PaymentHash([0; 32]), 100, 23, None, true, None, current_height);
15629
15656
15630
15657
// Should not return an error as this condition:
15631
15658
// https://github.com/lightning/bolts/blob/4dcc377209509b13cf89a4b91fde7d478f5b46d8/04-onion-routing.md?plain=1#L334
0 commit comments