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 ABI is not one
268    /// this node runs.
269    pub const ContractRejectUnsupportedAbi: Self = Self(6);
270    /// The gas schedule (version, digest) stamped into the artifact is not one
271    /// the node accepts: the artifact was lowered by a toolchain whose gas
272    /// schedule differs from the node's.
273    pub const ContractRejectGasScheduleMismatch: Self = Self(7);
274    /// The declared guest memory exceeds the chain's max_rv32_memory_bytes.
275    pub const ContractRejectMemoryTooLarge: Self = Self(8);
276    /// The code section is empty or exceeds the chain's max_rv32_code_bytes.
277    pub const ContractRejectCodeSizeInvalid: Self = Self(9);
278    /// The initial memory image does not fit in the declared guest memory, or
279    /// an empty image declares a nonzero load address.
280    pub const ContractRejectInitialMemoryInvalid: Self = Self(10);
281    /// A section's bytes do not match the SHA-256 digest the header records.
282    pub const ContractRejectDigestMismatch: Self = Self(11);
283    /// The code does not translate: it contains an unsupported or malformed
284    /// instruction.
285    pub const ContractRejectInvalidProgram: Self = Self(12);
286}
287
288impl From<i32> for ContractRejectCode {
289    fn from(v: i32) -> Self {
290        Self(v)
291    }
292}
293
294impl xdrs::XDRDiscriminant for ContractRejectCode {
295    const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
296    fn discriminant(&self) -> i32 {
297        self.0
298    }
299    fn from_discriminant(d: i32) -> Self {
300        Self(d)
301    }
302}
303
304#[cfg(feature = "std")]
305impl core::fmt::Display for ContractRejectCode {
306    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
307        match self.0 {
308            x if x == Self::ContractRejectTooMany.0 => {
309                f.write_str("ContractRejectCode::ContractRejectTooMany")
310            }
311            x if x == Self::ContractRejectBlobTooLarge.0 => {
312                f.write_str("ContractRejectCode::ContractRejectBlobTooLarge")
313            }
314            x if x == Self::ContractRejectNotDeployable.0 => {
315                f.write_str("ContractRejectCode::ContractRejectNotDeployable")
316            }
317            x if x == Self::ContractRejectDuplicate.0 => {
318                f.write_str("ContractRejectCode::ContractRejectDuplicate")
319            }
320            x if x == Self::ContractRejectMalformedArtifact.0 => {
321                f.write_str("ContractRejectCode::ContractRejectMalformedArtifact")
322            }
323            x if x == Self::ContractRejectUnsupportedFormat.0 => {
324                f.write_str("ContractRejectCode::ContractRejectUnsupportedFormat")
325            }
326            x if x == Self::ContractRejectUnsupportedAbi.0 => {
327                f.write_str("ContractRejectCode::ContractRejectUnsupportedAbi")
328            }
329            x if x == Self::ContractRejectGasScheduleMismatch.0 => {
330                f.write_str("ContractRejectCode::ContractRejectGasScheduleMismatch")
331            }
332            x if x == Self::ContractRejectMemoryTooLarge.0 => {
333                f.write_str("ContractRejectCode::ContractRejectMemoryTooLarge")
334            }
335            x if x == Self::ContractRejectCodeSizeInvalid.0 => {
336                f.write_str("ContractRejectCode::ContractRejectCodeSizeInvalid")
337            }
338            x if x == Self::ContractRejectInitialMemoryInvalid.0 => {
339                f.write_str("ContractRejectCode::ContractRejectInitialMemoryInvalid")
340            }
341            x if x == Self::ContractRejectDigestMismatch.0 => {
342                f.write_str("ContractRejectCode::ContractRejectDigestMismatch")
343            }
344            x if x == Self::ContractRejectInvalidProgram.0 => {
345                f.write_str("ContractRejectCode::ContractRejectInvalidProgram")
346            }
347            _ => write!(f, "ContractRejectCode({})", self.0),
348        }
349    }
350}
351
352/// The first contract attachment the executor refused.
353#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
354#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
355#[derive(schemars::JsonSchema)]
356#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
357#[repr(C)]
358pub struct ContractRejectDiagnostic {
359    /// Position in Transaction.contracts_to_deploy of the refused contract.
360    /// For ContractRejectTooMany, the first position past the limit.
361    pub contract_index: u32,
362    pub code: ContractRejectCode,
363}
364
365#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
366#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
367#[cfg_attr(feature = "serde", serde(transparent))]
368#[derive(schemars::JsonSchema)]
369#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
370#[derive(Copy)]
371#[repr(transparent)]
372pub struct TxFailureKind(pub i32);
373
374impl TxFailureKind {
375    /// Two-phase commit could not apply the transaction's storage deltas.
376    pub const TxFailureDbConflict: Self = Self(0);
377    /// The executor refused a contract attachment before execution.
378    pub const TxFailureContractRejected: Self = Self(1);
379}
380
381impl From<i32> for TxFailureKind {
382    fn from(v: i32) -> Self {
383        Self(v)
384    }
385}
386
387impl xdrs::XDRDiscriminant for TxFailureKind {
388    const ENCODING: xdrs::DiscriminantEncoding = xdrs::DiscriminantEncoding::Signed;
389    fn discriminant(&self) -> i32 {
390        self.0
391    }
392    fn from_discriminant(d: i32) -> Self {
393        Self(d)
394    }
395}
396
397#[cfg(feature = "std")]
398impl core::fmt::Display for TxFailureKind {
399    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
400        match self.0 {
401            x if x == Self::TxFailureDbConflict.0 => {
402                f.write_str("TxFailureKind::TxFailureDbConflict")
403            }
404            x if x == Self::TxFailureContractRejected.0 => {
405                f.write_str("TxFailureKind::TxFailureContractRejected")
406            }
407            _ => write!(f, "TxFailureKind({})", self.0),
408        }
409    }
410}
411
412#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
413#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
414#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
415#[xdr(discriminant = "TxFailureKind")]
416#[derive(schemars::JsonSchema)]
417#[repr(i32)]
418#[non_exhaustive]
419pub enum TxFailureCause {
420    TxFailureDbConflict {
421        conflict: DbConflictDiagnostic,
422    } = TxFailureKind::TxFailureDbConflict.0 as i32,
423    TxFailureContractRejected {
424        contract: ContractRejectDiagnostic,
425    } = TxFailureKind::TxFailureContractRejected.0 as i32,
426}
427
428impl TxFailureCause {
429    #[allow(clippy::match_single_binding)]
430    pub fn kind(&self) -> TxFailureKind {
431        match self {
432            TxFailureCause::TxFailureDbConflict { .. } => {
433                TxFailureKind::TxFailureDbConflict
434            }
435            TxFailureCause::TxFailureContractRejected { .. } => {
436                TxFailureKind::TxFailureContractRejected
437            }
438        }
439    }
440}
441
442/// Best-effort diagnostic for a transaction the proposer excluded from a
443/// proposal: the executing block height of the failed attempt plus why it
444/// failed -- the first conflicting storage op the database reported during
445/// two-phase commit, or the first contract attachment the executor refused.
446/// Fixed-size by construction; the wire and caches carry exactly one
447/// diagnostic per failure to bound memory end to end.
448#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
449#[derive(ReadXDR, WriteXDR, ConstXDRSize)]
450#[derive(schemars::JsonSchema)]
451#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
452#[repr(C)]
453pub struct TxFailureDiagnostic {
454    pub attempt_height: BlockHeight,
455    pub cause: TxFailureCause,
456}