区块链入门

社区广播:运维派(Yunweipai.com)是国内最早成立的IT运维社区,欢迎大家投稿,让运维人不再孤寂的成长!

概述

对于近期很火热的数字货币,吃瓜群众也就只能看它涨看它跌。支撑数字货币运行的平台是的核心技术是区块链,技术免费且没有风险,最近也抽时间学习了区块链,将学习的内容总结于此。

一句话总结

用一句话总结区块链:一个分布式网络中各个参与者通过共识算法,维护网络中随着时间不断增长的不可篡改的链。

区块链DNA

区块链DNA,顾名思义是区块链区别于他物的关键要素。

  • De-Centralize&Share 去中心化&共享
  • Consensus 共识
  • Immutability 不可更改

De-Centralize&Share 去中心化&共享

基于P2P网络,P2P网络中每个参与者之间共享数据,网络中任何两个节点(参与者)可以发起交易,请求改变共享的数据,请求被其他节点认可之后,纪录到块中。通过这种方式免去了交易的中间人,简化交易流程,提升交易效率。

Consensus 共识

网络中的节点通过共识算法达成一致,同意或拒绝网络中节点发起的交易。共识算法是区块链的核心。共识算法是的网络中节点对节点之间的点对点交易成为可能,免去中间人。

Immutability 不可更改

通过共识算法达成的交易记录被记录到一个区块中,区块一旦生成之后就不可更改。此特性是的区块链可以用于记录合约,避免单方面篡改合约。

三个主流区块链平台

回看区块链的发展历史,可以分为三个阶段:区块链1.0,区块链2.0,区块链3.0。

区块链1.0: BitCoin 比特币

区块链1.0就是比特币,比特币是区块链目前最成功的应用,没有之一。区块链1.0是一个封闭系统,不开放给开发者扩展,不是一个通用平台,可以将比特币与区块链1.0等同起来。

区块链2.0: Etherenum 以太坊

以太坊是一个开放的区块链平台,并通过EVM(Etherenum Virtual Machine)使得开发者可以基于以太坊开发区块链应用(Smart Contract 智能合约)。以太坊是由一个平台+一系列的工具组成以及应用开发的环境组成。以太坊平台是开放给所有用户、开发者使用的,不过开发者运行应用需要消耗以太币,以太币使用比特币兑换。以太坊本身是开源的,当前微软等企业有提供基于开源的以太坊构建的BaaS服务(Blockchain as a Service)。

区块链3.0: Hyperledger 超级账本

超级账本定位是企业级的区块链平台,区块链按照公开程度分为公开链、联盟链/私有链。前面的比特币与以太坊属于公开链,超级账本瞄准的目标用户是企业,属于联盟链/私有链。企业级的区块链应用与Internet上公开的区块链平台是有显著区别的,前面说到微软基于以太坊构建了BaaS服务,当前微软正在开发一个CoCo Framework的区块链框架,这个就是瞄准企业用户的。CoCo Farmeowk还正在开发中,预计2018年开源给社区,当前已经放出了白皮书,里面总结了公开链与企业级区块链之间的Gap:

  • 交易吞吐量(TPS)太小:以太坊的交易吞吐量TPS大约为20交易/秒,而像Visa信用卡系统需要的吞吐量为2000交易/秒
  • 缺少灵活、丰富的信息安全模型:企业应用涉及到很多企业机密信息,并不是网络中所有参与者都可以获取到同样的信息
  • 缺少用户权限管理:企业应用需要对网络中不同节点赋予不同的权限,并不是所有节点都是等价的
  • 不节能:当前以太坊、比特币使用的基于PoW(Proof of Work)的共识算法非常耗电,不适合在企业级区块链应用中使用

超级账本以及微软的Coco Framework都是为了解决上述问题而设计的。

系统结构

BitCoin

http://www.vamsitalkstech.com/?p=1451

Blocalchain Layer

区块链层是去中心化的技术实现层,区块链层被所有的节点共享,矿工通过挖矿的方式更新区块链,通过加密与共识算法等技术维持区块链的更新。

BitCoin Protocol & Client

特定的数字货币(如比特币)协议层,承载比特币的共识算法规则与API。比特币有三种客户端:移动客户端、完全客户端、Web客户端。

Blockchain Explorer&tools

用于查询、浏览区块链的工具。

Etherenum

Internet

P2P网络层。

Hardware Clients

网络中的节点,包括矿工等。

Swarm(Storage)

以太坊网络中用于存储的部件,由于Blockchain本身不适合用于存储大文件,因此通常的做法是将索引信息存储到块中,而大文件本身单独存储。可以将Swarm理解为以太坊网络中的BitTorrent。

Whisper(Message)

以太坊网络中用于节点之间互相发送消息的部件,使用此部件节点之间可以互相通信。

EVM(Consensus)

以太坊网络中用于解析并执行用户的智能合约部件,可以理解为代码执行的沙箱。

Decentrailzed Applications

基于上述网络开发的各种去中心化的应用,包括以太坊钱包,也是其中一种应用。

Mist Browser

浏览以太坊区块链的工具。

图灵完备性

通过提供可编程的语言与运行环境,使得以太坊具备图灵完备特性,因此开发者可以基于以太坊开发出很多去中心的应用,这个是以太坊与BitCoin的显著区别。由于图灵完备性,理论上开发者可以开发出永久在线运行的应用,但是应用运行是需要消耗资源的,因此以太坊为在设计上,增加了Gas的概念,应用运行需要消耗Gas,Gas是需要使用以太币购买的,通过这种方式防止恶意应用攻击网络。

World Computer

以太坊的图灵完备+P2P网络的特点,使得以太坊平台可以成为World Computer,对于基于以太坊开发的去中心化应用来说确实是如此,因为你付钱给以太坊购买算力,来运行你的应用。

Hyperledger

http://www.the-blockchain.com/docs/Hyperledger%20Whitepaper.pdf超级账本的白皮书里面对超级账本的结构已经阐述的很清楚,超级账本的目标就是为了使得区块链能够在企业使用。下面的内容是从白皮书直接摘要出来的,也很直白。

Membership

Hyperledger is a private­validator network protocol, so all entities are required to register with membership services to obtain an identity with access and transaction authority on the network. Validators during network setup can determine the level of permission that is required to transact. Network setup also defines the network as permissive, allowing ease of access and support for rapid and high adoption, or restrictive for a more controlledenvironment.

Registration​service offers the control and management of authorizations for Hyperledger participation.

Identity Management​service provides the management of assurance and authorized disclosure of association of identities and roles to Hyperledger participants.

Auditability​service offers the capability to provide authorized entities with the means to link transactions of individual users, or groups of users according to affiliations or roles, and to access the activity of a particular user of the system, or the operation of the system itself.

Blockchain

Blockchain services consists of three key components: Peer­to­Peer (P2P) Protocol, Distributed Ledger and Consensus Manager.

P2P Protocol​uses Google RPC, which is implemented over HTTP/2 standards, providing many capabilities including bidirectional streaming, flow control, and multiplexing requests over a single connection. Most importantly, it works with existing Internet infrastructure, including firewalls, proxies and security. This component defines messages used by peer nodes, from point­to­point to multicast.

Distributed Ledger ​manages the blockchain and the world state by implementing three key attributes:

  • Efficiently calculating a cryptographic hash of the entire dataset after each block.
  • Efficiently transmitting a minimal “delta” of changes to the dataset, when a peer is out of sync and needs to “catch up.”
  • Minimizing the amount of stored data that is required for each peer to operate.

Hyperledger supports two types of transactions: code­deploying transactions and code­invoking transactions. A code­deploying transaction can submit, update or terminate a piece of chaincode, and the validating node must protect the authenticity and integrity of the code and its execution environment. By contrast, a code­invoking transaction is an API call to a chaincode function, which is similar to how URI invokes a servlet in JEE. Note that each chaincode maintains its own state, and a function call is a common method for triggering chaincode state changes.

Consensus Manager​ is an abstraction that defines the interface between the consensus algorithm and the other Hyperledger components. Consensus Manager receives transactions, and depending on the algorithm, decides how to organize and when to execute the transactions. Successful execution of transactions results in changes to the ledger.

Event Hub in a decentralized network is complex in nature, because an event can appear to occur multiple times, once on each peer node. Callbacks can end up receiving multiple invocations for the same event. Therefore, a peer node (preferably non­validating and local) manages the event pub/sub that applications are interacting with. The peer node emits events as conditions satisfied, in no particular order. Events do not persist, so applications should capture events if required.

Chaincode

As defined in the previous sections, a chaincode is a decentralized transactional program, running on the validating nodes.

Chaincode Services ​uses Docker to host the chaincode without relying on any particular virtual machine or computer language. Docker provides a secured, lightweight method to sandbox chaincode execution. The environment is a “locked down” and secured container, along with a set of of signed base images containing secure OS and chaincode language, runtime and SDK images for Golang. Additional programming languages can be enabled, if required.

Secure Registry Services​enables Secured Docker Registry of base Hyperledger images and custom images containing chaincodes.

Application programming interface

Hyperledger includes the REST and JSON RPC APIs, events, and an SDK for applications to communicate with the network. Typically, applications interact with a peer node, which requires some form of authentication to ensure that the entity has proper privilege; messages from a client are signed by the client identity and verified by the peer node.

网友评论comments

发表评论

电子邮件地址不会被公开。 必填项已用*标注

暂无评论

Copyright © 2012-2017 YUNWEIPAI.COM - 运维派 - 粤ICP备14090526号-3
扫二维码
扫二维码
返回顶部