@@ -490,7 +490,7 @@ pub struct ChannelManager<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref,
490
490
/// after reloading from disk while replaying blocks against ChannelMonitors.
491
491
///
492
492
/// Locked *after* channel_state.
493
- pending_outbound_payments : Mutex < HashSet < [ u8 ; 32 ] > > ,
493
+ pending_outbound_payments : Mutex < HashSet < ( [ u8 ; 32 ] , Option < MppId > ) > > ,
494
494
495
495
our_network_key : SecretKey ,
496
496
our_network_pubkey : PublicKey ,
@@ -1807,7 +1807,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1807
1807
let onion_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, prng_seed, payment_hash) ;
1808
1808
1809
1809
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
1810
- assert ! ( self . pending_outbound_payments. lock( ) . unwrap( ) . insert( session_priv_bytes) ) ;
1810
+ assert ! ( self . pending_outbound_payments. lock( ) . unwrap( ) . insert( ( session_priv_bytes, mpp_id ) ) ) ;
1811
1811
1812
1812
let err: Result < ( ) , _ > = loop {
1813
1813
let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
@@ -2676,11 +2676,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2676
2676
self . fail_htlc_backwards_internal ( channel_state,
2677
2677
htlc_src, & payment_hash, HTLCFailReason :: Reason { failure_code, data : onion_failure_data} ) ;
2678
2678
} ,
2679
- HTLCSource :: OutboundRoute { session_priv, .. } => {
2679
+ HTLCSource :: OutboundRoute { session_priv, mpp_id , .. } => {
2680
2680
if {
2681
2681
let mut session_priv_bytes = [ 0 ; 32 ] ;
2682
2682
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
2683
- self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & session_priv_bytes)
2683
+ self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & ( session_priv_bytes, mpp_id ) )
2684
2684
} {
2685
2685
self . pending_events . lock ( ) . unwrap ( ) . push (
2686
2686
events:: Event :: PaymentFailed {
@@ -2716,11 +2716,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2716
2716
// from block_connected which may run during initialization prior to the chain_monitor
2717
2717
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
2718
2718
match source {
2719
- HTLCSource :: OutboundRoute { ref path, session_priv, .. } => {
2719
+ HTLCSource :: OutboundRoute { ref path, session_priv, mpp_id , .. } => {
2720
2720
if {
2721
2721
let mut session_priv_bytes = [ 0 ; 32 ] ;
2722
2722
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
2723
- !self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & session_priv_bytes)
2723
+ !self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & ( session_priv_bytes, mpp_id ) )
2724
2724
} {
2725
2725
log_trace ! ( self . logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
2726
2726
return ;
@@ -2967,12 +2967,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2967
2967
2968
2968
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 ) {
2969
2969
match source {
2970
- HTLCSource :: OutboundRoute { session_priv, .. } => {
2970
+ HTLCSource :: OutboundRoute { session_priv, mpp_id , .. } => {
2971
2971
mem:: drop ( channel_state_lock) ;
2972
2972
if {
2973
2973
let mut session_priv_bytes = [ 0 ; 32 ] ;
2974
2974
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
2975
- self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & session_priv_bytes)
2975
+ self . pending_outbound_payments . lock ( ) . unwrap ( ) . remove ( & ( session_priv_bytes, mpp_id ) )
2976
2976
} {
2977
2977
let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
2978
2978
pending_events. push ( events:: Event :: PaymentSent {
@@ -4919,11 +4919,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> Writeable f
4919
4919
4920
4920
let pending_outbound_payments = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
4921
4921
( pending_outbound_payments. len ( ) as u64 ) . write ( writer) ?;
4922
- for session_priv in pending_outbound_payments. iter ( ) {
4922
+ let mut pending_outbound_mpp_ids = Vec :: new ( ) ;
4923
+ for ( session_priv, mpp_id) in pending_outbound_payments. iter ( ) {
4923
4924
session_priv. write ( writer) ?;
4925
+ pending_outbound_mpp_ids. push ( mpp_id) ;
4924
4926
}
4925
4927
4926
- write_tlv_fields ! ( writer, { } ) ;
4928
+ write_tlv_fields ! ( writer, {
4929
+ // (0, pending_outbound_mpp_ids, vec_type),
4930
+ } ) ;
4927
4931
4928
4932
Ok ( ( ) )
4929
4933
}
@@ -5177,14 +5181,35 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
5177
5181
}
5178
5182
5179
5183
let pending_outbound_payments_count: u64 = Readable :: read ( reader) ?;
5180
- let mut pending_outbound_payments: HashSet < [ u8 ; 32 ] > = HashSet :: with_capacity ( cmp:: min ( pending_outbound_payments_count as usize , MAX_ALLOC_SIZE /32 ) ) ;
5184
+ 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 ) ) ;
5185
+ let mut pending_outbound_session_privs = Vec :: new ( ) ;
5186
+
5181
5187
for _ in 0 ..pending_outbound_payments_count {
5182
- if !pending_outbound_payments. insert ( Readable :: read ( reader) ?) {
5183
- return Err ( DecodeError :: InvalidValue ) ;
5184
- }
5188
+ pending_outbound_session_privs. push ( Readable :: read ( reader) ?) ;
5185
5189
}
5186
5190
5187
- read_tlv_fields ! ( reader, { } ) ;
5191
+ let mut pending_outbound_mpp_ids = Vec :: new ( ) ;
5192
+ read_tlv_fields ! ( reader, {
5193
+ // TODO: how to make this line work
5194
+ // (0, pending_outbound_mpp_ids, vec_type),
5195
+ } ) ;
5196
+
5197
+ if pending_outbound_mpp_ids. len ( ) == pending_outbound_session_privs. len ( ) {
5198
+ for ( session_priv, mpp_id) in pending_outbound_session_privs. iter ( ) . zip (
5199
+ pending_outbound_mpp_ids. iter ( ) ) {
5200
+ if !pending_outbound_payments. insert ( ( * session_priv, * mpp_id) ) {
5201
+ return Err ( DecodeError :: InvalidValue )
5202
+ }
5203
+ }
5204
+ } else if pending_outbound_mpp_ids. len ( ) == 0 {
5205
+ for session_priv in pending_outbound_session_privs. iter ( ) {
5206
+ if !pending_outbound_payments. insert ( ( * session_priv, None ) ) {
5207
+ return Err ( DecodeError :: InvalidValue ) ;
5208
+ }
5209
+ }
5210
+ } else {
5211
+ return Err ( DecodeError :: InvalidValue ) ;
5212
+ }
5188
5213
5189
5214
let mut secp_ctx = Secp256k1 :: new ( ) ;
5190
5215
secp_ctx. seeded_randomize ( & args. keys_manager . get_secure_random_bytes ( ) ) ;
@@ -5428,7 +5453,7 @@ mod tests {
5428
5453
expect_payment_failed ! ( nodes[ 0 ] , our_payment_hash, true ) ;
5429
5454
5430
5455
// Send the second half of the original MPP payment.
5431
- nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id , & None ) . unwrap ( ) ;
5456
+ nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, mpp_id , & None ) . unwrap ( ) ;
5432
5457
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
5433
5458
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
5434
5459
assert_eq ! ( events. len( ) , 1 ) ;
0 commit comments