Module 2: Practical Exercises and Assessment

Practical Exercises

Exercise 1: Exploring Hyperledger Fabric Architecture

Objective: Understand the modular architecture of Hyperledger Fabric and the execute-order-validate transaction flow.

Tasks: 1. Create a diagram illustrating the execute-order-validate transaction flow in Hyperledger Fabric 2. Identify the key components involved at each stage 3. Compare this with the order-execute model used in other blockchain platforms 4. Explain the advantages of Fabric's approach

Deliverable: A detailed diagram with explanations of each step in the transaction flow and a 500-word analysis of the benefits of the execute-order-validate model.

Exercise 2: Setting Up a Multi-Organization Network

Objective: Gain hands-on experience with Hyperledger Fabric network components by configuring a multi-organization network.

Tasks: 1. Set up a Fabric test network with two organizations: ```bash # Navigate to the test network directory cd fabric-samples/test-network

# Start the network with two organizations ./network.sh up createChannel -c mychannel -ca ```

  1. Explore the network components: ```bash # List running Docker containers docker ps

# Examine the logs of a peer node docker logs peer0.org1.example.com

# Examine the logs of an ordering node docker logs orderer.example.com ```

  1. Investigate the cryptographic materials: ```bash # Navigate to the crypto materials directory cd organizations

# Examine the structure of certificates and keys find . -type f | grep -v ".yaml" | sort ```

  1. Analyze the channel configuration: ```bash # Set environment variables for Org1 export FABRIC_CFG_PATH=$PWD/../config/ export CORE_PEER_TLS_ENABLED=true export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp export CORE_PEER_ADDRESS=localhost:7051

# Fetch the channel configuration peer channel fetch config config_block.pb -c mychannel -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

# Convert to JSON for readability configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config.json ```

Deliverable: A report documenting the components of your Fabric network, including screenshots of the running containers, certificate structure, and key elements of the channel configuration.

Exercise 3: Working with Private Data Collections

Objective: Understand how to implement and use private data collections in Hyperledger Fabric.

Tasks: 1. Deploy the asset-transfer-private-data sample chaincode: bash # Deploy the private data chaincode ./network.sh deployCC -ccn private -ccp ../asset-transfer-private-data/chaincode-go -ccl go -ccep "OR('Org1MSP.peer','Org2MSP.peer')" -cccg ../asset-transfer-private-data/chaincode-go/collections_config.json

  1. Examine the private data collection definition: bash # View the collections configuration file cat ../asset-transfer-private-data/chaincode-go/collections_config.json

  2. Create an asset with private data: ```bash # Set environment variables for Org1 export FABRIC_CFG_PATH=$PWD/../config/ export PATH=${PWD}/../bin:$PATH export CORE_PEER_TLS_ENABLED=true export CORE_PEER_LOCALMSPID="Org1MSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp export CORE_PEER_ADDRESS=localhost:7051

# Create an asset with both public and private data peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n private -c '{"function":"CreateAsset","Args":["asset1","green","5","tom","100"]}' --transient '{"asset_properties":"{\"objectType\":\"asset_properties\",\"assetID\":\"asset1\",\"color\":\"green\",\"size\":5,\"owner\":\"tom\",\"appraisedValue\":100}"}' ```

  1. Query the asset from different organizations: ```bash # Query public data as Org1 peer chaincode query -C mychannel -n private -c '{"function":"ReadAsset","Args":["asset1"]}'

# Query private data as Org1 peer chaincode query -C mychannel -n private -c '{"function":"ReadAssetPrivateDetails","Args":["Org1MSPPrivateCollection","asset1"]}'

# Set environment variables for Org2 export CORE_PEER_LOCALMSPID="Org2MSP" export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp export CORE_PEER_ADDRESS=localhost:9051

# Query public data as Org2 peer chaincode query -C mychannel -n private -c '{"function":"ReadAsset","Args":["asset1"]}'

# Try to query Org1's private data as Org2 (should fail) peer chaincode query -C mychannel -n private -c '{"function":"ReadAssetPrivateDetails","Args":["Org1MSPPrivateCollection","asset1"]}' ```

Deliverable: A report documenting your experience with private data collections, including the collection configuration, transaction flow, and access control observations. Include screenshots of successful and failed query attempts.

Assessment

Multiple Choice Questions

  1. Which of the following best describes Hyperledger Fabric's architecture? a) Order-execute architecture with a single transaction flow b) Execute-order-validate architecture with modular components c) Proof-of-work consensus with mining nodes d) Centralized architecture with a master node

  2. In Hyperledger Fabric, the component responsible for establishing consensus on transaction order is: a) Peer b) Certificate Authority c) Ordering Service d) Membership Service Provider

  3. Which of the following is NOT a type of peer in Hyperledger Fabric? a) Endorsing peer b) Committing peer c) Mining peer d) Anchor peer

  4. The Membership Service Provider (MSP) in Hyperledger Fabric is responsible for: a) Ordering transactions b) Executing chaincode c) Managing identities and access control d) Storing the ledger

  5. Which database options are available for the world state in Hyperledger Fabric? a) MongoDB and PostgreSQL b) LevelDB and CouchDB c) MySQL and Oracle d) Cassandra and Redis

  6. In Hyperledger Fabric, channels provide: a) A way to increase transaction throughput b) Data isolation between different groups of organizations c) Direct communication with external systems d) A mechanism for mining new tokens

  7. Private Data Collections in Hyperledger Fabric: a) Store all data off-chain b) Share private data among all channel members c) Store private data peer-to-peer while keeping hashes on the ledger d) Require a separate channel for each collection

  8. The "block-to-live" parameter in a Private Data Collection defines: a) How many blocks must be created before the collection is active b) How many blocks until the private data is purged from storage c) The maximum number of blocks the collection can contain d) The minimum number of blocks required for consensus

  9. Which consensus mechanism is NOT typically used in Hyperledger Fabric? a) Raft b) Kafka c) Proof of Work d) Practical Byzantine Fault Tolerance

  10. X.509 certificates in Hyperledger Fabric are used for: a) Storing transaction data b) Identity and authentication c) Executing chaincode d) Implementing consensus

Short Answer Questions

  1. Explain the execute-order-validate transaction flow in Hyperledger Fabric and how it differs from traditional blockchain platforms.

  2. Describe the role of the ordering service in Hyperledger Fabric and explain why it's designed as a modular component.

  3. Compare and contrast channels and private data collections as privacy mechanisms in Hyperledger Fabric. When would you use one over the other?

  4. Explain how the Membership Service Provider (MSP) works in Hyperledger Fabric and why it's important for a permissioned blockchain.

  5. Describe the structure of the ledger in Hyperledger Fabric, including the world state and transaction log, and explain how they work together.

Answers to Multiple Choice Questions

  1. b) Execute-order-validate architecture with modular components
  2. c) Ordering Service
  3. c) Mining peer
  4. c) Managing identities and access control
  5. b) LevelDB and CouchDB
  6. b) Data isolation between different groups of organizations
  7. c) Store private data peer-to-peer while keeping hashes on the ledger
  8. b) How many blocks until the private data is purged from storage
  9. c) Proof of Work
  10. b) Identity and authentication