Consensus in Hyperledger Fabric
Mohan DhawanIBM Research, India
2
Hyperledger Fabric v/s Ethereum
Characteristic Hyperledger Fabric Ethereum
Description of platform Modular blockchain platform Generic blockchain platform
Governance Linux Foundation Ethereum developers
Usage Mission-critical managed enterprise applications
Anonymous “bitcoin-like” network optimized for “volume”, at the expense of managed governance
Mode of operation Permissioned, private Permissionless, public or private
Consensus Broad understanding of consensus that allows multiple approaches
Transaction level
Mining based on Proof of Work (PoW) or Proof of Stake (PoS)
Ledger level
Identity Participants declare who they are and their identities are confirmed
Anonymous
Network “OPEN” by providing transparency of participants
“OPEN” to everyone anonymously
Trust Trust in the parties Transactions can be trusted; parties cannot be trusted as they are anonymous
Smart contracts Smart contract code (e.g., Go, Java, JavaScript)
Smart contract code (e.g., Solidity)
Currency None
Currency and tokens via chaincode
Ether
Tokens via smart contract
3
Hyperledger Fabric V1 Architecture
● Ledger is a tamperproof record of transactions replicated across nodes in the network– A blockchain is a decentralized and distributed digital ledger
● Chaincode is a program that typically handles business logic agreed to by members of the network, so it may be considered as a “smart contract”– Initializes and manages ledger state through transactions submitted by
applications
● Types of nodes– Client
● Submits an actual transaction-invocation to the endorsers, and broadcasts transaction-proposals to the ordering service
– Peer● Commits transactions and maintains the state and a copy of the ledger. Besides, peers can
have a special endorser role
– Orderer● Runs the communication service that implements a delivery guarantee, such as atomic or
total order broadcast
4
Hyperledger Fabric V1 Architecture
OO
OO OO
OO
Ordering Service
ClientApplication
SDK (HFC)
MembershipServicesProvider
Peer
EndorserEndorser
Ledger
CommitterCommitter
AAChaincode BB
!Events
5
Endorser Ledger
Committing Peer Application
Ordering Node
Smart Contract(Chaincode)
Endorsement Policy
Key:
Application proposes transaction
Endorsement policy:• “E0, E1 and E2 must sign”• (P3, P4 are not part of the policy)
Client application submits a transaction proposal for Smart Contract A. It must target the required peers {E0, E1, E2}
E0E0
E1E1
E2E2
ClientApplication
SDK
Hyperledger Fabric
Ordering-Service
OO
OO OO
OOP
P4P4P3P3
AABB
AABB
AABB
AADD
Step 1/7 – Propose Transaction
6
Endorsement Policy
● Describes the conditions by which a transaction can be endorsed– A transaction can only be considered valid if it has been
endorsed according to its policy
– Each chaincode is associated with an Endorsement Policy
● Examples of policies– AND('Org1.member', 'Org2.member', 'Org3.member')
– OR('Org1.member', 'Org2.member')
– OR('Org1.member', AND('Org2.member', 'Org3.member'))
7
Step 2/7 – Execute Proposal
Endorsers Execute Proposals
E0, E1 & E2 will each execute the proposed transaction. None of these executions will update the ledger
Each execution will capture the set of Read and Written data, called RW sets, which will now flow in the fabric.
Transactions can be signed & encrypted
Endorser Ledger
Committing Peer Application
Ordering Node
Smart Contract(Chaincode)
Endorsement Policy
Key:
E0E0
ClientApplication E1E1
E2E2
SDK
Ordering-Service
OO
OO OO
OOP
P4P4P3P3
AABB
AABB
AABB
AADD
Hyperledger Fabric
8
Step 3/7 – Proposal Response
Endorser Ledger
Committing Peer Application
Ordering Node
Smart Contract(Chaincode)
Endorsement Policy
Key:
Application receives responses
RW sets are asynchronously returned to application
The RW sets are signed by each endorser, and also includes each record version number
(This information will be checked much later in the consensus process)
E0E0
ClientApplication E1E1
E2E2
SDK
Ordering-Service
OO
OO OO
OOP
P4P4P3P3
AABB
AABB
AABB
AADD
Hyperledger Fabric
9
Step 4/7 – Order Transaction
Endorser Ledger
Committing Peer Application
Ordering Node
Smart Contract(Chaincode)
Endorsement Policy
Key:
Application submits responses for ordering
Application submits responses as a transaction to be ordered.
Ordering happens across the fabric in parallel with transactions submitted by other applications
E0E0
E1E1
E2E2 OO
OO OO
OOP
ClientApplication
SDK
Ordering-Service
P4P4P3P3
AABB
AABB
AABB
AADD
Hyperledger Fabric
(other applications)
10
Step 5/7 – Deliver Transaction
Endorser Ledger
Committing Peer Application
Ordering Node
Smart Contract(Chaincode)
Endorsement Policy
Key:
Orderer delivers to all committing peers
Ordering service collects transactions into proposed blocks for distribution to committing peers. Peers can deliver to other peers in a hierarchy (not shown)
Different ordering algorithms available:• Solo (Single node, development)• Kafka (Crash fault tolerance)
E0E0
E1E1
E2E2 OO
OO OO
OOP
ClientApplication
SDK
Ordering-Service
P4P4P3P3
AABB
AABB
AABB
AADD
Hyperledger Fabric
11
Step 6/7 – Validate Transaction
Endorser Ledger
Committing Peer Application
Ordering Node
Smart Contract(Chaincode)
Endorsement Policy
Key:
E0E0
E1E1
E2E2 OO
OO OO
OOP
ClientApplication
SDK
Ordering-Service
P4P4P3P3
* * *
*
*
AABB
AABB
AABB
AADD
Hyperledger Fabric
Committing peers validate transactions
Every committing peer validates against the endorsement policy. Also check RW sets are valid for world state.
Validated transactions are applied to world state and retained on the ledger.
Invalid transactions are also retained on the ledger but do not update world state.
12
Step 7/7 – Notify Transaction
Endorser Ledger
Committing Peer Application
Ordering Node
Smart Contract(Chaincode)
Endorsement Policy
Key:
Committing peers notify applications
Applications can register to be notified when transactions succeed or fail, and when blocks are added to the ledger
Applications will be notified by each peer to which they are connected
E0E0
AABB
E1E1
AABB
E2E2
AABB
OO
OO OO
OOP
ClientApplication
SDK
Ordering-Service
P3P3
AADD
P4P4
!
!
!
!
! !
Hyperledger Fabric
13
Ordering Service
● Packages transactions into blocks to be delivered to peers
● Communication with the service is via channels
● Different configurations for the ordering service include– Solo: Single node for development
– Kafka: Crash fault tolerant consensus● 3 nodes minimum, Odd number of nodes recommended
Ordering-Service
OOOO
OO OO
14
Channels
● Separate channels isolate transactions on different ledgers– Concurrent execution for performance and scalability
● Peers can participate in multiple channels
● Ledgers exist in the scope of a channel – Can be shared across an entire network of peers
OOOO
OO OO
E1E1
E0E0
Ordering-Service
15
• All peers connect to the same system channel (blue).
• All peers have the same chaincode and maintain the same ledger
• Endorsement by peers E0, E1, E2 and E3
E0E0
AA
BB
E3E3
E2E2
E1E1
AA
BB
AA
BBAA
BB
OOOO
OO OO
Endorser Ledger
Committing Peer Application
Ordering Node
Smart Contract(Chaincode)
Endorsement Policy
Key:
ClientApplication
SDK
P
Ordering-Service
Hyperledger Fabric
Single Channel Network
16
• Peers E0 and E3 connect to the red channel for chaincodes Y and Z
• Peers E1 and E2 connect to the blue channel for chaincodes A and B
E0E0
ZZ
YY
E3E3
E2E2
E1E1
AA
BB
AA
BBYY
ZZ
OOOO
OO OO
ClientApplication
SDK
P
Ordering-Service
ClientApplication
SDK
P
Hyperledger Fabric
Endorser Ledger
Committing Peer Application
Ordering Node
Smart Contract(Chaincode)
Endorsement Policy
Key:
Multi Channel Network
17
www.ibm.com/blockchain
developer.ibm.com/blockchain
www.hyperledger.org
© Copyright IBM Corporation 2017. All rights reserved. The information contained in these materials is provided for informational purposes only, and is provided AS IS without warranty of any kind, express or implied. Any statement of direction represents IBM's current intent, is subject to change or withdrawal, and represents only goals and objectives. IBM, the IBM logo, and other IBM products and services are trademarks of the International Business Machines Corporation, in the United States, other countries or both. Other company, product, or service names may be trademarks or service marks of others.
Thank You