为广大币圈朋友提供币圈基础入门专业知识!
当前位置首页 > 区块链知识> 正文

java区块链实战项目,java实现区块链完整教程

发布时间:2023-12-06-06:09:00 来源:网络 区块链知识 区块   算法   demo

java区块链实战项目,java实现区块链完整教程


请查看相关英文文档

⑴ Tutorials for getting started with blockchain


However, there are very few simple and easy-to-understand introductory articles. What exactly blockchain is and what makes it special is rarely explained.
Next, I will try to write a best-understood blockchain tutorial. After all, it is not difficult. The core concept is very simple and can be explained clearly in a few sentences. I hope that after reading this article, you will not only understand the blockchain, but also understand what mining is, why mining is getting more and more difficult, and other issues.
It should be noted that I am not an expert in this area. Although I have been paying attention to it for a long time, my detailed understanding of blockchain started at the beginning of this year. You are welcome to correct any errors or inaccuracies in the article.
1. The essence of blockchain
What is blockchain? In a word, it is a special distributed database.
First of all, the main function of blockchain is to store information. Any information that needs to be saved can be written to the blockchain and read from it, so it is a database.
Secondly, anyone can set up a server, join the blockchain network, and become a node. In the world of blockchain, there is no central node. Every node is equal and stores the entire database. You can write/read data to any node, because all nodes will eventually be synchronized to ensure that the blockchain is consistent.
2. The biggest features of blockchain
Distributed databases are not a new invention, and there have been such products on the market for a long time. However, blockchain has a revolutionary feature.
Blockchain has no administrator, it is completely centerless. Other databases have administrators, but blockchain does not. If one wanted to add auditing to the blockchain, it would not be possible because it is designed to prevent the emergence of a central authority.
It is precisely because it is unmanageable that blockchain can be uncontrollable. Otherwise, once big companies and large groups control the management, they will control the entire platform, and other users will have to take orders from them.
However, without an administrator, everyone can write data into it. How can we ensure that the data is trustworthy? What if it is modified by a bad person? Please read on, this is the wonderful thing about blockchain place.
3. Block
Blockchain is composed of blocks. Blocks are much like database records. Every time data is written, a block is created.
Each block contains two parts.
Head: records the characteristic values ​​of the current block
Body: actual data
The block header contains multiple characteristic values ​​of the current block.
Generation time
Hash of the actual data (i.e. block body)
Hash of the previous block
...
Here, you need to understand what a hash is , which is necessary to understand blockchain.
The so-called hashing means that the computer can calculate a characteristic value of the same length for any content. The hash length of the blockchain is 256 bits, which means that regardless of the originalWhatever the initial content is, a 256-bit binary number will be calculated in the end. And it can be guaranteed that as long as the original content is different, the corresponding hash must be different.
For example, the hash of the string 123 is (hexadecimal), which is 256 bits when converted to binary, and only 123 can get this hash. (Theoretically, it is possible for other strings to get this hash, but the probability is extremely low and can be approximated as impossible.)
Therefore, there are two important inferences.
Corollary 1: The hash of each block is different, and the block can be identified by the hash.
Corollary 2: If the content of the block changes, its hash will definitely change.
4. The non-modifiable nature of Hash
Blocks and hashes have a one-to-one correspondence, and the hash of each block is calculated based on the block header (Head). That is to say, the characteristic values ​​​​of the block header are connected together in order to form a very long string, and then the hash is calculated on this string.
Hash = SHA256 (block header)
The above is the calculation formula of block hash. SHA256 is the hash algorithm of the blockchain. Note that this formula only contains the block header and not the block body. In other words, the hash is uniquely determined by the block header.
As mentioned before, the block header contains a lot of content, including the hash of the current block body. , and the hash of the previous block. This means that if the content of the current block body changes, or the hash of the previous block changes, it will definitely cause the hash of the current block to change.
This point has great significance for blockchain. If someone modifies a block, the hash of the block changes. In order for subsequent blocks to still be connected to it (because the next block contains the hash of the previous block), the person must modify all subsequent blocks in sequence, otherwise the modified block will be removed from the blockchain . Due to the reasons mentioned later, hash calculation is very time-consuming, and it is almost impossible to modify multiple blocks in a short period of time, unless someone controls more than 51% of the computing power of the entire network.
It is through this linkage mechanism that the blockchain ensures its own reliability. Once the data is written, it cannot be tampered with. This is just like history, what happened happened, and it can’t be changed from now on.
Each block is connected to the previous block, which is where the name blockchain comes from.
5. Mining
Since synchronization between nodes must be ensured, the adding speed of new blocks cannot be too fast. Just imagine, you have just synchronized a block and are preparing to generate the next block based on it, but at this time, another node generates a new block, and you have to give up half of the calculations and synchronize again. Because each block can only be followed by one block, you can only generate the next block after the latest block. So, you have no choice but to sync as soon as you hear the signal.
So, the inventor of the blockchain, Satoshi Nakamoto (this is a pseudonym, and his true identity is still unknown) deliberately made it difficult to add new blocks.His design is that on average, the entire network can generate a new block every 10 minutes, which is only six per hour.
This output speed is not achieved through commands, but by deliberately setting up massive calculations. In other words, only through an extremely large amount of calculations can the effective hash of the current block be obtained and the new block added to the blockchain. Because the amount of calculation is too large, it cannot be done quickly.
This process is called mining, because the difficulty of calculating a valid hash is like finding a grain of sand that meets the conditions among the sand in the world. The machine that calculates hashes is called a mining machine, and the person who operates the mining machine is called a miner.
6. Difficulty coefficient
After reading this, you may have a question. People say that mining is difficult, but isn’t mining just about using a computer to calculate a hash? This is the strength of computers. How could it be? It becomes very difficult, why can’t it be calculated?
It turns out that not just any hash can be used, only hashes that meet the conditions will be accepted by the blockchain. This condition is particularly harsh, causing most hashes to fail to meet the requirements and must be recalculated.
It turns out that the block header contains a difficulty coefficient (difficulty), which determines the difficulty of calculating the hash. For example, the difficulty coefficient of the 100,000th block is 14484.16236122.
The blockchain protocol stipulates that the target value (target) can be obtained by dividing the difficulty coefficient by a constant. Obviously, the greater the difficulty coefficient, the smaller the target value.
The validity of the hash is closely related to the target value. Only hashes smaller than the target value are valid, otherwise the hash is invalid and must be recalculated. Since the target value is very small, the chance that the hash is smaller than this value is extremely slim, and it may be calculated 1 billion times before it is considered a hit. This is the fundamental reason why mining is so slow.
As mentioned earlier, the hash of the current block is uniquely determined by the block header. If the hash of the same block needs to be calculated repeatedly, it means that the block header must keep changing, otherwise it is impossible to calculate different hashes. All feature values ​​in the block header are fixed. In order to make the block header change, Satoshi Nakamoto deliberately added a random item called Nonce.
Nonce is a random value. The role of the miner is actually to guess the value of Nonce so that the hash of the block header can be smaller than the target value so that it can be written to the blockchain. Nonce is very difficult to guess. At present, we can only use trial and error one by one through exhaustive methods. According to the protocol, Nonce is a 32-bit binary value, which can reach a maximum of 2.147 billion. The Nonce value of the 100,000th block is 274148111. It can be understood that the miner started from 0 and calculated 274 million times before obtaining a valid Nonce value so that the calculated hash can meet the conditions.
If you are lucky, you may find Nonce in a while. If you are unlucky, you may have calculated 2.147 billion times without finding the Nonce, which is the current area.It is impossible for the block to calculate a hash that satisfies the condition. At this time, the protocol allows miners to change the block body and start a new calculation.
7. Dynamic adjustment of difficulty coefficient
As mentioned in the previous section, mining is random, and there is no guarantee that a block will be produced in exactly ten minutes. Sometimes it can be calculated in one minute, and sometimes it may take several hours. No result. Overall, with the improvement of hardware equipment and the increase in the number of mining machines, the computing speed will definitely become faster and faster.
In order to keep the output rate constant at ten minutes, Satoshi Nakamoto also designed a dynamic adjustment mechanism for the difficulty coefficient. He stipulated that the difficulty factor should be adjusted every two weeks (2016 blocks). If the average block generation speed in these two weeks is 9 minutes, it means that it is 10% faster than the legal speed, so the next difficulty factor will be increased by 10%; if the average block generation speed is 11 minutes, it means It is 10% slower than the legal speed, so the difficulty factor of the next step must be lowered by 10%.
The difficulty coefficient is adjusted higher and higher (the target value is getting smaller and smaller), which makes mining more and more difficult.
8. Forks of the blockchain
Even if the blockchain is reliable, there is still an unresolved problem: if two people write data to the blockchain at the same time, that is to say, two people write data to the blockchain at the same time. Blocks join because they are connected to the previous block, forming a fork. Which block should be adopted at this time?
The current rule is that new nodes always adopt the longest blockchain. If there is a fork in the blockchain, it will look at which branch is behind the fork to reach 6 new blocks first (called six confirmations). Based on a block calculation of 10 minutes, it can be confirmed in one hour.
Since the generation speed of new blocks is determined by computing power, this rule means that the branch with the most computing power is the authentic blockchain.
9. Summary
Blockchain, as an unmanaged distributed database, has been running for 8 years since 2009 without major problems. This proves it works.
However, in order to ensure the reliability of data, blockchain also has its own price. The first is efficiency. You have to wait at least ten minutes to write data to the blockchain. All nodes synchronize the data, which requires more time. The second is energy consumption. The generation of blocks requires miners to perform countless meaningless calculations. This is Very energy consuming.
Therefore, the applicable scenarios of blockchain are actually very limited.
There is no management authority that all members trust
The written data does not require real-time use
The benefits of mining can make up for its own costs
If the above conditions cannot be met, then the traditional database is Better solution.
Currently, the largest application scenario (and possibly the only application scenario) of blockchain is the cryptocurrency represented by Bitcoin.

⑵ Getting started with blockchain technology, which programming languages ​​are involved

Go language

Go language (Golang) is a language launched by Google in 2009 A new programming language that can be used without compromisingReduce the complexity of your code without sacrificing application performance. Rob Pike, chief software engineer at Google, said: "We developed Go because the difficulty of software development over the past 10 years or so has been frustrating."

In addition to Bitcoin being developed in C, At present, the clients of most mainstream workshops are developed with Go language, which is enough to show the status of Go language in the entire blockchain industry.

C

C further expands and improves the C language and is an object-oriented programming language. C runs on a variety of platforms, such as Windows, MAC operating systems, and various versions of UNIX. C is a very widely used computer programming language. It is a general programming language that supports multiple programming patterns, such as procedural programming, data abstraction, object-oriented programming, generic programming, and design patterns.

Most blockchain companies choose to use C to write the bottom layer of the blockchain. The most famous ones are Bitcoin, Ripple, etc., which mainly reflect strong computation.

Java

Java is different from general compiled languages ​​or interpreted languages. It first compiles the source code into bytecode, and then relies on virtual machines on various platforms to interpret and execute the bytecode, thereby achieving the cross-platform feature of "write once, run anywhere". The development of blockchain projects has obvious dependence on Java.

Others include Python, system architecture, Ethereum, Linux, hyperledger, JavaScript, etc. will be covered.

⑶ Beida Jade Bird Java Training: The development trend of blockchain technology implementation

With the continuous development of blockchain technology, more and more people are beginning to pay attention to blockchain How technology is implemented to achieve project conversion and development.
Today, let’s take a look at the development trends of blockchain technology implementation.
Blockchain is finding ways to form new industries and enterprise applications every day, and it won’t be long before this technology will be everywhere.
In the future, start-ups, academic institutions, open source institutions, alliances and financial institutions will all participate in this technology.
The current controversy over the prospects of blockchain focuses on the uncertainty of its implementation direction and value.
In the fog, there are different opinions. Some people say that "blockchain does not make money without ICO", while others are trying to find the true value of blockchain technology in real-life scenarios outside the currency circle.
Here are some things worth paying attention to.
Blockchain core technology refers to blockchain core technology, which generally includes key technologies in the application layer, contract layer, incentive layer, consensus layer, network layer, and data layer.
The research hotspots here include consensus, distributed ledger, cross-chain technology, P2P network and some application practices.
You may ask: There are currently many blockchain platforms on the market, how to correctly understand and evaluate the appropriate ones?What is the underlying technology chosen by joint ventures? What key pain points and technical challenges does blockchain face in enterprise-level applications, and how to solve them? What experience do you have in the development and operation of blockchain projects related to life and medical data? Lessons? What is the essence of cross-chain? What problems need to be solved? What are the technical difficulties and implementation models? What are the characteristics and implementation principles of the file system? How to implement the DPoS algorithm in Ethereum and its significance? Blockchain finance When blockchain technology was first proposed, finance was considered one of the main application scenarios, including the establishment of inter-bank point-to-point payment settlement systems and cross-border payment systems based on blockchain technology, and the use of blockchain technology in exchanges. Realize the registration and transfer of equity, etc.
Blockchain has inherent absolute advantages when applied to the financial field. From a subjective point of view, financial institutions have a strong willingness to explore blockchain applications and need new technologies to improve operational efficiency and reduce costs to cope with the current situation of the entire global economy. status quo.
Objectively speaking, the financial industry has a huge market space, and a little progress can bring huge benefits.
Shanxi Computer Training http://www.kmbdqn.cn/ found that the financial industry is an industry with extremely high requirements for security and stability. If the application of blockchain in the financial field can be verified, a huge demonstration will be produced The effect was quickly promoted in other industries.

⑷ Beijing Java course shares the consensus algorithm in blockchain technology

We have shared some explanations and knowledge point analysis about blockchain technology with you many times . Today, in the Beijing Java course, we will learn about some basic definitions and characteristics of consensus algorithms in blockchain technology.

A brief look at the blockchain

The chain in our general ideology is an iron chain, made of iron. One link after another. Figuratively, the blockchain can also be understood in this way, except that it is not made of iron, but connected by blocks with a certain data structure. This is a simple prototype

Popular explanation of consensus

The so-called consensus, in layman’s terms, means that we all agree on the understanding of something. For example, we have daily meetings to discuss issues, or we can judge whether an animal is a cat. After looking at it with the naked eye, we feel it looks like a cat. If it meets the characteristics of a cat, then we think it is a cat. Consensus is a rule.

Continue to use our meeting example. Participants in the meeting discuss and solve problems through meetings.

Compared with the blockchain, miners participating in mining use a certain consensus method (algorithm) to make their own ledger consistent with the ledgers of other nodes. The deeper meaning of keeping the ledger consistent is to keep the block information in the chain consistent.

Why is consensus needed? Is it possible to not need it? Of course not, there is no rule of consensus in life, everything is in chaos. The blockchain loses consensus rules, and each node does its own thing, losing its consistent meaning.

The corresponding relationship between these two examples is as follows:

Meeting people = mining miners

Meeting = consensus method (algorithm)

Talk about solving problems = make your own ledger consistent with the ledgers of other nodes

If you don’t understand the concept of a node, please first understand it as a miner. A node contains many roles, and miners are one of them.

Consensus algorithm

Currently in the blockchain, nodes allow their own ledgers to match those of other nodes. There are several consensus methods (algorithms) that maintain consistency:

PoW, represented by Bitcoin (BTC)

Disadvantages:

The emergence of mining pools violates the original intention of decentralization to a certain extent, and also makes 51% attacks possible, affecting its security.

There is a huge waste of computing power. Look at the mining pool that consumes a lot of electricity resources. As the difficulty increases, not enough is mined to pay the electricity bill

PoS, represented by Ethereum (ETH), transitioning from PoW to PoS

Disadvantages:

The cost of attackers attacking the network is very low, and they can compete by owning tokens

In addition, nodes with a large number of tokens will have a higher probability of obtaining accounting rights. If it is large, the network consensus will be dominated by a few wealthy accounts, thus losing fairness.

⑸ Java course shares the component architecture of blockchain technology

With the continuous development of the Internet, more and more people have learned about Some characteristics and usage of blockchain technology. Today we will introduce some elements of blockchain.

The composition of blockchain

Blockchain consists of blocks and chains. Each block contains three elements: data, hash value, and the hash value of the previous block.

The first element of the block is data. The data stored in the block is related to the type of blockchain. For example, blocks in the Bitcoin blockchain store relevant transaction information, including the seller, buyer, and the amount of Bitcoin traded.

The second positive element of the block is the hash value. Each block contains a hash value, which is used to identify a block and all the content it contains. Once a block is created, its hash value is calculated accordingly. Changing something in the block will cause the hash value to change. So in other words: Hash values ​​are helpful when you want to detect changes in the contents of a block. If a block's fingerprint changes, it is no longer the same block as before.

The third element of the block is the hash value of the previous block. This element allows links to be formed between blocks and makes the blockchain very secure.

As an example, suppose we have a blockchain containing 3 blocks. Each block contains its own hash and the hash of the previous block. Block No. 3 points to block No. 2, and block No. 2 points to block No. 1. But block No. 1 is a bit special. It cannot point to the previous block because it is the first block. We call block 1 the genesis block.

So, now let's say you tampered with the second block. This will cause the hash value of the second block to change, so the data stored in block 3 will be wrong and illegal. Once the data stored in block No. 3 is illegal, the subsequent blocks must also be illegal.

So if a person wants to tamper with any block in the blockchain, he must modify this block and all blocks after this block. This will be an onerous task.

Blockchain proof-of-work

However, the method of using hash values ​​alone is not enough to prevent users from tampering with the zone. piece. Because today's computers are powerful enough to calculate thousands of hash values ​​per second. The Java course suggests that you can completely tamper with a block and recalculate the hash values ​​of other blocks, thus making your block legal again.

博客主人唯心底涂
男,单身,无聊上班族,闲着没事喜欢研究股票,无时无刻分享股票入门基础知识,资深技术宅。
  • 36285 文章总数
  • 3637265访问次数
  • 3078建站天数