Skip to main content

thruput_xdr/
network_config.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};
20#[cfg(feature = "xdrs")]
21use xdrs::*;
22
23
24#[cfg(feature = "serde")]
25use ::serde::{{Serialize, Deserialize}};
26
27
28
29// clang-format on
30
31/// Names one consensus-critical configuration parameter.
32///
33/// Append-only: an id, once assigned, means that parameter forever, and a
34/// retired parameter keeps its id rather than freeing it for reuse.
35#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
36#[cfg_attr(feature = "serde", serde(transparent))]
37#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
38#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
39#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
40#[derive(Copy)]
41#[repr(transparent)]
42pub struct ConfigParamID(pub i32);
43
44impl ConfigParamID {
45    pub const kConfigParamMaxSHA256Buffers: Self = Self(0);
46    pub const kConfigParamMaxCrossInvokeDepth: Self = Self(1);
47    pub const kConfigParamMaxNewContractsPerTx: Self = Self(2);
48    pub const kConfigParamMaxBytestringLen: Self = Self(3);
49    pub const kConfigParamMaxContractSizeBytes: Self = Self(4);
50    pub const kConfigParamMaxSavepointDepth: Self = Self(5);
51    pub const kConfigParamMaxSHA256BufferBytes: Self = Self(6);
52    pub const kConfigParamMaxAuthTokenDepth: Self = Self(7);
53    pub const kConfigParamMaxRv32CodeBytes: Self = Self(8);
54    pub const kConfigParamMaxRv32MemoryBytes: Self = Self(9);
55    pub const kConfigParamMaxAuthTokens: Self = Self(10);
56    pub const kConfigParamMaxCalldataLen: Self = Self(11);
57    pub const kConfigParamMaxReturnBufferLen: Self = Self(12);
58    pub const kConfigParamMaxTxGas: Self = Self(13);
59}
60impl From<i32> for ConfigParamID {
61    fn from(v: i32) -> Self {
62        Self(v)
63    }
64}
65#[cfg(feature = "std")]
66impl core::fmt::Display for ConfigParamID {
67    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
68        match self.0 {
69            x if x == Self::kConfigParamMaxSHA256Buffers.0 => {
70                write!(f, "ConfigParamID::kConfigParamMaxSHA256Buffers")
71            },
72            x if x == Self::kConfigParamMaxCrossInvokeDepth.0 => {
73                write!(f, "ConfigParamID::kConfigParamMaxCrossInvokeDepth")
74            },
75            x if x == Self::kConfigParamMaxNewContractsPerTx.0 => {
76                write!(f, "ConfigParamID::kConfigParamMaxNewContractsPerTx")
77            },
78            x if x == Self::kConfigParamMaxBytestringLen.0 => {
79                write!(f, "ConfigParamID::kConfigParamMaxBytestringLen")
80            },
81            x if x == Self::kConfigParamMaxContractSizeBytes.0 => {
82                write!(f, "ConfigParamID::kConfigParamMaxContractSizeBytes")
83            },
84            x if x == Self::kConfigParamMaxSavepointDepth.0 => {
85                write!(f, "ConfigParamID::kConfigParamMaxSavepointDepth")
86            },
87            x if x == Self::kConfigParamMaxSHA256BufferBytes.0 => {
88                write!(f, "ConfigParamID::kConfigParamMaxSHA256BufferBytes")
89            },
90            x if x == Self::kConfigParamMaxAuthTokenDepth.0 => {
91                write!(f, "ConfigParamID::kConfigParamMaxAuthTokenDepth")
92            },
93            x if x == Self::kConfigParamMaxRv32CodeBytes.0 => {
94                write!(f, "ConfigParamID::kConfigParamMaxRv32CodeBytes")
95            },
96            x if x == Self::kConfigParamMaxRv32MemoryBytes.0 => {
97                write!(f, "ConfigParamID::kConfigParamMaxRv32MemoryBytes")
98            },
99            x if x == Self::kConfigParamMaxAuthTokens.0 => {
100                write!(f, "ConfigParamID::kConfigParamMaxAuthTokens")
101            },
102            x if x == Self::kConfigParamMaxCalldataLen.0 => {
103                write!(f, "ConfigParamID::kConfigParamMaxCalldataLen")
104            },
105            x if x == Self::kConfigParamMaxReturnBufferLen.0 => {
106                write!(f, "ConfigParamID::kConfigParamMaxReturnBufferLen")
107            },
108            x if x == Self::kConfigParamMaxTxGas.0 => {
109                write!(f, "ConfigParamID::kConfigParamMaxTxGas")
110            },
111            _ => {
112                write!(f, "ConfigParamID({})", self.0)
113            }
114        }
115    }
116}
117
118
119/// One configuration parameter and the value in force for it.
120///
121/// Serves both uses of that pairing: `NetworkConfigV0` states a chain's
122/// configuration as a list of these, and is meant to carry one per parameter
123/// being changed by a consensus upgrade, where everything a block does not
124/// name keeps the value it already has. No upgrade mechanism exists yet:
125/// `ConsensusValue::upgrades` is opaque, and the node leaves it empty. Each arm
126/// carries its own type, so a future parameter need not be an `unsigned int`.
127///
128/// There is no `default` arm on purpose: a node that cannot name a parameter
129/// cannot know what value is in force for it, so an unrecognized id must fail
130/// to decode rather than decode to something the node then ignores.
131#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
132#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
133#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
134#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
135#[repr(i32)]
136#[non_exhaustive]
137pub enum ConfigParam {
138    /// Concurrently open incremental SHA-256 buffers permitted per invocation
139    /// frame (`SHA256Update`, `SHA256Copy`, `SHA256Finalize`). 32 is the value
140    /// in force for a configuration that does not state one.
141    // case kConfigParamMaxSHA256Buffers:
142    //   u32 max_sha256_buffers;
143    kConfigParamMaxSHA256Buffers { max_sha256_buffers: u32 } = ConfigParamID::kConfigParamMaxSHA256Buffers.0 as i32,
144    /// Invocation frames one transaction may have open at once, counting every
145    /// invoke rather than only the savepoint-pushing ones that
146    /// `kConfigParamMaxSavepointDepth` bounds. Each open frame holds a live contract
147    /// runtime, so this is what stops a recursive call chain from growing until
148    /// the executor runs out of room for it. 16 is the value in force for a
149    /// configuration that does not state one.
150    // case kConfigParamMaxCrossInvokeDepth:
151    //   u32 max_cross_invoke_depth;
152    kConfigParamMaxCrossInvokeDepth { max_cross_invoke_depth: u32 } = ConfigParamID::kConfigParamMaxCrossInvokeDepth.0 as i32,
153    /// Contracts one transaction may attach in `contracts_to_deploy`.
154    ///
155    /// Counted over what is attached rather than what a contract goes on to
156    /// deploy: the executor holds every attached contract for the whole
157    /// transaction, and the ones deployed are a subset chosen during execution.
158    /// Attaching the same contract twice is rejected outright, so the count is
159    /// over distinct contracts either way. 4 is the value in force for a
160    /// configuration that does not state one.
161    ///
162    /// Together with `kConfigParamMaxContractSizeBytes` this is what bounds the
163    /// transaction's final commit batch, which the executor sends to storage as
164    /// a single message. A chain must set the pair low enough that the largest
165    /// batch it admits still fits that message; the node rejects a genesis
166    /// that does not.
167    // case kConfigParamMaxNewContractsPerTx:
168    //   u32 max_new_contracts_per_tx;
169    kConfigParamMaxNewContractsPerTx { max_new_contracts_per_tx: u32 } = ConfigParamID::kConfigParamMaxNewContractsPerTx.0 as i32,
170    /// Bytes one bytestring storage item may hold, checked where a contract
171    /// writes one rather than where one is read, so that lowering it leaves
172    /// existing items readable instead of stranding state.
173    ///
174    /// `kBytestringCeilingLen` bounds this. A chain must also keep it low
175    /// enough that its own storage engine handles the largest item it thereby
176    /// admits; the ceiling does not guarantee that.
177    // case kConfigParamMaxBytestringLen:
178    //   u32 max_bytestring_len;
179    kConfigParamMaxBytestringLen { max_bytestring_len: u32 } = ConfigParamID::kConfigParamMaxBytestringLen.0 as i32,
180    /// Bytes one attached contract's code blob (`ContractBlob.data`) may hold,
181    /// checked before any attached contract is verified or executed. It is
182    /// the same quantity `contract_deployment_cost_per_byte` charges for.
183    ///
184    /// `kDefaultMaxContractSizeBytes` is the value in force for a
185    /// configuration that does not state one. The wire format does not bound
186    /// `ContractBlob`, so nothing here caps what a chain may state: a chain
187    /// must keep it low enough that its own storage engine stores the largest
188    /// contract it thereby admits, that every attached contract still fits a
189    /// transaction (`kMaxBytesSignedTransaction`), and that the commit batch
190    /// `kConfigParamMaxNewContractsPerTx` bounds fits one storage message.
191    /// The node rejects a genesis that does not.
192    // case kConfigParamMaxContractSizeBytes:
193    //   u32 max_contract_size_bytes;
194    kConfigParamMaxContractSizeBytes { max_contract_size_bytes: u32 } = ConfigParamID::kConfigParamMaxContractSizeBytes.0 as i32,
195    /// Storage savepoints one transaction may hold at once: one per successful
196    /// `TryInvoke` whose writes are still held (finished siblings included),
197    /// plus the one the root commit takes. A `TryInvoke` whose child would go
198    /// past the limit still runs, then fails deterministically, as one that
199    /// loses a lock conflict does, and its writes are discarded.
200    /// 1024 is the value in force for a configuration that does not state
201    /// one.
202    ///
203    /// Every open savepoint is a live nested VM on one executor thread, so a
204    /// chain must keep this within what its executors' stacks hold; the
205    /// node rejects a genesis above its build ceiling.
206    // case kConfigParamMaxSavepointDepth:
207    //   u32 max_savepoint_depth;
208    kConfigParamMaxSavepointDepth { max_savepoint_depth: u32 } = ConfigParamID::kConfigParamMaxSavepointDepth.0 as i32,
209    /// Legacy cumulative SHA-256 byte limit. Retained for wire compatibility
210    /// and configuration hashing; no longer enforced. SHA256Update checks gas
211    /// before processing input and keeps constant-size incremental state.
212    // case kConfigParamMaxSHA256BufferBytes:
213    //   u32 max_sha256_buffer_bytes;
214    kConfigParamMaxSHA256BufferBytes { max_sha256_buffer_bytes: u32 } = ConfigParamID::kConfigParamMaxSHA256BufferBytes.0 as i32,
215    /// Levels of `AuthTokenNode` nesting an auth token may carry, counted from
216    /// its root, checked where a token is minted or forwarded into a view.
217    /// `kAuthTokenMaxDepth` is the value in force for a configuration that
218    /// does not state one. The wire type bounds a node's payload and its
219    /// direct children (`kAuthTokenMaxLen`, `kAuthTokenMaxChildNodes`) but not
220    /// the depth, so this is what bounds a token's total size.
221    // case kConfigParamMaxAuthTokenDepth:
222    //   u32 max_auth_token_depth;
223    kConfigParamMaxAuthTokenDepth { max_auth_token_depth: u32 } = ConfigParamID::kConfigParamMaxAuthTokenDepth.0 as i32,
224    /// Bytes of code (`code_size` in the artifact header) an RV32 artifact may
225    /// carry to be admitted as an attached contract.
226    /// 262144 is the value in force for a configuration that does not state
227    /// one.
228    ///
229    /// Checked where a contract is attached, not where a deployed one is
230    /// instantiated, so lowering it leaves deployed contracts runnable. The
231    /// artifact format itself does not bound the field; the node rejects a
232    /// genesis above what its VM can translate.
233    // case kConfigParamMaxRv32CodeBytes:
234    //   u32 max_rv32_code_bytes;
235    kConfigParamMaxRv32CodeBytes { max_rv32_code_bytes: u32 } = ConfigParamID::kConfigParamMaxRv32CodeBytes.0 as i32,
236    /// Bytes of guest data memory (`memory_bytes` in the artifact header) an
237    /// RV32 artifact may declare to be admitted as an attached contract.
238    /// 65536 is the value in force for a configuration that does not state
239    /// one.
240    ///
241    /// Checked at attachment like `kConfigParamMaxRv32CodeBytes`. Every
242    /// invocation provisions and seeds the declared memory outside gas, so a
243    /// chain raising this accepts that per-call cost; the node rejects a
244    /// genesis above what its VM provisions.
245    // case kConfigParamMaxRv32MemoryBytes:
246    //   u32 max_rv32_memory_bytes;
247    kConfigParamMaxRv32MemoryBytes { max_rv32_memory_bytes: u32 } = ConfigParamID::kConfigParamMaxRv32MemoryBytes.0 as i32,
248    /// Auth token ids one call may carry in a list: `Invoke`'s
249    /// `owned_auth_token_ids_list` and `Return`'s `returned_auth_token_ids`,
250    /// each read as a `[u32]` span.
251    ///
252    /// Checked against the span's length before the ids are read, so a list
253    /// past the bound is refused without being copied and what a rejected call
254    /// costs does not scale with the memory that held it. The ids in a list are
255    /// distinct and owned by the frame naming them, so this bounds what one
256    /// frame hands another in a single call rather than what a frame may hold.
257    ///
258    /// Neither wire type bounds its list, and no value was in force before this
259    /// parameter: a list was limited only by the memory holding it. A
260    /// configuration omitting this one is not continuing an older rule: the
261    /// value in force is 64.
262    // case kConfigParamMaxAuthTokens:
263    //   u32 max_auth_tokens;
264    kConfigParamMaxAuthTokens { max_auth_tokens: u32 } = ConfigParamID::kConfigParamMaxAuthTokens.0 as i32,
265    /// Bytes of calldata one invocation may be given, whether a transaction
266    /// supplies it in `Invocation::calldata` or a contract supplies it in
267    /// `Invoke`'s `calldata` span.
268    ///
269    /// Checked before the bytes are copied, so an oversized call is refused
270    /// rather than materialized. `Calldata` is `opaque<>`, so the wire type
271    /// bounds neither form and this is what bounds them in execution.
272    /// `kConfigParamMaxReturnBufferLen` bounds the other direction the same
273    /// way.
274    ///
275    /// The executor holds a frame's calldata for the life of that frame and
276    /// every open frame holds its own, so a chain must keep this within what
277    /// `kConfigParamMaxCrossInvokeDepth` frames of it leave room for. No value
278    /// was in force before this parameter; for a configuration that does not
279    /// state one, the value in force is 65536.
280    // case kConfigParamMaxCalldataLen:
281    //   u32 max_calldata_len;
282    kConfigParamMaxCalldataLen { max_calldata_len: u32 } = ConfigParamID::kConfigParamMaxCalldataLen.0 as i32,
283    /// Bytes one invocation frame may return, whether to a calling frame or,
284    /// from the root frame, into `TxEventLog::root_output`.
285    ///
286    /// Checked where the Return syscall writes a buffer, which is the only
287    /// place one is built. A root frame's buffer is committed to by the events
288    /// root, so what a chain states here it stores and serves for every
289    /// transaction; together with the event bounds it is what keeps a
290    /// `TxEventLog` inside the RPC transport message limit.
291    ///
292    /// `ReturnBuffer` bounded itself at 1024 bytes before this parameter, so a
293    /// configuration omitting this one is continuing an older rule rather than
294    /// lifting it: the value in force for a configuration that does not state
295    /// one is 1024.
296    // case kConfigParamMaxReturnBufferLen:
297    //   u32 max_return_buffer_len;
298    kConfigParamMaxReturnBufferLen { max_return_buffer_len: u32 } = ConfigParamID::kConfigParamMaxReturnBufferLen.0 as i32,
299    /// Gas one transaction may budget: the most a root `Invocation::gas_limit`
300    /// may state.
301    ///
302    /// Checked before any attached contract is verified or any body runs, so
303    /// a transaction over the bound is refused outright rather than clamped:
304    /// the budget a transaction signs is the one it executes under or none.
305    /// Subinvocations are already capped at their caller's remaining gas, so
306    /// bounding the root bounds every frame.
307    ///
308    /// Native-token availability bounded a transaction's budget before this
309    /// parameter, and nothing else did. A configuration omitting this one does
310    /// not continue that rule: the value in force is `1,000,000,000`. A
311    /// `GasAmount` rather than an `unsigned int` so that a chain may state any
312    /// budget a transaction can.
313    // case kConfigParamMaxTxGas:
314    //   GasAmount max_tx_gas;
315    kConfigParamMaxTxGas { max_tx_gas: GasAmount } = ConfigParamID::kConfigParamMaxTxGas.0 as i32,
316    
317}
318
319/// The parameters a chain states, as a list rather than fixed fields. A new
320/// parameter is then an id and a [`ConfigParam`] arm, with no new version here
321/// and no change to the layout of anything embedding one.
322///
323/// `params` MUST be a prefix of the id space: ids run 0, 1, 2, ... in order,
324/// with no gaps. The encoding is hashed into `ProposalHeader::config_hash`, so
325/// permitting one arrangement per configuration is what gives it one hash. A
326/// list that is unordered, repeats an id, or skips one must fail validation
327/// rather than resolve to one of the values. The rule also bounds the list: a
328/// prefix cannot be longer than the number of parameters that exist.
329///
330/// Ascending order alone would leave interior gaps legal, and a gap is what
331/// makes the encoding ambiguous: a parameter at its default value could be
332/// written down or left out. A prefix settles which -- below the list's length
333/// a parameter is stated, past it it is not -- and makes resolving one an
334/// index rather than a search.
335///
336/// A parameter absent from the list takes the value the protocol defines for
337/// it. Absence says nothing about why: the list may be short because the
338/// configuration predates the parameter, or because its creator declined to
339/// state one it knew, and nothing on the wire tells those apart. A creator
340/// SHOULD state every parameter it knows; a verifier cannot check that.
341#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
342#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
343#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
344#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
345#[repr(C)]
346pub struct NetworkConfigV0 {
347    pub params: VecM<ConfigParam>,
348}
349
350/// The consensus-critical execution parameters a block executes under.
351///
352/// A chain states its configuration at genesis. A parameter the
353/// configuration does not state takes the value its [`ConfigParam`] arm
354/// documents (see [`NetworkConfigV0`]).
355///
356/// One version, because `v0` states its parameters as a list: a new parameter
357/// is an id and a [`ConfigParam`] arm, not a new arm here. The discriminant is
358/// kept so that if a change ever does need one, it is a new case rather than a
359/// silent reinterpretation of these bytes. A node meeting a version it cannot
360/// name must fail to decode rather than guess what is in force.
361#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
362#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
363#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
364#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
365#[repr(i32)]
366#[non_exhaustive]
367pub enum NetworkConfig {
368    // case 0:
369    //   NetworkConfigV0 v0;
370    _0 { v0: NetworkConfigV0 } = 0 as i32,
371    
372}
373
374/// The network configuration committed to by ProposalHeader::config_hash.
375/// New consensus-critical configuration belongs in this preimage.
376#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
377#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
378#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
379#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
380#[repr(C)]
381pub struct ConfigHashPreimage {
382    pub storage_cost_model: StorageCostModelXdr,
383    pub network_config: NetworkConfig,
384    /// The contract a root invocation of an undeployed address resolves to, as
385    /// `GenesisConfiguration` states it and every `DbTip` carries it forward.
386    ///
387    /// It selects executing code, so a node running under a different one from
388    /// its peers executes a different chain. Nothing else commits to it: a
389    /// node's copy travels in the tip, which implementations are free to keep
390    /// outside the state the storage hash covers, and some do. Committing to
391    /// it here is what binds the value a node executes under to the one
392    /// consensus agreed, rather than to whatever its own storage returns.
393    pub default_wallet: DeployedContractHash,
394}
395
396
397//
398// XDR internals below this point
399//
400
401impl ConfigParam {
402    #[allow(clippy::match_single_binding)]
403    pub fn param(&self) -> ConfigParamID {
404        match self {
405            
406            _ => (unsafe { *(self as *const Self as *const i32) }).into(),
407        }
408    }
409}
410
411impl NetworkConfig {
412    #[allow(clippy::match_single_binding)]
413    pub fn v(&self) -> i32 {
414        match self {
415            
416            _ => unsafe { *(self as *const Self as *const i32) },
417        }
418    }
419}
420
421