长安链研究笔记 - 数据存储
作者:李
- 2022 年 7 月 14 日
本文字数:1872 字
阅读完需:约 6 分钟
本文已参与「开源摘星计划」,欢迎正在阅读的你加入。活动链接:https://github.com/weopenprojects/WeOpen-Star
长安链研究笔记-数据存储
先熟悉一些基本概念,后面再逐渐分析源码
一.存储数据主要分为 5 类
1.区块数据(Block DB)
主要记录区块元信息和交易数据
区块元数据包括:区块头、区块 DAG、区块中交易的 txid 列表,additionalData 等;
交易数据,即序列化后的交易体,为了提供对单笔交易数据的查询,所以对交易数据进行了单独存储。
type Block struct { // 区块头 Header *BlockHeader `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` //区块DAG Dag *DAG `protobuf:"bytes,2,opt,name=dag,proto3" json:"dag,omitempty"` // 区块中交易信息 Txs []*Transaction `protobuf:"bytes,3,rep,name=txs,proto3" json:"txs,omitempty"` //附加信息 AdditionalData *AdditionalData `protobuf:"bytes,4,opt,name=additional_data,json=additionalData,proto3" json:"additional_data,omitempty"`}复制代码
type BlockHeader struct { // 区块版本号 BlockVersion uint32 `protobuf:"varint,1,opt,name=block_version,json=blockVersion,proto3" json:"block_version,omitempty"` // 区块类型:配置区块,普通区块,其他 BlockType BlockType `protobuf:"varint,2,opt,name=block_type,json=blockType,proto3,enum=common.BlockType" json:"block_type,omitempty"` // 区块所在链 ChainId string `protobuf:"bytes,3,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` // 区块高度 BlockHeight uint64 `protobuf:"varint,4,opt,name=block_height,json=blockHeight,proto3" json:"block_height,omitempty"` // 区块hash BlockHash []byte `protobuf:"bytes,5,opt,name=block_hash,json=blockHash,proto3" json:"block_hash,omitempty"` // 前一个区块hash PreBlockHash []byte `protobuf:"bytes,6,opt,name=pre_block_hash,json=preBlockHash,proto3" json:"pre_block_hash,omitempty"` //前一个配置区块高度,用来跟踪和检查链配置是否正确 PreConfHeight uint64 `protobuf:"varint,7,opt,name=pre_conf_height,json=preConfHeight,proto3" json:"pre_conf_height,omitempty"` // 交易数量 TxCount uint32 `protobuf:"varint,8,opt,name=tx_count,json=txCount,proto3" json:"tx_count,omitempty"`
//merkle树的根节点,用来验证交易是否存在 TxRoot []byte `protobuf:"bytes,9,opt,name=tx_root,json=txRoot,proto3" json:"tx_root,omitempty"` //DagHash DagHash []byte `protobuf:"bytes,10,opt,name=dag_hash,json=dagHash,proto3" json:"dag_hash,omitempty"` // The root hash of Merkle tree generated by read_write_set_digest in the result of each transaction in the block // used to verify the read-write set of the block RwSetRoot []byte `protobuf:"bytes,11,opt,name=rw_set_root,json=rwSetRoot,proto3" json:"rw_set_root,omitempty"` // the time stamp of the block BlockTimestamp int64 `protobuf:"varint,12,opt,name=block_timestamp,json=blockTimestamp,proto3" json:"block_timestamp,omitempty"` // consensus parameters // used to store information, include in block hash calculation ConsensusArgs []byte `protobuf:"bytes,13,opt,name=consensus_args,json=consensusArgs,proto3" json:"consensus_args,omitempty"`
//proposal 节点标识 Proposer *accesscontrol.Member `protobuf:"bytes,14,opt,name=proposer,proto3" json:"proposer,omitempty"` //proposer 签名 Signature []byte `protobuf:"bytes,15,opt,name=signature,proto3" json:"signature,omitempty"`}复制代码
// transaction execution sequence// Using adjacency table storagetype DAG struct { // sequence number of transaction topological sort // the sequence number of the transaction topological sort associated with the transaction Vertexes []*DAG_Neighbor `protobuf:"bytes,2,rep,name=vertexes,proto3" json:"vertexes,omitempty"`}复制代码
2.状态数据(State DB)
3.历史数据(History DB)
4.合约执行结果读写集数据(Result DB)
5.事件数据(Contract Event DB)
二.存储预写日志机制(wal)
为了保障不同数据库间的不一致性,引入了 Block binary log 来持久化原始内容,用于重启过程中的数据恢复
三逻辑架构图
划线
评论
复制
发布于: 刚刚阅读数: 4
李
关注
还未添加个人签名 2018.05.04 加入
还未添加个人简介










评论