Skip to content

Commit ecd058b

Browse files
committed
Update transactions.md from PR 1553 with link fixes
Replace the initial transactions.md with the comprehensive version from PR 1553. Convert undefined transaction type links to section anchors to prevent broken links until those documentation pages are created.
1 parent 1aa335b commit ecd058b

File tree

1 file changed

+180
-0
lines changed

1 file changed

+180
-0
lines changed
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
---
2+
sidebar_position: 5
3+
title: Introduction
4+
description: Understanding transaction types in the Mina protocol implementation
5+
slug: /developers/transactions
6+
---
7+
8+
# Introduction
9+
10+
## Overview
11+
12+
Transactions in Mina represent state changes to the ledger. The protocol
13+
supports both user-initiated transactions and protocol-generated transactions,
14+
each serving distinct purposes in the blockchain's operation.
15+
16+
This document provides an entry point for developers to understand how
17+
transactions are structured and processed in the Rust codebase.
18+
19+
## Transaction Types
20+
21+
The top-level `Transaction` enum represents all possible transactions in the
22+
Mina protocol:
23+
24+
<!-- CODE_REFERENCE: ledger/src/scan_state/transaction_logic/mod.rs#L1093-L1100 -->
25+
26+
```rust reference title="ledger/src/scan_state/transaction_logic/mod.rs"
27+
https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/transaction_logic/mod.rs#L1093-L1100
28+
```
29+
30+
### User-Initiated Transactions
31+
32+
**User Commands** are transactions submitted and signed by users:
33+
34+
- **Payment transactions** - Transfer MINA tokens between accounts
35+
- **Stake delegation** - Delegate stake to block producers
36+
- **zkApp commands** - Execute complex multi-account zero-knowledge operations
37+
38+
### Protocol Transactions
39+
40+
**Protocol transactions** (also called **system transactions**) are generated
41+
automatically by the system:
42+
43+
- **Fee transfers** - Distribute collected transaction fees to block producers
44+
- **[Coinbase rewards](./transactions/coinbase)** - Issue block production
45+
rewards
46+
47+
## Transaction Application Model
48+
49+
Transactions in Mina are applied in two phases:
50+
51+
### First Pass (`apply_transaction_first_pass`)
52+
53+
The first pass validates preconditions and begins transaction application:
54+
55+
- Validates account existence and permissions
56+
- Checks nonces and balances
57+
- Applies fee payments
58+
- Performs initial state changes
59+
- Returns `TransactionPartiallyApplied` containing transaction state
60+
61+
**Function:**
62+
[`ledger/src/scan_state/transaction_logic/transaction_partially_applied.rs`](https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/transaction_logic/transaction_partially_applied.rs#L190)
63+
64+
### Second Pass (`apply_transaction_second_pass`)
65+
66+
The second pass completes the transaction after SNARK work:
67+
68+
- Finalizes account updates
69+
- Applies protocol-specific logic
70+
- Updates receipt chain hashes
71+
- Returns final `TransactionApplied` status
72+
73+
**Function:**
74+
[`ledger/src/scan_state/transaction_logic/transaction_applied.rs`](https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/transaction_logic/transaction_applied.rs)
75+
76+
## Common Transaction Components
77+
78+
### Fees
79+
80+
All user-initiated transactions require fees. The `Fee` type is generated by a
81+
macro along with other currency types in
82+
[`ledger/src/scan_state/currency.rs`](https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/currency.rs#L575-L578).
83+
84+
Fees serve two purposes: they compensate block producers for including
85+
transactions and prevent network spam by making it economically infeasible to
86+
flood the network with transactions. Fees are paid by the transaction sender (or
87+
fee payer in zkApp commands) and distributed to block producers through fee
88+
transfers.
89+
90+
### Nonces
91+
92+
User accounts maintain nonces to prevent replay attacks. The `Nonce` type is
93+
generated by a macro along with other currency types in
94+
[`ledger/src/scan_state/currency.rs`](https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/currency.rs#L575-L578).
95+
96+
Each user-initiated transaction must specify the correct nonce, which increments
97+
after successful application.
98+
99+
### Memos
100+
101+
Transactions can include optional 32-byte memos:
102+
103+
<!-- CODE_REFERENCE: ledger/src/scan_state/transaction_logic/mod.rs#L548-L548 -->
104+
105+
```rust reference title="ledger/src/scan_state/transaction_logic/mod.rs"
106+
https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/transaction_logic/mod.rs#L548-L548
107+
```
108+
109+
Memos provide auxiliary information and are included in transaction commitments.
110+
111+
### Slots
112+
113+
A slot is a fixed time interval in the consensus protocol during which a block
114+
can be produced. Slots are used to measure time in the blockchain and determine
115+
block production opportunities.
116+
117+
Transactions include validity windows using slot numbers. The `Slot` type is
118+
generated by a macro along with other currency types in
119+
[`ledger/src/scan_state/currency.rs`](https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/currency.rs#L575-L578).
120+
121+
The `valid_until` field specifies when a transaction expires.
122+
123+
## Account Creation
124+
125+
Creating new accounts requires an account creation fee (1 MINA by default):
126+
127+
```rust
128+
ConstraintConstants {
129+
account_creation_fee: 1_000_000_000, // 1 MINA in nanomina
130+
// ...
131+
}
132+
```
133+
134+
The fee is deducted from the amount being transferred to the new account:
135+
136+
- **Payments**: Sender pays `amount + fee`, receiver gets
137+
`amount - account_creation_fee` (if creating account)
138+
- **Fee transfers**: Receiver gets `fee_amount - account_creation_fee` (if
139+
creating account)
140+
- **Coinbase**: Receiver gets `coinbase_amount - account_creation_fee` (if
141+
creating account)
142+
143+
## Transaction Status
144+
145+
After application, transactions have a status:
146+
147+
<!-- CODE_REFERENCE: ledger/src/scan_state/transaction_logic/mod.rs#L240-L243 -->
148+
149+
```rust reference title="ledger/src/scan_state/transaction_logic/mod.rs"
150+
https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/transaction_logic/mod.rs#L240-L243
151+
```
152+
153+
Failed transactions may still consume fees in some cases (zkApp commands with
154+
fee payer failures).
155+
156+
## Further Reading
157+
158+
- [Coinbase Rewards](./transactions/coinbase) - Block production rewards
159+
160+
Documentation for additional transaction types is coming soon:
161+
162+
- Payment Transactions - Transferring tokens between accounts
163+
- Stake Delegation - Delegating stake to block producers
164+
- Fee Transfers - Protocol fee distribution
165+
- zkApp Commands - Zero-knowledge applications
166+
167+
## Related Files
168+
169+
- [`ledger/src/scan_state/transaction_logic/mod.rs`](https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/transaction_logic/mod.rs) -
170+
Transaction type definitions
171+
- [`ledger/src/scan_state/transaction_logic/transaction_partially_applied.rs`](https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/transaction_logic/transaction_partially_applied.rs) -
172+
First pass application
173+
- [`ledger/src/scan_state/transaction_logic/transaction_applied.rs`](https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/transaction_logic/transaction_applied.rs) -
174+
Second pass application
175+
- [`ledger/src/scan_state/transaction_logic/signed_command.rs`](https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/transaction_logic/signed_command.rs) -
176+
Signed command types
177+
- [`ledger/src/scan_state/transaction_logic/zkapp_command/`](https://github.com/o1-labs/mina-rust/tree/develop/ledger/src/scan_state/transaction_logic/zkapp_command) -
178+
zkApp command implementation
179+
- [`ledger/src/scan_state/currency.rs`](https://github.com/o1-labs/mina-rust/blob/develop/ledger/src/scan_state/currency.rs) -
180+
Currency types (Fee, Nonce, Slot, Amount, Balance)

0 commit comments

Comments
 (0)