Skip to content

Commit e0c71dc

Browse files
authored
Merge pull request #1531 from o1-labs/dw/documentation-transaction-logic
Document codebase in transaction_logic
2 parents b8d4c16 + d02f8d0 commit e0c71dc

File tree

12 files changed

+974
-347
lines changed

12 files changed

+974
-347
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7979
are now built as part of the existing build workflows across all platforms,
8080
reusing build caches for efficiency
8181
([#1539](https://github.com/o1-labs/mina-rust/pull/1539))
82+
- **Ledger**: document, clean and add tests for the crate `mina-tree`
83+
([#1531](https://github.com/o1-labs/mina-rust/pull/1531).
8284

8385
## v0.17.0
8486

core/src/constants.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,28 @@ pub struct ForkConstants {
2121
pub global_slot_since_genesis: u32,
2222
}
2323

24+
/// Protocol constraint constants
2425
#[derive(Clone, Debug)]
2526
pub struct ConstraintConstants {
27+
/// Number of sub-windows in a single slot window
2628
pub sub_windows_per_window: u64,
29+
/// Depth of the account ledger Merkle tree
2730
pub ledger_depth: u64,
31+
/// Number of slots to delay SNARK work for proof generation
2832
pub work_delay: u64,
33+
/// Duration of each block window in milliseconds
2934
pub block_window_duration_ms: u64,
35+
/// Log2 of maximum transactions per block
3036
pub transaction_capacity_log_2: u64,
37+
/// Depth of the pending coinbase Merkle tree
3138
pub pending_coinbase_depth: usize,
39+
/// Base amount awarded for producing a block
3240
pub coinbase_amount: u64,
41+
/// Multiplier for coinbase when account is "supercharged"
3342
pub supercharged_coinbase_factor: u64,
43+
/// Fee charged for creating a new account
3444
pub account_creation_fee: u64,
45+
/// Optional fork configuration for protocol upgrades
3546
pub fork: Option<ForkConstants>,
3647
}
3748
#[derive(Clone, Debug, BinProtWrite)]

ledger/src/account/account.rs

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,24 +1264,98 @@ pub struct PermsConst {
12641264
pub or_const: bool,
12651265
}
12661266

1267-
// <https://github.com/MinaProtocol/mina/blob/1765ba6bdfd7c454e5ae836c49979fa076de1bea/src/lib/mina_base/account.ml#L368>
1267+
/// Represents a Mina account stored in the ledger.
1268+
///
1269+
/// An account is the fundamental unit of state in the Mina ledger. Each
1270+
/// account is uniquely identified by a public key and token ID pair, and
1271+
/// contains the account's balance, transaction nonce, and various protocol
1272+
/// metadata.
1273+
///
1274+
/// Accounts can be regular user accounts holding the native Mina token, or
1275+
/// more complex entities such as custom token accounts or zkApp accounts with
1276+
/// programmable smart contract functionality.
1277+
///
1278+
/// The account structure is designed to support:
1279+
/// - Token transfers and balance tracking
1280+
/// - Stake delegation for consensus participation
1281+
/// - Time-locked vesting schedules
1282+
/// - Flexible permission policies for different operations
1283+
/// - Zero-knowledge application state and verification
1284+
///
1285+
/// OCaml reference: src/lib/mina_base/account.ml L:201-224
1286+
/// Commit: fc6be4c58091c761f827c858229c2edf9519e941
1287+
/// Last verified: 2025-10-13
12681288
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
12691289
#[serde(into = "v2::MinaBaseAccountBinableArgStableV2")]
12701290
#[serde(try_from = "v2::MinaBaseAccountBinableArgStableV2")]
12711291
pub struct Account {
1272-
pub public_key: CompressedPubKey, // Public_key.Compressed.t
1273-
pub token_id: TokenId, // Token_id.t
1274-
/// the `token_symbol` describes a token id owned by the account id
1275-
/// from this account, not the token id used by this account
1276-
pub token_symbol: TokenSymbol, // Token_symbol.t
1277-
pub balance: Balance, // Balance.t
1278-
pub nonce: Nonce, // Nonce.t
1279-
pub receipt_chain_hash: ReceiptChainHash, // Receipt.Chain_hash.t
1280-
pub delegate: Option<CompressedPubKey>, // Public_key.Compressed.t option
1281-
pub voting_for: VotingFor, // State_hash.t
1282-
pub timing: Timing, // Timing.t
1283-
pub permissions: Permissions<AuthRequired>, // Permissions.t
1284-
pub zkapp: Option<Box<ZkAppAccount>>, // Zkapp_account.t
1292+
/// The public key that controls this account. This is the address used
1293+
/// to identify the account and authorize transactions.
1294+
pub public_key: CompressedPubKey,
1295+
1296+
/// The token type this account holds. The default token (value 1)
1297+
/// represents the native Mina token. Custom tokens have different
1298+
/// values derived from their creator's account.
1299+
pub token_id: TokenId,
1300+
1301+
/// The symbol for a custom token that this account can create or manage.
1302+
/// Note: this describes a token ID owned by this account (i.e., a token
1303+
/// this account can create), not the token type used by this account's
1304+
/// balance.
1305+
pub token_symbol: TokenSymbol,
1306+
1307+
/// The current balance of the account in the smallest unit (nanomina for
1308+
/// the default token, or the smallest unit for custom tokens).
1309+
pub balance: Balance,
1310+
1311+
/// The sequence number for transactions from this account. Incremented by
1312+
/// [`pay_fee_impl`](crate::scan_state::transaction_logic::transaction_partially_applied::pay_fee_impl)
1313+
/// for signed commands and by the zkApp application logic in
1314+
/// [`apply`](crate::zkapps::zkapp_logic::apply) when processing account
1315+
/// updates.
1316+
pub nonce: Nonce,
1317+
1318+
/// A hash chain of all transaction receipts involving this account,
1319+
/// providing a tamper-evident history. Updated by
1320+
/// [`cons_signed_command_payload`](crate::scan_state::transaction_logic::transaction_union_payload::cons_signed_command_payload)
1321+
/// for signed commands and
1322+
/// [`cons_zkapp_command_commitment`](crate::scan_state::transaction_logic::transaction_union_payload::cons_zkapp_command_commitment)
1323+
/// for zkApp commands.
1324+
pub receipt_chain_hash: ReceiptChainHash,
1325+
1326+
/// The public key of the account to which this account delegates its
1327+
/// stake for consensus. If `None`, the account delegates to itself (or
1328+
/// cannot delegate if using a custom token). Delegation allows accounts
1329+
/// to participate in consensus without running a block producer.
1330+
pub delegate: Option<CompressedPubKey>,
1331+
1332+
/// The state hash this account is voting for in the consensus protocol.
1333+
/// Updated through zkApp account updates in
1334+
/// [`apply`](crate::zkapps::zkapp_logic::apply).
1335+
pub voting_for: VotingFor,
1336+
1337+
/// The vesting schedule for this account's funds. Either `Untimed`
1338+
/// (fully liquid) or `Timed` with parameters defining when and how
1339+
/// tokens unlock over time. Updated by
1340+
/// [`pay_fee_impl`](crate::scan_state::transaction_logic::transaction_partially_applied::pay_fee_impl)
1341+
/// for signed commands and through zkApp account updates in
1342+
/// [`apply`](crate::zkapps::zkapp_logic::apply).
1343+
pub timing: Timing,
1344+
1345+
/// The permissions controlling what operations can be performed on this
1346+
/// account and what authorization is required (none, signature, proof,
1347+
/// or both). Updated through zkApp account updates in
1348+
/// [`apply`](crate::zkapps::zkapp_logic::apply).
1349+
pub permissions: Permissions<AuthRequired>,
1350+
1351+
/// zkApp-specific account data. If `Some`, this account is a zkApp
1352+
/// (zero-knowledge application) with additional state including app
1353+
/// state fields, a verification key, action state, and other zkApp
1354+
/// metadata. Regular accounts have `None`. Managed through
1355+
/// [`AccountInterface::make_zkapp`](crate::zkapps::interfaces::AccountInterface::make_zkapp)
1356+
/// and
1357+
/// [`AccountInterface::unmake_zkapp`](crate::zkapps::interfaces::AccountInterface::unmake_zkapp).
1358+
pub zkapp: Option<Box<ZkAppAccount>>,
12851359
}
12861360

12871361
impl Account {

0 commit comments

Comments
 (0)