Why use Go language to write blockchain
Reason: 1. Go language has the advantages of simple deployment, excellent performance, good parallel execution performance, good language design, a large number of built-in libraries, and an awesome team. 2. Both Ethereum and Hyperledger choose to use Go as the development language; these two super blockchains have great influence. They not only occupy a large niche in the ecology, but also implicitly formulate the blockchain standards.
The operating environment of this tutorial: windows10 system, GO 1.18, thinkpad t480 computer.
In the public blockchain development circle, we have found some popular programming languages, including C, Golang, Python and the recently launched Rust, etc.
Let’s make some statistics on the programming languages used by the more famous projects, as shown below:
The older generation of public chains, such as Bitcoin and Litcoin, are generally C/C was used more (let’s look at that time, Go had not yet emerged). The new generation of public chains such as Ethereum and the leader of the alliance chain, Hyperledger, began to use the Go language more. Of course, we saw the development of Rust. The momentum is also very strong. In the past two years, many public chains such as Polkadot and Grin have begun to use the Rust language for development.
Advantages of Go language
Easy deployment
Go compile What is generated is a static executable file with no other external dependencies except glibc. This makes deployment extremely convenient: only a basic system and necessary management and monitoring tools are needed on the target machine, and there is no need to worry about the dependencies of various packages and libraries required by the application, greatly reducing the burden of maintenance. It can be directly compiled into machine code and does not rely on other libraries. The version of glibc has certain requirements. Deployment is completed by throwing a file up.
Excellent performance
Although it is not as good as C and Java, it is usually an order of magnitude higher than native Python applications, and is suitable for writing some bottleneck businesses. The memory usage is also very economical.
Concurrency & Channel
Goroutine and channel make it very easy to write high-concurrency server software, and in many cases it is completely unnecessary Consider the locking mechanism and the various problems it brings. A single Go application can also effectively utilize multiple CPU cores and achieve good parallel execution performance.
Good language design
Go is very simple and easy to learn. From an academic perspective, the Go language is actually very mediocre and does not support many advanced language features; but from an engineering perspective, Go's design is very good: the specifications are simple and flexible enough. Because of Go's simplicity, any Python, Elixir, C, Scala or Java developer can form an efficient Go team within a month.
Standard Library & Tools
Go currently has a large number of built-in libraries, especially the network library which is very powerful. More importantly, Go comes with a complete tool chain, which greatly improves the consistency of team collaboration. For example, gofmt automatically formats Go code, which largely eliminates the problem of inconsistent formatting styles of codes written by different people. Configure the editor to automatically run gofmt when editing the archive, so that you can place it anywhere when writing code, and it will automatically become correctly formatted code when archiving. In addition, there are very useful tools such as gofix and govet.
The team is awesome
The supporter behind Go language is Google. The language is enough to be tested in various scenarios. At the same time, the founder is still The father of the C language, we can look forward to future development and innovation.
Go successful projects
Go language has been widely used in the cloud era, especially killer products like Docker and K8s The emergence of the Go language has given it a place in the engineering world. In addition to the Go language, there are many successfully running software:
nsq: bitly's open source message queue system has very high performance. Currently, they process it every day Billions of messages
packer: used to generate image files for different platforms, such as VM, vbox, AWS, etc. The author is the author of vagrant
skynet: distributed scheduling framework Doozer: Distributed synchronization tool, similar to ZooKeeper
Heka: mazila open source log processing system
cbfs: couchbase open source distributed file system
tsuru: open source PAAS platform, and The functions implemented by SAE are exactly the same
groupcache: a caching system written by the author of memcahe for the Google download system
god: a caching system similar to redis, but supports distribution and scalability
gor: Network traffic packet capture and replay tool
Ecological card slots and implicit standards
In addition to the need for hard work, there are also opportunities and luck that made the blockchain choose the Go language. Let’s take a look at the most successful public and consortium chain representatives since blockchain 2.0, Ethereum and Hyperledger Fabric. Without exception, they all choose to use Go as the development language (although Ethereum actually has client versions in other languages, but entering After the Homestead stage, the Go client occupies a dominant position). The influence of these two super blockchains is not comparable to that of ordinary projects. Not only do they occupy a large niche in the ecology, but they are also implicitly formulated. Without the standards of the blockchain, whether it is smart contracts in the public chain or alliance chain technology, Ethereum and Fabric cannot be bypassed. So for a company that wants to choose blockchain technology, the fastest way What is the implementation of ?
Naturally, we directly copy the innovations of these two projects. Another shortcut is to directly modify the open source code. Then naturally Go language becomes the first choice for latecomers. It is not easy to re-implement it in another language, and If you choose some innovative but not very mature languages, you will also lack the support of some specific libraries, which will make the project unable to be carried out.
Many people have no doubt about the influence of Ethereum, but in fact Fabric’s influence on enterprise blockchain deployment cannot be underestimated:
Chart source "2019 Global Enterprise Blockchain Benchmark Research Report"
Hyperledger Fabric is the most used protocol framework in deployed enterprise blockchain networks, and Hyperledger Hyperledger (of which Fabric is the flagship protocol) is The protocol framework most commonly supported by integrators and software development platforms reaches 53%. Among all the blockchain technology books, the fact that books on Hyperledger are the most popular also confirms the influence of Hyperledger.
Practice of Bytom in Go
In the process of selecting programming languages, we considered C, C, Java , but large C/C projects are difficult to maintain, and Java is a bit cumbersome. At this time, the Go language has already shined in blockchain projects, and has gradually formed a head-end effect on technology and talents, so follow the trend and carry out technology The selection will naturally reduce the resistance encountered by the initial Bytom project. Of course, during the gradual development process, we also felt the convenience and advantages brought by choosing the Go language.
A Case of Go on the blockchain
Technically speaking, blockchain nodes require multiple modules to work together asynchronously, so Go language concurrency And channels are very advantageous. Let's look at the following example of transaction verification:
func ValidateTxs(txs []*bc.Tx, block *bc.Block) []*ValidateTxResult { txSize := len(txs) //init the goroutine validate worker var wg sync.WaitGroup workCh := make(chan *validateTxWork, txSize) resultCh := make(chan *ValidateTxResult, txSize) closeCh := make(chan struct{}) for i := 0; i <= validateWorkerNum && i < txSize; i++ { wg.Add(1) go validateTxWorker(workCh, resultCh, closeCh, &wg) } //sent the works for i, tx := range txs { workCh <- &validateTxWork{i: i, tx: tx, block: block} } //collect validate results results := make([]*ValidateTxResult, txSize) for i := 0; i < txSize; i++ { result := <-resultCh results[result.i] = result } close(closeCh) wg.Wait() close(workCh) close(resultCh) return results }
We use Routine Ch WaitGroup to build a concurrent transaction verification function within 30 lines of code. In a high-configuration In the case of a server, it can run more than 100,000 TPS.
Easily become a Go language master
In terms of talents, some members of the Bytom core development team have never done Go language development before, but they are all able to You get started quickly, and you can basically participate in the development and maintenance of the core code within half a month (especially easy for developers with experience in C/C/Java). This is the benefit of simple language to team building.
Unified collaboration
In terms of collaboration, gofmt automatically typesets Go code, allowing core team members and even community developers to submit The differences in coding styles are minimized, improving the overall quality and maintainability of the project.
Summary
The characteristics and advantages of the Go language itself pave the way for it, and the two super blocks of Ethereum and Hyperledger The blessing of chain projects has also made Go language the first choice for many blockchain projects. Bytom chose Go language to fully realize its advantages in developing the underlying blockchain, but there is no need to fall into the trap of language disputes and pay attention to pragmatism. This is the proper meaning of engineering. Bytom's core project is completed in Go language, but many surrounding sub-projects are also implemented in Java, Python or JavaScript. After all, ecological diversity is the foundation for the longevity of a project.
Recommended learning: Golang tutorial
The above is the detailed content of Why use Go language to write blockchain. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The top ten cryptocurrency trading platforms in the world include Binance, OKX, Gate.io, Coinbase, Kraken, Huobi Global, Bitfinex, Bittrex, KuCoin and Poloniex, all of which provide a variety of trading methods and powerful security measures.

The top ten digital currency exchanges such as Binance, OKX, gate.io have improved their systems, efficient diversified transactions and strict security measures.

With the popularization and development of digital currency, more and more people are beginning to pay attention to and use digital currency apps. These applications provide users with a convenient way to manage and trade digital assets. So, what kind of software is a digital currency app? Let us have an in-depth understanding and take stock of the top ten digital currency apps in the world.

OKX provides a convenient trading experience, and the app can be downloaded on the App Store and Google Play. The top three exchanges are Binance, OKX and Gate.io.

The built-in quantization tools on the exchange include: 1. Binance: Provides Binance Futures quantitative module, low handling fees, and supports AI-assisted transactions. 2. OKX (Ouyi): Supports multi-account management and intelligent order routing, and provides institutional-level risk control. The independent quantitative strategy platforms include: 3. 3Commas: drag-and-drop strategy generator, suitable for multi-platform hedging arbitrage. 4. Quadency: Professional-level algorithm strategy library, supporting customized risk thresholds. 5. Pionex: Built-in 16 preset strategy, low transaction fee. Vertical domain tools include: 6. Cryptohopper: cloud-based quantitative platform, supporting 150 technical indicators. 7. Bitsgap:

This groundbreaking development will enable financial institutions to leverage the globally recognized ISO20022 standard to automate banking processes across different blockchain ecosystems. The Ease protocol is an enterprise-level blockchain platform designed to promote widespread adoption through easy-to-use methods. It announced today that it has successfully integrated the ISO20022 messaging standard and directly incorporated it into blockchain smart contracts. This development will enable financial institutions to easily automate banking processes in different blockchain ecosystems using the globally recognized ISO20022 standard, which is replacing the Swift messaging system. These features will be tried soon on "EaseTestnet". EaseProtocolArchitectDou

Recommended cryptocurrency trading platforms include: 1. Binance: the world's largest trading volume, supports 1,400 currencies, FCA and MAS certification. 2. OKX: Strong technical strength, supports 400 currencies, approved by the Hong Kong Securities Regulatory Commission. 3. Coinbase: The largest compliance platform in the United States, suitable for beginners, SEC and FinCEN supervision. 4. Kraken: a veteran European brand, ISO 27001 certified, holds a US MSB and UK FCA license. 5. Gate.io: The most complete currency (800), low transaction fees, and obtained a license from multiple countries. 6. Huobi Global: an old platform that provides a variety of services, and holds Japanese FSA and Hong Kong TCSP licenses. 7. KuCoin

The download, installation and registration process of the Hong Kong Digital Currency Exchange app is very simple. Users can quickly obtain and use this app through the official app download link provided in this article. This article will introduce in detail how to download, install and register the Hong Kong Digital Currency Exchange app to ensure that every user can complete the operation smoothly.
