## 1、一切从数据开始。
我们对比下etherum和pe:
下面是ethereum的block header:
~~~
type Header struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner"`
Root common.Hash `json:"stateRoot" gencodec:"required"`
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Number *big.Int `json:"number" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Time uint64 `json:"timestamp" gencodec:"required"`
Extra []byte `json:"extraData" gencodec:"required"`
MixDigest common.Hash `json:"mixHash"`
Nonce BlockNonce `json:"nonce"`
// BaseFee was added by EIP-1559 and is ignored in legacy headers.
BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"`
/*
TODO (MariusVanDerWijden) Add this field once needed
// Random was added during the merge and contains the BeaconState randomness
Random common.Hash `json:"random" rlp:"optional"`
*/
}
~~~
下面是ep的block header:
~~~
type Header struct {
ParentHash Hash `json:"parentHash"`
Sha3Uncles Hash `json:"sha3Uncles"`
Miner Address `json:"miner"`
StateRoot Hash `json:"stateRoot"`
TxRoot Hash `json:"transactionsRoot"`
ReceiptsRoot Hash `json:"receiptsRoot"`
LogsBloom Bloom `json:"logsBloom"`
Difficulty uint64 `json:"difficulty"`
Number uint64 `json:"number"`
GasLimit uint64 `json:"gasLimit"`
GasUsed uint64 `json:"gasUsed"`
Timestamp uint64 `json:"timestamp"`
ExtraData []byte `json:"extraData"`
MixHash Hash `json:"mixHash"`
Nonce Nonce `json:"nonce"`
Hash Hash `json:"hash"`
}
~~~
ep 目前不支持以太坊最新的EIP-1599协议,其它部分和ethereum玩去一致(虽然变量名称有些有区别,但数据类型完全一致,甚至映射的json名称也完全一致)。
我们再看看block的结构比较:
下面是ep的block结构:
~~~
type Block struct {
Header *Header
Transactions []*Transaction
Uncles []*Header
// Cache
size atomic.Value // *uint64
}
~~~
下面是ethereum的block结构:
~~~
type Block struct {
header *Header
uncles []*Header
transactions Transactions
// caches
hash atomic.Value
size atomic.Value
// These fields are used by package eth to track
// inter-peer block relay.
ReceivedAt time.Time
ReceivedFrom interface{}
}
~~~
其中Transactions类型结构定义如下:
~~~
type Transactions []*Transaction
~~~
可以看出,ep的block结构相比,少了hash(cache字段,可以计算出来)、ReceviedAt、ReceivedFrom字段(后两个字段用于eth进行跟踪)。ep少了这几个字段,对于跨链数据交换影响不大(跨链交换当然需要对源链的block数据进行数据抽取,然后按照目标链的结构进行重构)。
block的真正content是body,我们看看两者的结构:
ethereum的body结构:
~~~
// Body is a simple (mutable, non-safe) data container for storing and moving
// a block's data contents (transactions and uncles) together.
type Body struct {
Transactions []*Transaction
Uncles []*Header
}
~~~
下面是ep的body结构:
~~~
type Body struct {
Transactions []*Transaction
Uncles []*Header
}
~~~
两者的body结构完全相同。
以下是对block结构字段的阐述:
1. **parentHash:**The block header hash of the previous block. Each block contains the hash of the previous block, all the way back to the genesis block on the chain. This is the structural design that maintains the data from being tampered with (any tampering to the previous block will affect the hash value of all subsequent blocks).
2. **ommersHash:**The uncle block header and the hash value of part of the block body.
3. **beneficiary:**The Ethereum account that gets paid for mining this block.
4. **stateRoot:**The hash of the root node of the world state tree (after all transactions have been executed).
5. **transactionsRoot:**The hash value of the root node of the transaction tree. This tree contains all transactions in the block body.
6. **receiptsRoot:**Every time a transaction is executed, Ethereum generates a transaction receipt corresponding to the result. Here is the root node hash of this transaction receipt tree.
7. **logsBloom:**It is used to judge whether the transaction of a certain block generates a certain log. This avoids storing log information in chunks (saves a lot of space).
8. **difficulty:**The difficulty value of this block. This is a measure of the mining difficulty of the current block
9. **number:**The total number of preorder blocks. This indicates the height of the blockchain (i.e. how many blocks are on the blockchain). The number of the genesis block is 0 .
10. **gasLimit:**Every transaction requires gas. The gas limit indicates the total amount of gas that can be used by all transactions recorded in this block. This is a means of limiting the number of transactions in a block.
11. **gasUsed:**The total amount of gas actually consumed by each exchange in the block.
12. **timestamp:**The Unix timestamp when the block was created.
13. **extraData:**A variable-length byte array that can enter anything. When miners create blocks, anything can be added to this area.
14. **mixHash:**The hash value used to verify that a block was actually recorded on the chain.
15. **nonce:**Like**mixHash**, the value used to verify that the block was actually recorded on-chain.
简要翻译如下:
* Prev Hash - 父区块的Keccak哈希值
* Nonce - 用于工作证明的计算
* Timestamp - 时间戳
* Uncles Hash - 叔块的Keccak哈希值
* Benficiary - 受益人地址,矿工地址
* Logs Bloom - 事件地址和事件topic的布隆滤波器
* Difficult - 前一个区块的难度
* Extra Data - 与该区块相关的32字节数据
* Block Num - 祖先块数
* Gas Limit -当前每个区块的gas使用限制值
* Gas Used - 该区块中用于交易的gas消耗值
* Mix Hash - 与nonce一起用来证明工作证明计算的256位值
* State Root - 状态树的根哈希值
* Transaction Root - 交易树的根哈希值
* Receipt Root - 收据树的根哈希值
## 2、数据存储结构
我们先看看bitcoin的链结构:
![](https://img.kancloud.cn/91/9d/919d05cc142e506cb4b234d50d70b68f_1048x582.png)
图描述很清楚,不做赘述。
我们再看看以太坊的链结构:
![](https://img.kancloud.cn/53/3e/533e9c911dc25c0a45cfffe15010cc8d_1048x728.png)
- 重要更新说明
- linechain发布
- linechain新版设计
- 引言一
- 引言二
- 引言三
- vs-code设置及开发环境设置
- BoltDB数据库应用
- 关于Go语言、VS-code的一些Tips
- 区块链的架构
- 网络通信与区块链
- 单元测试
- 比特币脚本语言
- 关于区块链的一些概念
- 区块链组件
- 区块链第一版:基本原型
- 区块链第二版:增加工作量证明
- 区块链第三版:持久化
- 区块链第四版:交易
- 区块链第五版:实现钱包
- 区块链第六版:实现UTXO集
- 区块链第七版:网络
- 阶段小结
- 区块链第八版:P2P
- P2P网络架构
- 区块链网络层
- P2P区块链最简体验
- libp2p建立P2P网络的关键概念
- 区块链结构层设计与实现
- 用户交互层设计与实现
- 网络层设计与实现
- 建立节点发现机制
- 向区块链网络请求区块信息
- 向区块链网络发布消息
- 运行区块链
- LineChain
- 系统运行流程
- Multihash
- 区块链网络的节点发现机制深入探讨
- DHT
- Bootstrap
- 连接到所有引导节点
- Advertise
- 搜索其它peers
- 连接到搜到的其它peers
- 区块链网络的消息订发布-订阅机制深入探讨
- LineChain:适用于智能合约编程的脚本语言支持
- LineChain:解决分叉问题
- LineChain:多重签名
- libp2p升级到v0.22版本
- 以太坊基础
- 重温以太坊的树结构
- 世界状态树
- (智能合约)账户存储树
- 交易树
- 交易收据树
- 小结
- 以太坊的存储结构
- 以太坊状态数据库
- MPT
- 以太坊POW共识算法
- 智能合约存储
- Polygon Edge
- block结构
- transaction数据结构
- 数据结构小结
- 关于本区块链的一些说明
- UML工具-PlantUML
- libp2p介绍
- JSON-RPC
- docker制作:启动多个应用系统
- Dockerfile
- docker-entrypoint.sh
- supervisord.conf
- docker run
- nginx.conf
- docker基础操作整理
- jupyter计算交互环境
- git技巧一
- git技巧二
- 使用github项目的最佳实践
- windows下package管理工具