pub struct GradientSyncService { /* private fields */ }Expand description
gRPC-style service that streams gradient chunks to clients as they arrive from peers.
The service wraps a BlockStore so that concurrent sync sessions can
safely share the same block store without requiring access to the full
Node type (which lives in the ipfrs crate and cannot be referenced
from ipfrs-interface without a circular dependency).
§Usage
use ipfrs_interface::gradient_sync::{GradientSyncRequest, GradientSyncService};
use ipfrs_storage::{BlockStoreConfig, SledBlockStore};
use ipfrs_tensorlogic::gradient::arrow_ipc::store_gradient_as_arrow;
use std::sync::Arc;
let config = BlockStoreConfig { path: std::env::temp_dir().join("grad"), cache_size: 64 * 1024 * 1024 };
let store = Arc::new(SledBlockStore::new(config)?);
let service = GradientSyncService::new(store);
let gradient: Vec<f32> = (0u32..256).map(|i| i as f32 * 0.01).collect();
let local_gradient = store_gradient_as_arrow(&gradient)?;
let request = GradientSyncRequest {
session_id: "round-1".to_string(),
local_gradient,
min_peers: 0,
timeout_secs: 30,
};
let (tx, mut rx) = tokio::sync::mpsc::channel(64);
service.sync_gradients(request, tx).await?;
while let Some(chunk) = rx.recv().await {
println!("received chunk {}/{}", chunk.chunk_index + 1, chunk.total_chunks);
}Implementations§
Source§impl GradientSyncService
impl GradientSyncService
Sourcepub fn new(store: Arc<dyn BlockStore>) -> Self
pub fn new(store: Arc<dyn BlockStore>) -> Self
Create a new service backed by store.
Sourcepub async fn sync_gradients(
&self,
request: GradientSyncRequest,
chunk_tx: Sender<GradientChunkResponse>,
) -> Result<()>
pub async fn sync_gradients( &self, request: GradientSyncRequest, chunk_tx: Sender<GradientChunkResponse>, ) -> Result<()>
Start a gradient sync session and stream chunks via chunk_tx.
§Workflow
- Decode
request.local_gradientfrom Arrow IPC. - Commit the local gradient to the block store via
DistributedGradientAccumulator::commit_local. - Poll for peer gradients (stubbed — no live network in this layer).
- Push one
GradientChunkResponseper local chunk ontochunk_txso that the caller can observe streaming behaviour end-to-end.
When full peer-to-peer transport is wired up at the ipfrs crate
level, step 3 would await actual peer CIDs from the GossipSub
GRADIENT_SYNC event loop.
Auto Trait Implementations§
impl !RefUnwindSafe for GradientSyncService
impl !UnwindSafe for GradientSyncService
impl Freeze for GradientSyncService
impl Send for GradientSyncService
impl Sync for GradientSyncService
impl Unpin for GradientSyncService
impl UnsafeUnpin for GradientSyncService
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.