Skip to content

Commit 0c07c76

Browse files
committed
Introduce HTLCDestination enum
1 parent eac86fa commit 0c07c76

File tree

3 files changed

+86
-43
lines changed

3 files changed

+86
-43
lines changed

lightning/src/ln/channel.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use io;
4646
use prelude::*;
4747
use core::{cmp,mem,fmt};
4848
use core::ops::Deref;
49+
use std::io::Error;
4950
#[cfg(any(test, fuzzing, debug_assertions))]
5051
use sync::Mutex;
5152
use bitcoin::hashes::hex::ToHex;
@@ -799,6 +800,36 @@ impl fmt::Debug for ChannelError {
799800
}
800801
}
801802

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+
802833
macro_rules! secp_check {
803834
($res: expr, $err: expr) => {
804835
match $res {
@@ -5577,7 +5608,7 @@ impl<Signer: Sign> Channel<Signer> {
55775608
/// those explicitly stated to be allowed after shutdown completes, eg some simple getters).
55785609
/// Also returns the list of payment_hashes for channels which we can safely fail backwards
55795610
/// 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)>) {
55815612
// Note that we MUST only generate a monitor update that indicates force-closure - we're
55825613
// called during initialization prior to the chain_monitor in the encompassing ChannelManager
55835614
// being fully configured in some cases. Thus, its likely any monitor events we generate will
@@ -5591,7 +5622,7 @@ impl<Signer: Sign> Channel<Signer> {
55915622
for htlc_update in self.holding_cell_htlc_updates.drain(..) {
55925623
match htlc_update {
55935624
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 }));
55955626
},
55965627
_ => {}
55975628
}

0 commit comments

Comments
 (0)