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
}
發佈了107 篇原創文章 · 獲贊 147 · 訪問量 51萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章