v0.3.12-pre.007

This commit is contained in:
2026-09-09 16:21:23 +02:00
parent 07b9b20eb5
commit ba69a5ad20
13 changed files with 1037 additions and 105 deletions

View File

@@ -1,8 +1,9 @@
// file: crates/ksp-worker-raw-transaction-ingest-lib/src/runtime.rs
// version: 9
// version: 10
type PersistencePort = std::sync::Arc<dyn crate::RawTransactionIngestPersistencePort + 'static>;
type PersistenceTasks = tokio::task::JoinSet<ksp_core_lib::Result<crate::RawTransactionIngestPersistenceOutcome>>;
type ProcessingFrontierReceiver = tokio::sync::watch::Receiver<crate::RawTransactionIngestProcessingFrontierProjection>;
type SourceTasks = tokio::task::JoinSet<ksp_core_lib::Result<()>>;
/// Runtime-neutral boxed future resolving after one RAW transaction ingest Worker has fully reached a terminal lifecycle state.
@@ -115,11 +116,20 @@ impl crate::RawTransactionIngestWorker {
}
let source = runtime_resources.into_yellowstone_source();
let source_settings = settings.clone();
return start_foundation_with_source_spawner(settings, runtime, std::option::Option::Some(store), move |children, stop_receiver, admission_sender| {
let _abort_handle = children.spawn(async move {
return source.run(source_settings, stop_receiver, admission_sender).await;
});
});
let (processing_frontier_sender, processing_frontier_receiver) =
tokio::sync::watch::channel(crate::RawTransactionIngestProcessingFrontierProjection::empty());
let port: PersistencePort = store;
return start_foundation_with_port_source_spawner_and_frontier(
settings,
runtime,
std::option::Option::Some(port),
std::option::Option::Some(processing_frontier_receiver),
move |children, stop_receiver, admission_sender| {
let _abort_handle = children.spawn(async move {
return source.run(source_settings, stop_receiver, admission_sender, processing_frontier_sender).await;
});
},
);
}
}
@@ -179,6 +189,7 @@ async fn drain_admission_and_persistence(
persistence: &mut PersistenceTasks,
port: &std::option::Option<PersistencePort>,
snapshots: &mut crate::RawTransactionIngestSnapshotPublisher,
processing_frontier_receiver: &mut std::option::Option<ProcessingFrontierReceiver>,
) -> std::option::Option<ksp_core_lib::ErrorCode> {
let mut fault = std::option::Option::None;
admission.close();
@@ -344,6 +355,7 @@ async fn run_supervisor<Spawner>(
port: std::option::Option<PersistencePort>,
mut stop_receiver: tokio::sync::watch::Receiver<bool>,
mut snapshots: crate::RawTransactionIngestSnapshotPublisher,
mut processing_frontier_receiver: std::option::Option<ProcessingFrontierReceiver>,
source_spawner: Spawner,
) where
Spawner:
@@ -380,6 +392,7 @@ async fn run_supervisor<Spawner>(
&mut persistence,
&port,
&mut snapshots,
&mut processing_frontier_receiver,
)
.await;
source_stop_sender.send_replace(true);
@@ -431,6 +444,26 @@ fn start_foundation_with_port_and_source_spawner<Spawner>(
port: std::option::Option<PersistencePort>,
source_spawner: Spawner,
) -> ksp_core_lib::Result<crate::RawTransactionIngestHandle>
where
Spawner:
FnOnce(&mut SourceTasks, tokio::sync::watch::Receiver<bool>, tokio::sync::mpsc::Sender<crate::RawTransactionIngress>) + std::marker::Send + 'static,
{
return start_foundation_with_port_source_spawner_and_frontier(
settings,
runtime,
port,
std::option::Option::None,
source_spawner,
);
}
fn start_foundation_with_port_source_spawner_and_frontier<Spawner>(
settings: crate::RawTransactionIngestSettings,
runtime: tokio::runtime::Handle,
port: std::option::Option<PersistencePort>,
processing_frontier_receiver: std::option::Option<ProcessingFrontierReceiver>,
source_spawner: Spawner,
) -> ksp_core_lib::Result<crate::RawTransactionIngestHandle>
where
Spawner:
FnOnce(&mut SourceTasks, tokio::sync::watch::Receiver<bool>, tokio::sync::mpsc::Sender<crate::RawTransactionIngress>) + std::marker::Send + 'static,
@@ -447,7 +480,15 @@ where
let (stop_sender, stop_receiver) = tokio::sync::watch::channel(false);
let (snapshots, snapshot_source) = crate::RawTransactionIngestSnapshotPublisher::new(&settings, &lifecycle);
let handle = crate::RawTransactionIngestHandle { snapshots: snapshot_source, stop_sender, stop_token };
std::mem::drop(runtime.spawn(run_supervisor(settings, lifecycle, port, stop_receiver, snapshots, source_spawner)));
std::mem::drop(runtime.spawn(run_supervisor(
settings,
lifecycle,
port,
stop_receiver,
snapshots,
processing_frontier_receiver,
source_spawner,
)));
return std::result::Result::Ok(handle);
}
@@ -504,6 +545,25 @@ async fn supervise_until_stop(
break;
}
}
processing_frontier = wait_processing_frontier(processing_frontier_receiver) => {
match processing_frontier {
std::option::Option::Some(projection) => {
let published = snapshots.record_processing_frontier(
lifecycle.state(),
admission.queue_depth(),
persistence.len(),
projection,
);
if let std::result::Result::Err(error) = published {
source_stop_sender.send_replace(true);
return std::option::Option::Some(error.code());
}
},
std::option::Option::None => {
*processing_frontier_receiver = std::option::Option::None;
},
}
}
joined = children.join_next(), if !children.is_empty() => {
let source_fault = match joined {
std::option::Option::Some(value) => source_completion(value, lifecycle.state(), admission.queue_depth(), persistence.len(), snapshots),
@@ -571,6 +631,21 @@ async fn supervise_until_stop(
return std::option::Option::None;
}
async fn wait_processing_frontier(
receiver: &mut std::option::Option<ProcessingFrontierReceiver>,
) -> std::option::Option<crate::RawTransactionIngestProcessingFrontierProjection> {
let receiver = match receiver.as_mut() {
std::option::Option::Some(value) => value,
std::option::Option::None => {
return std::future::pending::<std::option::Option<crate::RawTransactionIngestProcessingFrontierProjection>>().await;
},
};
if receiver.changed().await.is_err() {
return std::option::Option::None;
}
return std::option::Option::Some(*receiver.borrow_and_update());
}
fn validate_store_network(settings: &crate::RawTransactionIngestSettings, store_network: &ksp_store_lib::RawNetworkId) -> ksp_core_lib::Result<()> {
if settings.network() != store_network {
return std::result::Result::Err(crate::runtime_error("start.store_network_mismatch"));