Abstract
This e-book on blockchain development and operation and maintenance.
Chapter 1 Blockchain
Table of Contents
1.1. What is a blockchain?
1.2. What is a smart contract?
1.3. What should we do?
1.4. How to learn blockchain
1.5. What can the blockchain do?
1.6. Problems that the blockchain cannot solve
1.7. Understand decentralization
1.8. Understand not to change
1.9. Blockchain is not a substitute for traditional data
Blockchain can be said to be the hottest technology in 2018. I believe many developers have already eager to invest in the blockchain development team, but they feel that they can't start. You will find that most of the books in the world are on the theoretical paper. Some whimsical ideas that can't be reached, this book will use a lot of examples to explain how to let technology fall.
At present, blockchain technology is still in the high-speed development stage of both Ethereum and Hyperledger. Each version of the iteration update changes greatly, and it takes at least one to three years to become a mature technology.
1.1. What is a blockchain?
Many books talk about blockchains starting with bitcoin. The media often pulls bitcoin out of the way. First, there is a problem with HD: Bitcoin is a blockchain, but blockchain is not bitcoin.
What is the blockchain? In a word, it is a special (non-relational) distributed database that can only do insert and find operations and has no administrator.
First, the main role of the blockchain is to store information. Any information that needs to be saved can be written to the blockchain or read from it, so it is a database.
Second, anyone can set up a server and join the blockchain network to become a node. In the world of blockchains, there are no central nodes, and each node is equal, and the entire database is preserved. You can write/read data to any node because all nodes will be synchronized at the end, ensuring that the blockchain is consistent.
1.2. What is a smart contract?
Can you understand the stored procedure + database structure, so it should be well understood?
Accessing a contract is just like accessing a stored procedure. The variables defined in the contract are not directly accessible and can only be manipulated by functions.
So very similar to the database to define the table structure, but can not directly select, insert, delete, update data, can only operate the database through the stored procedure.
1.3. What should we do?
Very simple, connect to the blockchain system by IP address and port number, and complete a transaction by calling the contract method through the API (usually json-rpc) to generate a block record.
In theory, the blockchain is simpler than the database.
1.4. How to learn blockchain
I haven't read any books in the blockchain technology. I use fragmented learning methods, mainly through search engines and official documents. I am better at self-study and rarely communicate with people.
I also tried to buy books, but I found that these books are of little value. Almost two-thirds of the content is about principles, theoretical things, and the remaining one-third of the content is nothing more than installation, configuration, and Helloword instances. In addition, the publication period of books is usually six months to one year. When the books are published, the content is outdated. The difference in the software version causes the examples in the book to fail, so I gave up the idea of buying books and at the same time, I have to write one. This e-book based on dry goods content, try to avoid the theoretical things in the book, the software version I choose the current mainstream version, directly on the example, as long as you follow the step Step by Step experiment will be successful, this sense of achievement will drive You continue to learn.
The problems that can't be solved in the process of learning can be solved by the search engine, which is the best learning tool.
I advocate learning the blockchain. Don't look at too many principles. You can go through it quickly. Many books start with bitcoin. I don't think it is necessary. The learning blockchain has two directions, one is the development of the token, and the other is the development of the blockchain. Now the media confuses the two directions, which are two independent directions.
If you want to engage in token development, then the goal is clear. Ethereum is the best choice. Your learning content is coin contract development, contract deployment, web3 contract operation, token exchange, etc...
The industry's blockchain is not a token development, but a decentralization. It is expected that blockchain technology will help companies solve practical problems. Usually both Ethereum and Hyperledger can meet the needs of the enterprise, you need to decide which solution to choose.
Blockchain is a tool, just like a mobile phone is a communication tool. You don't need to learn the communication principle and computer principle, you can use the mobile phone. The development of blockchain must be stupid and easier to use and develop.
1.5. What can the blockchain do?
Blockchains have decentralized security, traceability, and non-tamperability.
The current bottom layer of the blockchain is only suitable for low-frequency, high-value businesses. For example, blockchain + credit, blockchain + assets, blockchain + payment, blockchain + supply chain, real estate + blockchain (registration, transfer)
1.6. Problems that the blockchain cannot solve
You can guarantee that the data on the chain will never be tampered with; but you can't guarantee that the uploaded data is true.
The problem that the blockchain cannot solve:
-
User uploads fake data
-
Items are transferred
-
High frequency trading
Let's take a real-life example of "ID card". For example, an ID card may prove that you are you, but someone else can pretend to be with your ID card. In addition, you cannot guarantee that the household registration personnel will not make mistakes when entering identity information. In reality, we often have ID numbers or information errors.
It is not safe to implement the blockchain technology. Security is divided into many layers, and the blockchain can only achieve the security of the storage layer. For example, security is divided into user layer, application layer, logical layer, storage layer and so on. The blockchain cannot solve the security problems of the user layer, the application layer, the logic layer, etc., and he can only ensure that the blocks stored on the hard disk are not modified.
1.7. Understand decentralization
The traditional database is centralized. It provides services for applications through an IP address and a port number. Later, the "master-slave" and "master-master" structures emerged. Decentralization is a "multi-master" structure.
Compared with the database, the decentralization of the blockchain is more complicated. Their data synchronization is not a simple binary log synchronization, but is transmitted through encryption. After the node consensus, data storage is performed.
1.8. Understand not to change
Many people are misled by this sentence, thinking that the blockchain data is permanently incapable of being modified once it is created, so it is safe. In fact, the data of the blockchain can be modified, but it cannot be modified.
First of all, you have to figure out what is written and modified. The copying means illegally modifying the blockchain data, while the modification is legally changing the data.
The data on the blockchain can be modified, and the content can be modified at any time, no matter how long the data is stored.
Often the blockchain data is often referred to as a modification of the data storage level. The modification is to change the data in the blockchain through the modification function provided by chaincode.
For example, in a scenario, in the credit information system, the user is sometimes pulled into the blacklist, but the user should immediately move it to the whitelist after paying the arrears. This process requires modifying the data on the blockchain.
In addition, I also tell you that most blockchain platforms do not have a user authentication rights management module. Therefore, it is impossible to control which data in the block may be modified, those that cannot be modified, those data XXX users can modify, and so on. Even if some blockchain platforms have permission control, the granularity can't think of the current database.
1.9. Blockchain is not a substitute for traditional data
Returning to the essence of technology, I believe that blockchain technology itself is a database that pursues distributed consistency.
We have learned about CAP theory. CAP theory means that in a distributed system, Consistency, Availability, and Partition tolerance are not available. Most blockchains give up some usability and favor consistency and partition tolerance.
The blockchain can't solve all the problems. Although he is also a kind of database, it can solve the problem very limited. Its data management and query capabilities can't reach the level of NoSQL, let alone the complex application of SQL. So in practical applications, blockchains cannot replace data and can only complement each other.
So before the project is implemented, think about your needs, do you really need a blockchain? Still need some features on the blockchain? For example, data cannot be changed. If only a certain feature of the blockchain is needed. We can address this need and think about whether it can be solved using traditional databases.