use liminal_protocol::wire::{MarkerSettlementBackpressure, ServerValue};
use super::{InstalledParticipantService, ParticipantSemanticError};
pub const MARKER_SETTLED_FOLLOWS_EVERY_SETTLEMENT_REFUSAL: bool = true;
impl InstalledParticipantService {
pub(super) fn settle_refused_marker(
&self,
value: &ServerValue,
) -> Result<(), ParticipantSemanticError> {
let ServerValue::MarkerSettlementBackpressure(refusal) = value else {
return Ok(());
};
let (conversation_id, refused_epoch) = match *refusal {
MarkerSettlementBackpressure::CredentialAttach {
conversation_id,
refused_epoch,
}
| MarkerSettlementBackpressure::Detach {
conversation_id,
refused_epoch,
} => (conversation_id, refused_epoch),
};
let (result, impact) = self
.handler
.drain_candidate_lane_with_impact(conversation_id)
.into_parts();
self.notify_impact(&impact)?;
if result.is_ok() {
self.fire_settlements(conversation_id, &[refused_epoch])?;
}
if let Err(error) = result {
tracing::warn!(
conversation_id,
%error,
"a marker-settlement refusal could not drain its conversation's lane; the \
refusal stands and its wake waits for the next drain"
);
}
Ok(())
}
#[cfg(test)]
pub(in crate::server::participant) fn settle_refused_marker_for_test(
&self,
value: &ServerValue,
) -> Result<(), ParticipantSemanticError> {
self.settle_refused_marker(value)
}
}