前序博客见:
- Mina如何实现22KB?
genesis_proof结构比genesis_proof.Inputs结构多一个proof_data字段,少一个blockchain_proof_system_id字段。 但是,proof_data字段中更包含了blockchain_proof_system_id字段。 且Precomputed_values类型等价为genesis_proof结构。
(* genesis_proof.ml中有: *) module T = struct type t = { runtime_config : Runtime_config.t ; constraint_constants : Genesis_constants.Constraint_constants.t ; genesis_constants : Genesis_constants.t ; proof_level : Genesis_constants.Proof_level.t ; genesis_ledger : Genesis_ledger.Packed.t ; genesis_epoch_data : Consensus.Genesis_epoch_data.t ; consensus_constants : Consensus.Constants.t ; protocol_state_with_hashes : Protocol_state.value State_hash.With_state_hashes.t ; constraint_system_digests : (string * Md5_lib.t) list Lazy.t ; proof_data : Proof_data.t option } module Proof_data = struct type t = { blockchain_proof_system_id : Pickles.Verification_key.Id.t ; genesis_proof : Proof.t } end module Inputs = struct type t = { runtime_config : Runtime_config.t ; constraint_constants : Genesis_constants.Constraint_constants.t ; proof_level : Genesis_constants.Proof_level.t ; genesis_constants : Genesis_constants.t ; genesis_ledger : Genesis_ledger.Packed.t ; genesis_epoch_data : Consensus.Genesis_epoch_data.t ; consensus_constants : Consensus.Constants.t ; protocol_state_with_hashes : Protocol_state.value State_hash.With_state_hashes.t ; constraint_system_digests : (string * Md5_lib.t) list option ; blockchain_proof_system_id : (* This is only used for calculating the hash to lookup the genesis proof with. It is re-calculated when building the blockchain prover, so it is always okay -- if less efficient at startup -- to pass [None] here. *) Pickles.Verification_key.Id.t option }
Proof类型为:
type t = (Nat.N2.n, Nat.N2.n) Pickles.Proof.t (* Pickles.Proof结构为: *) module Make (W : Nat.Intf) (MLMB : Nat.Intf) : sig type nonrec t = (W.n, MLMB.n) t [@@deriving sexp, compare, yojson, hash] end type t = (Verification_key.Max_width.n, Verification_key.Max_width.n) Proof.t type ('max_width, 'mlmb) t
State_hash.With_state_hashes类型为:
type 'a t = ('a, State_hashes.t) With_hash.t (* State_hash结构为: *) type t = Field.t (* State_hashes结构为: *) module State_hashes = struct [%%versioned module Stable = struct module V1 = struct type t = { mutable state_body_hash : State_body_hash.Stable.V1.t option ; state_hash : T.Stable.V1.t }
Mina节点启动时,会从配置文件中加载precomputed_values信息:
创世区块的产块者会该precomputed_values信息会作为Genesis_proof.Input,调用Prover.create_genesis_block(…)
来获得创世区块genesis_breadcrumb。genesis_breadcrumb为Blockchain_snark.Blockchain.t结构:【其中的state为Protocol_state结构,proof即为protocol_state_proof。】【将创世区块protocol_state_proof替换precomputed_values的proof_data字段,构建出的即为genesis_proof。】
{ state : Protocol_state.Value.Stable.V2.t; proof : Proof.Stable.V2.t }1.1 Genesis_ledger.Packed结构
type t = (module Intf.S) let t ((module L) : t) = L.t val t : Mina_ledger.Ledger.t Lazy.t include Merkle_mask.Maskable_merkle_tree_intf.S with module Location := Location with module Addr = Location.Addr with type root_hash := Ledger_hash.t and type hash := Ledger_hash.t and type account := Account.t and type key := Public_key.Compressed.t and type token_id := Token_id.t and type token_id_set := Token_id.Set.t and type account_id := Account_id.t and type account_id_set := Account_id.Set.t and type t = Mask.Attached.t and type attached_mask = Mask.Attached.t and type unattached_mask = Mask.t1.2 Constraint_constants结构
所谓Constraint_constants,是指会影响proof约束系统以及密钥生成的常量。当proof_level为Full时,注意这些值应与proving keys和verification keys匹配,否则生成的证明将无效。
Constraint_constants示例为:
Genesis_constants.Constraint_constants结构为:
type t = { sub_windows_per_window : int ; ledger_depth : int ; work_delay : int ; block_window_duration_ms : int ; transaction_capacity_log_2 : int ; pending_coinbase_depth : int ; coinbase_amount : Currency.Amount.Stable.Latest.t ; supercharged_coinbase_factor : int ; account_creation_fee : Currency.Fee.Stable.Latest.t ; fork : Fork_constants.t option } (* 赋值为: *) let compiled = { sub_windows_per_window ; ledger_depth ; work_delay ; block_window_duration_ms ; transaction_capacity_log_2 ; pending_coinbase_depth ; coinbase_amount = Currency.Amount.of_formatted_string coinbase_amount_string ; supercharged_coinbase_factor ; account_creation_fee = Currency.Fee.of_formatted_string account_creation_fee_string ; fork }
而Snark_keys_header.Constraint_constants结构为:【为用于constraint system的常量,Mina主网中未定义fork_previous_length,因此fork=None】
(** The constants used in the constraint system. *) type t = { sub_windows_per_window : int ; ledger_depth : int ; work_delay : int ; block_window_duration_ms : int ; transaction_capacity : Transaction_capacity.t ; pending_coinbase_depth : int ; coinbase_amount : UInt64.t ; supercharged_coinbase_factor : int ; account_creation_fee : UInt64.t ; fork : (Fork_config.t option [@to_yojson Fork_config.opt_to_yojson] [@of_yojson Fork_config.opt_of_yojson]) }1.3 Transition frontier 之 full_frontier结构
(* Invariant: The path from the root to the tip inclusively, will be max_length *) type t = { root_ledger : Ledger.Any_ledger.witness ; mutable root : State_hash.t ; mutable best_tip : State_hash.t ; logger : Logger.t ; table : Node.t State_hash.Table.t ; mutable protocol_states_for_root_scan_state : Protocol_states_for_root_scan_state.t ; consensus_local_state : Consensus.Data.Local_state.t ; max_length : int ; precomputed_values : Precomputed_values.t ; time_controller : Block_time.Controller.t ; persistent_root_instance : Persistent_root.Instance.t } module Node = struct type t = { breadcrumb : Breadcrumb.t ; successor_hashes : State_hash.t list ; length : int }1.4 Mina中的account结构
Mina分为public账号和private账号,结构均为:
module Public_accounts = struct type account_data = { pk : Public_key.Compressed.t ; balance : int ; delegate : Public_key.Compressed.t option ; timing : Timing.t } module Private_accounts = struct type account_data = { pk : Public_key.Compressed.t ; sk : Private_key.t ; balance : int ; timing : Timing.t }
其中account的timing结构为:
type t = (int, int, int) Account_timing.Poly.t type ('slot, 'balance, 'amount) t = (*'slot, 'balance,'amount均为int类型。*) | Untimed | Timed of { initial_minimum_balance : 'balance ; cliff_time : 'slot ; cliff_amount : 'amount ; vesting_period : 'slot ; vesting_increment : 'amount }2. Snark transition
snark transition结构为:
(* snark_transition结构为: *) type t = ( Blockchain_state.Value.Stable.V2.t (* 字段名为blockchain_state *) , Consensus.Data.Consensus_transition.Value.Stable.V1.t (* 字段名为consensus_transition *) , Pending_coinbase.Update.Stable.V1.t ) (* 字段名为pending_coinbase_update *) Poly.Stable.V1.t type ('blockchain_state, 'consensus_transition, 'pending_coinbase_update) t = { blockchain_state : 'blockchain_state ; consensus_transition : 'consensus_transition ; pending_coinbase_update : 'pending_coinbase_update }2.1 Blockchain_state结构
Blockchain_state结构为:
(* Blockchain_state.value结构为: *) type t = ( Staged_ledger_hash.Stable.V1.t (* 字段名为staged_ledger_hash *) , Frozen_ledger_hash.Stable.V1.t (* 字段名为snarked_ledger_hash *) , Local_state.Stable.V1.t (* 字段名为local_state *) , Block_time.Stable.V1.t ) (* 字段名为timestamp *) Poly.Stable.V2.t type ('staged_ledger_hash, 'snarked_ledger_hash, 'local_state, 'time) t = { staged_ledger_hash : 'staged_ledger_hash ; genesis_ledger_hash : 'snarked_ledger_hash (* 字段名为genesis_ledger_hash,又名snarked_ledger_hash *) ; registers : (* 字段名registers中封装了genesis_ledger_hash、unit、local_state 以及Registers*) ('snarked_ledger_hash, unit, 'local_state) Registers.Stable.V1.t ; timestamp : 'time } (* Registers.Stable.V1.1结构为: *) type ('ledger, 'pending_coinbase_stack, 'local_state) t = { ledger : 'ledger ; pending_coinbase_stack : 'pending_coinbase_stack ; local_state : 'local_state }
Local_state结构为:
(* mina_transaction_logic.ml中: *) module Local_state = struct type t = ( Parties.t , Call_stack.t , Token_id.t , Amount.t , Ledger.t , Bool.t , Transaction_commitment.t , Bool.failure_status_tbl ) Parties_logic.Local_state.t (* Parties_logic.Local_data结构为: *) type ( 'parties , 'call_stack , 'token_id , 'excess , 'ledger , 'bool , 'comm , 'failure_status_tbl ) t = { parties : 'parties (* parties字段为Parties类型 *) ; call_stack : 'call_stack (* call_stack字段为Call_stack类型 *) ; transaction_commitment : 'comm (* transaction_commitment字段为Transaction_commitment类型 *) ; full_transaction_commitment : 'comm (* full_transaction_commitment字段为Transaction_commitment类型 *) ; token_id : 'token_id (* token_id字段为Token_id类型 *) ; excess : 'excess (* excess字段为Amount类型 *) ; ledger : 'ledger (* ledger字段为Ledger类型 *) ; success : 'bool (* success字段为Bool类型 *) ; failure_status_tbl : 'failure_status_tbl (* failure_status_tbl字段为Bool.failure_status_tbl类型 *) }
创世块的该结构类似为:
Registers结构为:
(* Registers结构为: *) type t = ( Frozen_ledger_hash.t , Pending_coinbase.Stack.t , Local_state.t ) Stable.Latest.t type ('ledger, 'pending_coinbase_stack, 'local_state) t = { ledger : 'ledger (* ledger字段为Frozen_ledger_hash类型 *) ; pending_coinbase_stack : 'pending_coinbase_stack (* pending_coinbase_stack字段为Pending_coinbase.Stack类型 *) ; local_state : 'local_state (* local_state字段为Local_state类型 *) }
Pending_coinbase.Stack结构为:
(* Pending_coinbase.Stack结构为: *) type t = (Coinbase_stack.Stable.V1.t, (* 为Field.t *) State_stack.Stable.V1.t) Poly.Stable.V1.t module V1 = struct type ('data_stack, 'state_stack) t = { data : 'data_stack; state : 'state_stack } (* State_stack类型为: *) type t = Stack_hash.Stable.V1.t (* 为Field.t *) Poly.Stable.V1.t module V1 = struct type 'stack_hash t = { init : 'stack_hash; (* init字段为Stack_hash字段 *) curr : 'stack_hash } (* curr字段为Stack_hash字段 *)2.2 Consensus.Data.Consensus_transition结构
Consensus.Data.Consensus_transition结构为:【就是global slot数字】
(* Consensus.Data.Consensus_transition结构为: *) module Consensus_transition = struct include Mina_numbers.Global_slot module Value = Mina_numbers.Global_slot type var = Checked.t let genesis = zero end2.3 Pending_coinbase.Update结构
Pending_coinbase.Update结构为:
(* Pending_coinbase.Update结构为:*) type t = (Action.Stable.V1.t, Amount.Stable.V1.t) (* 为unsigned类型 *) Poly.Stable.V1.t type ('action, 'coinbase_amount) t = { action : 'action; (* action字段为Action类型 *) coinbase_amount : 'coinbase_amount } (* coinbase_amount字段为Amount类型 *) (* Actiion为枚举类型: *) type t = | Update_none | Update_one | Update_two_coinbase_in_first | Update_two_coinbase_in_second3. Internal transition
internal transition结构为:
(* internal transition结构为: *) type t = Stable.Latest.t = { snark_transition : Snark_transition.Value.t (* 见上一节Snark transition内容 *) ; ledger_proof : Ledger_proof.t option ; prover_state : Consensus.Data.Prover_state.t ; staged_ledger_diff : Staged_ledger_diff.t }3.1 Snark_transition结构
Snark_transition结构:见上一节Snark transition内容。
3.2 Ledger_proof结构Ledger_proof结构:【等价为Transaction_snark结构】
(* Ledger_proof结构为: *) module Prod : Ledger_proof_intf.S with type t = Transaction_snark.t = struct [%%versioned module Stable = struct module V2 = struct type t = Transaction_snark.Stable.V2.t
- 2.1)Transaction_snark结构为:
(* transaction_snark/transaction_snark.ml中有Transaction_snark结构为:: *) module Stable = struct module V2 = struct type t = { statement : Statement.With_sok.Stable.V2.t; proof : Proof.Stable.V2.t }
Statement.With_sok结构为:
(* Statement.With_sok结构为: *) module With_sok = struct [%%versioned module Stable = struct module V2 = struct type t = ( Frozen_ledger_hash.Stable.V1.t , Currency.Amount.Stable.V1.t , Pending_coinbase.Stack_versioned.Stable.V1.t (* 见上面的 Pending_coinbase.Stack结构 *) , Fee_excess.Stable.V1.t , Sok_message.Digest.Stable.V1.t (* 为string类型 *) , Local_state.Stable.V1.t ) (* 见上面Local_state结构 *) (* Fee_excess结构为: *) type t = ( Token_id.Stable.V1.t , (Fee.Stable.V1.t, (* 为uint64 *) Sgn.Stable.V1.t) (* Sgn为枚举:Pos或Neg,即代表极性。 *) Signed_poly.Stable.V1.t ) Poly.Stable.V1.t (* Signed_poly中字段有: *) type ('magnitude, 'sgn) t = { magnitude : 'magnitude; (* magnitude字段为Fee类型 *) sgn : 'sgn } (* sgn字段为Sgn枚举类型,Pos或Neg *) (* Poly中字段有: *) type ('token, 'fee) t = { fee_token_l : 'token (* fee_token_l字段为Token_id类型 *) ; fee_excess_l : 'fee (* fee_excess_l字段为Sgined_poly类型,包含magnitude和sgn这2个字段。 *) ; fee_token_r : 'token (* fee_token_r字段为Token_id类型 *) ; fee_excess_r : 'fee (* fee_excess_r字段为Sgined_poly类型,包含magnitude和sgn这2个字段。 *) }
- 2.2)Proof结构为:
module Proof = struct [%%versioned module Stable = struct module V2 = struct type t = Pickles.Proof.Branching_2.Stable.V2.t
Pickles.Proof.Branching_2结构为:
(* Pickles.Proof.Branching_2结构为: *) type t = ( ( Tock.Inner_curve.Affine.t , Reduced_me_only.Wrap.Challenges_vector.t MLMB_vec.t ) Types.Wrap.Proof_state.Me_only.t , ( unit , Tock.Curve.Affine.t Max_branching_at_most.t , Challenge.Constant.t Scalar_challenge.t Bulletproof_challenge.t Step_bp_vec.t Max_branching_at_most.t ) Base.Me_only.Step.t ) Base.Wrap.t3.3 Consensus.Data.Prover_state结构
Consensus.Data.Prover_state结构为:【等同为Stake_proof结构】
(* Consensus.Data.Prover_state结构为: *) type t = { delegator : Account.Index.Stable.V1.t (* 为int类型,即delegator在Account tree中的位置? *) ; delegator_pk : Public_key.Compressed.Stable.V1.t (* 为压缩公钥 *) ; coinbase_receiver_pk : Public_key.Compressed.Stable.V1.t (* 为压缩公钥 *) ; ledger : Mina_ledger.Sparse_ledger.Stable.V2.t ; producer_private_key : Private_key.Stable.V1.t (* 为产块者私钥 *) ; producer_public_key : Public_key.Stable.V1.t (* 为产块者公钥 *) }
Mina_ledger.Sparse_ledger结构为:
(* Mina_ledger.Sparse_ledger结构为: *) type t = ( Ledger_hash.Stable.V1.t (* 为Field.t类型 *) , Account_id.Stable.V2.t (* 类型为Public_key.Compressed.Stable.V1.t * Digest.Stable.V1.t *) , Account.Stable.V2.t ) Sparse_ledger_lib.Sparse_ledger.T.Stable.V2.t type ('hash, 'key, 'account) t = { indexes : ('key * int) list ; depth : int ; tree : ('hash, 'account) Tree.Stable.V1.t }
Account结构为:【具有的字段为:public_key、token_id、token_permissions、token_symbol、balance、balance、nonce、receipt_chain_hash、delegate、voting_for、timing、permissions、zkapp、zkapp_url。】
type t = ( Public_key.Compressed.Stable.V1.t , Token_id.Stable.V1.t , Token_permissions.Stable.V1.t , Token_symbol.Stable.V1.t , Balance.Stable.V1.t , Nonce.Stable.V1.t , Receipt.Chain_hash.Stable.V1.t , Public_key.Compressed.Stable.V1.t option , State_hash.Stable.V1.t , Timing.Stable.V1.t , Permissions.Stable.V2.t , Zkapp_account.Stable.V2.t option , string ) (* TODO: Cache the digest of this? *) Poly.Stable.V2.t type ( 'pk , 'id , 'token_permissions , 'token_symbol , 'amount , 'nonce , 'receipt_chain_hash , 'delegate , 'state_hash , 'timing , 'permissions , 'zkapp_opt , 'zkapp_uri ) t = { public_key : 'pk ; token_id : 'id ; token_permissions : 'token_permissions ; token_symbol : 'token_symbol ; balance : 'amount ; nonce : 'nonce ; receipt_chain_hash : 'receipt_chain_hash ; delegate : 'delegate ; voting_for : 'state_hash ; timing : 'timing ; permissions : 'permissions ; zkapp : 'zkapp_opt ; zkapp_uri : 'zkapp_uri }3.4 Staged_ledger_diff结构
Staged_ledger_diff结构为:
type t = Pre_diff_with_at_most_two_coinbase.t * Pre_diff_with_at_most_one_coinbase.t option (* Pre_diff_with_at_most_two_coinbase结构为: *) module Pre_diff_with_at_most_two_coinbase : sig type t = (Transaction_snark_work.t, User_command.t With_status.t) Pre_diff_two.t (* With_status中字段有: *) type 'a t = { data : 'a; (* data字段为User_command类型 *) status : Transaction_status.Stable.V2.t } (* Pre_diff_two中字段有: *) type ('a, 'b) t = { completed_works : 'a list (* completed_works为数组,元素均为Transaction_snark_work类型 *) ; commands : 'b list (* commands为数组,元素均为With_status类型 *) ; coinbase : Ft.Stable.V1.t At_most_two.Stable.V1.t ; internal_command_balances : Transaction_status.Internal_command_balance_data.Stable.V1.t list (* 数组 *) } (* Transaction_status为枚举类型: *) type t = Applied | Failed of Failure.Collection.Stable.V1.t (* User_command *) type t = ( Signed_command.With_valid_signature.Stable.V2.t , Parties.Valid.Stable.V1.t ) Poly.Stable.V2.t (* 为枚举类型:type ('u, 's) t = Signed_command of 'u | Parties of 's *) (* Signed_command: *) type t = ( Payload.Stable.V2.t , Public_key.Stable.V1.t , Signature.Stable.V1.t ) Poly.Stable.V1.t type ('payload, 'pk, 'signature) t = { payload : 'payload; signer : 'pk; signature : 'signature } (* Pre_diff_with_at_most_one_coinbase结构为: *) type t = ( Transaction_snark_work.Stable.V2.t , User_command.Stable.V2.t With_status.Stable.V2.t ) Pre_diff_one.Stable.V1.t (* Pre_diff_one中字段有: *) type ('a, 'b) t = { completed_works : 'a list ; commands : 'b list ; coinbase : Ft.Stable.V1.t At_most_one.Stable.V1.t ; internal_command_balances : Transaction_status.Internal_command_balance_data.Stable.V1.t list }4. External transition
external transition结构为:【等价为Block结构】
(* external transition结构为: *) type t = Block.t type t = { header : Header.Stable.V1.t; body : Body.Stable.V1.t }4.1 Header结构
Header结构为:
type t = { protocol_state : Protocol_state.Value.Stable.V2.t ; protocol_state_proof : Proof.Stable.V2.t [@sexp.opaque] ; delta_block_chain_proof : (* TODO: abstract *) State_hash.Stable.V1.t * State_body_hash.Stable.V1.t list ; current_protocol_version : Protocol_version.Stable.V1.t ; proposed_protocol_version_opt : Protocol_version.Stable.V1.t option ; body_reference : Body_reference.Stable.V1.t }
其中:
- (1)protocol_state、protocol_state_proof内容见:Mina概览 第5节“Mina区块结构”。
- (2)delta_block_chain_proof内容见: Mina中的delta_transition_chain_proof/delta_block_chain_proof
- (3)current_protocol_version结构为:
type t = { major : int; minor : int; patch : int }
- (4)Body_reference结构为:
(* type t = State_body_hash.Stable.V1.t *) type t = unit [@@deriving compare, sexp, yojson]4.2 Body结构
Body结构为:
type t = { staged_ledger_diff : Staged_ledger_diff.Stable.V2.t }
Staged_ledger_diff结构见上面。
5. BreadcrumbTransition Frontier:为本地data store中包含的网络中的最新 k k k个区块。为rose tree-type数据结构,该tree中的每个节点可能有多个children,即分叉。该tree中的每个节点都可称为breadcrumb。其实就是已验证通过的区块。
Breadcrumb结构为:
type t = { validated_transition : Mina_block.Validated.t ; staged_ledger : Staged_ledger.t [@sexp.opaque] ; just_emitted_a_proof : bool ; transition_receipt_time : Time.t option }5.1 Mina_block.Validated结构
Mina_block.Validated结构,即为validated_block结构:【其实就是一个结构体,其data字段为External_transition结构,其hash字段为State_hashes结构(包含state_body_hash和state_hash字段)。以及,一个State_hash*State_hash数组。】
type t = Block.t State_hash.With_state_hashes.t * State_hash.t Non_empty_list.t
- 1)State_hash.With_state_hashes结构为:【在上面的代码语境中,'a表示的是Block.t结构】
type 'a t = ('a, State_hashes.t) With_hash.t (* State_hashes.t结构为: *) type t = { mutable state_body_hash : State_body_hash.Stable.V1.t option (* 均为Field.t *) ; state_hash : T.Stable.V1.t (* 均为Field.t *) } (* With_hash结构为:【此语境下,'a表示的是Block.t结构,'h表示的是State_hashes结构】*) type ('a, 'h) t = ('a, 'h) Stable.Latest.t = { data : 'a; hash : 'h }
- 2)State_hash.t为Field.t,而Non_empty_list结构为:【其实表示的就是State_hash*State_hash数组。此代码语境下,'a表示的State_hash结构。为a tuple of the head and the rest (as a list)】
type 'a t = 'a * 'a list5.2 Staged_ledger结构
Staged_ledger结构为:
type t = { scan_state : Scan_state.t ; ledger : ((* Invariant: this is the ledger after having applied all the transactions in the above state. *) Ledger.attached_mask [@sexp.opaque]) ; constraint_constants : Genesis_constants.Constraint_constants.t ; pending_coinbase_collection : Pending_coinbase.t }5.2.1 Scan_state结构
Scan_state结构为:【等价为Transaction_snark_scan_state】
type t = ( Ledger_proof_with_sok_message.Stable.V2.t , Transaction_with_witness.Stable.V2.t ) Parallel_scan.State.Stable.V1.t type ('merge, 'base) t = ('merge, 'base) Binable_arg.Stable.V1.t = { trees : ('merge Merge.Stable.V1.t, 'base Base.Stable.V1.t) Tree.Stable.V1.t Non_empty_list.Stable.V1.t (*use non empty list*) ; acc : ('merge * 'base list) option (*last emitted proof and the corresponding transactions*) ; curr_job_seq_no : int (*Sequence number for the jobs added every block*) ; max_base_jobs : int (*transaction_capacity_log_2*) ; delay : int }
- 1)Ledger_proof_with_sok_message结构为:【其中Ledger_proof结构见上面3.2节。】
type t = Ledger_proof.Stable.V2.t * Sok_message.Stable.V1.t (* Sok_message结构为: *) type t = { fee : Currency.Fee.Stable.V1.t ; prover : Public_key.Compressed.Stable.V1.t }
-
2)Transaction_with_witness结构为:
(* TODO: The statement is redundant here - it can be computed from the witness and the transaction *) type t = { transaction_with_info : Mina_transaction_logic.Transaction_applied.Stable.V2.t ; state_hash : State_hash.Stable.V1.t * State_body_hash.Stable.V1.t ; statement : Transaction_snark.Statement.Stable.V2.t ; init_stack : Transaction_snark.Pending_coinbase_stack_state.Init_stack.Stable.V1 .t ; ledger_witness : Mina_ledger.Sparse_ledger.Stable.V2.t [@sexp.opaque] }
- 2.1)Mina_transaction_logic.Transaction_applied结构为:
type t = { previous_hash : Ledger_hash.Stable.V1.t (* 为Field.t结构 *) ; varying : Varying.Stable.V2.t } (* Varying为枚举结构: *) type t = | Command of Command_applied.Stable.V2.t | Fee_transfer of Fee_transfer_applied.Stable.V2.t | Coinbase of Coinbase_applied.Stable.V2.t (* Command_applied结构为: *) type t = | Signed_command of Signed_command_applied.Stable.V2.t | Parties of Parties_applied.Stable.V1.t (* Signed_command_applied结构为: *) type t = { common : Common.Stable.V2.t; body : Body.Stable.V2.t } (* Parties_applied结构为: *) type t = { accounts : (Account_id.Stable.V2.t * Account.Stable.V2.t option) list ; command : Parties.Stable.V1.t With_status.Stable.V2.t ; previous_empty_accounts : Account_id.Stable.V2.t list } (* Fee_transfer_applied结构为: *) type t = { fee_transfer : Fee_transfer.Stable.V2.t ; previous_empty_accounts : Account_id.Stable.V2.t list ; receiver_timing : Account.Timing.Stable.V1.t } (* Coinbase_applied结构为: *) type t = { coinbase : Coinbase.Stable.V1.t ; previous_empty_accounts : Account_id.Stable.V2.t list ; receiver_timing : Account.Timing.Stable.V1.t }
- 2.2)Transaction_snark.Statement结构为:
type t = ( Frozen_ledger_hash.Stable.V1.t , Currency.Amount.Stable.V1.t , Pending_coinbase.Stack_versioned.Stable.V1.t , Fee_excess.Stable.V1.t , unit , Local_state.Stable.V1.t ) Poly.Stable.V2.t type ( 'ledger_hash , 'amount , 'pending_coinbase , 'fee_excess , 'sok_digest , 'local_state ) t = { source : ( 'ledger_hash , 'pending_coinbase , 'local_state ) Registers.Stable.V1.t ; target : ( 'ledger_hash , 'pending_coinbase , 'local_state ) Registers.Stable.V1.t ; supply_increase : 'amount ; fee_excess : 'fee_excess ; sok_digest : 'sok_digest }
Pending_coinbase.Stack_versioned结构为:type t = (Coinbase_stack.Stable.V1.t, (* 为Field.t *) State_stack.Stable.V1.t) Poly.Stable.V1.t type ('data_stack, 'state_stack) t = { data : 'data_stack; state : 'state_stack } (* State_stack结构为: *) type t = Stack_hash.Stable.V1.t (* 为Field.t *) Poly.Stable.V1.t type 'stack_hash t = { init : 'stack_hash; curr : 'stack_hash }
- 2.3) Transaction_snark.Pending_coinbase_stack_state.Init_stack结构为:【为Pending_coinbase.Stack_versioned】
type t = Base of Pending_coinbase.Stack_versioned.Stable.V1.t | Merge
Ledger.attached_mask结构为:【等效为Mask.Attached.t,见masking_merkle_tree.ml】
type t = { uuid : Uuid.Stable.V1.t ; account_tbl : Account.t Location_binable.Table.t ; token_owners : Account_id.Stable.Latest.t Token_id.Table.t ; mutable parent : Parent.t ; detached_parent_signal : Detached_parent_signal.t ; hash_tbl : Hash.t Addr.Table.t ; location_tbl : Location.t Account_id.Table.t ; mutable current_location : Location.t option ; depth : int }5.2.3 Genesis_constants.Constraint_constants结构
Genesis_constants.Constraint_constants结构为:
(** Constants that affect the constraint systems for proofs (and thus also key generation). Care must be taken to ensure that these match against the proving/ verification keys when [proof_level=Full], otherwise generated proofs will be invalid. *) module Constraint_constants = struct type t = { sub_windows_per_window : int ; ledger_depth : int ; work_delay : int ; block_window_duration_ms : int ; transaction_capacity_log_2 : int ; pending_coinbase_depth : int ; coinbase_amount : Currency.Amount.Stable.Latest.t ; supercharged_coinbase_factor : int ; account_creation_fee : Currency.Fee.Stable.Latest.t ; fork : Fork_constants.t option }5.2.4 Pending_coinbase结构
Pending_coinbase结构为:
(* A pending coinbase is basically a Merkle tree of "stacks", each of which contains two hashes. The first hash is computed from the components in the coinbase via a "push" operation. The second hash, a protocol state hash, is computed from the state *body* hash in the coinbase. The "add_coinbase" operation takes a coinbase, retrieves the latest stack, or creates a new one, and does a push. A pending coinbase also contains a stack id, used to determine the chronology of stacks, so we can know which is the oldest, and which is the newest stack. The name "stack" here is a misnomer: see issue #3226 *) type t = ( Merkle_tree_versioned.Stable.V2.t , Stack_id.Stable.V1.t ) (* 为int *) Poly_versioned.Stable.V1.t type ('tree, 'stack_id) t = ('tree, 'stack_id) T.Poly.t = { tree : 'tree; pos_list : 'stack_id list; new_pos : 'stack_id }
Merkle_tree_versioned结构为:
type t = ( Hash_versioned.Stable.V1.t (* 为Field.t *) , Stack_id.Stable.V1.t (* 为int *) , Stack_versioned.Stable.V1.t ) (* 见上面Stack_versioned *) Sparse_ledger_lib.Sparse_ledger.T.Stable.V2.t type ('hash, 'key, 'account) t = { indexes : ('key * int) list ; depth : int ; tree : ('hash, 'account) Tree.Stable.V1.t }附录1. Mina系列博客
Mina系列博客有:
- Mina概览
- Mina的支付流程
- Mina的zkApp
- Mina中的Pasta(Pallas和Vesta)曲线
- Mina中的Schnorr signature
- Mina中的Pickles SNARK
- Mina中的Kimchi SNARK
- Mina Kimchi SNARK 代码解析
- Mina Berkeley QANet测试网zkApp初体验
- Mina中的Poseidon hash
- Mina中的多项式承诺方案
- Recursive SNARKs总览
- Mina技术白皮书
- Mina代码解析
- Mina中的Snark Worker
- Mina中的Scan State
- Mina中的VRF
- Mina中的delta_transition_chain_proof/delta_block_chain_proof
- Mina中的stake delegation
- Mina如何实现22KB?
- Mina中的stake_proof