|
| 1 | +//! Transaction logic module |
| 2 | +//! |
| 3 | +//! This module implements the core logic for applying and validating all |
| 4 | +//! transaction types in the Mina protocol. It is a direct port of the OCaml |
| 5 | +//! implementation from `src/lib/transaction_logic/mina_transaction_logic.ml` |
| 6 | +//! and maintains identical business logic. |
| 7 | +//! |
| 8 | +//! # Transaction Types |
| 9 | +//! |
| 10 | +//! The module handles three main categories of transactions: |
| 11 | +//! |
| 12 | +//! ## User Commands |
| 13 | +//! - **Signed Commands**: Payments and stake delegations |
| 14 | +//! - **zkApp Commands**: Complex multi-account zero-knowledge operations |
| 15 | +//! |
| 16 | +//! ## Protocol Transactions |
| 17 | +//! - **Fee Transfers**: Distribution of transaction fees to block producers |
| 18 | +//! - **Coinbase**: Block rewards for successful block production |
| 19 | +//! |
| 20 | +//! # Two-Phase Application |
| 21 | +//! |
| 22 | +//! Transaction application follows a two-phase model to enable efficient proof |
| 23 | +//! generation: |
| 24 | +//! |
| 25 | +//! 1. **First Pass** ([`apply_transaction_first_pass`]): Validates |
| 26 | +//! preconditions and begins application. For zkApp commands, applies the fee |
| 27 | +//! payer and first phase of account updates. |
| 28 | +//! |
| 29 | +//! 2. **Second Pass** ([`apply_transaction_second_pass`]): Completes |
| 30 | +//! application. For zkApp commands, applies the second phase of account |
| 31 | +//! updates and finalizes state. |
| 32 | +//! |
| 33 | +//! # Key Types |
| 34 | +//! |
| 35 | +//! - [`Transaction`]: Top-level enum for all transaction types |
| 36 | +//! - [`UserCommand`]: User-initiated transactions (signed or zkApp) |
| 37 | +//! - [`TransactionStatus`]: Applied or failed with specific error codes |
| 38 | +//! - [`TransactionFailure`]: 50+ specific failure reasons |
| 39 | +//! - [`FeeTransfer`]: Fee distribution transaction |
| 40 | +//! - [`Coinbase`]: Block reward transaction |
| 41 | +//! |
| 42 | +//! # Module Organization |
| 43 | +//! |
| 44 | +//! - [`local_state`]: Local state management during zkApp application |
| 45 | +//! - [`protocol_state`]: Protocol state views for transaction application |
| 46 | +//! - [`signed_command`]: Payment and stake delegation logic |
| 47 | +//! - [`transaction_applied`]: Final transaction application results |
| 48 | +//! - [`transaction_partially_applied`]: Two-phase transaction application |
| 49 | +//! - [`transaction_union_payload`]: Unified transaction representation for SNARK circuits |
| 50 | +//! - [`transaction_witness`]: Witness generation for transaction proofs |
| 51 | +//! - [`valid`]: Valid (but not yet verified) user commands |
| 52 | +//! - [`verifiable`]: Verifiable user commands ready for proof verification |
| 53 | +//! - [`zkapp_command`]: zkApp command processing |
| 54 | +//! - [`zkapp_statement`]: zkApp statement types for proof generation |
| 55 | +
|
1 | 56 | use self::{ |
2 | 57 | local_state::{apply_zkapp_command_first_pass, apply_zkapp_command_second_pass, LocalStateEnv}, |
3 | 58 | protocol_state::{GlobalState, ProtocolStateView}, |
@@ -243,12 +298,15 @@ impl<T> WithStatus<T> { |
243 | 298 |
|
244 | 299 | pub trait GenericCommand { |
245 | 300 | fn fee(&self) -> Fee; |
| 301 | + |
246 | 302 | fn forget(&self) -> UserCommand; |
247 | 303 | } |
248 | 304 |
|
249 | 305 | pub trait GenericTransaction: Sized { |
250 | 306 | fn is_fee_transfer(&self) -> bool; |
| 307 | + |
251 | 308 | fn is_coinbase(&self) -> bool; |
| 309 | + |
252 | 310 | fn is_command(&self) -> bool; |
253 | 311 | } |
254 | 312 |
|
|
0 commit comments