Skip to main content

thruput_node_types/
rpc_types.rs

1// -*-Rust-*-
2// Generated Code: DO NOT CHECK IN
3
4// Generated from xdrc commit: cb9cab8a8d69ace37c18d49b505f1e93ec802af8
5
6// clang-format off
7
8#![allow(non_camel_case_types)]
9#![allow(non_snake_case)]
10#![allow(non_upper_case_globals)]
11#![allow(unused_imports)]
12#![allow(dead_code)]
13#![allow(unused_variables)]
14#![allow(clippy::unnecessary_cast)]
15
16use crate::*;
17use core::option::Option;
18use core::ops::{Deref, DerefMut};
19
20#[cfg(feature = "std")]
21use std::io::{Read, Write};
22use xdrs::*;
23
24
25#[cfg(feature = "serde")]
26use ::serde::{{Serialize, Deserialize}};
27
28
29
30// clang-format on
31
32// An internal unique ID describing a block.
33pub type BlockID = u64;
34
35/// The contract-visible facts about the block an executor is running.
36///
37/// Passed to both executor open-block calls so that a block looks identical
38/// to the executor whether it is being proposed or validated, and so that
39/// everything a contract can observe about "the current block" comes from
40/// one place rather than being inferred from the parent tip.
41///
42/// This is deliberately not `ProposalContext` (its `protocol` and `proposer`
43/// are scheduler concerns, and `protocol` is not recoverable from a
44/// `ProposalHeader` when validating) and not `ProposalHeader` (whose txs,
45/// storage, events and config hashes are outputs of executing the block, so
46/// they do not exist when it is opened).
47///
48/// Does not travel on network: the scheduler builds it per block, from the
49/// coordinator's `ProposalContext` when proposing and from the proposal's
50/// `ProposalHeader` when validating. A validator must take these values from
51/// the proposal it is validating rather than regenerating them, or its
52/// execution diverges from the proposer's and consensus splits.
53#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
54#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
55#[derive(schemars::JsonSchema)]
56#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
57#[repr(C)]
58pub struct BlockExecutionContext {
59    /// Height of the block being executed -- the parent tip's height plus one.
60    /// Supplied rather than derived so that height and timepoint have a single
61    /// source; the executor is expected to check it against the tip it reads.
62    pub block_height: BlockHeight,
63    /// The block's timepoint, fixed before execution begins. Unlike the
64    /// height there is no way to recover this from the parent tip: the
65    /// parent's timepoint is the previous block's.
66    pub block_timepoint: TimePoint,
67}
68
69#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
70#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
71#[derive(schemars::JsonSchema)]
72#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
73#[repr(C)]
74pub struct DbTip {
75    pub id: BlockID,
76    pub storage_long_hash: StorageLongHash,
77    pub value: ConsensusValue,
78    /// The chain-configured contract resolved for a root invocation of an
79    /// address with no deployed contract (see
80    /// SystemCallHandler::resolve_runtime). Set at genesis from
81    /// GenesisConfiguration::default_wallet; carried forward verbatim by
82    /// every subsequent commit, and committed to by this tip's own
83    /// ProposalHeader::config_hash through ConfigHashPreimage.
84    pub default_wallet: DeployedContractHash,
85    /// The execution parameters in force for the block that follows this tip.
86    /// Set at genesis from GenesisConfiguration::network_config and carried
87    /// forward verbatim by every commit: no mechanism changes it after genesis
88    /// yet (see [`ConfigParam`]).
89    pub network_config: NetworkConfig,
90}
91
92// Internal unique ID describing a transaction.
93// Can be reused across blocks but cannot be reused within one block.
94pub type TransactionID = u64;
95
96// This is missing error codes, and is here purely as a placeholder.
97// These are some of the error codes I suspect we will need, but these
98// are not organized in any particular manner.
99//
100// TODO: This probably should get moved to a different file?
101#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
102#[cfg_attr(feature = "serde", serde(transparent))]
103#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
104#[derive(schemars::JsonSchema)]
105#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
106#[derive(Copy)]
107#[repr(transparent)]
108pub struct RPCError(pub i32);
109
110impl RPCError {
111    pub const kRPCNone: Self = Self(0);
112
113    // Lookup on an item in the database that does not exist.
114    // Used by any database lookup RPC, not just for one type.
115    pub const kRPCNotFound: Self = Self(1);
116
117    // BlockID does not exist, or is not in correct state
118    pub const kRPCBadBlockID: Self = Self(3);
119
120    // bad storage modification
121    pub const kRPCStorageWriteFailed: Self = Self(4);
122
123    // tx validation or proposal failed
124    pub const kRPCTransactionFailed: Self = Self(5);
125
126    // Unimplemented RPC
127    pub const kRPCUnimplemented: Self = Self(6);
128
129    // Unrecoverable error in the server (i.e. OOM, DB corruption)
130    pub const kRPCUnrecoverable: Self = Self(7);
131}
132impl From<i32> for RPCError {
133    fn from(v: i32) -> Self {
134        Self(v)
135    }
136}
137#[cfg(feature = "std")]
138impl core::fmt::Display for RPCError {
139    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
140        match self.0 {
141            x if x == Self::kRPCNone.0 => {
142                write!(f, "RPCError::kRPCNone")
143            },
144            x if x == Self::kRPCNotFound.0 => {
145                write!(f, "RPCError::kRPCNotFound")
146            },
147            x if x == Self::kRPCBadBlockID.0 => {
148                write!(f, "RPCError::kRPCBadBlockID")
149            },
150            x if x == Self::kRPCStorageWriteFailed.0 => {
151                write!(f, "RPCError::kRPCStorageWriteFailed")
152            },
153            x if x == Self::kRPCTransactionFailed.0 => {
154                write!(f, "RPCError::kRPCTransactionFailed")
155            },
156            x if x == Self::kRPCUnimplemented.0 => {
157                write!(f, "RPCError::kRPCUnimplemented")
158            },
159            x if x == Self::kRPCUnrecoverable.0 => {
160                write!(f, "RPCError::kRPCUnrecoverable")
161            },
162            _ => {
163                write!(f, "RPCError({})", self.0)
164            }
165        }
166    }
167}
168
169
170// The mode in which a block executes.
171#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
172#[cfg_attr(feature = "serde", serde(transparent))]
173#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
174#[derive(schemars::JsonSchema)]
175#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
176#[derive(Copy)]
177#[repr(transparent)]
178pub struct BlockExecutionMode(pub i32);
179
180impl BlockExecutionMode {
181    pub const kBlockExecutionModeValidation: Self = Self(0);
182    pub const kBlockExecutionModeProposal: Self = Self(1);
183
184    // Read-only access to the database.
185    // Used for view RPCs, guaranteeing that the executor cannot accidentally
186    // do a write operation when it should not be able to.
187    pub const kBlockExecutionModeViewing: Self = Self(2);
188}
189impl From<i32> for BlockExecutionMode {
190    fn from(v: i32) -> Self {
191        Self(v)
192    }
193}
194#[cfg(feature = "std")]
195impl core::fmt::Display for BlockExecutionMode {
196    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
197        match self.0 {
198            x if x == Self::kBlockExecutionModeValidation.0 => {
199                write!(f, "BlockExecutionMode::kBlockExecutionModeValidation")
200            },
201            x if x == Self::kBlockExecutionModeProposal.0 => {
202                write!(f, "BlockExecutionMode::kBlockExecutionModeProposal")
203            },
204            x if x == Self::kBlockExecutionModeViewing.0 => {
205                write!(f, "BlockExecutionMode::kBlockExecutionModeViewing")
206            },
207            _ => {
208                write!(f, "BlockExecutionMode({})", self.0)
209            }
210        }
211    }
212}
213
214
215pub type StorageCost = int128_xdr;
216
217#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
218#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
219#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
220#[derive(schemars::JsonSchema)]
221#[repr(i32)]
222#[non_exhaustive]
223pub enum ExpectedStorageCost {
224    // case kRPCNone:
225    //   StorageCost storage_cost;
226    kRPCNone { storage_cost: StorageCost } = RPCError::kRPCNone.0 as i32,
227    // default:
228    //   void;
229    #[xdr(default_variant)] Default { error: i32 },
230}
231
232// Is this the XDR pattern we want?
233#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
234#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
235#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
236#[derive(schemars::JsonSchema)]
237#[repr(i32)]
238#[non_exhaustive]
239pub enum ExpectedContract {
240    // case kRPCNone:
241    //   Contract contract;
242    kRPCNone { contract: Contract } = RPCError::kRPCNone.0 as i32,
243    // default:
244    //   void;
245    #[xdr(default_variant)] Default { error: i32 },
246}
247
248#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
249#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
250#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
251#[derive(schemars::JsonSchema)]
252#[repr(i32)]
253#[non_exhaustive]
254pub enum ExpectedDeployment {
255    // case kRPCNone:
256    //   DeployedContractHash deployed_hash;
257    kRPCNone { deployed_hash: DeployedContractHash } = RPCError::kRPCNone.0 as i32,
258    // default:
259    //   void;
260    #[xdr(default_variant)] Default { error: i32 },
261}
262
263#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
264#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
265#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
266#[derive(schemars::JsonSchema)]
267#[repr(i32)]
268#[non_exhaustive]
269pub enum ExpectedProposalData {
270    // case kRPCNone:
271    //   NondeterministicProposalData proposal_data;
272    kRPCNone { proposal_data: NondeterministicProposalData } = RPCError::kRPCNone.0 as i32,
273    // default:
274    //   void;
275    #[xdr(default_variant)] Default { error: i32 },
276}
277
278#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
279#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
280#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
281#[derive(schemars::JsonSchema)]
282#[repr(i32)]
283#[non_exhaustive]
284pub enum ExpectedRetrocausalQueueBlock {
285    // case kRPCNone:
286    //   RetrocausalQueueBlock queue_block;
287    kRPCNone { queue_block: RetrocausalQueueBlock } = RPCError::kRPCNone.0 as i32,
288    // default:
289    //   void;
290    #[xdr(default_variant)] Default { error: i32 },
291}
292
293#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
294#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
295#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
296#[derive(schemars::JsonSchema)]
297#[repr(i32)]
298#[non_exhaustive]
299pub enum ExpectedQueueEntry {
300    // case kRPCNone:
301    //   QueueEntry queue_entry;
302    kRPCNone { queue_entry: QueueEntry } = RPCError::kRPCNone.0 as i32,
303    // default:
304    //   void;
305    #[xdr(default_variant)] Default { error: i32 },
306}
307
308#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
309#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
310#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
311#[derive(schemars::JsonSchema)]
312#[repr(i32)]
313#[non_exhaustive]
314pub enum ExpectedDBTip {
315    // case kRPCNone:
316    //   DbTip db_tip;
317    kRPCNone { db_tip: DbTip } = RPCError::kRPCNone.0 as i32,
318    // default:
319    //   void;
320    #[xdr(default_variant)] Default { error: i32 },
321}
322
323#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
324#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
325#[derive(schemars::JsonSchema)]
326#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
327#[repr(C)]
328pub struct ViewingSnapshot {
329    pub viewing_block_id: BlockID,
330    pub tip: DbTip,
331}
332
333#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
334#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
335#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
336#[derive(schemars::JsonSchema)]
337#[repr(i32)]
338#[non_exhaustive]
339pub enum ExpectedViewingSnapshot {
340    // case kRPCNone:
341    //   ViewingSnapshot snapshot;
342    kRPCNone { snapshot: ViewingSnapshot } = RPCError::kRPCNone.0 as i32,
343    // default:
344    //   void;
345    #[xdr(default_variant)] Default { error: i32 },
346}
347
348/// Typedef for a list of contract addresses.
349pub type ContractAddressBatch = VecM::<ContractAddress>;
350
351
352//
353// XDR internals below this point
354//
355
356impl ExpectedStorageCost {
357    #[allow(clippy::match_single_binding)]
358    pub fn error(&self) -> RPCError {
359        match self {
360            ExpectedStorageCost::Default{ error } => (*error).into(),
361
362            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
363        }
364    }
365}
366
367impl ExpectedContract {
368    #[allow(clippy::match_single_binding)]
369    pub fn error(&self) -> RPCError {
370        match self {
371            ExpectedContract::Default{ error } => (*error).into(),
372
373            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
374        }
375    }
376}
377
378impl ExpectedDeployment {
379    #[allow(clippy::match_single_binding)]
380    pub fn error(&self) -> RPCError {
381        match self {
382            ExpectedDeployment::Default{ error } => (*error).into(),
383
384            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
385        }
386    }
387}
388
389impl ExpectedProposalData {
390    #[allow(clippy::match_single_binding)]
391    pub fn error(&self) -> RPCError {
392        match self {
393            ExpectedProposalData::Default{ error } => (*error).into(),
394
395            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
396        }
397    }
398}
399
400impl ExpectedRetrocausalQueueBlock {
401    #[allow(clippy::match_single_binding)]
402    pub fn error(&self) -> RPCError {
403        match self {
404            ExpectedRetrocausalQueueBlock::Default{ error } => (*error).into(),
405
406            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
407        }
408    }
409}
410
411impl ExpectedQueueEntry {
412    #[allow(clippy::match_single_binding)]
413    pub fn error(&self) -> RPCError {
414        match self {
415            ExpectedQueueEntry::Default{ error } => (*error).into(),
416
417            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
418        }
419    }
420}
421
422impl ExpectedDBTip {
423    #[allow(clippy::match_single_binding)]
424    pub fn error(&self) -> RPCError {
425        match self {
426            ExpectedDBTip::Default{ error } => (*error).into(),
427
428            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
429        }
430    }
431}
432
433impl ExpectedViewingSnapshot {
434    #[allow(clippy::match_single_binding)]
435    pub fn error(&self) -> RPCError {
436        match self {
437            ExpectedViewingSnapshot::Default{ error } => (*error).into(),
438
439            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
440        }
441    }
442}
443
444