@@ -593,15 +593,52 @@ impl OutboundHTLCOutput {
593593 where
594594 L::Target: Logger,
595595 {
596+ mem::drop(self.state_wrapper.waiting_on_peer_span.take());
597+ mem::drop(self.state_wrapper.waiting_on_monitor_persist_span.take());
596598 mem::drop(self.state_wrapper.span.take());
597599 self.state_wrapper =
598600 OutboundHTLCStateWrapper::new(state, self.span.as_user_span_ref::<L>(), logger);
599601 }
602+
603+ fn waiting_on_peer<L: Deref>(&mut self, logger: &L)
604+ where
605+ L::Target: Logger,
606+ {
607+ self.state_wrapper.waiting_on_peer_span = Some(BoxedSpan::new(logger.start(
608+ Span::WaitingOnPeer,
609+ self.state_wrapper.span.as_ref().map(|s| s.as_user_span_ref::<L>()).flatten(),
610+ )));
611+ }
612+
613+ fn peer_responded(&mut self) {
614+ if self.state_wrapper.waiting_on_peer_span.is_some() {
615+ mem::drop(self.state_wrapper.waiting_on_peer_span.take());
616+ }
617+ }
618+
619+ fn waiting_on_monitor_persist<L: Deref>(&mut self, logger: &L)
620+ where
621+ L::Target: Logger,
622+ {
623+ self.state_wrapper.waiting_on_monitor_persist_span = Some(BoxedSpan::new(logger.start(
624+ Span::WaitingOnMonitorPersist,
625+ self.state_wrapper.span.as_ref().map(|s| s.as_user_span_ref::<L>()).flatten(),
626+ )));
627+ }
628+
629+ fn monitor_persisted(&mut self) {
630+ if self.state_wrapper.waiting_on_monitor_persist_span.is_some() {
631+ mem::drop(self.state_wrapper.waiting_on_monitor_persist_span.take());
632+ }
633+ }
600634}
601635
602636#[cfg_attr(test, derive(Clone, Debug, PartialEq))]
603637struct OutboundHTLCStateWrapper {
604638 state: OutboundHTLCState,
639+ waiting_on_peer_span: Option<BoxedSpan>,
640+ waiting_on_monitor_persist_span: Option<BoxedSpan>,
641+ // Drop full span last.
605642 span: Option<BoxedSpan>,
606643}
607644
@@ -615,7 +652,12 @@ impl OutboundHTLCStateWrapper {
615652 {
616653 let state_span =
617654 logger.start(Span::OutboundHTLCState { state: (&state).into() }, parent_span);
618- OutboundHTLCStateWrapper { state, span: Some(BoxedSpan::new(state_span)) }
655+ OutboundHTLCStateWrapper {
656+ state,
657+ span: Some(BoxedSpan::new(state_span)),
658+ waiting_on_peer_span: None,
659+ waiting_on_monitor_persist_span: None,
660+ }
619661 }
620662}
621663
@@ -6866,6 +6908,7 @@ where
68666908 return Err(ChannelError::close(format!("Remote tried to fulfill/fail HTLC ({}) before it had been committed", htlc_id))),
68676909 OutboundHTLCState::Committed => {
68686910 htlc.set_state(OutboundHTLCState::RemoteRemoved(outcome), logger);
6911+ htlc.waiting_on_peer(logger);
68696912 },
68706913 OutboundHTLCState::AwaitingRemoteRevokeToRemove(_) | OutboundHTLCState::AwaitingRemovedRemoteRevoke(_) | OutboundHTLCState::RemoteRemoved(_) =>
68716914 return Err(ChannelError::close(format!("Remote tried to fulfill/fail HTLC ({}) that they'd already fulfilled/failed", htlc_id))),
@@ -7284,6 +7327,9 @@ where
72847327 claimed_htlcs.push((SentHTLCId::from_source(&htlc.source), preimage));
72857328 }
72867329 htlc.set_state(OutboundHTLCState::AwaitingRemoteRevokeToRemove(reason), logger);
7330+ if self.context.channel_state.is_awaiting_remote_revoke() {
7331+ htlc.waiting_on_peer(logger);
7332+ }
72877333 need_commitment = true;
72887334 }
72897335 }
@@ -7849,6 +7895,7 @@ where
78497895 let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None);
78507896 mem::swap(outcome, &mut reason);
78517897 htlc.set_state(OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason), logger);
7898+ htlc.waiting_on_monitor_persist(logger);
78527899 require_commitment = true;
78537900 }
78547901 }
@@ -8288,6 +8335,16 @@ where
82888335 _ => {},
82898336 }
82908337 }
8338+ for htlc in self.context.pending_outbound_htlcs.iter_mut() {
8339+ match htlc.state() {
8340+ OutboundHTLCState::LocalAnnounced(_) |
8341+ OutboundHTLCState::AwaitingRemovedRemoteRevoke(_) => {
8342+ htlc.monitor_persisted();
8343+ htlc.waiting_on_peer(logger);
8344+ },
8345+ _ => {},
8346+ }
8347+ }
82918348
82928349 // If we're past (or at) the AwaitingChannelReady stage on an outbound (or V2-established) channel,
82938350 // try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
@@ -10964,7 +11021,7 @@ where
1096411021 // that are simple to implement, and we do it on the outgoing side because then the failure message that encodes
1096511022 // the hold time still needs to be built in channel manager.
1096611023 let send_timestamp = duration_since_epoch();
10967- self.context.pending_outbound_htlcs.push( OutboundHTLCOutput::new(
11024+ let mut htlc = OutboundHTLCOutput::new(
1096811025 self.context.channel_id(),
1096911026 OutboundHTLCOutputParams {
1097011027 htlc_id: self.context.next_holder_htlc_id,
@@ -10979,7 +11036,9 @@ where
1097911036 },
1098011037 forward_span,
1098111038 logger,
10982- ));
11039+ );
11040+ htlc.waiting_on_monitor_persist(logger);
11041+ self.context.pending_outbound_htlcs.push(htlc);
1098311042 self.context.next_holder_htlc_id += 1;
1098411043
1098511044 Ok(true)
@@ -11029,6 +11088,7 @@ where
1102911088 let mut reason = OutboundHTLCOutcome::Success(PaymentPreimage([0u8; 32]), None);
1103011089 mem::swap(outcome, &mut reason);
1103111090 htlc.set_state(OutboundHTLCState::AwaitingRemovedRemoteRevoke(reason), logger);
11091+ htlc.waiting_on_monitor_persist(logger);
1103211092 }
1103311093 }
1103411094 if let Some((feerate, update_state)) = self.context.pending_update_fee {
0 commit comments