Demystifying Blockchain: Business Applications with Hyperledger Fabric

ASQ Quality 4.0 Summit on
Disruption, Innovation, & Change

Tuesday, November 13th, 2018

Dallas TX

Morgan C. Benton

morgan.benton@gmail.com               @morphatic

About Me

  • 13th year in BS Integrated Science and Technology program at JMU
  • Teach mostly web/mobile app development, agile methodology
  • Unofficial Secretary of the Hyperledger Training and Education Working Group
  • Probably only 15 minutes ahead of you in terms of what I know about blockchain...

DISCLAIMER: Blockchain may be
hazardous to your health...

THIS SOFTWARE PRESENTATION IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND FOR THE IDEAS CONTAINED HEREIN, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE WHATSOEVER. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE IMPLEMENTATION OF SOFTWARE BASED ON THE IDEAS DISCUSSED TODAY.

(paraphrased from the MIT license...)

...that being said, I hope you'll find this useful and interesting...

Why Blockchain?

"I don't want to create or trade cryptocurrencies, so what possible use could I have for incorporating blockchain into the software and tools that I or my company uses or the software that I'm building for clients?"

  1. Decentralized trust mechanism that could potentially replace centralized trust, i.e. banks and governments
  2. Could greatly reduce or eliminate the need and expense of hiring external auditors
  3. Potential to automate processes that must currently be manually executed (for verification purposes)

Permissionless

Anyone can participate.
The ledger is freely downloadable by all participants in the network

 

  • Bitcoin
  • Ethereum

Permissioned

Participation is restricted. The ledger is available only to authorized participants.

 

 

  • Hyperledger

TWO Major Categories of Blockchain Technology

What is Hyperledger?

  • Standards-setting consortium
  • >250 members w/ dues $10k ~ $270k /yr
  • Run by the Linux Foundation
  • Focused on industrial blockchain applications

                   Taking a

              Deep Dive

          into

     Hyperledger

Fabric

  • Assets
  • Participants
  • Membership Service Provider (MSP)
  • World State DB
  • Chaincode ("Smart Contract")
  • Transaction
  • Block
  • Blockchain
  • Ledgers & Channels
  • Peers
  • Networks
  • Applications
  • Consensus

Key Concepts

  • Can be anything with a monetary value, e.g.
    • Tangible goods: cars, apples, books
    • Real estate
    • Intangible: copyright
  • Represented in JSON and/or binary form
  • Stored as a key/value pair

Asset

{
  "$class": "org.acme.Shipment",
  "shipmentId": "6646",
  "type": "BANANAS",
  "status": "IN_TRANSIT",
  "unitCount": 100,
  "unit": "kg",
  "contract": "Contract#3298"
}

{
  "$class": "org.acme.Contract",
  "contractId": "3298",
  "grower": "Grower#0904",
  "shipper": "Shipper#7456",
  "importer": "Importer#1052",
  "arrivalETA": "2018-09-23T23:48:57.991Z",
  "unitPrice": 0.89,
  "unit": "USD",
  "minTemperature": 5,
  "maxTemperature": 15,
  "minPenaltyFactor": 0.05,
  "maxPenaltyFactor": 0.25
}
  • Any actor in or out of the network that can consume services
  • Identified by X.509 digital certificate
  • Identity used to determine capabilities
  • Identity issued, managed, and verified by an MSP...

Participant

{
  "$class": "org.acme.Grower",
  "email": "0904",
  "address": {
    "$class": "org.acme.Address",
    "country": "CR"
  },
  "accountBalance": 310448.73
}

{
  "$class": "org.acme.Shipper",
  "email": "7456",
  "address": {
    "$class": "org.acme.Address",
    "country": "US"
  },
  "accountBalance": 18540830.66
}
  • Component that defines rules for valid identities
  • Based on PKI
  • Specifies trusted Root and Intermediate Certificate Authorities (CAs) 
  • Defines roles and privileges of identities
  • Tracks revoked identities
  • Defined at local (within org) level and channel (between org) level

Membership Service Provider

  • From the Hyperledger Docs
  • Each block above represents a folder in the filesystem of a node in the network
  • Common MSPs include:
    Network, Channel, Peer, Orderer
  • A database that holds the current values describing the states of a set of assets important to an organization
  • Usually stored as key-value pairs, but flexible
  • Theoretically can be stored in most any modern DBMS, but current support exists for CouchDB and LevelDB

World State DB

{
  "key": "CAR1",
  "value": "Audi",
  "version": 0
}

{
  "key": "CAR2",
  "value": {
    "type": "BMW",
    "color": "red",
    "owner": "Jane
  },
  "version": 0
}
  • AKA "smart contracts"
  • Code invoked by Fabric apps with instructions for modifying assets by executing transactions
  • Currently written using either Go or NodeJS
  • Runs in a secured Docker container
  • Implements a fairly simple API (mostly CRUD)
  • Follows an endorsement policy

Chaincode

package main

import (
  "fmt"
  "github.com/hyperledger/fabric/core/chaincode/shim"
  "github.com/hyperledger/fabric/protos/peer"
)

// SimpleAsset implements a simple chaincode to manage an asset
type SimpleAsset struct {}

// Init is called during chaincode instantiation to initialize any
// data. Note that chaincode upgrade also calls this function to reset
// or to migrate data, so be careful to avoid a scenario where you
// inadvertently clobber your ledger's data!
func (t *SimpleAsset) Init(stub shim.ChaincodeStubInterface) peer.Response {
  // Get the args from the transaction proposal
  args := stub.GetStringArgs()
  if len(args) != 2 {
    return shim.Error("Incorrect arguments. Expecting a key and a value")
  }

  // Set up any variables or assets here by calling stub.PutState()

  // We store the key and the value on the ledger
  err := stub.PutState(args[0], []byte(args[1]))
  if err != nil {
    return shim.Error(fmt.Sprintf("Failed to create asset: %s", args[0]))
  }
  return shim.Success(nil)
}

// Invoke is called per transaction on the chaincode. Each transaction is
// either a 'get' or a 'set' on the asset created by Init function. The Set
// method may create a new asset by specifying a new key-value pair.
func (t *SimpleAsset) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
    // Extract the function and args from the transaction proposal
    fn, args := stub.GetFunctionAndParameters()

    var result string
    var err error
    if fn == "set" {
            result, err = set(stub, args)
    } else {
            result, err = get(stub, args)
    }
    if err != nil {
            return shim.Error(err.Error())
    }

    // Return the result as success payload
    return shim.Success([]byte(result))
}
  • A data structure that contains:
    • Header: essential metadata such as the chaincode to run
    • Signature: cryptographic digital signature used for verification; requires private key of the signing application
    • Proposal: input parameters for the chaincode
    • Response: before/after values of world state as a Read Write (RW) set
    • Endorsements: verifications from endorsing peers that transaction is valid

Transaction

  • A block is a data structure that contains:
    • Header: a hash of the transactions in the block + the hash of the prior block's header
    • Data: a set of chronologically  ordered transactions
    • Metadata

Block

  • A tamper-resistant transaction log structured as interlinked blocks
  • "Interlinked" because each block is partially formed from the hash of all of the data in the previous block
  • Implemented as a file rather than a DB since current API only allows Append and Search

Blockchain

  • The sequence of blocks is described as "immutable" (which roughly means "unchangeable")
  • A "ledger" in Fabric is composed of a copy of a blockchain plus the world state database that reflects the blockchain
  • Each participant in a Hyperledger Fabric network maintains their own copy of the ledger

Ledgers & Channels

  • For privacy, members of a Fabric network can create "channels" each of which has its own ledger possessed only by members of the channel

Example of a network with channels

  • A computer maintained by one of the member organizations in a Fabric network
  • Identified by a digital certificate issued by an MSP
  • Hosts chaincode (smart contracts) and the ledgers for the network and any channels of which the peer is a member
  • Organizations may maintain many peers

Peers

  • There are several types of peers:
    • Ordering Peer
      Orders transactions and packs them into blocks
    • Endorsing Peer
      Endorses proposed txns
    • Anchor Peer
      ​Facilitates awareness of peers across orgs
    • Leading Peer
      Conduit between Ordering peer and other peers within an organization

Networks & Applications

Consensus

Questions?

Demystifying Blockchain: Business Applications with Hyperledger Fabric

By Morgan Benton

Demystifying Blockchain: Business Applications with Hyperledger Fabric

While the permissionless blockchain technologies that support software like Bitcoin and Ethereum dominate headlines, there are still very significant unsolved technological challenges that prevent these platforms from becoming truly mainstream. Meanwhile, big companies like IBM, Intel, Cisco, and American Express are putting their energy behind a less ambitious, less risky, but no less impactful form of blockchain platform--the permissioned blockchain. The dominant player in the permissioned blockchain space is Hyperledger (www.hyperledger.org), a massive, open-source family of blockchain frameworks being managed by the Linux Foundation. In this session, we will briefly cover the key differences between permissioned and permissionless blockchains, and demonstrate why wise developers looking to break into the blockchain space should invest their time and energy learning to develop solutions with Hyperledger. We'll dive right into a demonstration of what blockchain development looks like with Hyperledger Fabric, one of the five frameworks currently being incubated by the Hyperledger project.

  • 1,322