Skip to content

Commit 98df707

Browse files
committed
Do not expose RemoteAnnounced state to users
1 parent 8884077 commit 98df707

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

lightning/src/ln/channel.rs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ enum InboundHTLCState {
173173
/// This can be used to inspect what next message an HTLC is waiting for to advance its state.
174174
#[derive(Clone, Debug, PartialEq)]
175175
pub enum InboundHTLCStateDetails {
176-
/// The remote node announced the HTLC with update_add_htlc but the HTLC is not added to any
177-
/// commitment transactions yet.
178-
RemoteAnnounced,
179176
/// We have added this HTLC in our commitment transaction by receiving commitment_signed and
180177
/// returning revoke_and_ack. We are awaiting the appropriate revoke_and_ack's from the remote
181178
/// before this HTLC is included on the remote commitment transaction.
@@ -200,33 +197,31 @@ pub enum InboundHTLCStateDetails {
200197
AwaitingRemoteRevokeToRemoveFail,
201198
}
202199

203-
impl From<&InboundHTLCState> for InboundHTLCStateDetails {
204-
fn from(state: &InboundHTLCState) -> InboundHTLCStateDetails {
200+
impl From<&InboundHTLCState> for Option<InboundHTLCStateDetails> {
201+
fn from(state: &InboundHTLCState) -> Option<InboundHTLCStateDetails> {
205202
match state {
206-
InboundHTLCState::RemoteAnnounced(_) =>
207-
InboundHTLCStateDetails::RemoteAnnounced,
203+
InboundHTLCState::RemoteAnnounced(_) => None,
208204
InboundHTLCState::AwaitingRemoteRevokeToAnnounce(_) =>
209-
InboundHTLCStateDetails::AwaitingRemoteRevokeToAdd,
205+
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToAdd),
210206
InboundHTLCState::AwaitingAnnouncedRemoteRevoke(_) =>
211-
InboundHTLCStateDetails::AwaitingRemoteRevokeToAdd,
207+
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToAdd),
212208
InboundHTLCState::Committed =>
213-
InboundHTLCStateDetails::Committed,
209+
Some(InboundHTLCStateDetails::Committed),
214210
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailRelay(_)) =>
215-
InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail,
211+
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
216212
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::FailMalformed(_)) =>
217-
InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail,
213+
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFail),
218214
InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) =>
219-
InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill,
215+
Some(InboundHTLCStateDetails::AwaitingRemoteRevokeToRemoveFulfill),
220216
}
221217
}
222218
}
223219

224220
impl_writeable_tlv_based_enum!(InboundHTLCStateDetails,
225-
(0, RemoteAnnounced) => {},
226-
(2, AwaitingRemoteRevokeToAdd) => {},
227-
(4, Committed) => {},
228-
(6, AwaitingRemoteRevokeToRemoveFulfill) => {},
229-
(8, AwaitingRemoteRevokeToRemoveFail) => {};
221+
(0, AwaitingRemoteRevokeToAdd) => {},
222+
(2, Committed) => {},
223+
(4, AwaitingRemoteRevokeToRemoveFulfill) => {},
224+
(6, AwaitingRemoteRevokeToRemoveFail) => {};
230225
);
231226

232227
struct InboundHTLCOutput {
@@ -2219,14 +2214,16 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
22192214
};
22202215
let holder_dust_limit_success_sat = htlc_success_dust_limit + self.holder_dust_limit_satoshis;
22212216
for htlc in self.pending_inbound_htlcs.iter() {
2222-
inbound_details.push(InboundHTLCDetails{
2223-
htlc_id: htlc.htlc_id,
2224-
amount_msat: htlc.amount_msat,
2225-
cltv_expiry: htlc.cltv_expiry,
2226-
payment_hash: htlc.payment_hash,
2227-
state: holding_cell_states.remove(&htlc.htlc_id).unwrap_or((&htlc.state).into()),
2228-
is_dust: htlc.amount_msat / 1000 < holder_dust_limit_success_sat,
2229-
});
2217+
if let Some(state_details) = (&htlc.state).into() {
2218+
inbound_details.push(InboundHTLCDetails{
2219+
htlc_id: htlc.htlc_id,
2220+
amount_msat: htlc.amount_msat,
2221+
cltv_expiry: htlc.cltv_expiry,
2222+
payment_hash: htlc.payment_hash,
2223+
state: holding_cell_states.remove(&htlc.htlc_id).unwrap_or(state_details),
2224+
is_dust: htlc.amount_msat / 1000 < holder_dust_limit_success_sat,
2225+
});
2226+
}
22302227
}
22312228
inbound_details
22322229
}

0 commit comments

Comments
 (0)