0
点赞
收藏
分享

微信扫一扫

Mina中的Scan State

未定义变量 2022-04-21 阅读 77
区块链

1. 引言

前序博客见:

  • Mina中的Snark Worker

Mina中的Scan State为一种数据结构,用于解耦transaction SNARKs的生成,可由Snark Worker而不需由产块者来生成。

由于产块者不再需要生成transaction SNARKs,使得不论交易吞吐量如何,可使block production time保持为常量。此外,scan state数据结构支持并行化生成transaction SNARK proof,可由多个竞争的Snark Workers来完成。

scan state由 a forest of full-binary trees组成,其中这些tree的每个节点都为需要snark worker需要完成的job。该scan state会定期返回a single proof from the top of a tree that attests to the correctness of all transactions at the base of the tree。

产块者在其生成的blockchain SNARK中包含发出的ledger proof,证明链的当前状态有效,并证明snarked ledger中包含的所有交易的有效性。
因此,无论交易吞吐量如何,块时间都可能保持不变,scan state能够调整以匹配所需的交易吞吐量。

注意:在稳定状态下,当所有slot都已填满,并且所有必需的证明都已完成时,每个区块都会发出ledger proof。

2. scan state 参数

scan state主要有以下参数:

  • 1)transaction_capacity_log_2:定义了可在一个区块内包含的最大交易数:max_no_of_transactions = 2^{transaction_capacity_log_2}
  • 2)work_delay:保证有足够的时间让snark workers完成该snark work。若没有可用的已完成proof,产块者将无法包含任何交易。通过work_delay,可定义scan sate中允许的最大tree数量:max_number_of_trees = (transaction_capacity_log_2 + 1) * (work_delay + 1) + 1

每个区块内允许包含的最大proof数量为:
max_number_of_proofs = 2^{transaction_capacity_log_2 + 1} - 1

以上这些对scan state的约束可保证,每个区块技能释放一个proof,以及the merge node that is to be updated after adding proofs corresponding to its children is always empty。

当确定了最大交易数,就可动态调整交易吞吐量。scan state可处理无上限的交易吞吐量,代价是logarithmically增加transaction proof latency。

3. including transactions

产块者在构建区块时可包含scan state中定义的最大交易数。在包含交易时,可选择任意可用的交易手续费然后给自己支付a coinbase reward。产块者所增加的每笔交易都被转换为new base jobs,并添加到scan state中。

每增加一笔交易,产块者必须包含等额数量的completed snark work that corresponds to a sequence of jobs that already exist in the scan state。这些completed jobs,当添加到scan state时,create new merge jobs except when it is for the root node, in which case the proof is simply returned as a result。

产块者并不自己完成snark work,而是根据snark pool中的竞价从任意snark workers中购买completed work。

4. Scan state举例

假设scan state的参数为:max_no_of_transactions = 4, work_delay = 1,则意味着 there can be a maximum amount of work to complete equal to 7 and a maximum number of 7 trees。

基本流程为:
B表示base job,M表示merge job,后面的数字表示添加到scan state 的顺序。】
【橙色:表示待由Snark Workers待完成的pending work;
绿色:表示已完成的work,Snark Workers会将已完成的work提交到snark pool中。可能会有多个Snark Worker完成同一work,但是,产块者仅可能购买snark pool中手续费最低的那个。】

  • 1)genesis时,scan state为空。
    在这里插入图片描述
  • 2)Block 1: A block producer includes four transactions into the scan state labeled B1. These transactions fill the base of the first tree.
    在这里插入图片描述
  • 3)Block 2: At the second block, a block producer adds another four transactions (B2). These are added to a second tree, once again filling the base. There are no proofs required due to the work delay of 1 block.
    在这里插入图片描述
  • 4)Block 3: At the third block, a block producer adds four B3 transactions to the third tree but must include four proofs for the first tree. As a result of including these completed base proofs, two new M3 merge jobs are created.
    在这里插入图片描述
  • 5)Block 4: For the fourth block, a block producer adds another four transactions (B4) to the base of the fourth tree. They must include four proofs corresponding to the work added in block 2. Again, two M4 merge jobs are created as a result.
    在这里插入图片描述
  • 6)Block 5: In the fifth block, another four transactions are included to fill the base of tree five (B5), and six proofs must be included (B3s and M3s). The M3 merge jobs result in a final pending merge job for the first tree (M5).
    在这里插入图片描述
  • 7)Block 6: In the sixth block, another four transactions (B6) are added, filling the base of the sixth tree. Six proofs are included (B4 and M4), and three new merge jobs are created (M6).
    在这里插入图片描述
  • 8)Block 7: In the seventh block, a further four transactions (B7) are added by the block producer filling the base of the seventh tree. Seven trees are the maximum number of trees according to the specified scan state constants. The maximum number of proofs (7) are included (B5 and M5). These included proofs create three new merge jobs (M7), and additionally, the top M5 proof is emitted from the scan state.
    在这里插入图片描述
    第一棵树释放的proof 即为对应Block 1中所加入交易的ledger proof,此时,第一颗树的所有内容都将清除,以为额外的交易创造空间。
    在这里插入图片描述
  • 9)Block 8: In the eighth block, the block producer adds two transactions (B8) and includes 4 (B6) proofs. These included proofs result in two new merge jobs (M8). Note that only four proofs are required for adding two transactions.【注意,此时,当添加2笔交易时,仅需要4个proofs。】
    在这里插入图片描述

附录

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
举报

相关推荐

0 条评论