@@ -493,7 +493,7 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
493
493
/// after reloading from disk while replaying blocks against ChannelMonitors.
494
494
///
495
495
/// Locked *after* channel_state.
496
- pending_outbound_payments : Mutex < HashSet < [ u8 ; 32 ] > > ,
496
+ pending_outbound_payments : Mutex < HashSet < ( [ u8 ; 32 ] , Option < MppId > ) > > ,
497
497
498
498
our_network_key : SecretKey ,
499
499
our_network_pubkey : PublicKey ,
@@ -1854,7 +1854,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1854
1854
let onion_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, prng_seed, payment_hash) ;
1855
1855
1856
1856
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
1857
- assert ! ( self . pending_outbound_payments. lock( ) . unwrap( ) . insert( session_priv_bytes) ) ;
1857
+ assert ! ( self . pending_outbound_payments. lock( ) . unwrap( ) . insert( ( session_priv_bytes, mpp_id ) ) ) ;
1858
1858
1859
1859
let err: Result < ( ) , _ > = loop {
1860
1860
let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
@@ -2835,11 +2835,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2835
2835
self . fail_htlc_backwards_internal ( channel_state,
2836
2836
htlc_src, & payment_hash, HTLCFailReason :: Reason { failure_code, data : onion_failure_data} ) ;
2837
2837
} ,
2838
- HTLCSource :: OutboundRoute { session_priv, .. } => {
2838
+ HTLCSource :: OutboundRoute { session_priv, mpp_id , .. } => {
2839
2839
if {
2840
2840
let mut session_priv_bytes = [ 0 ; 32 ] ;
2841
2841
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
2842
- self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & session_priv_bytes)
2842
+ self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & ( session_priv_bytes, mpp_id ) )
2843
2843
} {
2844
2844
self . pending_events . lock ( ) . unwrap ( ) . push (
2845
2845
events:: Event :: PaymentFailed {
@@ -2875,11 +2875,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2875
2875
// from block_connected which may run during initialization prior to the chain_monitor
2876
2876
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
2877
2877
match source {
2878
- HTLCSource :: OutboundRoute { ref path, session_priv, .. } => {
2878
+ HTLCSource :: OutboundRoute { ref path, session_priv, mpp_id , .. } => {
2879
2879
if {
2880
2880
let mut session_priv_bytes = [ 0 ; 32 ] ;
2881
2881
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
2882
- !self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & session_priv_bytes)
2882
+ !self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & ( session_priv_bytes, mpp_id ) )
2883
2883
} {
2884
2884
log_trace ! ( self . logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
2885
2885
return ;
@@ -3126,12 +3126,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3126
3126
3127
3127
fn claim_funds_internal ( & self , mut channel_state_lock : MutexGuard < ChannelHolder < Signer > > , source : HTLCSource , payment_preimage : PaymentPreimage , forwarded_htlc_value_msat : Option < u64 > , from_onchain : bool ) {
3128
3128
match source {
3129
- HTLCSource :: OutboundRoute { session_priv, .. } => {
3129
+ HTLCSource :: OutboundRoute { session_priv, mpp_id , .. } => {
3130
3130
mem:: drop ( channel_state_lock) ;
3131
3131
if {
3132
3132
let mut session_priv_bytes = [ 0 ; 32 ] ;
3133
3133
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
3134
- self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & session_priv_bytes)
3134
+ self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & ( session_priv_bytes, mpp_id ) )
3135
3135
} {
3136
3136
let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
3137
3137
pending_events. push ( events:: Event :: PaymentSent {
@@ -5068,11 +5068,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
5068
5068
5069
5069
let pending_outbound_payments = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
5070
5070
( pending_outbound_payments. len ( ) as u64 ) . write ( writer) ?;
5071
- for session_priv in pending_outbound_payments. iter ( ) {
5071
+ let mut pending_outbound_mpp_ids = Vec :: new ( ) ;
5072
+ for ( session_priv, mpp_id) in pending_outbound_payments. iter ( ) {
5072
5073
session_priv. write ( writer) ?;
5074
+ pending_outbound_mpp_ids. push ( mpp_id) ;
5073
5075
}
5074
5076
5075
- write_tlv_fields ! ( writer, { } ) ;
5077
+ write_tlv_fields ! ( writer, {
5078
+ ( 0 , pending_outbound_mpp_ids, vec_type) ,
5079
+ } ) ;
5076
5080
5077
5081
Ok ( ( ) )
5078
5082
}
@@ -5326,14 +5330,39 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
5326
5330
}
5327
5331
5328
5332
let pending_outbound_payments_count: u64 = Readable :: read ( reader) ?;
5329
- let mut pending_outbound_payments: HashSet < [ u8 ; 32 ] > = HashSet :: with_capacity ( cmp:: min ( pending_outbound_payments_count as usize , MAX_ALLOC_SIZE /32 ) ) ;
5333
+ let mut pending_outbound_payments: HashSet < ( [ u8 ; 32 ] , Option < MppId > ) > = HashSet :: with_capacity ( cmp:: min ( pending_outbound_payments_count as usize , MAX_ALLOC_SIZE /32 ) ) ;
5334
+ let mut pending_outbound_session_privs = Vec :: new ( ) ;
5335
+
5330
5336
for _ in 0 ..pending_outbound_payments_count {
5331
- if !pending_outbound_payments. insert ( Readable :: read ( reader) ?) {
5332
- return Err ( DecodeError :: InvalidValue ) ;
5333
- }
5337
+ pending_outbound_session_privs. push ( Readable :: read ( reader) ?) ;
5334
5338
}
5335
5339
5336
- read_tlv_fields ! ( reader, { } ) ;
5340
+ let mut pending_outbound_mpp_ids_opt = Some ( Vec :: new ( ) ) ;
5341
+ read_tlv_fields ! ( reader, {
5342
+ ( 0 , pending_outbound_mpp_ids_opt, vec_type) ,
5343
+ } ) ;
5344
+
5345
+ let pending_outbound_mpp_ids = match pending_outbound_mpp_ids_opt {
5346
+ Some ( outbounds) => outbounds,
5347
+ None => Vec :: new ( )
5348
+ } ;
5349
+
5350
+ if pending_outbound_mpp_ids. len ( ) == pending_outbound_session_privs. len ( ) {
5351
+ for ( session_priv, mpp_id) in pending_outbound_session_privs. iter ( ) . zip (
5352
+ pending_outbound_mpp_ids. iter ( ) ) {
5353
+ if !pending_outbound_payments. insert ( ( * session_priv, * mpp_id) ) {
5354
+ return Err ( DecodeError :: InvalidValue )
5355
+ }
5356
+ }
5357
+ } else if pending_outbound_mpp_ids. len ( ) == 0 {
5358
+ for session_priv in pending_outbound_session_privs. iter ( ) {
5359
+ if !pending_outbound_payments. insert ( ( * session_priv, None ) ) {
5360
+ return Err ( DecodeError :: InvalidValue ) ;
5361
+ }
5362
+ }
5363
+ } else {
5364
+ return Err ( DecodeError :: InvalidValue ) ;
5365
+ }
5337
5366
5338
5367
let mut secp_ctx = Secp256k1 :: new ( ) ;
5339
5368
secp_ctx. seeded_randomize ( & args. keys_manager . get_secure_random_bytes ( ) ) ;
@@ -5577,7 +5606,7 @@ mod tests {
5577
5606
expect_payment_failed ! ( nodes[ 0 ] , our_payment_hash, true ) ;
5578
5607
5579
5608
// Send the second half of the original MPP payment.
5580
- nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id , & None ) . unwrap ( ) ;
5609
+ nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, mpp_id , & None ) . unwrap ( ) ;
5581
5610
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
5582
5611
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
5583
5612
assert_eq ! ( events. len( ) , 1 ) ;
0 commit comments