Skip to content

Commit f9e49d2

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 f9e49d2

File tree

1 file changed

+181
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)