v0.3.11-pre.009
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-worker-raw-transaction-ingest-lib/src/admission.rs
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
use sha2::Digest; // rust-rules: trait-import
|
||||
|
||||
@@ -19,6 +19,8 @@ pub(crate) struct RawTransactionIngress {
|
||||
|
||||
/// Receiver side of the bounded central RAW transaction admission queue owned by the Worker supervisor.
|
||||
pub(crate) struct RawTransactionAdmission {
|
||||
backpressure_wait_observed: bool,
|
||||
capacity: usize,
|
||||
receiver: tokio::sync::mpsc::Receiver<crate::RawTransactionIngress>,
|
||||
}
|
||||
|
||||
@@ -27,7 +29,7 @@ impl crate::RawTransactionAdmission {
|
||||
#[must_use]
|
||||
pub(crate) fn new(capacity: usize) -> (crate::RawTransactionAdmission, tokio::sync::mpsc::Sender<crate::RawTransactionIngress>) {
|
||||
let (sender, receiver) = tokio::sync::mpsc::channel(capacity);
|
||||
return (Self { receiver }, sender);
|
||||
return (Self { backpressure_wait_observed: false, capacity, receiver }, sender);
|
||||
}
|
||||
|
||||
/// Returns the latest receiver-side queue depth without consuming an ingress entry.
|
||||
@@ -47,6 +49,7 @@ impl crate::RawTransactionAdmission {
|
||||
&mut self,
|
||||
expected_network: &ksp_store_lib::RawNetworkId,
|
||||
) -> ksp_core_lib::Result<std::option::Option<ksp_raw_transaction_lib::RawTransactionAcquisition>> {
|
||||
self.backpressure_wait_observed = self.receiver.len() == self.capacity;
|
||||
let ingress = match self.receiver.recv().await {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::result::Result::Ok(std::option::Option::None),
|
||||
@@ -57,6 +60,14 @@ impl crate::RawTransactionAdmission {
|
||||
std::result::Result::Err(error) => std::result::Result::Err(error),
|
||||
};
|
||||
}
|
||||
|
||||
/// Takes and clears the source-neutral signal that the previous dequeue observed the bounded queue at full capacity.
|
||||
#[must_use]
|
||||
pub(crate) fn take_backpressure_wait_observed(&mut self) -> bool {
|
||||
let observed = self.backpressure_wait_observed;
|
||||
self.backpressure_wait_observed = false;
|
||||
return observed;
|
||||
}
|
||||
}
|
||||
|
||||
fn canonicalize_ingress(
|
||||
|
||||
Reference in New Issue
Block a user