IBM openblockchain学习(五)--consensus源码分析

这段时间小编一直忙着找实习,现在开始接着分析了,不好意思让大家久等了。好了,直接上干货。
consensus是blockchain中实现obc peer端一致性的插件,诸位请看

consensus

// Consenter用于从网络接收消息
// 每一个consensus插件需要实现这个接口
type Consenter interface {
    RecvMsg(msg *pb.OpenchainMessage, senderHandle *pb.PeerID) error
}

// Inquirer 用于获取有关网络网络的验证信息
type Inquirer interface {
    GetNetworkInfo() (self *pb.PeerEndpoint, network []*pb.PeerEndpoint, err error)
    GetNetworkHandles() (self *pb.PeerID, network []*pb.PeerID, err error)
}

// Communicator 用于发送消息给其他验证端
type Communicator interface {
    Broadcast(msg *pb.OpenchainMessage, peerType pb.PeerEndpoint_Type) error
    Unicast(msg *pb.OpenchainMessage, receiverHandle *pb.PeerID) error
}

// SecurityUtils 用于访问标志/验证crypto包中的方法
type SecurityUtils interface {
    Sign(msg []byte) ([]byte, error)
    Verify(peerID *pb.PeerID, signature []byte, message []byte) error
}

// ReadOnlyLedger 用于询问区块链
type ReadOnlyLedger interface {
    GetBlock(id uint64) (block *pb.Block, err error)
    GetCurrentStateHash() (stateHash []byte, err error)
    GetBlockchainSize() (uint64, error)
}

// UtilLedger 包含询问区块链的附加的实用功能
type UtilLedger interface {
    HashBlock(block *pb.Block) ([]byte, error)
    VerifyBlockchain(start, finish uint64) (uint64, error)
}

// WritableLedger is 用户更新转移blockchain状态过程
type WritableLedger interface {
    PutBlock(blockNumber uint64, block *pb.Block) error
    ApplyStateDelta(id interface{}, delta *statemgmt.StateDelta) error
    CommitStateDelta(id interface{}) error
    RollbackStateDelta(id interface{}) error
    EmptyState() error
}

// Ledger is 一个不受限制的读取、效用和更新的联合
type Ledger interface {
    ReadOnlyLedger
    UtilLedger
    WritableLedger
}

// Executor is 用于调用交易接口,有可能修改依托总账
type Executor interface {
    BeginTxBatch(id interface{}) error
    ExecTxs(id interface{}, txs []*pb.Transaction) ([]byte, error)
    CommitTxBatch(id interface{}, metadata []byte) (*pb.Block, error)
    RollbackTxBatch(id interface{}) error
    PreviewCommitTxBatch(id interface{}, metadata []byte) (*pb.Block, error)
}

// RemoteLedgers is 用于查询blockchain的其他副本
type RemoteLedgers interface {
    GetRemoteBlocks(replicaID *pb.PeerID, start, finish uint64) (<-chan *pb.SyncBlocks, error)
    GetRemoteStateSnapshot(replicaID *pb.PeerID) (<-chan *pb.SyncStateSnapshot, error)
    GetRemoteStateDeltas(replicaID *pb.PeerID, start, finish uint64) (<-chan *pb.SyncStateDeltas, error)
}

// LedgerStack 用作面向blockchain的活动接口,诸如执行交易,查询和更新总账
type LedgerStack interface {
    Executor
    Ledger
    RemoteLedgers
}

// Stack 可用于consensus插件的一套面向堆栈的方法
type Stack interface {
    Inquirer
    Communicator
    SecurityUtils
    LedgerStack
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值