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.
The Block Process Stages
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:
- Block Import Task: to download and verify the block produced by the previous validator
- Block Mine Task: to generate its own block and broadcast it to other validator peers
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:
- WorldState Update: the blockchain is a linear world state change history, one block followed by another。 Each block could update the shared world state and the following block relies on the previous block’s process results
- Block Verification: to verify the block hash, the signature of the transaction sender, the MPT root. Only valid blocks will be accepted and inserted into the blockchain
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:
- WorldState Update: the same as block import
- Generate Verification: to produce a block, the validator not only needs to wrap the transactions into a block, but also add proofs, especially the MPT root proof
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.
How Did NodeReal Help
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.
State Verification Pipeline
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.
What Are The Benefits
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 the NodeReal Community
Join our community to learn more about NodeReal and stay up to date!