Skip to main content

NodeLifecycle

Trait NodeLifecycle 

Source
pub trait NodeLifecycle:
    Send
    + Sync
    + 'static {
    const NAME: Option<&'static str> = None;

    // Required methods
    fn pre_start<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ctx: &'life1 StartContext<'life2>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn on_start<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ctx: &'life1 StartContext<'life2>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn run<'life0, 'async_trait>(
        &'life0 self,
        ctx: RunContext,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn on_stop<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ctx: &'life1 StopContext<'life2>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn post_stop<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ctx: &'life1 StopContext<'life2>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

The business-logic core of a service.

Implementors own all in-memory state (stores, pools, caches) and expose it through the five lifecycle hooks. See crate-level docs for ordering.

§Associated constants

  • NAME — an optional static identifier surfaced via ServiceHandle::name and used in tracing spans. Set to Some("validator") etc.

Provided Associated Constants§

Source

const NAME: Option<&'static str> = None

Optional static name. Used in logs; may be None.

Required Methods§

Source

fn pre_start<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 StartContext<'life2>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called before peer / RPC servers bind. Typical work: open stores, replay journal, restore state.

Source

fn on_start<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 StartContext<'life2>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called after peer / RPC servers bind but before run begins. Typical work: announce capabilities, warm caches.

Source

fn run<'life0, 'async_trait>( &'life0 self, ctx: RunContext, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Main run loop. Returns on:

  • ctx.shutdown.cancelled() firing (graceful), OR
  • a fatal internal error (Err).
Source

fn on_stop<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 StopContext<'life2>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called after run returns. Typical work: flush stores, write snapshots. Errors here are reported but do not stop post_stop from also running.

Source

fn post_stop<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 StopContext<'life2>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Final hook. Typical work: close stores, release file locks.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§