v0.3.12-pre.009
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-worker-raw-transaction-ingest-lib/src/runtime_resources.rs
|
||||
// version: 11
|
||||
// version: 12
|
||||
|
||||
use sha2::Digest; // rust-rules: trait-import
|
||||
|
||||
@@ -472,7 +472,7 @@ impl crate::RawTransactionIngestYellowstoneSource {
|
||||
}
|
||||
}
|
||||
}
|
||||
coordinator.abort_all().await;
|
||||
coordinator.abort_all(&mut processing_frontier).await;
|
||||
processing_frontier.set_source_state(crate::RawTransactionIngestSourceState::Closing);
|
||||
let closed = session.close().await;
|
||||
if let std::option::Option::Some(error) = fault {
|
||||
@@ -850,22 +850,36 @@ impl RawTransactionIngestProcessingFrontier {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::result::Result::Err(crate::runtime_error("source.frontier_pending_counter_exhausted")),
|
||||
};
|
||||
let state = self.slots.entry(slot).or_insert(RawTransactionIngestProcessingSlotState { pending: 0, settled: 0 });
|
||||
state.pending = match state.pending.checked_add(1) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::result::Result::Err(crate::runtime_error("source.frontier_slot_pending_counter_exhausted")),
|
||||
};
|
||||
match self.slots.entry(slot) {
|
||||
std::collections::btree_map::Entry::Occupied(mut entry) => {
|
||||
let pending = match entry.get().pending.checked_add(1) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::result::Result::Err(crate::runtime_error("source.frontier_slot_pending_counter_exhausted")),
|
||||
};
|
||||
entry.get_mut().pending = pending;
|
||||
},
|
||||
std::collections::btree_map::Entry::Vacant(entry) => {
|
||||
entry.insert(RawTransactionIngestProcessingSlotState { pending: 1, settled: 0 });
|
||||
},
|
||||
}
|
||||
self.pending_total = pending_total;
|
||||
self.compact();
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
|
||||
fn observe_settled(&mut self, slot: u64) -> ksp_core_lib::Result<()> {
|
||||
let state = self.slots.entry(slot).or_insert(RawTransactionIngestProcessingSlotState { pending: 0, settled: 0 });
|
||||
state.settled = match state.settled.checked_add(1) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::result::Result::Err(crate::runtime_error("source.frontier_slot_settled_counter_exhausted")),
|
||||
};
|
||||
match self.slots.entry(slot) {
|
||||
std::collections::btree_map::Entry::Occupied(mut entry) => {
|
||||
let settled = match entry.get().settled.checked_add(1) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::result::Result::Err(crate::runtime_error("source.frontier_slot_settled_counter_exhausted")),
|
||||
};
|
||||
entry.get_mut().settled = settled;
|
||||
},
|
||||
std::collections::btree_map::Entry::Vacant(entry) => {
|
||||
entry.insert(RawTransactionIngestProcessingSlotState { pending: 0, settled: 1 });
|
||||
},
|
||||
}
|
||||
self.compact();
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
@@ -878,16 +892,26 @@ impl RawTransactionIngestProcessingFrontier {
|
||||
if state.pending == 0 || self.pending_total == 0 {
|
||||
return std::result::Result::Err(crate::runtime_error("source.frontier_pending_counter_invalid"));
|
||||
}
|
||||
state.pending -= 1;
|
||||
self.pending_total -= 1;
|
||||
state.settled = match state.settled.checked_add(1) {
|
||||
let settled = match state.settled.checked_add(1) {
|
||||
std::option::Option::Some(value) => value,
|
||||
std::option::Option::None => return std::result::Result::Err(crate::runtime_error("source.frontier_slot_settled_counter_exhausted")),
|
||||
};
|
||||
state.pending -= 1;
|
||||
self.pending_total -= 1;
|
||||
state.settled = settled;
|
||||
self.compact();
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
|
||||
fn discard_all_pending(&mut self) {
|
||||
self.pending_total = 0;
|
||||
self.slots.retain(|_slot, state| {
|
||||
return state.pending == 0 && state.settled > 0;
|
||||
});
|
||||
self.compact();
|
||||
return;
|
||||
}
|
||||
|
||||
fn projection(&self) -> crate::RawTransactionIngestProcessingFrontierProjection {
|
||||
let oldest_pending_slot = self.slots.iter().find_map(|(slot, state)| {
|
||||
if state.pending == 0 {
|
||||
@@ -1006,6 +1030,12 @@ impl RawTransactionIngestProcessingFrontierReporter {
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
|
||||
fn discard_all_pending(&mut self) {
|
||||
self.frontier.discard_all_pending();
|
||||
self.publish();
|
||||
return;
|
||||
}
|
||||
|
||||
fn observe_session_snapshot(&mut self, snapshot: ksp_onchain_transport_lib::YellowstoneGrpcSubscribeSnapshot) -> ksp_core_lib::Result<()> {
|
||||
return self.observe_source_continuity(
|
||||
map_yellowstone_source_state(snapshot.state()),
|
||||
@@ -1240,11 +1270,12 @@ impl RawTransactionIngestHydrationCoordinator {
|
||||
return std::result::Result::Ok(true);
|
||||
}
|
||||
|
||||
async fn abort_all(&mut self) {
|
||||
async fn abort_all(&mut self, processing_frontier: &mut RawTransactionIngestProcessingFrontierReporter) {
|
||||
self.tasks.abort_all();
|
||||
while self.tasks.join_next().await.is_some() {}
|
||||
self.pending.clear();
|
||||
self.pending_signal_count = 0;
|
||||
processing_frontier.discard_all_pending();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user