rialo-types 0.1.0

Rialo Types
Documentation
// Copyright (c) Subzero Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::collections::{BTreeMap, HashMap};

use serde::{Deserialize, Serialize};

use crate::{OracleDutyConfig, OracleId, OracleUpdateResult};

/// Raw 32-byte public key for an authority (a set of validator nodes).
/// Used to identify which authority submitted a particular update.
pub type ProtocolKeyBytes = [u8; 32];

/// Map structure for tracking oracle duties and their execution status.
///
/// The map is keyed by `OracleDutiesMapKey`.
///
/// The value is `OracleDutiesMapValue` which tracks validator assignments and their update results.
///
/// This structure enables efficient tracking of oracle duties ordered by round priority,
/// with the most recent rounds processed first.
pub type OracleDutiesMap = BTreeMap<OracleDutiesMapKey, OracleDutiesMapValue>;

/// Key type for the oracle duties map, consisting of a proposal round and oracle identifier and retries made.
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct OracleDutiesMapKey {
    pub proposal_round: u64,
    pub oracle_id: OracleId,
}

/// Value type for the oracle duties map, tracking validator assignments and their update results.
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct OracleDutiesMapValue {
    /// This is a `HashMap` where:
    /// - Key (`ProtocolKeyBytes`): The validator's 32-byte protocol public key
    /// - Value (`Option<OracleUpdateResult>`): The result of the validator's oracle update,
    ///   where `None` indicates the duty is still pending and `Some(result)` indicates completion
    pub updates: HashMap<ProtocolKeyBytes, Option<OracleUpdateResult>>,

    /// The configuration parameters that define how this oracle duty is scheduled and finalized,
    /// including request delay, collection window size, and commitment buffer.
    pub config: OracleDutyConfig,

    /// Which retry attempt this duty is on.
    /// The value is zero for the first attempt and gets increasing with each attempt.
    pub retries_made: u32,
}