Skip to content

Commit

Permalink
Do not expose RemoteAnnounced state to users
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanlint committed Feb 1, 2024
1 parent 8884077 commit 98df707
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ enum InboundHTLCState {
/// This can be used to inspect what next message an HTLC is waiting for to advance its state.
#[derive(Clone, Debug, PartialEq)]
pub enum InboundHTLCStateDetails {
/// The remote node announced the HTLC with update_add_htlc but the HTLC is not added to any
/// commitment transactions yet.
RemoteAnnounced,
/// We have added this HTLC in our commitment transaction by receiving commitment_signed and
/// returning revoke_and_ack. We are awaiting the appropriate revoke_and_ack's from the remote
/// before this HTLC is included on the remote commitment transaction.
Expand All @@ -200,33 +197,31 @@ pub enum InboundHTLCStateDetails {
AwaitingRemoteRevokeToRemoveFail,
}

impl From<&InboundHTLCState> for InboundHTLCStateDetails {
fn from(state: &InboundHTLCState) -> InboundHTLCStateDetails {
impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
fn from(state: &InboundHTLCState) -> Option<InboundHTLCStateDetails> {
match state {
InboundHTLCState::RemoteAnnounced(_) =>
InboundHTLCStateDetails::RemoteAnnounced,
InboundHTLCState::RemoteAnnounced(_) => None,
InboundHTLCState::AwaitingRemoteRevokeToAnnounce(_) =>
InboundHTLCStateDetails::AwaitingRemoteRevokeToAdd,
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToAdd),
InboundHTLCState::AwaitingAnnouncedRemoteRevoke(_) =>
InboundHTLCStateDetails::AwaitingRemoteRevokeToAdd,
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToAdd),
InboundHTLCState::Committed =>
InboundHTLCStateDetails::Committed,
Some(InboundHTLCStateDetails::Committed),
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(_)) =>
InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail,
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(_)) =>
InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail,
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) =>
InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill,
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill),
}
}
}

impl_writeable_tlv_based_enum!(InboundHTLCStateDetails,
(0, RemoteAnnounced) => {},
(2, AwaitingRemoteRevokeToAdd) => {},
(4, Committed) => {},
(6, AwaitingRemoteRevokeToRemoveFulfill) => {},
(8, AwaitingRemoteRevokeToRemoveFail) => {};
(0, AwaitingRemoteRevokeToAdd) => {},
(2, Committed) => {},
(4, AwaitingRemoteRevokeToRemoveFulfill) => {},
(6, AwaitingRemoteRevokeToRemoveFail) => {};
);

struct InboundHTLCOutput {
Expand Down Expand Up @@ -2219,14 +2214,16 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
};
let holder_dust_limit_success_sat = htlc_success_dust_limit + self.holder_dust_limit_satoshis;
for htlc in self.pending_inbound_htlcs.iter() {
inbound_details.push(InboundHTLCDetails{
htlc_id: htlc.htlc_id,
amount_msat: htlc.amount_msat,
cltv_expiry: htlc.cltv_expiry,
payment_hash: htlc.payment_hash,
state: holding_cell_states.remove(&htlc.htlc_id).unwrap_or((&htlc.state).into()),
is_dust: htlc.amount_msat / 1000 < holder_dust_limit_success_sat,
});
if let Some(state_details) = (&htlc.state).into() {
inbound_details.push(InboundHTLCDetails{
htlc_id: htlc.htlc_id,
amount_msat: htlc.amount_msat,
cltv_expiry: htlc.cltv_expiry,
payment_hash: htlc.payment_hash,
state: holding_cell_states.remove(&htlc.htlc_id).unwrap_or(state_details),
is_dust: htlc.amount_msat / 1000 < holder_dust_limit_success_sat,
});
}
}
inbound_details
}
Expand Down

0 comments on commit 98df707

Please sign in to comment.