@@ -442,17 +442,63 @@ impl FailureCollection {
442442 }
443443}
444444
445- /// Structure of the failure status:
446- /// I. No fee transfer and coinbase transfer fails: `[[failure]]`
447- /// II. With fee transfer-
448- /// Both fee transfer and coinbase fails:
449- /// `[[failure-of-fee-transfer]; [failure-of-coinbase]]`
450- /// Fee transfer succeeds and coinbase fails:
451- /// `[[];[failure-of-coinbase]]`
452- /// Fee transfer fails and coinbase succeeds:
453- /// `[[failure-of-fee-transfer];[]]`
445+ /// Applies a coinbase transaction to the ledger.
446+ ///
447+ /// Processes the coinbase by first applying the optional fee transfer (if present),
448+ /// then applying the coinbase reward to the receiver. Updates account balances and
449+ /// timing, creates accounts if needed, and handles permission checks.
450+ ///
451+ /// # Implementation Notes
452+ ///
453+ /// - When `coinbase.fee_transfer` is `Some`, processes fee transfer first, then
454+ /// coinbase receiver gets `coinbase.amount - fee_transfer.fee`
455+ /// - When `coinbase.fee_transfer` is `None`, coinbase receiver gets full
456+ /// `coinbase.amount`
457+ /// - Calls `has_permission_to_receive` for each recipient
458+ /// - Calls `sub_account_creation_fee` when creating new accounts
459+ /// - Calls `update_timing_when_no_deduction` for timing validation
460+ /// - Only updates coinbase receiver timing when `fee_transfer` is `None`
461+ /// - Uses `FailureCollection` to track which operations succeeded/failed
462+ ///
463+ /// # Parameters
464+ ///
465+ /// - `constraint_constants`: Protocol constants including account creation fees
466+ /// - `txn_global_slot`: Current global slot for timing validation
467+ /// - `ledger`: Mutable ledger to update
468+ /// - `coinbase`: Coinbase transaction containing receiver, amount, and optional
469+ /// fee transfer
470+ ///
471+ /// # Returns
472+ ///
473+ /// Returns [`CoinbaseApplied`] containing:
474+ /// - `coinbase`: The input coinbase with transaction status
475+ /// - `new_accounts`: Vector of newly created account IDs
476+ /// - `burned_tokens`: Amount of tokens burned from failed transfers
454477///
455- /// <https://github.com/MinaProtocol/mina/blob/2ee6e004ba8c6a0541056076aab22ea162f7eb3a/src/lib/transaction_logic/mina_transaction_logic.ml#L2022>
478+ /// # Errors
479+ ///
480+ /// Returns `Err` if:
481+ /// - `fee_transfer.fee` exceeds `coinbase.amount` (checked subtraction fails)
482+ /// - Burned tokens overflow when summing across transfers
483+ ///
484+ /// For protocol-level documentation and behavioral specification, see:
485+ /// <https://o1-labs.github.io/mina-rust/docs/developers/transactions/coinbase>
486+ ///
487+ /// # Tests
488+ ///
489+ /// Test coverage (in `ledger/tests/test_transaction_logic_first_pass_coinbase.rs`):
490+ ///
491+ /// - `test_apply_coinbase_without_fee_transfer`
492+ /// - `test_apply_coinbase_with_fee_transfer`
493+ /// - `test_apply_coinbase_with_fee_transfer_creates_account`
494+ /// - `test_apply_coinbase_with_fee_transfer_to_same_account`
495+ /// - `test_apply_coinbase_creates_account`
496+ ///
497+ /// # OCaml Reference
498+ ///
499+ /// OCaml reference: src/lib/transaction_logic/mina_transaction_logic.ml L:2074-2178
500+ /// Commit: 0063f0196d046d9d2fc8af0cea76ff30f51b49b7
501+ /// Last verified: 2025-10-16
456502pub fn apply_coinbase < L > (
457503 constraint_constants : & ConstraintConstants ,
458504 txn_global_slot : & Slot ,
0 commit comments