@@ -46,6 +46,7 @@ use io;
46
46
use prelude:: * ;
47
47
use core:: { cmp, mem, fmt} ;
48
48
use core:: ops:: Deref ;
49
+ use std:: io:: Error ;
49
50
#[ cfg( any( test, fuzzing, debug_assertions) ) ]
50
51
use sync:: Mutex ;
51
52
use bitcoin:: hashes:: hex:: ToHex ;
@@ -799,6 +800,36 @@ impl fmt::Debug for ChannelError {
799
800
}
800
801
}
801
802
803
+ /// Used to return destination of where we are forwarding our HTLC to.
804
+ #[ derive( Clone , Debug ) ]
805
+ pub enum HTLCDestination {
806
+ OpenChannel { node_id : PublicKey , channel_id : [ u8 ; 32 ] } ,
807
+ Unknown { previous_hop_scid : u64 } ,
808
+ Payment { payment_hash : PaymentHash , payment_preimage : Option < PaymentPreimage > } ,
809
+ }
810
+
811
+ impl Writeable for HTLCDestination {
812
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , Error > {
813
+ match self {
814
+ HTLCDestination :: OpenChannel { ref node_id, ref channel_id } => {
815
+ 0u8 . write ( writer) ?;
816
+ node_id. write ( writer) ?;
817
+ channel_id. write ( writer) ?;
818
+ } ,
819
+ HTLCDestination :: Unknown { ref previous_hop_scid } => {
820
+ 1u8 . write ( writer) ?;
821
+ previous_hop_scid. write ( writer) ?;
822
+ } ,
823
+ HTLCDestination :: Payment { ref payment_hash, ref payment_preimage } => {
824
+ 2u8 . write ( writer) ?;
825
+ payment_hash. write ( writer) ?;
826
+ payment_preimage. write ( writer) ?;
827
+ }
828
+ }
829
+ Ok ( ( ) )
830
+ }
831
+ }
832
+
802
833
macro_rules! secp_check {
803
834
( $res: expr, $err: expr) => {
804
835
match $res {
@@ -5577,7 +5608,7 @@ impl<Signer: Sign> Channel<Signer> {
5577
5608
/// those explicitly stated to be allowed after shutdown completes, eg some simple getters).
5578
5609
/// Also returns the list of payment_hashes for channels which we can safely fail backwards
5579
5610
/// immediately (others we will have to allow to time out).
5580
- pub fn force_shutdown ( & mut self , should_broadcast : bool ) -> ( Option < ( OutPoint , ChannelMonitorUpdate ) > , Vec < ( HTLCSource , PaymentHash , PublicKey ) > ) {
5611
+ pub fn force_shutdown ( & mut self , should_broadcast : bool ) -> ( Option < ( OutPoint , ChannelMonitorUpdate ) > , Vec < ( HTLCSource , PaymentHash , HTLCDestination ) > ) {
5581
5612
// Note that we MUST only generate a monitor update that indicates force-closure - we're
5582
5613
// called during initialization prior to the chain_monitor in the encompassing ChannelManager
5583
5614
// being fully configured in some cases. Thus, its likely any monitor events we generate will
@@ -5591,7 +5622,7 @@ impl<Signer: Sign> Channel<Signer> {
5591
5622
for htlc_update in self . holding_cell_htlc_updates . drain ( ..) {
5592
5623
match htlc_update {
5593
5624
HTLCUpdateAwaitingACK :: AddHTLC { source, payment_hash, .. } => {
5594
- dropped_outbound_htlcs. push ( ( source, payment_hash, counterparty_node_id) ) ;
5625
+ dropped_outbound_htlcs. push ( ( source, payment_hash, HTLCDestination :: OpenChannel { node_id : counterparty_node_id, channel_id : self . channel_id } ) ) ;
5595
5626
} ,
5596
5627
_ => { }
5597
5628
}
0 commit comments