agglayer_types/
network_info.rs

1use agglayer_interop_types::aggchain_proof;
2use agglayer_primitives::Digest;
3use agglayer_tries::roots::LocalExitRoot;
4use serde::{Deserialize, Serialize};
5
6use crate::{CertificateId, CertificateStatus, CertificateStatusError, Height, NetworkId};
7
8/// The status of a network.
9/// TODO: implement more detailed status tracking including
10/// separate service that would monitor status of the network.
11#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
12pub enum NetworkStatus {
13    /// Unknown status.
14    Unknown = 0,
15    /// The network is active and functioning normally.
16    Active = 1,
17    /// The network is currently syncing.
18    Syncing = 2,
19    /// The network is experiencing an error.
20    Error = 3,
21    /// The network is disabled.
22    Disabled = 4,
23}
24
25#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
26pub enum DisabledBy {
27    /// Default value, should not be used.
28    Unknown = 0,
29    /// The network was disabled by an admin.
30    Admin = 1,
31}
32
33// The aggchain type of network
34#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
35pub enum NetworkType {
36    Unspecified = 0,
37    /// ECDSA-based network type.
38    Ecdsa = 1,
39    /// Generic network type.
40    Generic = 2,
41    /// Multisig-only network type.
42    MultisigOnly = 3,
43    /// Multisig and aggchain proof network type.
44    MultisigAndAggchainProof = 4,
45}
46
47impl From<&aggchain_proof::AggchainData> for NetworkType {
48    fn from(value: &aggchain_proof::AggchainData) -> Self {
49        match value {
50            aggchain_proof::AggchainData::ECDSA { .. } => NetworkType::Ecdsa,
51            aggchain_proof::AggchainData::Generic { .. } => NetworkType::Generic,
52            aggchain_proof::AggchainData::MultisigOnly { .. } => NetworkType::MultisigOnly,
53            aggchain_proof::AggchainData::MultisigAndAggchainProof { .. } => {
54                NetworkType::MultisigAndAggchainProof
55            }
56        }
57    }
58}
59
60#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
61pub struct SettledClaim {
62    /// Global index, indicating uniquely which tree leaf is claimed.
63    pub global_index: Digest,
64    /// / Hash of the claimed imported bridge exit.
65    pub bridge_exit_hash: Digest,
66}
67
68#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
69pub struct NetworkInfo {
70    /// The current status of the network (e.g., "active", "syncing", "error").
71    pub network_status: NetworkStatus,
72    /// The aggchain type of a network
73    pub network_type: NetworkType,
74    /// The unique identifier for this network.
75    pub network_id: NetworkId,
76    /// The height of the latest settled certificate.
77    pub settled_height: Option<Height>,
78    /// The ID of the latest settled certificate.
79    pub settled_certificate_id: Option<CertificateId>,
80    /// The pessimistic proof root of the latest settled certificate.
81    pub settled_pp_root: Option<Digest>,
82    /// The local exit root of the latest settled certificate.
83    pub settled_ler: Option<LocalExitRoot>,
84    /// The leaf count of the latest settled local exit tree.
85    pub settled_let_leaf_count: Option<u64>,
86    /// Info about the latest settled claim in the network.
87    pub settled_claim: Option<SettledClaim>,
88    /// The height of the latest pending certificate.
89    pub latest_pending_height: Option<Height>,
90    /// The status of the latest pending certificate.
91    pub latest_pending_status: Option<CertificateStatus>,
92    /// Any error message associated with the latest pending certificate.
93    pub latest_pending_error: Option<CertificateStatusError>,
94    /// The epoch number of the latest settlement.
95    pub latest_epoch_with_settlement: Option<u64>,
96}
97
98impl NetworkInfo {
99    pub const fn from_network_id(network_id: NetworkId) -> Self {
100        Self {
101            network_status: NetworkStatus::Unknown,
102            network_type: NetworkType::Unspecified,
103            network_id,
104            settled_height: None,
105            settled_certificate_id: None,
106            settled_pp_root: None,
107            settled_ler: None,
108            settled_let_leaf_count: None,
109            settled_claim: None,
110            latest_pending_height: None,
111            latest_pending_status: None,
112            latest_pending_error: None,
113            latest_epoch_with_settlement: None,
114        }
115    }
116}