Hyperledger Burrow StateDB

Burrow 借助 Tendermint 管理 p2p 网络和区块共识,在 Tendermint 之外自己维护了一个 StateDB 存储 Burrow 中各种交易的状态数据。

1. 存储结构


Burrow 在 KV DB 之上通过前缀的形式划分出了多个用途的空间,主要有三大类

在这里插入图片描述

1.1 Plain


这一类简单直接,直接操作 DB 存储 KV

包含两种数据:

  1. Tx 存储的存储位置
    存储 Tx 的区块高度和在 Event Tree 中的区块数据中的偏移
    前缀 + Tx Hash 为key,存储区块高度和偏移值

    hth + <tx_hash> -> {height, offset}

    type TxExecutionKey struct {
    	// The block height
    	Height uint64 `protobuf:"varint,1,opt,name=Height,proto3" json:"Height,omitempty"`
    	// The offset of the TxExecution in bytes
    	Offset               uint64   `protobuf:"varint,2,opt,name=Offset,proto3" json:"Offset,omitempty"`
    }
    
  2. 智能合约的元数据
    存储智能合约相关 abi 的元数据,与存放在 Account Tree 下的智能合约账号中 ContractMeta 通过 codehashmetahash 进行关联

    habi + <metahash> -> <abi meta>

1.2 Tree


这一类是大部分状态数据的存储形式,Burrow 使用 IAVL+ Tree 来组织各前缀空间下的数据。

iavl 是一个平衡二叉树实现,只在叶子节点存放数据

存储结构:

  1. 版本对应的 root hash
    ft<type>r + version -> <root hash>

  2. hash 对应的 Node
    ft<type>n + hash -> {Node}

    // Node represents a node in a Tree.
    type Node struct {
    	key       []byte
    	value     []byte
    	hash      []byte
    	leftHash  []byte
    	rightHash []byte
    	version   int64
    	size      int64
    	leftNode  *Node
    	rightNode *Node
    	height    int8
    	saved     bool // saved to memory or disk
    	persisted bool // persisted to disk
    }
    

<type> 为各种类别的前缀

主要有以下的状态树:

类别前缀描述Node KeyNode Value
Accounta存储账号状态,包含智能合约账号addressAccount
Storages智能合约中字段的状态数据address + Field KeyField Value
NamenNameReg提供一个基于名称,数据对的全局键值存储,这些数据对受帐户的到期和所有权约束nameEntry
Proposalp存储 ProposalTx 信息proposalHashBallot
Validatorv存储参与 Tendermint Voting 的节点 Poweraddresspower
Evente存储区块执行的状态信息Height[]StreamEvent
Registryr存储 Validator 节点信息addressNodeIdentity

1.3 Commit


Commit 类状态与 1.2 一样也使用 IAVL+ Tree 来组织数据,不同的是,Commit 记录的是 1.2 中所有 Tree 的保存状态也就是账本的 Commit 状态

存储结构:

  1. 版本对应的 root hash
    fcr + version -> <root hash>

  2. hash 对应的 Node
    fcn + hash -> {Node}

node key:<type prefix>
node value: CommitID

// This is the object that is stored in the leaves of the commitsTree - it captures the sub-tree hashes so that the
// commitsTree's hash becomes a mixture of the hashes of all the sub-trees.
type CommitID struct {
	Version              int64    `protobuf:"varint,1,opt,name=Version,proto3" json:"Version,omitempty"`
	Hash                 []byte   `protobuf:"bytes,2,opt,name=Hash,proto3" json:"Hash,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

2. 代码结构


Burrow 抽出 Forest 来管理各种状态树(包括Commit),State 封装 Forest 对外提供状态查询、更新功能

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1444. Elephpotamus Time limit: 0.5 second Memory limit: 64 MB Harry Potter is taking an examination in Care for Magical Creatures. His task is to feed a dwarf elephpotamus. Harry remembers that elephpotamuses are very straightforward and imperturbable. In fact, they are so straightforward that always move along a straight line and they are so imperturbable that only move when attracted by something really tasty. In addition, if an elephpotamus stumbles into a chain of its own footprints, it falls into a stupor and refuses to go anywhere. According to Hagrid, elephpotamuses usually get back home moving along their footprints. This is why they never cross them, otherwise they may get lost. When an elephpotamus sees its footprints, it tries to remember in detail all its movements since leaving home (this is also the reason why they move along straight lines only, this way it is easier to memorize). Basing on this information, the animal calculates in which direction its burrow is situated, then turns and goes straight to it. It takes some (rather large) time for an elephpotamus to perform these calculations. And what some ignoramuses recognize as a stupor is in fact a demonstration of outstanding calculating abilities of this wonderful, though a bit slow-witted creature. Elephpotamuses' favorite dainty is elephant pumpkins, and some of such pumpkins grow on the lawn where Harry is to take his exam. At the start of the exam, Hagrid will drag the elephpotamus to one of the pumpkins. Having fed the animal with a pumpkin, Harry can direct it to any of the remaining pumpkins. In order to pass the exam, Harry must lead the elephpotamus so that it eats as many pumpkins as possible before it comes across its footprints. Input The first input line contains the number of pumpkins on the lawn N (3 ≤ N ≤ 30000). The pumpkins are numbered from 1 to N, the number one being assigned to the pumpkin to which the animal is brought at the start of the trial. In the next N lines, the coordinates of the pumpkins are given in the order corresponding to their numbers. All the coordinates are integers in the range from −1000 to 1000. It is guaranteed that there are no two pumpkins at the same location and there is no straight line passing through all the pumpkins. Output In the first line write the maximal number K of pumpkins that can be fed to the elephpotamus. In the next K lines, output the order in which the animal will eat them, giving one number in a line. The first number in this sequence must always be 1.写一段Java完成此目的
最新发布
06-03

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值