Skip to main content

EventSubscriber

Trait EventSubscriber 

Source
pub trait EventSubscriber<N: Network = Ethereum>: Send {
    // Required methods
    fn register_interests(
        &mut self,
        interests: &[ReactiveInterest<N>],
    ) -> SubscriberOperation<'_, ()>;
    fn next_batch(&mut self) -> SubscriberNextBatch<'_, N>;

    // Provided methods
    fn chain_id(&self) -> Option<u64> { ... }
    fn capabilities(&self) -> SubscriberCapabilities { ... }
    fn restore_position(
        &mut self,
        _position: &SubscriberResumePosition,
    ) -> Result<(), SubscriberError> { ... }
    fn acknowledge_delivery(
        &mut self,
        _token: SubscriberDeliveryToken,
    ) -> SubscriberOperation<'_, ()> { ... }
}
Expand description

Provider-agnostic subscriber interface.

Required Methods§

Source

fn register_interests( &mut self, interests: &[ReactiveInterest<N>], ) -> SubscriberOperation<'_, ()>

Replace all interests registered with the subscriber.

Implementations may use this as a full setup/reset operation. The in-crate AlloySubscriber clears owner-scoped interest state and delivery/dedupe bookkeeping when this method is called.

The returned operation must complete only after the replacement has committed to the subscriber’s desired state. Remote implementations can use this asynchronous boundary to wait for an authoritative service-side acknowledgement before returning Ok(()). On error, or when the future is dropped before completion, the previously committed desired state must remain authoritative (or be reconciled before later delivery can expose the uncommitted change) so callers can safely retry.

§Errors

The returned operation reports SubscriberError when the replacement cannot be validated or committed by the underlying source.

Source

fn next_batch(&mut self) -> SubscriberNextBatch<'_, N>

Return the next input batch, or Ok(None) when the stream is exhausted.

The returned future must be cancellation-safe: dropping it while pending must not discard a complete input that a later call could otherwise deliver. Composite subscribers use this property to race historical and live sources without dedicating a task to each transport.

§Errors

The returned future reports SubscriberError for transport, continuity, decoding, or source-resource failures.

Provided Methods§

Source

fn chain_id(&self) -> Option<u64>

Chain identity attached to emitted records, when it has been resolved.

Remote and provider-backed subscribers should cache one authoritative identity before exposing input. Returning None is reserved for synthetic or genuinely chain-agnostic subscribers; composite sources can use this hook to reject accidentally mixed networks.

Source

fn capabilities(&self) -> SubscriberCapabilities

Behaviors this subscriber can uphold for topology validation.

Source

fn restore_position( &mut self, _position: &SubscriberResumePosition, ) -> Result<(), SubscriberError>

Restore the subscriber’s committed position before polling resumes.

The engine invokes this synchronously from ReactiveEngine::resume_from_durable_checkpoint after decoding runtime recovery state and before publishing that state as resumed. Implementations should validate that provider/service cursors cannot regress and seed any source epoch or overlap history required for safe replay. A composite may rebuild an ephemeral live child from coverage_head plus historical reconciliation rather than require that child to replay bytes itself, but it may advertise SubscriberCapability::DurableReplay only when the complete restore closes that cutover gap before exposing live input. On error, either the prior position must remain authoritative, or the subscriber may retain this exact restore as pending intent; in the latter case it must block delivery and reject conflicting restores until retry/reconciliation commits the same position. This permits synchronous adapters over durable remote state without exposing a half-restored stream.

§Errors

Returns SubscriberError when the position is invalid, regresses or conflicts with committed source state, or cannot be restored durably.

Source

fn acknowledge_delivery( &mut self, _token: SubscriberDeliveryToken, ) -> SubscriberOperation<'_, ()>

Commit a subscriber-owned delivery token after runtime ingestion.

Ephemeral subscribers can rely on this no-op default. Durable remote subscribers should make acknowledgement idempotent because cancellation or transport failure can cause a successfully ingested batch to replay. Re-emitting a token must reproduce the same immutable records, routing, chain controls, chain identity, and provider checkpoint; the checkpointed engine verifies its persisted delivery witness before skipping ingestion.

§Errors

The returned operation reports SubscriberError when the delivery token cannot be committed idempotently by the source.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<P, N> EventSubscriber<N> for AlloySubscriber<P, N>
where P: Provider<N> + Send + Sync, N: Network + 'static, N::HeaderResponse: Send + 'static,