NodeReal is writing a series about the performance of BNB Smart Chain and what it has done to keep improving its performance by reducing the block processing time.
For your convenience, the previous article links have been provided below:
In this post (Chapter IV), we will talk about pipeline, a high-frequency vocabulary in concurrency architecture design.
In a nutshell, pipeline is a mechanism to divide a process into several stages, different stages can be processed concurrently in an organized way. Pipeline can be quite complicated, as it needs to guarantee an efficient performance improvement and also satisfy some sequential dependencies of the whole process.
As we have introduced the stages of the block process in the first post - Chapter I: The Critical 3 Seconds, let’s take a brief retrospect on the whole process.
Within the 3 seconds period, each validator mainly needs to accomplish 2 tasks:
Although the general procedure for import and mine tasks are similar: download -> execution -> validation -> commit, they have some differences which make the pipeline approach a bit different.
The main purpose of block import can be summarized as:
Before a block can be processed, an accurate world state is a must, but the verification result is optional, which means the world state update is essential while verification can be optional.
While for block mine task, it has 2 main purposes as well:
Before a block can be broadcasted to other peers, the block producer must attach the corresponding proofs, which means both world state update and verification generation are essential.
As we have explained some rationales of the block process procedure, next let us introduce you our approaches to the pipelined block process at NodeReal.
What we have done are mainly included in the following patches. If you are an engineer, you could just review these patches and get a deeper understanding of its inner implementation.
The state verification & Snapshot/MPT commit takes a lot of time. While in most cases, the verification can pass, there is no need to wait for the verification result sequentially.
For snapshot/MPT commit, we only persist the bottom diff layer to disk, there is no need to wait for it to finish. NodeReal proposed an asynchronous state verification and asynchronous snapshot/MPT commit solution.
Once Block Process and Snapshot Commit are done, there is no need to wait for State Verification, the blockchain can process the next block. For the next block, before it starts State Verification, it has to wait until the State Verification of its parent finishes.
Both MPT and Snapshot need to be persisted into storage, the storage can be Memory DB and Disk DB, NodeReal introduced the asynchronous persistence of Disk DB without breaking the processing of the following blocks.
With the pipelined state verification and commit enabled, the cost of the two stages has reduced tremendously.
The numbers say it all. Take a look at the comparison test we had done. The following image shows that the cost of state verification has been reduced by ~30% -> ~70% and the cost of block commit has even been reduced by ~90%.
The pipeline feature was delivered in v1.1.9 on Apr 12 2022, it can improve the performance a lot by saving most of the MerkleRoot calculation cause.
The feature can easily be turned on by adding an option: “--pipecommit” to the start command line, just have a try with the latest release if you are interested.
As one of the core contributors to BNB Chain, NodeReal is in full support of it by not only contributing to the core tech development, and also providing a one-stop infrastructure for the BNB Chain builders as shown below. Learn more about it here and let NodeReal make your Web3 REAL
NodeReal is a one-stop blockchain infrastructure and service provider that embraces the high-speed blockchain era and empowers developers by “Make your Web3 Real”. We provide scalable, reliable, and efficient blockchain solutions for everyone, aiming to support the adoption, growth, and long-term success of the Web3 ecosystem.
Join our community to learn more about NodeReal and stay up to date!