以太坊有3种节点:
- Full node
- Light node
- Archive node
其中light node为:
- Stores the header chain and requests everything else.
- Can verify the validity of the data against the state roots in the block headers.
- Useful for low capacity devices, such as embedded devices or mobile phones, which can’t afford to store gigabytes of blockchain data.
当前Geth已支持light client,最新消息可参与 ethereum light client官方群。
根据 Light Ethereum Subprotocol (LES) 可知,light client仅下载区块头,不挖矿也不参与共识。
2. Canonical Hash TrieLES使用Canonical Hash Trie (CHT) structure 来快速initial syncing and secure on-demand retrieval of canonical hash mappings, block headers and total difficulty (TD) values。
A CHT为a Merkle trie(以太坊state 使用Merkle Patricia Trie) 。 CHT中包含了blockNumber->[blockHash, TD]
mappings,其中keys为binary big endian encoded 64 bit integers,values为RLP-encoded [hash, number]
pairs。
CHT由LES servers每隔32768个区块生成。CHT[i]
中包含了0..(i+1)*322768-1
区块数据。若client知道CHT[i]
的root hash,且想fetch header number N
(其中N< (i+1)*32768
),client可获取该header,并通过GetHelperTrieProofs
请求来获取相应的Merkle proof of the CHT。
CHT仅在2048个确认之后才会生成,这样才可保证chain不会被reorg。当前版本的light client实现中将主网和测试网的[chtNumber, chtRoot]
写死了。未来,计划将实现trustless validation algorithm。
BloomBits优化了log search,采用的方法为: 通过bitwise transformation,使得retrieve bloom filter data relevant to a specific filter的成本更低。
当 search in a long section of the block history时,需要check three specific bits of each bloom filter per queried address/topic。为此,LES必须retrieve a ~550 byte block header per filtered block。
通过a “bitwise 90 degree rotation” of the bloom filters,BloomBits结构可优化bloom filter lookups。 会将固定数量的区块打包(LES BloomBits Trie的size为32768 blocks)。 BloomBits[bitIdx][sectionIdx]
is a 32768 bit (4096 byte) long bit vector that contains a single bit of each bloom filter from the block range sectionIdx*SectionSize ... (sectionIdx+1)*SectionSize-1
。 由于bloom filters通常是系数的,可采用压缩算法进一步压缩,效率会更高。 通过read并binary-add three BloomBits sections,可一次性filter an address/topic in 32768 blocks(“1” bits in the binary AND result mean bloom matches)。
BloomBits数据是以压缩形式存在的。该压缩算法对具有很多zero bytes的稀疏数据进行了优化。 解压缩时需要知道the decompressed data length。
压缩算法的伪代码表示为:
if data only contains zeroes,
CompressBytes(data) == nil
otherwise if len(data)
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?