@@ -78,16 +78,20 @@ fn check_blinded_forward(
7878fn check_trampoline_onion_constraints (
7979 outer_hop_data : & msgs:: InboundTrampolineEntrypointPayload , trampoline_cltv_value : u32 ,
8080 trampoline_amount : u64 ,
81- ) -> Result < ( ) , LocalHTLCFailureReason > {
81+ ) -> Result < ( ) , ( LocalHTLCFailureReason , Vec < u8 > ) > {
8282 if outer_hop_data. outgoing_cltv_value < trampoline_cltv_value {
83- return Err ( LocalHTLCFailureReason :: FinalIncorrectCLTVExpiry ) ;
83+ let mut err_data = Vec :: new ( ) ;
84+ outer_hop_data. outgoing_cltv_value . write ( & mut err_data) . unwrap ( ) ;
85+ return Err ( ( LocalHTLCFailureReason :: FinalIncorrectCLTVExpiry , err_data) ) ;
8486 }
8587 let outgoing_amount = outer_hop_data
8688 . multipath_trampoline_data
8789 . as_ref ( )
8890 . map_or ( outer_hop_data. amt_to_forward , |mtd| mtd. total_msat ) ;
8991 if outgoing_amount < trampoline_amount {
90- return Err ( LocalHTLCFailureReason :: FinalIncorrectHTLCAmount ) ;
92+ let mut err_data = Vec :: new ( ) ;
93+ outgoing_amount. write ( & mut err_data) . unwrap ( ) ;
94+ return Err ( ( LocalHTLCFailureReason :: FinalIncorrectHTLCAmount , err_data) ) ;
9195 }
9296
9397 Ok ( ( ) )
@@ -155,17 +159,8 @@ pub(super) fn create_fwd_pending_htlc_info(
155159 err_data : Vec :: new ( ) ,
156160 } ) ,
157161 onion_utils:: Hop :: TrampolineForward { ref outer_hop_data, next_trampoline_hop_data, next_trampoline_hop_hmac, new_trampoline_packet_bytes, trampoline_shared_secret, .. } => {
158- check_trampoline_onion_constraints ( outer_hop_data, next_trampoline_hop_data. outgoing_cltv_value , next_trampoline_hop_data. amt_to_forward ) . map_err ( |reason| {
159- let mut err_data = Vec :: new ( ) ;
160- match reason {
161- LocalHTLCFailureReason :: FinalIncorrectCLTVExpiry => {
162- outer_hop_data. outgoing_cltv_value . write ( & mut err_data) . unwrap ( ) ;
163- }
164- LocalHTLCFailureReason :: FinalIncorrectHTLCAmount => {
165- outer_hop_data. amt_to_forward . write ( & mut err_data) . unwrap ( ) ;
166- }
167- _ => unreachable ! ( )
168- }
162+ check_trampoline_onion_constraints ( outer_hop_data, next_trampoline_hop_data. outgoing_cltv_value , next_trampoline_hop_data. amt_to_forward ) . map_err ( |( reason, err_data) | {
163+ //TODO: return reason as forward issue, not as receiving issue.
169164 // The Trampoline onion's amt and CLTV values cannot exceed the outer onion's
170165 InboundHTLCErr {
171166 reason,
@@ -333,17 +328,7 @@ pub(super) fn create_recv_pending_htlc_info(
333328 cltv_expiry_height, payment_metadata, ..
334329 } , ..
335330 } => {
336- check_trampoline_onion_constraints ( outer_hop_data, cltv_expiry_height, sender_intended_htlc_amt_msat) . map_err ( |reason| {
337- let mut err_data = Vec :: new ( ) ;
338- match reason {
339- LocalHTLCFailureReason :: FinalIncorrectCLTVExpiry => {
340- outer_hop_data. outgoing_cltv_value . write ( & mut err_data) . unwrap ( ) ;
341- }
342- LocalHTLCFailureReason :: FinalIncorrectHTLCAmount => {
343- outer_hop_data. amt_to_forward . write ( & mut err_data) . unwrap ( ) ;
344- }
345- _ => unreachable ! ( )
346- }
331+ check_trampoline_onion_constraints ( outer_hop_data, cltv_expiry_height, sender_intended_htlc_amt_msat) . map_err ( |( reason, err_data) | {
347332 // The Trampoline onion's amt and CLTV values cannot exceed the outer onion's
348333 InboundHTLCErr {
349334 reason,
0 commit comments