{区块链教程}以太坊源码分析fast sync算法二

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了{区块链教程}以太坊源码分析fast sync算法二相关的知识,希望对你有一定的参考价值。

{区块链教程}以太坊源码分析fast sync算法二:
上面的表格应该这样解释:如果我们每隔K个区块头验证一次区块头,在N个区块头之后,伪造的概率小于***者产生SHA3冲突的概率。这也意味着,如果确实发现了伪造,那么最后的N个头部应该被丢弃,因为不够安全。可以从上表中选择任何{N,K}对,为了选择一个看起来好看点的数字,我们选择N = 2048,K = 100。后续可能会根据网络带宽/延迟影响以及可能在一些CPU性能比较受限的设备上运行的情况来进行调整。

Using this caveat however would mean, that the pivot point can be considered secure only after N headers have been imported after the pivot itself. To prove the pivot safe faster, we stop the "gapped verificatios" X headers before the pivot point, and verify every single header onward, including an additioanl X headers post-pivot before accepting the pivot‘s state. Given the above N and K numbers, we chose X=24 as a safe number.

然而,使用这个特性意味着,只有导入N个区块之后再导入pivot节点才被认为是安全的。 为了更快地证明pivot的安全性,我们在距离pivot节点X距离的地方停止隔块验证的行为,对随后出现的每一个块进行验证直到pivot。鉴于上述N和K数字,我们选择X = 24作为安全数字。

With this caveat calculated, the fast sync should be modified so that up to the pivoting point - X, only every K=100-th header should be verified (at random), after which all headers up to pivot point + X should be fully verified before starting state database downloading. Note: if a sync fails due to header verification the last N headers must be discarded as they cannot be trusted enough.

通过计算caveat,快速同步需要修改为pivoting point - X,每隔100个区块头随机挑选其中的一个来进行验证,之后的每一个块都需要在状态数据库下载完成之后完全验证,如果因为区块头验证失败导致的同步失败,那么最后的N个区块头都需要被丢弃,应为他们达不到信任标准。

缺点 Weakness

Blockchain protocols in general (i.e. Bitcoin, Ethereum, and the others) are susceptible to Sybil attacks, where an attacker tries to completely isolate a node from the rest of the network, making it believe a false truth as to what the state of the real network is. This permits the attacker to spend certain funds in both the real network and this "fake bubble". However, the attacker can only maintain this state as long as it‘s feeding new valid blocks it itself is forging; and to successfully shadow the real network, it needs to do this with a chain height and difficulty close to the real network. In short, to pull off a successful Sybil attack, the attacker needs to match the network‘s hash rate, so it‘s a very expensive attack.

常见的区块链(比如比特币,以太坊以及其他)是比较容易受女巫的影响,者试图把被者从主网络上完全隔离开,让被者接收一个虚假的状态。这就允许者在真实的网络同时这个虚假的网络上花费同一笔资金。然而这个需要者提供真实的自己锻造的区块,而且需要成功的影响真实的网络,就需要在区块高度和难度上接近真实的网络。简单来说,为了成功的实施女巫者需要接近主网络的hash rate,所以是一个非常昂贵的***。

Compared to the classical Sybil attack, fast sync provides such an attacker with an extra ability, that of feeding a node a view of the network that‘s not only different from the real network, but also that might go around the EVM mechanics. The Ethereum protocol only validates state root hashes by processing all the transactions against the previous state root. But by skipping the transaction processing, we cannot prove that the state root contained within the fast sync pivot point is valid or not, so as long as an attacker can maintain a fake blockchain that‘s on par with the real network, it could create an invalid view of the network‘s state.

与传统的女巫相比,快速同步为者提供了一种额外的能力,即为节点提供一个不仅与真实网络不同的网络视图,而且还可能绕过EVM机制。 以太坊协议只通过处理所有事务与以前的状态根来验证状态根散列。 但是通过跳过事务处理,我们无法证明快速同步pivot point中包含的state root是否有效,所以只要***者能够保持与真实网络相同的假区块链,就可以创造一个无效的网络状态视图。

To avoid opening up nodes to this extra attacker ability, fast sync (beside being solely opt-in) will only ever run during an initial sync (i.e. when the node‘s own blockchain is empty). After a node managed to successfully sync with the network, fast sync is forever disabled. This way anybody can quickly catch up with the network, but after the node caught up, the extra attack vector is plugged in. This feature permits users to safely use the fast sync flag (--fast), without having to worry about potential state root attacks happening to them in the future. As an additional safety feature, if a fast sync fails close to or after the random pivot point, fast sync is disabled as a safety precaution and the node reverts to full, block-processing based synchronization.

为了避免将节点开放给这个额外的者能力,快速同步(特别指定)将只在初始同步期间运行(节点的本地区块链是空的)。 在一个节点成功与网络同步后,快速同步永远被禁用。 这样任何人都可以快速地赶上网络,但是在节点追上之后,额外的矢量就被插入了。这个特性允许用户安全地使用快速同步标志(--fast),而不用担心潜在的状态 在未来发生的根***。 作为附加的安全功能,如果快速同步在随机 pivot point附近或之后失败,则作为安全预防措施禁用快速同步,并且节点恢复到基于块处理的完全同步。

性能 Performance

To benchmark the performance of the new algorithm, four separate tests were run: full syncing from scrath on Frontier and Olympic, using both the classical sync as well as the new sync mechanism. In all scenarios there were two nodes running on a single machine: a seed node featuring a fully synced database, and a leech node with only the genesis block pulling the data. In all test scenarios the seed node had a fast-synced database (smaller, less disk contention) and both nodes were given 1GB database cache (--cache=1024).

为了对新算法的性能进行基准测试,运行了四个单独的测试:使用经典同步以及新的同步机制,从Frontier和Olympic上的scrath完全同步。 在所有情况下,在一台机器上运行两个节点:具有完全同步的数据库的种子节点,以及只有起始块拉动数据的水蛭节点。 在所有测试场景中,种子节点都有一个快速同步的数据库(更小,更少的磁盘争用),两个节点都有1GB的数据库缓存(--cache = 1024)。

The machine running the tests was a Zenbook Pro, Core i7 4720HQ, 12GB RAM, 256GB m.2 SSD, Ubuntu 15.04.

运行测试的机器是Zenbook Pro,Core i7 4720HQ,12GB RAM,256GB m.2 SSD,Ubuntu 15.04。

Dataset (blocks, states)?? Normal sync (time, db)???? Fast sync (time, db)
Frontier, 357677 blocks, 42.4K states?? 12:21 mins, 1.6 GB???? 2:49 mins, 235.2 MB
Olympic, 837869 blocks, 10.2M states??? 4:07:55 hours, 21 GB?? 31:32 mins, 3.8 GB

The resulting databases contain the entire blockchain (all blocks, all uncles, all transactions), every transaction receipt and generated logs, and the entire state trie of the head 1024 blocks. This allows a fast synced node to act as a full archive node from all intents and purposes.

结果数据库包含整个区块链(所有区块,所有的区块,所有的交易),每个交易收据和生成的日志,以及头1024块的整个状态树。 这使得一个快速的同步节点可以充当所有意图和目的的完整归档节点。

结束语 Closing remarks

The fast sync algorithm requires the functionality defined by eth/63. Because of this, testing in the live network requires for at least a handful of discoverable peers to update their nodes to eth/63. On the same note, verifying that the implementation is truly correct will also entail waiting for the wider deployment of eth/63.

快速同步算法需要由eth / 63定义的功能。 正因为如此,现网中的测试至少需要少数几个可发现的对等节点将其节点更新到eth / 63。 同样的说明,验证这个实施是否真正正确还需要等待eth / 63的更广泛部署。

以上是关于{区块链教程}以太坊源码分析fast sync算法二的主要内容,如果未能解决你的问题,请参考以下文章

以太坊源码分析(52)以太坊fast sync算法

区块链教程以太坊源码分析core-state源码分析

区块链教程以太坊源码分析core-state-process源码分析

区块链教程以太坊源码分析core-state源码分析

区块链教程以太坊源码分析以太坊随机数生成方式一

区块链教程以太坊源码分析core-state-process源码分析