6. HyperLedger中的共识机制

IBM开源技术微讲堂
区块链和HyperLedger系列列
第六讲
Hyperledger中的共识机制
扫码⼊入群,与讲师互动
h,p://ibm.biz/opentech-ma
1
“区块链和HyperLedger”系列列公开课
•  每周四晚8点档
1. 
2. 
3. 
4. 
5. 
6. 
7. 
8. 
区块链商⽤用之道
HyperLedger项⽬目与社区概览
HyperLedgerFabric架构解读
ChainCode实战
HyperLedger中的共享账本
HyperLedger中的共识机制
HyperLedger中的隐私与安全
HyperLedger应⽤用案例例赏析
Q&A环节
扫码⼊入群,与讲师互动
课程Wiki:h,p://ibm.biz/opentech-ma
往期视频:h,p://list.youku.com/albumlist/show?id=49106065
2
讲师介绍
3
议程
• Blockchain-Hyperledger
• Distributedsystemanditsrelatedissues
• Consensus
•  Permissioned(voUng)consensus
•  BFTindetails
•  Constraintsrelatedto(Vanilla)BFT
•  ConsensusmechanisminHyperledgerv1.0
• Summary
• Q&A
4
Blockchain-
Hyperledger
5
DistributedSystems
•  CAPM
•  TemporalOrders
•  SynchronizaUon
•  …
•  …
6
Permissioned(vo@ng)Consensus
•  ClassicalDistributedCompuUngprotocols(since‘80s)
•  VoUngbased
•  Consensusdespitemachinefaultsand(temporary)networkparUUons
Whatmachinefaults?
•  Crashfaults(CFT):AmachinesimplystopsexecuUonandhalts
•  Paxos,RAFT,ZookeeperAB,…
•  Non-crash(a.k.a.ByzanUne)faults(BFT)
#237
A
Somecryptocurrenciescases:
…
#234
#235
#236
#237
B
#238
B
#239
B
Noforks!
7
GrowingPermissionedBlockchains
Client A
txA
Party A
Client B
Party F
txB
Party B
Distributed
Consensus
Client E
txE
Party C
Party E
Party D
#237
A
…
#234
#235
#236
#237
B
Noforks!
(finality)
#238
B
#239
B
8
Permissionedconsensusguarantees
•  (Vanilla)BFT:Upton/3ParUescanbemalicious,notfollowprotocol
•  CFT–Upton/2ParUescanfailbycrashing
•  Newmodels–XFT[OSDI2016]
•  Consensuswithupton/2corrupt,ByzanUneParUes(withcertain
assumpUonsonnetworkparUUons)
Faultmodel
CFT
XFT
BFT
NumberofNodes
2f+1
2f+1
3f+1
Tolera@ngByzan@ne
Nodes
no
yes
yes
Performance
Good
PracUcallyasgoodasCFT
WorsethanCFT
9
BFTConsensus
(exampleofPBFT[TOCS2002])
Blockchain
Operator
Smart
Contract
peer
O
deployedtoand
executeson
peernodes
configures,
operates
Exactnetworkstructuredepends
onconsensusmechanism.e.g.
PBFThasleader,validaUngand
non-validaUngpeers
sc sc sc
…
…
sc sc sc
…
…
ApplicaUon
invokeSC
sc sc sc
…
consensusmsg
sc sc sc
…
…
…
Consensus
Network
consensusmessagesflow
betweenappropriatepeersto
ensuretheBlockchainSC
transacUonsarekeptin
order;worldstateiskept
consistentthroughlocal
transacUonreplay
10
HowaPBFTNetworkWorks(1/4)–Submission
N
Non-validaUngpeer
V
ValidaUngpeer
VL
456
789
123
N
ValidaUngLeader
456
789
123
VL
123
456
123
789
V
…
…
TransacUon
submi,edto
network
789
V
…
V
TransacUon
submi,edto
network
456
N
456
789
…
N
TransacUon
submi,edto
network
123
N
11
HowaPBFTNetworkWorks(2/4)–Ordering
N
Non-validaUngpeer
V
ValidaUngpeer
VL
123
456
N
ValidaUngLeader
123
456
789
VL
123
123
456
789
V
…
…
789
V
…
V
456
789
N
456
789
…
N
N
123
Consensusnetwork
establishesorderas
123
456
789
…
12
HowaPBFTNetworkWorks(3/4)–Execu@on
N
V
VL
123
Non-validaUngpeer
456
N
ValidaUngpeer
ValidaUngLeader
123
456
789
Δ
VL
123
123
456
789
…
V
…
Δ
Δ
V
…
V
789
N
456
789
…
N
Δ
N
Consensusnetwork
establishesorderas
123
456
789
…
13
HowaPBFTNetworkWorks(4/4)–Distribu@on
N
Non-validaUngpeer
V
ValidaUngpeer
VL
123
456
N
ValidaUngLeader
123
456
789
VL
123
123
456
789
V
…
…
V
…
V
789
N
456
789
…
N
N
Consensusnetwork
establishesorderas
123
456
789
…
14
BFTConsensus
(exampleofPBFT[TOCS2002])
Seq#24
Viewno
Tx1 Tx3
Tx2 Tx4
Node A (leader)
Node B
Node C
Node D
…
Seq#24
Viewno
#21
#22
#23
Tx1 Tx3
Tx2 Tx4
Executetxintheblockand
Committheblocktothe
localcopyofblockchain
(if2f+1outof3f+1agree)
ManyotherthingsburdentheimplementaUon(itisnotsimpleasitmightlook)
•  Non-determinisUcvalue
•  LeaderelecUon
•  Statetransfer(new,slowParty)
•  ReconfiguraUon
15
Nodesandroles
Peer:CommitstransacUons,maintainsledgerandstate
Endorsingpeer:SpecialisedpeerthatreceivesatransacUon
proposalforendorsement,respondsgranUngordenying
endorsement
Orderingpeer:ApprovestheinclusionoftransacUonblocks
intotheledgerandcommunicateswithpeerandendorsing
peernodes
16
EndorsementPolicies
AnendorsementpolicydescribesthecondiUonsbywhichatransacUon
canbeendorsed.AtransacUoncanonlybeconsideredvalidifithas
beenendorsedaccordingtothepolicy.
•  Peersmaintainasetofendorsementpolicies
•  Anendorsementpolicyisspecifiedondeploymentofchaincode
Peer
Chaincode
EndorsementPolicy
EndorsementPolicy
EndorsementPolicy
17
Channels
Nodessend/receivemessagestotheordering-servicevia
channels.
E0
O
O
– Enables chaincode privacy
•  Chaincode deployed to certain nodes
– Messages partitioned into separate channels
E1
O
O
Ordering-Service
•  Transactions stored depending on node and
channel
– Nodes can connect to one or more channels
18
OrderingServices
TheorderingservicepackagestransacUonsinto
blockstobedeliveredtopeers.CommunicaUon
withtheserviceisviachannels.
Different configuration options for the ordering service
include:
O
O
O
O
Ordering-Service
– SOLO
•  Single node for development
– Kafka / Zookeeper
•  1:n nodes providing Crash Fault Tolerance
•  Odd number of nodes recommended
– SBFT
•  1:n nodes providing Byzantine Fault Tolerance
19
IBM开源技术微讲堂
区块链和HyperLedger系列列
Q&A
扫码⼊入群,与讲师互动
更更多信息,请访问:h,p://ibm.biz/opentech-ma
20