@@ -78,16 +78,20 @@ fn check_blinded_forward(
78
78
fn check_trampoline_onion_constraints (
79
79
outer_hop_data : & msgs:: InboundTrampolineEntrypointPayload , trampoline_cltv_value : u32 ,
80
80
trampoline_amount : u64 ,
81
- ) -> Result < ( ) , LocalHTLCFailureReason > {
81
+ ) -> Result < ( ) , ( LocalHTLCFailureReason , Vec < u8 > ) > {
82
82
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) ) ;
84
86
}
85
87
let outgoing_amount = outer_hop_data
86
88
. multipath_trampoline_data
87
89
. as_ref ( )
88
90
. map_or ( outer_hop_data. amt_to_forward , |mtd| mtd. total_msat ) ;
89
91
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) ) ;
91
95
}
92
96
93
97
Ok ( ( ) )
@@ -155,17 +159,8 @@ pub(super) fn create_fwd_pending_htlc_info(
155
159
err_data : Vec :: new ( ) ,
156
160
} ) ,
157
161
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.
169
164
// The Trampoline onion's amt and CLTV values cannot exceed the outer onion's
170
165
InboundHTLCErr {
171
166
reason,
@@ -333,17 +328,7 @@ pub(super) fn create_recv_pending_htlc_info(
333
328
cltv_expiry_height, payment_metadata, ..
334
329
} , ..
335
330
} => {
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) | {
347
332
// The Trampoline onion's amt and CLTV values cannot exceed the outer onion's
348
333
InboundHTLCErr {
349
334
reason,
0 commit comments