Skip to main content

thruput_operator/
operator.rs

1// Generated by xdrc 0.18.0 (xdrs d7777c37264da66eb41f8139bd539c4aa049fcc5). Do not edit.
2
3// A read-only program every daemon can serve so thruput-ctl can ask what it is
4// and where it stands.  This file imports no other .x file.
5
6#![allow(non_camel_case_types)]
7#![allow(non_snake_case)]
8#![allow(non_upper_case_globals)]
9#![allow(unused_imports)]
10#![allow(dead_code)]
11#![allow(unused_variables)]
12#![allow(clippy::unnecessary_cast)]
13use crate::*;
14use core::ops::{Deref, DerefMut};
15use core::option::Option;
16#[cfg(feature = "std")]
17use std::io::{Read, Write};
18use xdrs::*;
19#[cfg(feature = "serde")]
20use ::serde::{Deserialize, Serialize};
21
22// always used optionally: absent, never short
23pub type OperatorHash = [u8; 32];
24
25pub type OperatorShortText = StringM<32>;
26
27pub type OperatorText = StringM<64>;
28
29pub type OperatorDetail = StringM<256>;
30
31// Closed by design: a new value needs a new program version.  A client that
32// sees a value it doesn't know reports it as an error.
33#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
34#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
35#[cfg_attr(feature = "serde", serde(transparent))]
36#[derive(schemars::JsonSchema)]
37#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
38#[derive(Copy)]
39#[repr(transparent)]
40pub struct OperatorReadiness(pub i32);
41
42impl OperatorReadiness {
43    // not yet able to serve its role
44    pub const OPERATOR_STARTING: Self = Self(0);
45    pub const OPERATOR_READY: Self = Self(1);
46    // was ready and is not (see detail); unused by coordinators in Operator1
47    pub const OPERATOR_NOT_READY: Self = Self(2);
48}
49
50impl From<i32> for OperatorReadiness {
51    fn from(v: i32) -> Self {
52        Self(v)
53    }
54}
55
56impl xdrs::XDRDiscriminant for OperatorReadiness {
57    const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
58    fn discriminant(&self) -> i32 {
59        self.0
60    }
61    fn from_discriminant(d: i32) -> Self {
62        Self(d)
63    }
64}
65
66#[cfg(feature = "std")]
67impl core::fmt::Display for OperatorReadiness {
68    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
69        match self.0 {
70            x if x == Self::OPERATOR_STARTING.0 => {
71                f.write_str("OperatorReadiness::OPERATOR_STARTING")
72            }
73            x if x == Self::OPERATOR_READY.0 => {
74                f.write_str("OperatorReadiness::OPERATOR_READY")
75            }
76            x if x == Self::OPERATOR_NOT_READY.0 => {
77                f.write_str("OperatorReadiness::OPERATOR_NOT_READY")
78            }
79            _ => write!(f, "OperatorReadiness({})", self.0),
80        }
81    }
82}
83
84// A height this process reports.  Names are lowercase snake_case ASCII.
85// A daemon may report names a client does not know; the client ignores them.
86//
87// Known names:
88//   decided    Highest height consensus has decided: the higher of committed
89//              and the highest externalized.
90//   committed  Highest height committed, as this process sees it.
91// Later daemons add their own names with no version bump.
92#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
93#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
94#[derive(schemars::JsonSchema)]
95#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
96#[repr(C)]
97pub struct OperatorPosition {
98    pub name: OperatorText,
99    // >= 0
100    // The block at that height, when known.  This is the same hash as the one
101    // derived from the ConsensusValue at that height, so values compare across
102    // sources.
103    pub height: i64,
104    pub block_hash: Option<OperatorHash>,
105}
106
107#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
108#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
109#[derive(schemars::JsonSchema)]
110#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
111#[repr(C)]
112pub struct OperatorStatus {
113    // What part the process plays, not which implementation it is:
114    // "coordinator", "scheduler", "db", ...  thruput-ctl checks it, so an
115    // endpoint that points at the wrong daemon is caught.
116    pub role: OperatorShortText,
117    // "chuckd", "coordinator", "hog-scheduler", ...
118    pub process_name: OperatorText,
119    // component release version
120    pub build_version: OperatorText,
121    // source commit of this build
122    pub build_commit: OperatorText,
123    // "hogp/..." (20 bytes); provenance only
124    pub protocol_token: OperatorShortText,
125    // absent until the daemon knows it
126    pub network_hash: Option<OperatorHash>,
127    pub readiness: OperatorReadiness,
128    pub readiness_detail: OperatorDetail,
129    pub positions: VecM<OperatorPosition, 64>,
130}
131
132/// Each handler replies with anything that encodes like the reply type.
133/// Implementations can be plain `async fn`s returning a concrete reply type
134/// under `#[allow(refining_impl_trait)]`.
135#[allow(non_camel_case_types)]
136pub trait Operator_Operator1: Send + Sync {
137    fn operator_null(
138        &self,
139    ) -> impl ::core::future::Future<
140        Output = Result<impl xdrs::EncodesAs<()>, ::thruput_rpc_api::ProgramError>,
141    > + Send;
142    fn operator_status(
143        &self,
144    ) -> impl ::core::future::Future<
145        Output = Result<
146            impl xdrs::EncodesAs<OperatorStatus>,
147            ::thruput_rpc_api::ProgramError,
148        >,
149    > + Send;
150}
151
152#[allow(non_camel_case_types)]
153pub struct Operator_Operator1_Dispatcher<__Handler> {
154    inner: Box<__Handler>,
155}
156
157impl<__Handler: Operator_Operator1> Operator_Operator1_Dispatcher<__Handler> {
158    pub fn new(inner: Box<__Handler>) -> Self {
159        Self { inner }
160    }
161}
162
163#[async_trait::async_trait]
164impl<__Handler: Operator_Operator1> ::thruput_rpc_api::RpcHandler
165for Operator_Operator1_Dispatcher<__Handler> {
166    fn prog_vers(&self) -> ::thruput_rpc_api::ProgVers {
167        ::thruput_rpc_api::ProgVers::new(0x20000000, 1)
168    }
169    async fn dispatch(
170        &self,
171        proc: u32,
172        data: &[u8],
173    ) -> Result<Vec<u8>, ::thruput_rpc_api::RpcError> {
174        match proc {
175            // operator_null
176            0 => {
177                let args: () = xdrs::txs::decode(data)
178                    .map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
179                let res = self
180                    .inner
181                    .operator_null()
182                    .await
183                    .map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
184                xdrs::txs::encode(&res)
185                    .map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
186            }
187            // operator_status
188            1 => {
189                let args: () = xdrs::txs::decode(data)
190                    .map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
191                let res = self
192                    .inner
193                    .operator_status()
194                    .await
195                    .map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
196                xdrs::txs::encode(&res)
197                    .map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
198            }
199            _ => Err(::thruput_rpc_api::RpcError::InvalidProcedure),
200        }
201    }
202}
203
204#[derive(Clone)]
205pub struct Operator_Operator1_Client {
206    handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>,
207}
208
209impl Operator_Operator1_Client {
210    pub fn new(handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>) -> Self {
211        Self { handle }
212    }
213    fn prog_vers() -> ::thruput_rpc_api::ProgVers {
214        ::thruput_rpc_api::ProgVers::new(0x20000000, 1)
215    }
216    // SAFETY: the call future is awaited within this method, so it lives in
217    // this method's future along with `out` and `decode`. Once that is
218    // polled it is pinned, so neither can be freed without the call future
219    // being dropped first. Decoding never blocks.
220    pub async fn operator_null(&self) -> Result<(), ::thruput_rpc_api::RpcError> {
221        let mut call = self.handle.call_buf();
222        call.append_with(|buf| {
223                let mut w = xdrs::txs::buf_writer::BufWriter::from(
224                    ::core::mem::take(buf),
225                );
226                let r = xdrs::write_xdr(&(), &mut w);
227                *buf = w.into();
228                r
229            })
230            .map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
231        let mut out = ::core::option::Option::None;
232        let mut decode = |
233            reply: &[u8],
234        | -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
235            out = ::core::option::Option::Some(
236                xdrs::txs::decode(reply)
237                    .map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?,
238            );
239            Ok(())
240        };
241        unsafe { self.handle.send_call_decoded(Self::prog_vers(), 0, call, &mut decode) }
242            .await?;
243        out.ok_or(::thruput_rpc_api::RpcError::SystemError)
244    }
245    // SAFETY: the call future is awaited within this method, so it lives in
246    // this method's future along with `out` and `decode`. Once that is
247    // polled it is pinned, so neither can be freed without the call future
248    // being dropped first. Decoding never blocks.
249    pub async fn operator_status(
250        &self,
251    ) -> Result<OperatorStatus, ::thruput_rpc_api::RpcError> {
252        let mut call = self.handle.call_buf();
253        call.append_with(|buf| {
254                let mut w = xdrs::txs::buf_writer::BufWriter::from(
255                    ::core::mem::take(buf),
256                );
257                let r = xdrs::write_xdr(&(), &mut w);
258                *buf = w.into();
259                r
260            })
261            .map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
262        let mut out = ::core::option::Option::None;
263        let mut decode = |
264            reply: &[u8],
265        | -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
266            out = ::core::option::Option::Some(
267                xdrs::txs::decode(reply)
268                    .map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?,
269            );
270            Ok(())
271        };
272        unsafe { self.handle.send_call_decoded(Self::prog_vers(), 1, call, &mut decode) }
273            .await?;
274        out.ok_or(::thruput_rpc_api::RpcError::SystemError)
275    }
276}
277
278impl From<::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>>
279for Operator_Operator1_Client {
280    fn from(handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>) -> Self {
281        Self::new(handle)
282    }
283}