channels_sv2 8.0.0

Sv2 Channel Primitives
Documentation
//! Mining job construction - Mining Server Abstraction.
//!
//! This module provides submodules and traits for representing, constructing, and managing
//! Extended and Standard mining jobs in Stratum V2 (SV2) mining servers.
//!
//! ## Responsibilities
//!
//! - **Error Handling**: See [`error`] submodule for job-related error types.
//! - **Extended Jobs**: See [`extended`] submodule for SV2 extended job implementation.
//! - **Standard Jobs**: See [`standard`] submodule for SV2 standard job implementation.
//! - **Job Factories**: See [`factory`] for job creation logic and unique job ID assignment.
//! - **Job Storage**: Uses an internal store for server-side job lifecycle management.
//! - **Job Origin Tracking**: Tracks job origin (template or custom job message).
//! - **Job Trait**: Unified trait for all mining job types, supporting activation and job ID
//!   retrieval.
//!
//! ## Usage
//!
//! Use these abstractions for implementing mining server job management and SV2 protocol logic.

pub mod error;
pub mod extended;
pub mod factory;
pub(crate) mod job_store;
pub mod standard;

use mining_sv2::SetCustomMiningJobOwned;
use template_distribution_sv2::NewTemplateOwned;

#[derive(Clone, Debug, PartialEq)]
pub enum JobOrigin {
    NewTemplate(NewTemplateOwned),
    SetCustomMiningJob(SetCustomMiningJobOwned),
}

/// Trait for mining job types in SV2 mining servers.
///
/// Types implementing `Job` must provide a unique job ID and support activation upon chain tip
/// update.
pub trait Job: Send + Sync {
    /// Returns the unique job ID for this job.
    fn get_job_id(&self) -> u32;

    /// Returns the extranonce prefix bytes this job was created under.
    ///
    /// Used by the job store to keep a rotated-out extranonce prefix (and therefore its
    /// allocator slot) reserved for as long as any job created under it can still accept shares.
    fn get_extranonce_prefix(&self) -> &[u8];

    /// Activates the job for a new chain tip or prev_hash header timestamp.
    fn activate(&mut self, prev_hash_header_timestamp: u32);
}