一文看懂什么是区块链 什么是区块链?简单来说

什么是区块链

区块链是一个概念,而比特币与以太币等其他加密货币均为区块链的应用之一。

以下简单一句话理解区块链:许多交易组成区块,许多区块前后互相链结,组成区块链

可先看这个简单介绍影片:https://www.youtube.com/watch?v=sYduOfRLHq0

想像今天主管口头下令新政策,虽然没有做记录,但大家听到后都会互相口耳相传,之后这个政策虽然没有被一个中心把它记录下来,但大家心中都知道这件事情了,如果之后这个下这个政策的主管离职了,剩下的人会以大家多数人讲的为算,但如果有人想更改,也会因为与大多数人讲的不同而被拒绝

理解区块链

比特币可以说是目前家喻户晓的一项使用区块链技术的应用。我们先来说明比特币是如何运作,说明过程中会将会一步一步讲解区块链的相关概念

Bitcoin is an innovative payment network and a new kind of money. 源自比特币官网

我们最常听到比特币是在新闻报导或朋友闲聊时,谈到今天比特币价格又飙涨到了多少,某位玩家又在中国又投资了新的矿机或矿场本书将会在后续章节介绍如何申请一个自己的比特币地址与钱包,并且进行购买比特币与转帐等动作

大家可能会想的第一个问题可能是: 在电脑上的货币他真的够安全吗?

接着我们会想到网路上刷信用卡不也是在网路上的虚拟交易吗,那线上刷信用卡跟我们使用比特币他的差别又在哪里

加密货币钱包

比特币地址类似于14qViLJfdGaP4EeHnDyJbEGQysnCpwn1g

可用的比特币位址数量接近2的161次方个,假如地球上约有2的63次方粒沙,如果每一粒沙中有一个地球,那么比特币位址总数远远超过所有这些地球上的所有的沙子的数量

为了能在区块链网路里进行交易,你需​​要一个比特币地址,它让你可以存放你的比特币。比特币地址是由一个私钥之后产生公钥在进行一些密码学方法出的一个比特币地址(将会在后续章节详细介绍产生方式)

每个公钥都是由一个私钥所产生

如果一个讯息被公钥加密,只有配对的私钥才能解密读到讯息。反之,如果你用你的私钥加密讯息,只有配对的公钥可以解密。所以当小明想要转帐小王,他需要用他的私钥将转帐讯息加密后,送到网路里,然后每个节点使用小明的公钥将讯息解开,以确认是由小明发送的。

在加密完成时会产生一个电子签名,它会被节点们用来确认交易讯息的发送来源和真伪。电子签名内容是一串文字,它是由私钥对交易讯息所签发出的一段hash。如果你更改交易讯息中任何一个字元,电子签名也会跟着改变,所以骇客很难更改你的交易讯息或是得知交易金额。

查询余额

我们转帐后比特币是如何知道我们现在帐户余额是多少呢?

刚才有提到比特币网路的组成是由全世界跑着比特币节点程式的电脑所构成

每个节点电脑会进行验证交易与同步其他节点资料的动作且都保有一份区块链帐本,但节点是如何知道你的帐户余额?区块链系统并没有记录每个人的帐户余额,事实上,它只有纪录网路上每笔交易纪录

持有比特币代表的是,于区块链帐本上查询你的地址还存在着尚未变成输入交易之纪录。


看到上图

如果在out没有连接着其他in的话则其即变为目前帐户的余额

区块中的交易


看到上图,每个产生的交易会先在交易池中等待被节点纳入区块中

每个节点都可以将若干个交易讯息从交易池中选取并打包成区块发送到网络上,并建议其为链上的最新区块。

区块链系统使用密码学方法(后面章节会提到实作)设计了一道复杂的数学题,只要有正确答案,就可以成为链上的最新区块。这个答案是由节点计算后一起被打包进区块。答案是一个数字,得到答案的唯一方法就是不断地计算。哪个节点先得到了答案,它就先有权利将它的候选区块放到链上。

每个节点都有一份区块链副本,当节点拿到其他节点丢出来的候选区块(已有正确答案的),就会把区块放到副本链上,同时系统会要求节点搜寻网路里有没有比它的副本链更长的链,如果有,舍弃原有的链,取用更长的链。

在上图中,我们可以看到每个方块中都包含一些数值这些值即为存放在区块链中的区块资料

1.区块链是由包含交易讯息的区块,从后向前有序接起来的数据结构,区块被从后向前有序地链接在这个链条里,每个区块都指向前一个区块

2.对每个区块头进行SHA256加密哈希,每个区块头都包含它的父区块哈希值。这样把每个区块链接到各自父区块的哈希值序列就创建了一条一直可以追溯到第一个区块(创世区块)的链条

3.由于区块头包含“父区块哈希值”,所以当前区块的哈希值因此也受到该字段的影响。如果父区块的hash不一样,则子区块也会有不同的hash,接着这个子区块的子区块也会有不同hash,这种瀑布效应将保证该区块不会被改变

4.区块内包含以下,区块头80字节(byte),而平均每个交易至少是250字节,而且平均每个区块至少包含超过500个交易

另一个相关介绍影片:https://www.youtube.com/watch?v=r43LhSUUGTQ

Merkle Tree

如果今天在区块中的某一笔交易本文被窜改,则计算出来之Merkel Root也一定不同

利用这个特性可避免区块中所含的历史交易遭任意窜改

Merkle树被用来归纳一个区块中的所有交易,同时生成整个交易集合的数字指纹,且提供了一种校验区块是否存在某交易的高效途径

为了创建父节点HAB,子节点A和子节点B的两个32字节的哈希值将被串联成64字节的字符串。随后将字符串进行两次哈希来产生父节点的哈希值:

HAB~=SHA256(SHA256(HA + HB))挖矿

Mining = Securing the network = verify computation

一个新的区块被“挖掘”出来,每个区块里包含着从上一个区块产生到目前这段时间内发生的所有交易,这些交易被依次添加到区块链中。我们把包含在区块内且被添加到区块链上的交易称为“确认”交易,交易经过“确认”之后,新的拥有者才能够花费他在交易中得到的比特币

矿工们在挖矿过程中会得到两种类型的奖励:创建新区块的新币奖励,以及区块中所含交易的交易费

在挖矿过程中成功“挖出”新区块的矿工可以得到该区块中包含的所有交易“小费”。目前,这笔费用占矿工收入的0.5%或更少,大部分收益仍来自挖矿所得的比特币奖励

Finding a nonce input to the algorithm so that the result is below a certain threshold

区块链用难度来控制下一个区块的产生速度,而矿工利用当前的区块头加上一个随机数nonce,并做hash,如果产生一个低于设定难度的值即可成功挖到矿

藉由改变nonce来产生不同hash,想办法让此hash小于目前所设定难度的数值

https://www.youtube.com/watch?v=lik9aaFIsl4&t=1s

挖矿困难度解释

https://en.bitcoin.it/wiki/Target

挖矿时间估计

http://coinish.com/bitcoin-mining-calculator/#calc-information

我们可以使用以下网页进行挖矿模拟

https://anders.com/blockchain/block.html


Nonce为一个随机值让我们更改实际挖矿时即为更改Nonce并想办法算出结果因为相同字串经过sha后的数值都一样

但无法预料哪个字串经过sha可以得到我们想要的数值

Data为模拟纳入区块的讯息

看到目前市面上的币种以及价格

当我们想要对目前市面上的加密货币进行投资时,我们必须先到市场上了解其价值

以下网站列出了一些市面上的加密货币可供我们参考

https://coinmarketcap.com/

其他相关Bitcoin schema介绍

以下网站列出了比特币相关schema

https://webbtc.com/api/schema

加密货币Market State图表

一样列了许多市面上可见的加密货币,但采用了另一种方式将之呈现

http://cryptomaps.org/


What is blockchain

Blockchain is a concept, and other cryptocurrencies such as Bitcoin and Ethereum are one of the applications of blockchain.

The following is a simple sentence to understand the blockchain: many transactions form blocks, and many blocks are linked to each other to form a blockchain

You can first watch this simple introduction video: https ://www.youtube.com/watch?v=sYduOfRLHq0

Imagine that today the supervisor verbally ordered a new policy. Although no records were kept, everyone will spread the word to each other after hearing it. After that, although the policy will not be It was recorded by a center, but everyone knows this matter in their hearts. If the person in charge of this policy resigns later, the remaining people will be based on what the majority of us say. But if someone wants to change it, it can be changed. Will be rejected because it is different from what most people say

Understanding Blockchain

Bitcoin can be said to be a well-known application using blockchain technology. Let’s first explain how Bitcoin works. During the explanation, we will explain the related concepts of blockchain step by step

Bitcoin is an innovative payment network and a new kind of money. From the Bitcoin official website

We most often hear about Bitcoin in news reports or when chatting with friends. We talk about how much the price of Bitcoin has soared today, and that a certain player has invested in a new mining machine or mine in China. This book will introduce in subsequent chapters how to apply for your own Bitcoin address and wallet, and perform actions such as purchasing Bitcoin and transferring funds.

The first question you may think about may be: How to use the computer Is the currency on the Internet really safe enough?

Then we will think about whether swiping a credit card online is also a virtual transaction on the Internet. What is the difference between swiping a credit card online and using Bitcoin? Where

Cryptocurrency wallet

The Bitcoin address is similar to 14qViLJfdGaP4EeHnDyJbEGQysnCpwn1g

The number of available Bitcoin addresses is close to 2^161, assuming there are about 2^63 grains on the earth Sand, if there is an earth in every grain of sand, then the total number of Bitcoin addresses far exceeds the number of all the sand on all these earths

In order to be able to conduct transactions in the blockchain network, You need a Bitcoin address, which allows you to store your Bitcoins. A Bitcoin address is a Bitcoin address that is generated from a private key and then performs some cryptographic methods to generate a public key (the generation method will be introduced in detail in subsequent chapters)

Each public key is composed of a Generated by a private key

If a message is encrypted by a public key, only the paired private key can decrypt and read the message. Conversely, if you encrypt a message with your private key, only the matching public key can decrypt it. So when Xiao Ming wants to transfer money to Xiao Wang, he needs to use his privateThe transfer message is encrypted with the key and sent to the network. Then each node uses Xiao Ming's public key to decrypt the message to confirm that it was sent by Xiao Ming.

When encryption is completed, an electronic signature will be generated, which will be used by nodes to confirm the source and authenticity of the transaction message. The content of the electronic signature is a string of text, which is a hash of the transaction message signed by the private key. If you change any character in the transaction message, the electronic signature will also change accordingly, so it is difficult for hackers to change your transaction message or learn the transaction amount.

Check the balance

How does Bitcoin know what our current account balance is after we transfer?

As mentioned just now, the composition of the Bitcoin network is It is composed of computers running Bitcoin node programs around the world

Each node computer will verify transactions and synchronize other node data and maintain a blockchain ledger, but how does a node Know your account balance? The blockchain system does not record everyone's account balance. In fact, it only records every transaction on the Internet

What holding Bitcoin means is that you can check your balance on the blockchain ledger. There is still a record of the address that has not yet been converted into an input transaction.


See the picture above

If out is not connected to other in, it will become the balance of the current account

Transactions in the block< p>
See the picture above, each generated transaction will first wait in the transaction pool to be included in the block by the node

Each node can transfer several transaction messages from the transaction pool Select and package it into a block and send it to the network, and propose it as the latest block on the chain.

The blockchain system uses cryptography methods (the implementation will be mentioned in the following chapters) to design a complex mathematical problem. As long as there is a correct answer, it can become the latest block on the chain. This answer is calculated by the node and packaged into the block. The answer is a number, and the only way to get it is to keep calculating. Whichever node gets the answer first has the first right to put its candidate block on the chain.

Each node has a copy of the blockchain. When a node gets the candidate block thrown out by other nodes (the one with the correct answer), it will put the block on the copy chain, and at the same time The system will ask the node to search the network for a longer chain than its copy chain. If so, discard the original chain and use the longer chain.

In the picture above, we can see that each box contains some values. These values ​​are the block data stored in the blockchain

< p>1. The blockchain is a data structure composed of blocks containing transaction information, connected in an orderly manner from back to front. The blocks are linked in this chain in an orderly manner from back to front, and each block points to Previous block

2. Perform a SHA256 cryptographic hash on each block header. Each block header contains its parent block hash value. This creates a sequence of hashes linking each block to its parent block.A chain that can be traced back to the first block (the genesis block)

3. Since the block header contains the "parent block hash value", the hash value of the current block is also affected by this field impact. If the hash of the parent block is different, the child block will also have a different hash, and then the child blocks of this child block will also have different hashes. This waterfall effect will ensure that the block will not be changed

4. The block contains the following, the block header is 80 bytes, and the average transaction is at least 250 bytes, and the average block contains at least more than 500 transactions

< p>Another related introduction video: https://www.youtube.com/watch?v=r43LhSUUGTQ

Merkle Tree

If a certain transaction in the block today is tampered with, it will be calculated The Merkel Root must also be different

Using this feature can prevent the historical transactions contained in the block from being arbitrarily tampered with

The Merkle tree is used to summarize a All transactions in the block simultaneously generate digital fingerprints of the entire transaction set, and provide an efficient way to verify whether a certain transaction exists in the block

In order to create the parent node HAB, child node A and child node The two 32-byte hashes of B will be concatenated into a 64-byte string. The string is then hashed twice to generate the hash value of the parent node:

HAB~=SHA256(SHA256(HA + HB)) Mining

Mining = Securing the network = verify computation

A new block is "mined", and each block contains all transactions that occurred during the period from the generation of the previous block to the present. These transactions are added to the blockchain in turn. We call the transactions included in the block and added to the blockchain as "confirmed" transactions. Only after the transaction is "confirmed" can the new owner spend the Bitcoins he received in the transaction

Miners will receive two types of rewards during the mining process: new currency rewards for creating new blocks, and transaction fees for transactions included in the blocks

Successful in the mining process" The miner who mines a new block gets a "tip" on all transactions included in that block. Currently, this fee accounts for 0.5% or less of miners' revenue, with most of the revenue still coming from the Bitcoin rewards earned from mining

Finding a nonce input to the algorithm so that the result is below acertain threshold

The blockchain uses difficulty to control the generation speed of the next block, and miners use the current block header to add a random number nonce and do a hash. If a block lower than the set difficulty is generated The value can be successfully mined

By changing the nonce to generate different hashes, find a way to make this hash smaller than the currently set difficulty value

https://www. youtube.com/watch?v=lik9aaFIsl4&t=1s

Mining difficulty explained

https://en.bitcoin.it/wiki/Target

Mining time estimate

http://coinish.com/bitcoin-mining-calculator/#calc-information

We can use the following web page for mining simulation

https://anders .com/blockchain/block.html


Nonce is a random value. When we change the actual mining, we change the Nonce and find a way to calculate the result, because the values ​​of the same string after sha are all the same. Same

But we can’t predict which string will get the value we want after sha

Data is the information included in the simulation block

See the currencies currently on the market and price

When we want to invest in the cryptocurrencies currently on the market, we must first go to the market to understand its value

The following website lists some of the cryptocurrencies on the market for us to Reference

https://coinmarketcap.com/

Other related Bitcoin schema introduction

The following website lists Bitcoin-related schemas

https://webbtc. com/api/schema

The Cryptocurrency Market State chart

also lists many cryptocurrencies available on the market, but uses another way to present them

< p>http://cryptomaps.org/

本文来源: 网络 文章作者: 网络投稿
    下一篇