超级账本Hyperledger fabric的区块结构

> 之前学习比特币和以太坊,必先学习其区块结构,当时在银行做Hyperledger相关项目时,我却对结构很忽略,只关心智能合约,居然也能初步掌握并开始项目相关的开发。这说明超级账本的区块属性其实比较弱,重要的是智能合约的属性。性能也不错。从这个意义上讲Hyperledger用来做存证是大材小用的。

问题1:交易是怎么存入区块的?

Transactions are collected into blocks/batches on the ordering service first. Blocks are cut either when the BatchSize is met, or when BatchTimeout elapses (provided a non-empty block).

也就是说,满足这2个条件,区块生成了:

  • 交易数量够了

  • 超时时间到了


所以Hyperledger的区块生成不是定时的,高峰时间,区块生成速度明显加快

  • configtx.yaml in the common/configtx/tool/ directory for more info on the block-cutting criteria.

  • The Block type definition in protos/common/common.proto

Hyperledger参数

和以太坊一样,hyperledger的区别,也有区块号、指向前一个区块的指针、指向数据的指针,因为没有挖矿,头部简洁了很多

// This is finalized block structure to be shared among the orderer and peer

// Note that the BlockHeader chains to the previous BlockHeader, and the BlockData hash is embedded

// in the BlockHeader. This makes it natural and obvious that the Data is included in the hash, but

// the Metadata is not.

message Block {

BlockHeader header = 1;

BlockData data = 2;

BlockMetadata metadata = 3;

}

// BlockHeader is the element of the block which forms the block chain

// The block header is hashed using the configured chain hashing algorithm

// over the ASN.1 encoding of the BlockHeader

message BlockHeader {

**uint64 number = 1;** // The position in the blockchain

**bytes previous_hash = 2;** // The hash of the previous block header

**bytes data_hash = 3;** // The hash of the BlockData, by MerkleTree

}

message BlockData {

repeated bytes data = 1;

}

message BlockMetadata {

repeated bytes metadata = 1;

}


问题2:怎么存入LevelDB

These blocks are stored locally to disk on every ordering service node along with a LevelDB to index these blocks by number – see orderer/ledger/file

// Append a new block to the ledger

func (fl *fileLedger) Append(block *cb.Block) error {

    err := fl.blockStore.AddBlock(block)

    if err == nil {

        close(fl.signal)

        fl.signal = make(chan struct{})

    }

    return err

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值