【通读EOS白皮书】应用程序的确定性并行执行-01

in #cn7 years ago

今年币圈链圈一个重大事件就是:EOS在6.1日正式发布,但是还有非常多的人从未阅读过EOS技术白皮书。在此我准备做一个通读EOS白皮书系列,主要是翻译官方原文并加入个人解释的形式展现,水平有限,欢迎大家讨论交流。
微信公众号:blockd-public
微信号:点击查看


应用程序的确定性并行执行

区块链共识依赖于确定性(可重复)行为。这也是说,所有并行执行必须不能涉及互斥或用到其他有锁特点的因素。在不使用锁时必须有办法保证所有账户只能读写自己的私有数据库。这表示每个账户要按顺序处理消息,并行机制发生在账户级别。

解释:确定性就是说,输入一样,结果也要一样。并行执行 简单理解成同时执行。锁可以理解成你上侧所的时候关门上锁,其他人必须等你出来之后才能进去。

在基于EOS.IO 软件的区块链中,区块生产者的一个任务就是组织消息传递到独立的线程,以便消息可以并行评估。每个账户的状态只取决于发送给它的消息。区块生产者输出的安排是确定性执行,但是输出安排的过程没必要是确定性的。这意味着区块生产者可以使用并行算法来调度安排交易。

解释:就像从上海开车去北京,线路有很多,但是方案定好就只有一个线路。

并行执行的某种程度上意味着当脚本生成一条新消息时不会立即发出,反而这条消息会被安排到下一周期发送。不能立即发送的原因是因为接收者可以正在另一个线程修改它自己的状态呢。

解释:一个账户同时只能处在一个状态。就像一个人接到了两个命令,向左转向右转,这是没办法同时做到的,所以只能按顺序来。


原文如下

Deterministic Parallel Execution of Applications

Blockchain consensus depends upon deterministic (reproducible) behavior. This means all parallel execution must be free from the use of mutexes or other locking primitives. Without locks there must be some way to guarantee that all accounts can only read and write their own private database. It also means that each account processes messages sequentially and that parallelism will be at the account level.

In an EOS.IO software-based blockchain, it is the job of the block producer to organize message delivery into independent threads so that they can be evaluated in parallel. The state of each account depends only upon the messages delivered to it. The schedule is the output of a block producer and will be deterministically executed, but the process for generating the schedule need not be deterministic. This means that block producers can utilize parallel algorithms to schedule transactions.

Part of parallel execution means that when a script generates a new message it does not get delivered immediately, instead it is scheduled to be delivered in the next cycle. The reason it cannot be delivered immediately is because the receiver may be actively modifying its own state in another thread.