Skip to main content

thruput_trace/
db_conflict.rs

1// Generated by xdrc 0.18.0 (xdrs d7777c37264da66eb41f8139bd539c4aa049fcc5). Do not edit.
2
3// clang-format off
4
5#![allow(non_camel_case_types)]
6#![allow(non_snake_case)]
7#![allow(non_upper_case_globals)]
8#![allow(unused_imports)]
9#![allow(dead_code)]
10#![allow(unused_variables)]
11#![allow(clippy::unnecessary_cast)]
12use crate::*;
13use core::ops::{Deref, DerefMut};
14use core::option::Option;
15#[cfg(feature = "std")]
16use std::io::{Read, Write};
17use xdrs::*;
18#[cfg(feature = "serde")]
19use ::serde::{Deserialize, Serialize};
20
21// clang-format on
22/// Reason a storage delta could not be applied during two-phase commit.
23/// These are the nondeterministic failures of try_push_new_subtransaction:
24/// any of them causes ExecResultTxNonDeterministicError, and the transaction
25/// is excluded from the block. Codes are intentionally coarse; finer-grained
26/// detail may be added later behind a debug-only extension.
27#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
28#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
29#[cfg_attr(feature = "serde", serde(transparent))]
30#[derive(schemars::JsonSchema)]
31#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
32#[derive(Copy)]
33#[repr(transparent)]
34pub struct DbConflictCode(pub i32);
35
36impl DbConflictCode {
37    /// Exclusive-lock collision: the key is exclusively locked by another
38    /// transaction (committed or concurrent), an exclusive lock could not be
39    /// acquired because other transactions hold the key, or an exclusive-lock
40    /// flag was used on a key type that does not support it.
41    pub const ExclusiveLockDenied: Self = Self(0);
42    /// Two transactions created different item types at the same key.
43    pub const TypeMismatch: Self = Self(1);
44    /// Two transactions wrote irreconcilable values of the same type at the
45    /// same key: different bytestrings, different nnint base values,
46    /// different auth-data bases, or different contract / deployment hashes.
47    pub const ValueMismatch: Self = Self(2);
48    /// A nonnegative int would go below zero given the deltas in this block.
49    /// A native-token balance that cannot cover its debits reports
50    /// InsufficientFunds instead.
51    pub const BoundsExceeded: Self = Self(3);
52    /// Integer overflow combining deltas on a nonnegative int or balance.
53    pub const Overflow: Self = Self(4);
54    /// Replay-protection conflict: uniquifier expired, already consumed (in
55    /// a prior block or by a concurrent transaction), or consumed twice by
56    /// this transaction.
57    pub const ReplayProtection: Self = Self(5);
58    /// A retrocausal queue already has a consumer in this block.
59    pub const QueueConsumer: Self = Self(6);
60    /// A per-item capacity limit was hit: replay-cache active heights or
61    /// nonces, retrocausal-queue block entries, or auth signer slots.
62    pub const CapacityExceeded: Self = Self(7);
63    /// The native-token balance at the diagnostic's address cannot cover the
64    /// debits in this block, or a newly created balance item cannot cover
65    /// its own storage cost. Storage written under a contract's address is
66    /// charged to that contract's balance, so a deployment reports this at
67    /// the new contract's address when it holds no native tokens.
68    pub const InsufficientFunds: Self = Self(8);
69    /// An auth-data change would register a public key in a slot while
70    /// another slot of the same address already holds that key, whether
71    /// committed or set by the same change. The table would count one
72    /// key's weight twice, so the change is refused.
73    pub const DuplicateSigner: Self = Self(9);
74}
75
76impl From<i32> for DbConflictCode {
77    fn from(v: i32) -> Self {
78        Self(v)
79    }
80}
81
82impl xdrs::XDRDiscriminant for DbConflictCode {
83    const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
84    fn discriminant(&self) -> i32 {
85        self.0
86    }
87    fn from_discriminant(d: i32) -> Self {
88        Self(d)
89    }
90}
91
92#[cfg(feature = "std")]
93impl core::fmt::Display for DbConflictCode {
94    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
95        match self.0 {
96            x if x == Self::ExclusiveLockDenied.0 => {
97                f.write_str("DbConflictCode::ExclusiveLockDenied")
98            }
99            x if x == Self::TypeMismatch.0 => f.write_str("DbConflictCode::TypeMismatch"),
100            x if x == Self::ValueMismatch.0 => {
101                f.write_str("DbConflictCode::ValueMismatch")
102            }
103            x if x == Self::BoundsExceeded.0 => {
104                f.write_str("DbConflictCode::BoundsExceeded")
105            }
106            x if x == Self::Overflow.0 => f.write_str("DbConflictCode::Overflow"),
107            x if x == Self::ReplayProtection.0 => {
108                f.write_str("DbConflictCode::ReplayProtection")
109            }
110            x if x == Self::QueueConsumer.0 => {
111                f.write_str("DbConflictCode::QueueConsumer")
112            }
113            x if x == Self::CapacityExceeded.0 => {
114                f.write_str("DbConflictCode::CapacityExceeded")
115            }
116            x if x == Self::InsufficientFunds.0 => {
117                f.write_str("DbConflictCode::InsufficientFunds")
118            }
119            x if x == Self::DuplicateSigner.0 => {
120                f.write_str("DbConflictCode::DuplicateSigner")
121            }
122            _ => write!(f, "DbConflictCode({})", self.0),
123        }
124    }
125}
126
127/// How much conflict diagnostic detail try_push_new_subtransaction reports
128/// on failure. Selected by the database from the block's execution mode:
129/// proposal blocks report First (release builds) or All (debug builds);
130/// validation and viewing blocks report None.
131#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
132#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
133#[cfg_attr(feature = "serde", serde(transparent))]
134#[derive(schemars::JsonSchema)]
135#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
136#[derive(Copy)]
137#[repr(transparent)]
138pub struct DbDiagnosticLevel(pub i32);
139
140impl DbDiagnosticLevel {
141    /// No diagnostics (validation / viewing; previous behavior).
142    pub const kDbDiagnosticNone: Self = Self(0);
143    /// Report only the first conflict encountered (proposal, release builds).
144    pub const kDbDiagnosticFirst: Self = Self(1);
145    /// Report a best-effort list of all conflicting deltas in the batch
146    /// (proposal, debug builds — SDK testing).
147    pub const kDbDiagnosticAll: Self = Self(2);
148}
149
150impl From<i32> for DbDiagnosticLevel {
151    fn from(v: i32) -> Self {
152        Self(v)
153    }
154}
155
156impl xdrs::XDRDiscriminant for DbDiagnosticLevel {
157    const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
158    fn discriminant(&self) -> i32 {
159        self.0
160    }
161    fn from_discriminant(d: i32) -> Self {
162        Self(d)
163    }
164}
165
166#[cfg(feature = "std")]
167impl core::fmt::Display for DbDiagnosticLevel {
168    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
169        match self.0 {
170            x if x == Self::kDbDiagnosticNone.0 => {
171                f.write_str("DbDiagnosticLevel::kDbDiagnosticNone")
172            }
173            x if x == Self::kDbDiagnosticFirst.0 => {
174                f.write_str("DbDiagnosticLevel::kDbDiagnosticFirst")
175            }
176            x if x == Self::kDbDiagnosticAll.0 => {
177                f.write_str("DbDiagnosticLevel::kDbDiagnosticAll")
178            }
179            _ => write!(f, "DbDiagnosticLevel({})", self.0),
180        }
181    }
182}
183
184/// One conflicting storage op. Fixed-size: `ContractAddress[32]` plus a
185/// fixed-size StorageKey plus the code — no heap allocation.
186#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
187#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
188#[derive(schemars::JsonSchema)]
189#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
190#[repr(C)]
191pub struct DbConflictDiagnostic {
192    pub addrkey: AddressAndKey,
193    pub code: DbConflictCode,
194}
195
196/// Conflict diagnostics attached to a failed try_push_new_subtransaction.
197/// The discriminant is the DbDiagnosticLevel the database selected from
198/// the block's execution mode, so the variable-length arm is only ever
199/// constructed in kDbDiagnosticAll mode (debug-build proposals); prod
200/// levels are allocation-free by construction.
201#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
202#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
203#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
204#[xdr(discriminant = "DbDiagnosticLevel")]
205#[derive(schemars::JsonSchema)]
206#[repr(i32)]
207#[non_exhaustive]
208pub enum DbConflictResult {
209    kDbDiagnosticNone = DbDiagnosticLevel::kDbDiagnosticNone.0 as i32,
210    kDbDiagnosticFirst {
211        first: DbConflictDiagnostic,
212    } = DbDiagnosticLevel::kDbDiagnosticFirst.0 as i32,
213    kDbDiagnosticAll {
214        conflicts: VecM<DbConflictDiagnostic>,
215    } = DbDiagnosticLevel::kDbDiagnosticAll.0 as i32,
216}
217
218impl DbConflictResult {
219    #[allow(clippy::match_single_binding)]
220    pub fn level(&self) -> DbDiagnosticLevel {
221        match self {
222            DbConflictResult::kDbDiagnosticNone => DbDiagnosticLevel::kDbDiagnosticNone,
223            DbConflictResult::kDbDiagnosticFirst { .. } => {
224                DbDiagnosticLevel::kDbDiagnosticFirst
225            }
226            DbConflictResult::kDbDiagnosticAll { .. } => {
227                DbDiagnosticLevel::kDbDiagnosticAll
228            }
229        }
230    }
231}
232
233/// Reason the executor refused a transaction's contract attachments
234/// (Transaction.contracts_to_deploy) at proposal time. Any of them drops the
235/// transaction from the proposal; none is a contract fault. The RV32 codes
236/// name which check of the artifact failed, so an author can tell a
237/// toolchain/node mismatch from an oversized or corrupt build.
238#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
239#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
240#[cfg_attr(feature = "serde", serde(transparent))]
241#[derive(schemars::JsonSchema)]
242#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
243#[derive(Copy)]
244#[repr(transparent)]
245pub struct ContractRejectCode(pub i32);
246
247impl ContractRejectCode {
248    /// The transaction attaches more contracts than the chain's
249    /// max_new_contracts_per_tx permits.
250    pub const ContractRejectTooMany: Self = Self(0);
251    /// The contract blob exceeds the chain's max_contract_size_bytes.
252    pub const ContractRejectBlobTooLarge: Self = Self(1);
253    /// The attachment is not an RV32 contract. Native contracts are registered
254    /// at genesis; RV32 is the only deployable type.
255    pub const ContractRejectNotDeployable: Self = Self(2);
256    /// The same contract is attached more than once.
257    pub const ContractRejectDuplicate: Self = Self(3);
258    /// The blob is not a readable RV32 artifact: too short, wrong magic, wrong
259    /// header size, or its length disagrees with the section sizes the header
260    /// declares.
261    pub const ContractRejectMalformedArtifact: Self = Self(4);
262    /// The artifact's format version is not one this node reads, or is outside
263    /// the range the chain's configuration admits
264    /// (`kConfigParamMinRv32ArtifactVersion`,
265    /// `kConfigParamMaxRv32ArtifactVersion`).
266    pub const ContractRejectUnsupportedFormat: Self = Self(5);
267    /// The artifact's VM profile, flags, entry ABI, or syscall API major is not
268    /// one this node runs, or the syscall API minor it declares is outside the
269    /// range the chain's configuration admits
270    /// (`kConfigParamMinSyscallApiMinor`, `kConfigParamMaxSyscallApiMinor`).
271    pub const ContractRejectUnsupportedAbi: Self = Self(6);
272    /// The gas schedule (version, digest) stamped into the artifact is not one
273    /// the node accepts: the artifact was lowered by a toolchain whose gas
274    /// schedule differs from the node's.
275    pub const ContractRejectGasScheduleMismatch: Self = Self(7);
276    /// The declared guest memory exceeds the chain's max_rv32_memory_bytes.
277    pub const ContractRejectMemoryTooLarge: Self = Self(8);
278    /// The code section is empty or exceeds the chain's max_rv32_code_bytes.
279    pub const ContractRejectCodeSizeInvalid: Self = Self(9);
280    /// The initial memory image does not fit in the declared guest memory, or
281    /// an empty image declares a nonzero load address.
282    pub const ContractRejectInitialMemoryInvalid: Self = Self(10);
283    /// A section's bytes do not match the SHA-256 digest the header records.
284    pub const ContractRejectDigestMismatch: Self = Self(11);
285    /// The code does not translate: it contains an unsupported or malformed
286    /// instruction.
287    pub const ContractRejectInvalidProgram: Self = Self(12);
288}
289
290impl From<i32> for ContractRejectCode {
291    fn from(v: i32) -> Self {
292        Self(v)
293    }
294}
295
296impl xdrs::XDRDiscriminant for ContractRejectCode {
297    const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
298    fn discriminant(&self) -> i32 {
299        self.0
300    }
301    fn from_discriminant(d: i32) -> Self {
302        Self(d)
303    }
304}
305
306#[cfg(feature = "std")]
307impl core::fmt::Display for ContractRejectCode {
308    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
309        match self.0 {
310            x if x == Self::ContractRejectTooMany.0 => {
311                f.write_str("ContractRejectCode::ContractRejectTooMany")
312            }
313            x if x == Self::ContractRejectBlobTooLarge.0 => {
314                f.write_str("ContractRejectCode::ContractRejectBlobTooLarge")
315            }
316            x if x == Self::ContractRejectNotDeployable.0 => {
317                f.write_str("ContractRejectCode::ContractRejectNotDeployable")
318            }
319            x if x == Self::ContractRejectDuplicate.0 => {
320                f.write_str("ContractRejectCode::ContractRejectDuplicate")
321            }
322            x if x == Self::ContractRejectMalformedArtifact.0 => {
323                f.write_str("ContractRejectCode::ContractRejectMalformedArtifact")
324            }
325            x if x == Self::ContractRejectUnsupportedFormat.0 => {
326                f.write_str("ContractRejectCode::ContractRejectUnsupportedFormat")
327            }
328            x if x == Self::ContractRejectUnsupportedAbi.0 => {
329                f.write_str("ContractRejectCode::ContractRejectUnsupportedAbi")
330            }
331            x if x == Self::ContractRejectGasScheduleMismatch.0 => {
332                f.write_str("ContractRejectCode::ContractRejectGasScheduleMismatch")
333            }
334            x if x == Self::ContractRejectMemoryTooLarge.0 => {
335                f.write_str("ContractRejectCode::ContractRejectMemoryTooLarge")
336            }
337            x if x == Self::ContractRejectCodeSizeInvalid.0 => {
338                f.write_str("ContractRejectCode::ContractRejectCodeSizeInvalid")
339            }
340            x if x == Self::ContractRejectInitialMemoryInvalid.0 => {
341                f.write_str("ContractRejectCode::ContractRejectInitialMemoryInvalid")
342            }
343            x if x == Self::ContractRejectDigestMismatch.0 => {
344                f.write_str("ContractRejectCode::ContractRejectDigestMismatch")
345            }
346            x if x == Self::ContractRejectInvalidProgram.0 => {
347                f.write_str("ContractRejectCode::ContractRejectInvalidProgram")
348            }
349            _ => write!(f, "ContractRejectCode({})", self.0),
350        }
351    }
352}
353
354/// The first contract attachment the executor refused.
355#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
356#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
357#[derive(schemars::JsonSchema)]
358#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
359#[repr(C)]
360pub struct ContractRejectDiagnostic {
361    /// Position in Transaction.contracts_to_deploy of the refused contract.
362    /// For ContractRejectTooMany, the first position past the limit.
363    pub contract_index: u32,
364    pub code: ContractRejectCode,
365}
366
367#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
368#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
369#[cfg_attr(feature = "serde", serde(transparent))]
370#[derive(schemars::JsonSchema)]
371#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
372#[derive(Copy)]
373#[repr(transparent)]
374pub struct TxFailureKind(pub i32);
375
376impl TxFailureKind {
377    /// Two-phase commit could not apply the transaction's storage deltas.
378    pub const TxFailureDbConflict: Self = Self(0);
379    /// The executor refused a contract attachment before execution.
380    pub const TxFailureContractRejected: Self = Self(1);
381}
382
383impl From<i32> for TxFailureKind {
384    fn from(v: i32) -> Self {
385        Self(v)
386    }
387}
388
389impl xdrs::XDRDiscriminant for TxFailureKind {
390    const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
391    fn discriminant(&self) -> i32 {
392        self.0
393    }
394    fn from_discriminant(d: i32) -> Self {
395        Self(d)
396    }
397}
398
399#[cfg(feature = "std")]
400impl core::fmt::Display for TxFailureKind {
401    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
402        match self.0 {
403            x if x == Self::TxFailureDbConflict.0 => {
404                f.write_str("TxFailureKind::TxFailureDbConflict")
405            }
406            x if x == Self::TxFailureContractRejected.0 => {
407                f.write_str("TxFailureKind::TxFailureContractRejected")
408            }
409            _ => write!(f, "TxFailureKind({})", self.0),
410        }
411    }
412}
413
414#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
415#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
416#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
417#[xdr(discriminant = "TxFailureKind")]
418#[derive(schemars::JsonSchema)]
419#[repr(i32)]
420#[non_exhaustive]
421pub enum TxFailureCause {
422    TxFailureDbConflict {
423        conflict: DbConflictDiagnostic,
424    } = TxFailureKind::TxFailureDbConflict.0 as i32,
425    TxFailureContractRejected {
426        contract: ContractRejectDiagnostic,
427    } = TxFailureKind::TxFailureContractRejected.0 as i32,
428}
429
430impl TxFailureCause {
431    #[allow(clippy::match_single_binding)]
432    pub fn kind(&self) -> TxFailureKind {
433        match self {
434            TxFailureCause::TxFailureDbConflict { .. } => {
435                TxFailureKind::TxFailureDbConflict
436            }
437            TxFailureCause::TxFailureContractRejected { .. } => {
438                TxFailureKind::TxFailureContractRejected
439            }
440        }
441    }
442}
443
444/// Best-effort diagnostic for a transaction the proposer excluded from a
445/// proposal: the executing block height of the failed attempt plus why it
446/// failed -- the first conflicting storage op the database reported during
447/// two-phase commit, or the first contract attachment the executor refused.
448/// Fixed-size by construction; the wire and caches carry exactly one
449/// diagnostic per failure to bound memory end to end.
450#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
451#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
452#[derive(schemars::JsonSchema)]
453#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
454#[repr(C)]
455pub struct TxFailureDiagnostic {
456    pub attempt_height: BlockHeight,
457    pub cause: TxFailureCause,
458}