@@ -71,6 +71,7 @@ use core::ops::Deref;
71
71
72
72
#[ cfg( any( test, feature = "std" ) ) ]
73
73
use std:: time:: Instant ;
74
+ use std:: any:: Any ;
74
75
use util:: crypto:: sign;
75
76
76
77
// We hold various information about HTLC relay in the HTLC objects in Channel itself:
@@ -3015,22 +3016,18 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3015
3016
} }
3016
3017
}
3017
3018
3018
- macro_rules! add_update_add_htlc {
3019
- ( $add_htlc_msg : expr, $channel_id: expr, $counterparty_node_id: expr) => { {
3019
+ macro_rules! add_update_htlc_msg {
3020
+ ( $htlc_msg : expr, $channel_id: expr, $counterparty_node_id: expr) => { {
3020
3021
add_channel_key!( $channel_id, $counterparty_node_id) ;
3021
3022
if let hash_map:: Entry :: Occupied ( mut entry) = htlcs_msgs_by_id. entry( $channel_id) {
3022
3023
let msgs_entry = entry. get_mut( ) ;
3023
- msgs_entry. 0 . push( $add_htlc_msg) ;
3024
- }
3025
- } }
3026
- }
3027
-
3028
- macro_rules! add_update_fail_htlc {
3029
- ( $fail_htlc_msg: expr, $channel_id: expr, $counterparty_node_id: expr) => { {
3030
- add_channel_key!( $channel_id, $counterparty_node_id) ;
3031
- if let hash_map:: Entry :: Occupied ( mut entry) = htlcs_msgs_by_id. entry( $channel_id) {
3032
- let msgs_entry = entry. get_mut( ) ;
3033
- msgs_entry. 1 . push( $fail_htlc_msg) ;
3024
+ if let Some ( msg) = ( & $htlc_msg as & Any ) . downcast_ref:: <msgs:: UpdateAddHTLC >( ) {
3025
+ msgs_entry. 0 . push( msg. clone( ) ) ;
3026
+ } else if let Some ( msg) = ( & $htlc_msg as & Any ) . downcast_ref:: <msgs:: UpdateFailHTLC >( ) {
3027
+ msgs_entry. 1 . push( msg. clone( ) ) ;
3028
+ } else {
3029
+ panic!( "Only UpdateAddHTLC or UpdateFailHTLC msgs supported for add_update_htlc_msg" ) ;
3030
+ }
3034
3031
}
3035
3032
} }
3036
3033
}
@@ -3154,7 +3151,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3154
3151
match update_add {
3155
3152
Some ( msg) => {
3156
3153
log_info ! ( self . logger, "Will forward HTLC with payment_hash {}, over channel {}" , log_bytes!( payment_hash. 0 ) , log_bytes!( chan_id) ) ;
3157
- add_update_add_htlc ! ( msg, chan_id, counterparty_node_id) ;
3154
+ add_update_htlc_msg ! ( msg, chan_id, counterparty_node_id) ;
3158
3155
} ,
3159
3156
None => {
3160
3157
// Nothing to do here...we're waiting on a remote
@@ -3197,7 +3194,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3197
3194
// the chain and sending the HTLC-Timeout is their problem.
3198
3195
continue ;
3199
3196
} ,
3200
- Ok ( Some ( msg) ) => { add_update_fail_htlc ! ( msg, forward_chan_id, counterparty_node_id) ; } ,
3197
+ Ok ( Some ( msg) ) => { add_update_htlc_msg ! ( msg, forward_chan_id, counterparty_node_id) ; } ,
3201
3198
Ok ( None ) => {
3202
3199
// Nothing to do here...we're waiting on a remote
3203
3200
// revoke_and_ack before we can update the commitment
0 commit comments