blockchain on go

39
BlockChain on Go @__timakin__ / DevFest Tokyo 2017

Upload: seiji-takahashi

Post on 21-Jan-2018

4.256 views

Category:

Engineering


2 download

TRANSCRIPT

BlockChain on Go@__timakin__ / DevFest Tokyo 2017

• Github: timakin / Twitter: @__timakin__ • Gunosy Inc.

• Go / Swift • community

• golang.tokyo • roppongi-golunch • blockchain.tokyo

golangtokyo.connpass.com

• Blockchain

• Go Blockchain

Blockchain•

• -> JSON

• P2P

Chain Flow

hash

target nonce

transactions transactions transactions

blockblock block

Example of block

{ difficulty: '137447', extraData: '0x476574682f76312e302e312f6c696e75782f676f312e342e32', gasLimit: 3141592, gasUsed: 0, hash: '0x4d3063b91cbaa12bf2de81014c1319febc9f197c93f81b0746afaffaa9496620', nonce: '0x28fda83cb19ed497', number: 100, parentHash: '0x5885cdec1d1410580eaaf1fb7ef9db245a735822d48e816c73d926b7c9872f15', size: 536, timestamp: 1439451765, totalDifficulty: '13551548', transactions: [ ], transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',}

Consensus Algorithm• Proof of Work

• Node 0 Node

• target nonce(hash value)

• Node

• Proof of Stake

• ex) SHA256(prevhash + address + timestamp) <= 2^256 * balance (volume of stake) / diff

• Proof of Stake Velocity

Decentralized Application

Processing

File Storage Database

Processing

File Storage Database

• • •

• •

• ms •

• • 2017/10/1 135GB

• • Bitcoin Ethereum

Read/Write

ms •

http://blockchaindemo.io/

Go Blockchain

• Go

C++ Python •

Go

Go?•

• •

btcd• Bitcoin fork

• bitcoin/bitcoin C++

• libbitcoin(C++), BitcoinJ(Java) •

• JSON-RPC API

geth(go-ethereum)• Go

• Ethereum protocol Go

• Ethereum

• Windows OS

• geth( 7832) cpp-ethereum( 1710),

pythereum( 1487), ethereumj(760)

Ethereum

(geth)

P2P Network

+

Mist Wallet

https://ethstats.net/

HyperLedger

• Supported by The Linux Foundation •

• IBM Intel J.P.Morgan MUFG NEC

etc…

HyperLedger

ref: http://gaiax-blockchain.com/hyperledger-project

HyperLedger Projects

Fabric PBFT

*

* http://www.jpx.co.jp/corporate/research-study/working-paper/tvdivq0000008q5y-att/

JPX_working_paper_No15.pdf

HyperLedger Fabric Network

ref: https://www.ibm.com/developerworks/jp/cloud/library/j_cl-blockchain-basics-bluemix/

PBFT (Practical Byzantine Fault Tolelance)

ref: https://www.ibm.com/developerworks/jp/cloud/library/j_cl-blockchain-basics-bluemix/

ChainCode

• Go Java

ChainCode

World State

• ChainCode R/W KVS JSON

ChainCode

shim.ChaincodeStubInterface• chaincode WorldState Ledger

API

• Init, Invoke

• Get/Put/Delete State World State

• shim.Success, shim.Error res payload writer

200, 400,

500

HyperLedger ComposerFabric

Web IDE

HyperLedger Composer

Web UI (Fabric)

4

Model:

Access Control: Read/Write

Script: JS

Query:

Model REST API

IPFS• P2P

• Blockchain

• ipfs.pics Gyazo Winny

Upload assets# $ ipfs add test.jpgadded QmaC9pUA3grWJ948u1VWRLG1wPLP8YZe7b3HopBGk4zZyA test.jpg

$ ipfs cat /ipfs/QmaC9pUA3grWJ948u1VWRLG1wPLP8YZe7b3HopBGk4zZyA > butaman.jpg$ open https://ipfs.io/ipfs/QmaC9pUA3grWJ948u1VWRLG1wPLP8YZe7b3HopBGk4zZyA

# $ ipfs add -r ~/myproject

# Fuse$ ipfs mount$ ls /ipfs/$hash/

# $ ipfs add -q test.mp4

API Client

var ipfs = require('ipfs-client'); var stream = ipfs.cat('QmTE9Xp76E67vkYeygbKJrsVj8W2LLcyUifuMHMEkyRfUL');stream.pipe(process.stdout);

ipfs.add(process.stdin, function(err, hash) { console.log(hash);});

https://www.npmjs.com/package/ipfs-client

API

Scala Go JavaScript

WebUI

• Go C++

• API

CLI

• WebUI