Skip to main content

thruput_node_rpc/
sched_db.rs

1// -*-Rust-*-
2// Generated Code: DO NOT CHECK IN
3
4// Generated from xdrc commit: 6ab835b07c234abb4b0b50b61d687904727a4f32
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)]
13
14use crate::*;
15use core::option::Option;
16use core::ops::{Deref, DerefMut};
17
18#[cfg(feature = "std")]
19use std::io::{Read, Write};
20use xdrs::*;
21
22
23#[cfg(feature = "serde")]
24use ::serde::{{Serialize, Deserialize}};
25
26
27
28// ShardCard uniquely describes a database shard instance and its initial
29// state.
30#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
31#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
32#[derive(schemars::JsonSchema)]
33#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
34#[repr(C)]
35pub struct ShardCard {
36    pub protocol: ProtocolCommit,
37    pub upid: UPID,
38    pub block_height: BlockHeight,
39    // This is the db address that the executor should connect to.
40    pub address_for_exec: ServerAddress,
41    // This is the db address that the scheduler should connect to.
42    pub address_for_sched: ServerAddress,
43    // This is the db address that the auth server should connect to.
44    pub address_for_auth: ServerAddress,
45}
46
47#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
48#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
49#[derive(schemars::JsonSchema)]
50#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
51#[repr(C)]
52pub struct Delta {
53    pub address: ContractAddress,
54    pub native_token_delta: int128_xdr,
55}
56
57// One slice of the native-token balance deltas a committed block finalized.
58//
59// The db publishes a block's deltas as a run of chunk_count chunks, all for
60// the same block, after the block is committed. The db chooses the chunk
61// size; the wire bounds a chunk only by the link's record cap. The chunks of
62// a run may be sent concurrently and over several connections, so they can
63// arrive in any order; the db starts the next block's run only after every
64// chunk of this one is acknowledged, so the mempool never has more than one
65// block's run in flight. An address appears in at most one chunk of a block's
66// run (a shard holds one balance per address) and every delta is nonzero. The
67// mempool treats the block's transfers as complete only once every chunk of
68// the run has arrived; nothing that gates on a block's transfers may open
69// before that.
70#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
71#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
72#[derive(schemars::JsonSchema)]
73#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
74#[repr(C)]
75pub struct NativeTokensTransferredChunk {
76    // The height of the block in which these transfers occurred. The scheduler
77    // uses this height to update average native-token ages.
78    pub block: BlockHeight,
79    // This chunk's position in the block's run, from 0, and the run's length.
80    // Every chunk of a run carries the same chunk_count, and each index in
81    // [0, chunk_count) is sent exactly once. A block that finalized no nonzero
82    // delta is a run of one empty chunk, so every committed block still sends
83    // a run.
84    pub chunk_index: u32,
85    pub chunk_count: u32,
86    pub deltas: VecM<Delta>,
87}
88
89
90/// Each handler replies with anything that encodes like the reply type.
91/// Implementations can be plain `async fn`s returning a concrete reply type
92/// under `#[allow(refining_impl_trait)]`.
93#[allow(non_camel_case_types)]
94pub trait SchedDb_SchedDb1: Send + Sync {        // [scheddb_intro_shard] is called by a db shard to introduce itself to the
95    // system.
96
97    fn scheddb_intro_shard(&self, arg0 : ShardCard) -> impl ::core::future::Future<Output = Result<impl xdrs::EncodesAs<()>, ::thruput_rpc_api::ProgramError>> + Send;
98        // Retired numbers, never to be reused, so that a peer built against one
99    // fails to dispatch rather than misparse a newer payload:
100    //   2: the unchunked form of procedure 4, a block's deltas in one
101    //      unbounded record, which a block with enough distinct recipients
102    //      grows past any single-record cap.
103    //   3: scheddb_changed_addresses(BlockHeight, ContractAddressBatch),
104    //      removed in e413dc9. Its payload also opens with a block height and
105    //      a vector length, so a chunk sent on 3 would decode there as
106    //      addresses.
107
108    // Deliver one chunk of a committed block's balance deltas. With several db
109    // shards the mempool completes the block once every registered shard has
110    // sent its run's last chunk.
111
112    fn scheddb_native_tokens_transferred_chunk(&self, arg0 : NativeTokensTransferredChunk) -> impl ::core::future::Future<Output = Result<impl xdrs::EncodesAs<()>, ::thruput_rpc_api::ProgramError>> + Send;
113}
114
115
116#[allow(non_camel_case_types)]
117pub struct SchedDb_SchedDb1_Dispatcher<__Handler> {
118  inner: Box<__Handler>,
119}
120
121impl<__Handler: SchedDb_SchedDb1> SchedDb_SchedDb1_Dispatcher<__Handler> {
122  pub fn new(inner: Box<__Handler>) -> Self {
123    Self { inner }
124  }
125}
126
127#[async_trait::async_trait]
128impl<__Handler: SchedDb_SchedDb1> ::thruput_rpc_api::RpcHandler for SchedDb_SchedDb1_Dispatcher<__Handler> {
129    fn prog_vers(&self) -> ::thruput_rpc_api::ProgVers {
130        ::thruput_rpc_api::ProgVers::new(0x7ee79998, 1)
131    }
132    async fn dispatch(&self, proc: u32, data: &[u8]) -> Result<Vec<u8>, ::thruput_rpc_api::RpcError> {
133        match proc {
134            // scheddb_intro_shard
135            1 => {
136                let args: (ShardCard, ) =
137                    xdrs::txs::decode(data).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
138                let res = self.inner.scheddb_intro_shard(args.0).await.map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
139                xdrs::txs::encode(&res).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
140            }
141            // scheddb_native_tokens_transferred_chunk
142            4 => {
143                let args: (NativeTokensTransferredChunk, ) =
144                    xdrs::txs::decode(data).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
145                let res = self.inner.scheddb_native_tokens_transferred_chunk(args.0).await.map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?;
146                xdrs::txs::encode(&res).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)
147            }
148            _ => Err(::thruput_rpc_api::RpcError::InvalidProcedure),
149        }
150    }
151}
152
153#[derive(Clone)]
154pub struct SchedDb_SchedDb1_Client {
155    handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>,
156}
157
158impl SchedDb_SchedDb1_Client {
159    pub fn new(handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>) -> Self {
160        Self { handle }
161    }
162
163    fn prog_vers() -> ::thruput_rpc_api::ProgVers {
164        ::thruput_rpc_api::ProgVers::new(0x7ee79998, 1)
165    }
166    pub async fn scheddb_intro_shard(&self, arg0 : &(impl xdrs::EncodesAs<ShardCard> + ?Sized)) -> Result<(), ::thruput_rpc_api::RpcError> {
167         let mut call = self.handle.call_buf();
168         call.append_with(|buf| {
169             let mut w = xdrs::txs::buf_writer::BufWriter::from(::core::mem::take(buf));
170             let r = xdrs::write_xdr(&(arg0), &mut w);
171             *buf = w.into();
172             r
173         }).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
174         let mut out = ::core::option::Option::None;
175         let mut decode = |reply: &[u8]| -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
176             out = ::core::option::Option::Some(xdrs::txs::decode(reply).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?);
177             Ok(())
178         };
179         // SAFETY: the call future is awaited right here, so it lives in
180         // this method's future along with `out` and `decode`. Once that
181         // is polled it is pinned, so neither can be freed without the
182         // call future being dropped first. Decoding never blocks.
183         unsafe { self.handle.send_call_decoded(Self::prog_vers(), 1, call, &mut decode) }.await?;
184         out.ok_or(::thruput_rpc_api::RpcError::SystemError)
185    }
186    pub async fn scheddb_native_tokens_transferred_chunk(&self, arg0 : &(impl xdrs::EncodesAs<NativeTokensTransferredChunk> + ?Sized)) -> Result<(), ::thruput_rpc_api::RpcError> {
187         let mut call = self.handle.call_buf();
188         call.append_with(|buf| {
189             let mut w = xdrs::txs::buf_writer::BufWriter::from(::core::mem::take(buf));
190             let r = xdrs::write_xdr(&(arg0), &mut w);
191             *buf = w.into();
192             r
193         }).map_err(|_| ::thruput_rpc_api::RpcError::GarbageArguments)?;
194         let mut out = ::core::option::Option::None;
195         let mut decode = |reply: &[u8]| -> ::core::result::Result<(), ::thruput_rpc_api::RpcError> {
196             out = ::core::option::Option::Some(xdrs::txs::decode(reply).map_err(|_| ::thruput_rpc_api::RpcError::SystemError)?);
197             Ok(())
198         };
199         // SAFETY: the call future is awaited right here, so it lives in
200         // this method's future along with `out` and `decode`. Once that
201         // is polled it is pinned, so neither can be freed without the
202         // call future being dropped first. Decoding never blocks.
203         unsafe { self.handle.send_call_decoded(Self::prog_vers(), 4, call, &mut decode) }.await?;
204         out.ok_or(::thruput_rpc_api::RpcError::SystemError)
205    }
206}
207
208impl From<::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>> for SchedDb_SchedDb1_Client {
209    fn from(handle: ::std::sync::Arc<dyn ::thruput_rpc_api::RpcSender>) -> Self {
210        Self::new(handle)
211    }
212}
213
214
215
216//
217// XDR internals below this point
218//
219
220