flowchain: a case study on building a blockchain for...
TRANSCRIPT
![Page 1: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/1.jpg)
Flowchain: A Case Study on Building a Blockchain for the IoT
Jollen, Devify Inc.
[email protected] https://flowchain.io
![Page 2: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/2.jpg)
Agenda
• Motivation
• Architecture Overview
• Handling Heterogeneous Hardware
• Device Interoperability
• Distributed Ledger for the IoT
• Consensus System
• Use the Flowchain SDK
2
![Page 3: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/3.jpg)
Motivation and Purpose
• Attempt to use the decentralized IoT model to ensure data privacy and security
3
D1D2D3D4N1
N2
N3
N4N5
N6
N7
N8
IoT PlatformX
![Page 4: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/4.jpg)
Goals and Assumption
• Decentralized IoT
• Centralized IoT model uses an IoT platform that acts as “hub” to control the data exchange between devices.
• The IoT needs a decentralized model for exchanging data without any centralized party.
• The blockchain technology is (maybe) a solution
• How does the blockchain technology help facilitate such challenges ?
• Recently, the blockchain for the IoT has considered an
4
![Page 5: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/5.jpg)
Agenda
• Motivation
• Architecture Overview
• Handling Heterogeneous Hardware
• Device Interoperability
• Distributed Ledger for the IoT
• Consensus System
• Use the Flowchain SDK
5
![Page 6: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/6.jpg)
Major IoT platforms are based on centralized model. The
platform acts as broker or hub to control the interactions
between devices.
!
Devices need to exchange data between themselves
autonomously. This leads to decentralized IoT platforms.
Blockchain IoT Purposes
6
![Page 7: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/7.jpg)
Preliminary
• A blockchain is only one type of data structure considered to be a distributed ledger
• A distributed ledger technology (DLT) provides a new data structure varies from the blockchain for various purposes
7
![Page 8: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/8.jpg)
Blockchain Data Structure
• Ordered and back-linked list
• Stored in a flat file or database
• Each block is identified by a hash
• Double SHA-256 hash function
8
![Page 9: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/9.jpg)
DLT Essentials
• A peer-to-peer network
• Consensus algorithms
9
![Page 10: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/10.jpg)
Background
• A study of a distributed ledger designed for the IoT devices
• A Web of Things server to represent the device as a Virtual Thing
WoT Server
Distributed Ledger
WoT Server
Distributed Ledger
WoT Server
Distributed Ledger
p2p p2p
10
![Page 11: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/11.jpg)
CoAP Server Websocket Client
WoT Servient
The Servient
• Composing the client and server in every single device
• Adopt the “broker service” architecture
11
Websocket Server CoAP Client
WoT Servient
CoAP Server Websocket Client
WoT Servient
(a) (b) (c)
![Page 12: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/12.jpg)
Goal and Purpose
• Decentralized IoT
• Centralized IoT model uses an IoT platform that acts as “hub” to control the data exchange between devices.
• The IoT needs a decentralized IoT platform for exchanging data without any centralized party.
• IoT Blockchain
• The Blockchain technology helps facilitate such challenges.
12
![Page 13: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/13.jpg)
Web of Things Layer Interoperable and decentralized IoT model
Chord Distributed hash table
Flowcoin Peer-to-peer trusted computing
Flowchain Software Framework
Data Store Distributed block store
Virtual Block Difficulty management
Miner Proof-of-stake
Broker Server Layer
Distributed Ledger Layer
Architecture Design
13
![Page 14: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/14.jpg)
Architecture Design
• Distributed Ledger Layer
• Usually known as the “Blockchain”
• Provides a distributed data store that shares transactional data across all IoT devices
• Broker Server Layer
• Provides a helper library to create the IoT application server and establishes the peer-to-peer IoT networking
• Web of Things (WoT) Layer
• Adopts the W3C’s WoT ontology that represents the physical IoT device as a virtual object
14
![Page 15: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/15.jpg)
Philosophy
• Open source
• Open standards
• Web technologies
• REST, JSON, JSON-LD, WebSocket, and etc
• All in JavaScript
• The Flowchain software framework is a 100% JavaScript implementation
15
![Page 16: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/16.jpg)
Agenda
• Motivation
• Architecture Overview
• Handling Heterogeneous Hardware
• Device Interoperability
• Distributed Ledger for the IoT
• Consensus System
• Use the Flowchain SDK
16
![Page 17: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/17.jpg)
Decentralized Model
17
Server
![Page 18: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/18.jpg)
Development Milestone
• Systems : Hardware, FreeRTOS, JavaScript engine, MCU, Application Processor and etc.
• P2P : Development of the peer-to-peer network for IoT devices
• The Ledger : Development of the blockchain data structure for time-series data (the “virtual blocks”)
• The Semantic Web+: Development of the time-series database (TSDB), profiles (the ontology content patterns) …
18
![Page 19: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/19.jpg)
Microprocessor System
19
OpenWRT (Linux)
WebSocket / CoAP
Thing (WoT)
RPC & DHT
The Ledger
System Level
Connectivity Level
P2P Level
Ledger Level
![Page 20: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/20.jpg)
Microcontroller System
20
FreeRTOS
WebSocket / CoAP
Thing (WoT)
RPC & DHT
The Ledger
Connectivity Level
P2P Level
Ledger Level
System Level
![Page 21: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/21.jpg)
Heterogeneous Hardware
21
OpenWRT (Linux)
WebSocket / CoAP
Thing (WoT)
RPC & DHT
The Ledger
FreeRTOS
WebSocket / CoAP
Thing (WoT)
RPC & DHT
The Ledger
MacOS
WebSocket / CoAP
Thing (WoT)
RPC & DHT
The Ledger
MIPS Processor ARM Cortex-M4 Intel Core 2
580MHz 128MB DDR2 32MB Flash
192MHz 352KB RAM 4MB Flash
1.4GHz 2GB DDR3 64GB SSD
LaptopLinkIt 7697LinkIt Smart 7688
![Page 22: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/22.jpg)
JavaScript Runtime
22
OpenWRT (Linux)
WebSocket / CoAP
Thing (WoT)
RPC & DHT
The Ledger
FreeRTOS
WebSocket / CoAP
Thing (WoT)
RPC & DHT
The Ledger
MacOS
WebSocket / CoAP
Thing (WoT)
RPC & DHT
The Ledger
Node.js 0.12 JerryScript Node.js 4.4+
![Page 23: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/23.jpg)
Why use JavaScript ?
23
WebSocket / CoAP
Thing (WoT)
RPC & DHT
The Ledger
JavaScript
JavaScript
JavaScript
JavaScript
Flowchain
DevifyThe Generic Software Framework
The Blockchain for the IoT Application
![Page 24: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/24.jpg)
Agenda
• Motivation
• Architecture Overview
• Handling Heterogeneous Hardware
• Device Interoperability
• Distributed Ledger for the IoT
• Consensus System
• Use the Flowchain SDK
24
![Page 25: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/25.jpg)
Overview
Node A
Node CPRC operations
• RPC for the inter-device communications
• Over the Websocket and CoAP open standards
Node B
PRC operations
Node D
PRC operations
PRC operations
25
![Page 26: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/26.jpg)
Interoperability of the IoT
• The Interoperable IoT devices
• Device communications via REST-style RPC, and
• A peer-to-peer network (p2p)
• Transactional data is transferred in the p2p network by the REST-style RPC
• The distributed ledger stores the transactional data in the JSON-LD format
26
![Page 27: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/27.jpg)
The REST-style RPC
• RPC operations over REST APIs
Node A
Node B
ws://192.168.0.20/
ws://192.168.0.10/
Request body: { “message”: …, “from”: … }
Request body: { “message”: …, “from”: … }
27
![Page 28: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/28.jpg)
28
/** * Send a RPC message. * * @param {Object} Destination * @param {Object} Data payload * @api private */ var send = function(to, packet) { var uri = util.format('ws://%s:%s/node/%s/receive', to.address, to.port, packet.message.id); var host = util.format('ws://%s:%s', to.address, to.port); var payload = { message: packet.message, from: packet.from }; var connection = connections[host] || null; // Connection cache ! if (connection) { if (connection.connected) connection.sendUTF(JSON.stringify(payload)); else delete connections[host]; return 0; } ! var client = new WebSocketClient(); ! client.on('connect', function(connection) { if (connection.connected) { connection.sendUTF(JSON.stringify(payload)); connections[host] = connection; } else { delete connections[host]; } }); ! client.connect(uri, ''); };
![Page 29: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/29.jpg)
RPC Operations
• RPC operations are built upon the Chord protocols
• RPCMessage.NOTIFY_STABILIZE
• RPCMessage.NOTIFY_PREDECESSOR
• RPCMessage.NOTIFY_SUCCESSOR
• RPCMessage.NOTIFY_JOIN
• RPCMessage.FIND_SUCCESSOR
• RPCMessage.FOUND_SUCCESSOR
• RPCMessage.CHECK_PREDECESSOR
• RPCMessage.CHECK_SUCESSOR
• RPCMessage.CHECK_TTL
• RPCMessage.MESSAG
29
![Page 30: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/30.jpg)
Chord Algorithm Extension
• Handling Churn
• The continuous activities of node join and leave
// It is called periodically. // n asks the successor // about its predecessor. n.stabilize() x = successor.predecessor; if (x is in (n, successor)) successor = x; successor.notify(n); !// n' thinks it might be our predecessor, and // n notify n' about its alive. n.notify(n') if (predecessor is nil or n' is in (predecessor, n)) predecessor = n'; n'.notify_ttl(); !// n updates the successor's TTL. n.notify_ttl() n.successor_ttl = MAX_TTL;
30
![Page 31: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/31.jpg)
Implement RPC Operations
• RPC operations are built upon the Chord protocols
switch (message.type) { case RPCMessage.NOTIFY_STABILIZE: ! if (this.predecessor === null) this.predecessor = from; ! if (ChordUtils.isInRange(this.predecessor.id, from.id, this.id)) { message.type = Chord.NOTIFY_PREDECESSOR; return this.send(this.predecessor, message, from); } ! message.type = Chord.NOTIFY_SUCCESSOR; this.send(from, message, this); ! break; ... }
// called periodically. n asks the successor // about its predecessor, verifies if n's immediate // successor is consistent, and tells the successor about n n.stabilize() x = successor.predecessor; if (x∈(n, successor)) successor = x; successor.notify(n); !Source: https://en.wikipedia.org/wiki/Chord_(peer-to-peer)
31
![Page 32: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/32.jpg)
Agenda
• Motivation
• Architecture Overview
• Handling Heterogeneous Hardware
• Device Interoperability
• Distributed Ledger for the IoT
• Consensus System
• Use the Flowchain SDK
32
![Page 33: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/33.jpg)
Preliminary
• A blockchain is only one type of data structure considered to be a distributed ledger
• A distributed ledger technology (DLT) provides a new data structure varies from the blockchain for various purposes
33
![Page 34: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/34.jpg)
DLT Essentials
• A peer-to-peer network+
• Consensus algorithms
34
![Page 35: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/35.jpg)
Blockchain Data Structure
• Ordered and back-linked list
• Stored in a flat file or database
• Each block is identified by a hash
• Double SHA-256 hash function
35
![Page 36: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/36.jpg)
Blockchain for the IoT
36
Bitcoin Blockchain Flowchain DLT
Datastructure Ordered and back-linked list V
Datastore A flat file or database Block Store
Block Identify Hash Hash
Consensus POW Mining-based POS
Data Transaction Unverified pool Unverified chunk data
![Page 37: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/37.jpg)
Data Transaction
• Use the Chord algorithm to organized the IoT devices as a “Ring” topology
• Each device maintains a “finger-table” (aka the DHT)
• The data transaction process
• Step 1: Generate the key of the data by SHA-256
• Step 2: Search the successor node of the key in the DHT
• Step 3: Send data to the successor node by the RPC operation
• Step 4: The successor node processes the data transaction
37
![Page 38: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/38.jpg)
Peer-to-Peer Networking
• RPC for the IoT devices
• Over the Websocket and CoAP open standards
N1
N2
N3
N4
N5
N6
N7
N8
SUCCESSOR(Item 1) = N3
SUCCESSOR(Item 2) = N7
Flowchain Node
Sensor Node
Item 1
Item 2
Endpoint Node
38
![Page 39: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/39.jpg)
Flowchain IoT Ideas
• Avoid “competition” and “mining fork” exception
• Propose and use “virtual blocks” concepts
• Aka the “virtual mining”
• Fork the “genesis block” and find blocks (mining) at the “branches”
39
![Page 40: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/40.jpg)
PreviousHash Timestamp
MerkleRoot Nonce
Genesis Block
function Block(block) { if (typeof block === 'undefined') { block = {}; } ! this.hash = block.hash || ''; this.previousHash = block.previousHash || ''; this.timestamp = block.timestamp || new Date(); this.merkleRoot = block.merkleRoot || '0000000000000000000000000000000000000000000000000000000000000000'; this.difficulty = block.difficulty || '00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'; this.nonce = block.nonce || 0; this.no = block.no < 0 ? 0 : block.no; }
Establish Genesis Block
40
![Page 41: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/41.jpg)
PreviousHash Timestamp
MerkleRoot Nonce
Genesis Block
PreviousHash Timestamp
MerkleRoot Nonce
Block #1
PreviousHash Timestamp
MerkleRoot Nonce
Block #2
Bitcoin Blockchain Data
41
![Page 42: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/42.jpg)
Flowchain Virtual Blocks
PreviousHash Timestamp
MerkleRoot Nonce
Genesis Block
PreviousHash Timestamp
MerkleRoot Nonce
Block #1
PreviousHash Timestamp
MerkleRoot Nonce
Block #2
PreviousHash Timestamp
MerkleRoot Nonce
Block #1“fork”
“fork”
PreviousHash Timestamp
MerkleRoot Nonce
Block #2
“branches”
42
![Page 43: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/43.jpg)
Real-Time Transaction
• Avoid “competition” and “mining fork” exception
• Flowchain mining is nonblocking
• Propose and use “virtual blocks” concepts
• Aka the POS “virtual mining”
• Fork the “genesis block” and find blocks (mining) at the “branches”
• Branches can be merged by hash join algorithm
43
![Page 44: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/44.jpg)
Flowchain Virtual Blocks
Block #1 Block #2
Block #1 Block #2
Block #1
Block #1
Block #1
Block #2
Block #2
Block #2
Block #3
Block #3
Block #4
Block #3 Block #4 Block #5
Block #0
Block #0
Block #0
Block #0
Block #0
N1
N2
N3
N4
N5
Genesis block
Invalid block
Valid block
44
![Page 45: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/45.jpg)
Use the Virtual Blocks
/* * Flowchain virtual block algorithm (the pseudo code) */ !Node.on(‘message’, function(key, value) { // Get a valid block of the device’s blockchain N = GetOneValidBlock(chains) ! // Put key-value pair in block “N” PutToBlock( N, { key: value } ); });
45
![Page 46: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/46.jpg)
“Virtual Blocks”
• Five IoT devices are labeled N1 to N5, and each device is a “node” in a peer-to-peer network
• All nodes are mining blocks that use the same genesis block
• In other words, each node creates a new “branch” for mining; thus, there is no blockchain “fork”
• Every block in each branch is called a Virtual Block
• Virtual Blocks can be labeled as valid or invalid
• Only valid blocks are available to record transactions
46
![Page 47: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/47.jpg)
Why “Virtual Blocks” ?
• Flowchain initially creates branches for each node when nodes mine their Virtual Blocks
• Estimate the block “forks” exception during the mining process
• Flowchain can act in a real-time manner
47
![Page 48: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/48.jpg)
Data Transaction
• Use the Chord algorithm to organized the IoT devices as a “Ring” topology
• Each device maintains a “finger-table” (aka the DHT)
• The data transaction process
• Step 1: Generate the key of the data - HDATA
• Step 2: Search the successor node of the key in the DHT - SUCCESSOR(HDATA)
• Step 3: Send data to the successor node by the RPC operation
• Step 4: The successor node processes the data transaction
48
![Page 49: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/49.jpg)
HBLOCK = SHA256( BlockNo + timestamp + nonce ) HDATA = SHA1( data + timestamp + ramdom ) !HtxID = SHA256( SHA256( HBLOCK + HDATA ) )
Generating Transaction ID
• Use SHA256, SHA1, and Double SHA256
• The HDATA hash key is generated by the Chord algorithm
49
![Page 50: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/50.jpg)
successor(HDATA) [1]
• Handling Churn
• the continuous activities of node join and leave
50
// ask node n to find the successor of HDATA n.successor(HDATA) //It is a half closed interval. if (id ∈ (n, successor] ) return successor; else // forward the query around the circle n0 = closest_preceding_node(id); return n0.find_successor(id);
[1]: https://en.wikipedia.org/wiki/Chord_(peer-to-peer)
![Page 51: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/51.jpg)
Simulating Data Transaction
• The successor node is represented as N’
• N' receives the chunk data, and combines the valid block ID and the data key to generate a transaction ID
• N’ signs the transaction with its private key embedded in the hardware
• N’ creates a record that comprises the transaction ID and the chunk data and stores the record in a valid block
51
![Page 52: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/52.jpg)
Linked Data for TransactionsN.put(data) { key = hashDataKey(data); ! // Send chunk data to N’ over the Chord ring. send( SUCESSOR(key), { payload: data } ); } !N’.PutToBlock(block, doc) { db = DatabaseAdapter.getDatabase(); ! txID = SHA256( SHA256( block.id + doc.key ) ); ! tx = new Transaction( doc.value ); tx.sign( privateKey ); ! record = { “@context”: “http://flowchain.io/ledger-context.jsonld”, “txID”: txID, “tx”: tx }; ! db.put( record ); }
52
![Page 53: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/53.jpg)
Vaild Block Lookup
N’.lookupBlock(doc) { db = DatabaseAdapter.getDatabase(); ! var blocks = db.queryValidBlocks(); ! blocks.forEach(function(block) { if (this.PutToBlock(block, doc) === true) return; }); }
53
![Page 54: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/54.jpg)
54Flowchain Node Endpoint Node
SUCCESSOR(D1) = N6
D1D2D3D4
N1N2
N3
N4N5
N6
N7
N8
SUCCESSOR(D2) = N3
N1N2
N3
N4N5
N6
N7
N8D2D3D4
SUCCESSOR(D3) = N5
N1N2
N3
N4N5
N6
N7
N8D3D4
SUCCESSOR(D4) = N7
N1N2
N3
N4N5
N6
N7
N8D4
(a) (b)
(c) (d)
![Page 55: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/55.jpg)
Ontology: Auditing Transactions
• The DLT can be “auditable”
• Use case example
• The “administrator” approve the data transaction
• The “monitor process” performs a “branch merge “operation that all “virtual blocks” merge imperceptibly into a single blockchain
55
![Page 56: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/56.jpg)
The Auditing Pattern
• RPC operations are built upon the Chord protocols
56
![Page 57: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/57.jpg)
Agenda
• Motivation
• Architecture Overview
• Handling Heterogeneous Hardware
• Device Interoperability
• Distributed Ledger for the IoT
• Consensus System
• Use the Flowchain SDK
57
![Page 58: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/58.jpg)
Understanding Block Time
• The “time” to find a valid block
• Often know as the “mining”, and
• Difficulty control
• Blockchain-based consensus system
• Aka mining-based consensus system
58
![Page 59: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/59.jpg)
Block #0 Transactions
Block #1 Transactions
Block #2 Transactions
Block #3 Paul’s
Transaction
Block Height Difficulty
Understanding “Difficulty”
59
![Page 60: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/60.jpg)
“Difficulty Control”
• The mining-based PoS system will use the “difficulty” concept derived from the PoW system
• Flowchain is the mining-based PoS system
• Used in the consensus mechanism
60
![Page 61: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/61.jpg)
Consensus Mechanisms
• Proof-of-Work (PoW)
• Proof-of-Stake (PoS)
• Proof-of-[ Resource, Existence, Reliability, and etc ]
• The “hybrid”
• Practical Byzantine Fault Tolerance (PBFT)
• Paxos / The Part-Time Parliament
• Delegate Proof-of-Stake (DPoS)
61
![Page 62: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/62.jpg)
Consensus for the IoT
• A mining-based proof-of-stake
• Minimal resource requirement
• Device reliability
• etc
62
![Page 63: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/63.jpg)
Flowchain Consensus System
• The miner is timed in a fixed number calculation per second in which the Flowchain can comprise a proof-of-stake mechanism
• Flowchain implements a mining-based proof-of-stake consensus system
• Use the probability density function to ensure a cost-effective difficulty control system
63
![Page 64: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/64.jpg)
Technical Challenges
• Resource-constrained devices
• Limited computation power
• Limited resource (memory and etc)
• Difficulty control for a mining-based PoS on the IoT
64
![Page 65: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/65.jpg)
Hashing Rate
• Problem-solving
• Brute-force
• Memory-hard functions
• Probability distribution
65
![Page 66: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/66.jpg)
Probability Density
• Probability density to control the mining difficulty
• Normal
• Poisson
Source: https://en.wikipedia.org/wiki/Normal_distribution (License: Public Domain)
66
![Page 67: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/67.jpg)
Flowchain Difficulty Control
var gaussian = require(‘gaussian'); !// the mean (μ) of the distribution var mean = 0; !//the variance (σ^2) of the distribution var variance = 0.2; !var distribution = gaussian(mean, variance); !function Difficulty(x) { if (!x) x = Math.random(); ! x = x - variance; ! var probability = distribution.pdf(x); ! return fixDifficulty(probability); }
67
![Page 68: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/68.jpg)
Flowchain PoS for the IoT
var Miner = require(‘./VirtualMiner’); // Import flowchain miner ! // Create a new miner this.miner = new Miner(); ! miner.setPreviousBlock(block); ! setInterval(function() { miner.generateHash(); ! // A success hash is generated if (miner.isSuccess()) { var block = miner.getNewBlock(); ! // Successful mined and save the new block self.blockchain.push(block); ! miner.setPreviousBlock(block); } else { var block = miner.getMiningBlock(); } }, 50);
68
![Page 69: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/69.jpg)
Permissioned DLT
• The p2p network authorizes nodes intending to join the network that only authorized nodes can operate as a Flowchain node
• Flowchain ensures the interoperability between different ledgers within the same IoT peer-to-peer network
• Flowchain DLT transactional protocols has been built upon the Chord algorithm and protocol
69
![Page 70: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/70.jpg)
Agenda
• Motivation
• Architecture Overview
• Handling Heterogeneous Hardware
• Device Interoperability
• Distributed Ledger for the IoT
• Consensus System
• Use the Flowchain SDK
70
![Page 71: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/71.jpg)
Flowchain Open Source
• A distributed ledger for the IoT
• A programming framework
• Software architecture designed from the ground up
• Visit https://flowchain.io
71
![Page 72: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/72.jpg)
URL Router Thing DescriptionEvent Emitter
wotcity.io: Application Layer Protocols
Request Handlers
Miner Chord Protocol
wwRPC: light-weight RPC over REST-style operations
Virtual Block
Flowcoin: peer-to-peer trusted computing
Dist
ribut
ed L
edge
r Lay
erBr
oker
Ser
ver L
ayer
Web
of T
hing
s La
yer
Distributed Hash Table
JavaScript Runtime (Node.js, V8, JerryScript, and etc.)
Data Store Assets Management Device Management Inter Ledger Protocols
Flowchain Software Framework
72
![Page 73: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/73.jpg)
Architecture Design
• Distributed Ledger Layer
• Usually known as the “Blockchain”
• Provides a distributed data store that shares transactional data across all IoT devices
• Broker Server Layer
• Provides a helper library to create the IoT application server and establishes the peer-to-peer IoT networking
• Web of Things (WoT) Layer
• Adopts the W3C’s WoT ontology that represents the physical IoT device as a virtual object
73
![Page 74: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/74.jpg)
TSDB with the Semantic
• A Linked Data document to support time series database (TSDB) via the semantic web technology
• the TSDB can use the semantic object in ```@context``` as the NoSQL schema design to index transaction records
74
001 1492041600 c20c44b5ba7a34e7ddd7ec8cbd2203d3 tx1
002 1492041600 21b15ca036d6c144fc14b6b7fb201290 tx2
003 1492041600 905a862315e2c58fcb8038792be3951b tx3
004 1492041610 685433e9d3fa916fdca73ebe8efd878a tx4
005 1492041610 7b46c90b7ac12d3ad47c4cb7645c5741 tx5
006 1492041650 7d2c0a88166f5b267613ea51f455adf7 tx6
007 1492041660 fb2cc23fe3f078aea367123a48799dd5 tx7
Object ID Timestamp Transaction ID (offset 0-31) Transaction Data+0 +32
74
![Page 75: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/75.jpg)
Flowchain Open Source
• A distributed ledger for the IoT
• A programming framework
• Software architecture designed from the ground up
• Visit https://flowchain.io
75
![Page 76: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/76.jpg)
Start an IoT Node
// Import the broker server middleware var server = require('./server'); !// Utils var crypto = require('crypto'); !// Database var Database = require('./database'); var db = new Database('picodb'); !// Start the IoT application server and start to find blocks server.start({ onstart: onstart, onmessage: onmessage, onquery: onquery, ondata: ondata, join: { address: '10.186.110.91', port: '8000' } });
76
![Page 77: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/77.jpg)
Store Transactions
// Use DatabaseAdapter to select a data store var Database = require('./database'); var db = new Database(‘picodb'); !var onmessage = function(req, res) { var payload = req.payload; var block = req.block; var node = req.node; ! // Key of the data var key = message.id; ! // Data var tx = message.data; ! // Block hash as the secret and data key as the context var hash = crypto.createHmac('sha256', block.hash) .update( key ) .digest(‘hex'); ! db.put(hash, tx, function (err) { if (err) return console.log('Ooops! onmessage =', err) }); }
77
![Page 78: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/78.jpg)
IoT Devices themselves in a decentralized IoT platforms
can have a new model to exchange data.
!
[device democracy] Blockchain IoT technology provides
such new model for secured and trusted data exchange
that keep trusted records of all exchanged data between
devices.
Flowchain Mission
78
![Page 79: Flowchain: A Case Study on Building a Blockchain for …schd.ws/hosted_files/lc3china2017/43/Flowchain-LC3_2017_Beijing...Flowchain: A Case Study on Building a Blockchain for the IoT](https://reader031.vdocument.in/reader031/viewer/2022022516/5b03b5f67f8b9a3c378c9b79/html5/thumbnails/79.jpg)
Future Work
• Open issues, contributions, and review comments through the open source development methodology
• Time-series database for the distributed ledger
• Benchmark tools
• User Guide and Developer Docs
• Developing Ontology Patterns
• Blockchain IoT Kit in Q4 2016 along with a fine-grained software framework
79