当前位置:网站首页>Cuckoo filter for Chang'an chain transaction
Cuckoo filter for Chang'an chain transaction
2022-06-26 16:21:00 【Changan chain open source community】
We will use three articles to explain the work of Chang'an chain in improving the anti duplication ability of transactions , This is the first one .
All three chapters mainly include the following contents :
1. Chang'an chain trading pool and anti duplication trading optimization ;
2. The cuckoo filter of Chang'an chain transaction ;
3. bigfilter Introduction and application of global transaction anti duplication component .
One 、 background
Chang'an chain has collected the needs of many actual scenarios in the process of commercialization . With the long-term operation of the blockchain system , The scale of ledger data continues to grow , Bring the following technical challenges :
1、 With the continuous growth of ledger data capacity , The anti duplication processing of transactions based on the full ledger takes more time , Lead to tps Lower and lower ;
2、 Transaction duplication prevention is based on the ledger base , In a massive trading scenario , The reading and writing burden of the ledger library is even heavier ;
Based on the above problems, we decided to launch Changan chain cuckoo filter .
Two 、 What is? Cuckoo filter
2.1 Probability filter
Probability filter is a fast 、 Space saving data structures , Is a common data structure , On whether there is a problem , Retrieve whether an element is in a collection ” be called “ Set membership test ”; There is a false positive rate “ Set membership test ” be called “ Approximate set membership test ”.
One of the two outstanding implementations of the probability filter is the bloom filter , The other is the cuckoo filter .
2.2 Why use cuckoo filters
Add from 、 Inquire about 、 Delete 、 This paper expounds why the transaction filter is implemented based on cuckoo filter in terms of space size .
add to
The add operation will add the transaction to the transaction filter when the node is out of the block ; Cuckoo capacity as approaching load factor , Efficiency will curve down , And the efficiency of the bloom filter is constant , This is better than the cuckoo filter , But we can reduce the probability of false positives by controlling the number of items we want to save below the load factor in practical use .
Inquire about
Transaction anti duplication mainly relies on the query method to check whether items in the filter exist ; The time complexity of the cuckoo filter is O(1), And the bloom filter is O(k),k = The number of hashes for the bloom filter , The time complexity of cuckoo filter is better than that of Bloom filter .
Delete
Cuckoo filter supports deletion , The bloom filter does not support .
The size
In the actual test 200w Compared with the measured number of items, the bulon filter takes up less space 24%.
summary
Compare... Based on the following table , Chang'an chain team selected cuckoo filter as the basic implementation of the anti weight component of the transaction .
Cuckoo Filter | Standard Bloom Filter | |
add to | The addition efficiency is O(1) As load factor capacity approaches , Efficiency will continue to decline | Fixed efficiency O(k) |
Inquire about | O(1) Fixed check two drums | O(k) |
Delete | O(1) Check up to two barrels | I won't support it |
The size | The paper mentions that the space size is reduced compared with the bloom filter 40%, Actually measured 24% about | 1 |
3、 ... and 、 Changan chain cuckoo transaction filter
3.1 brief introduction
Changan chain cuckoo transaction filter is based on cuckoo filter to add time rules 、 Fragmentation 、 Snapshot and other functions perfectly conform to the transaction anti duplication scenario of Chang'an chain .
3.2 characteristic
Nanosecond transaction duplication check
Through time ID The rules , Only the latest batch of transactions are retained in the transaction filter , Transactions excluded from the time frame , Transactions within the range can also be quickly routed to a cuckoo for duplicate checking through the grouping time interval .
Optimized to the extreme memory footprint
Based on cuckoo hashes, 100 million transactions occupy 550M Space , If you save 100 million transactions directly ID About need 6G Space , Improved storage efficiency 89%.
Sharding accelerated parallel processing capability
Each segment contains multiple sets of cuckoo filters , The transaction is distributed to each group evenly and quickly through the partition algorithm , Let each set of cuckoo transaction filters process transactions at the same time .
Data security without loss
Save the current transaction filter snapshot function according to the block height interval or time interval, so that the node can stop and start without losing data .
The transaction filter warms up , If the node has historical data , But no snapshots , Warm up node block data when the transaction filter is initialized , Ensure that the transactions in the transaction filter are consistent with the existing data in the node .
LRU Circular elimination strategy
A set of transaction filters in the transaction filter will internally utilize LRU The circular elimination strategy eliminates the oldest cuckoo filter and creates a new cuckoo filter , Let the transaction filter always save the latest batch of transactions .
Four 、 Use effect
4.1 Performance improvement
We choose the block height 26w+, The size of the deal 13 Billion + Performance comparison test under the environment of .
- chart 1 It shows the cuckoo's TPS Chart , Whole TPS unstable , Take the red line as the reference line , It is obvious that TPS The curve of gradually inclines downward .
- chart 2 It shows that after opening cuckoo TPS Chart , In such a large trading volume TPS It is still in a stable state , There will be no downward curve .
chart 1: Before opening
chart 2: After opening
4.2 Memory footprint
In the case of using a transaction filter with a capacity of 100million, only 305M Memory . The user can adjust the parameters of the transaction filter according to the actual situation .
4.3 How to use
Changan chain cuckoo transaction filter is a filter based on local memory , Use Changan chain v2.2.1 And above , stay `chainamker.yml` Set in `tx_filter` Configuration item , It can realize fast transaction anti duplication processing .
For specific configuration, please refer to 《 Transaction filters - Configuration Guide 》https://docs.chainmaker.org.cn/operation/%E4%BA%A4%E6%98%93%E8%BF%87%E6%BB%A4%E5%99%A8-%E9%85%8D%E7%BD%AE%E6%8C%87%E5%8D%97.html
RECOMMEND
Recommended reading
One 、 Changan chain ChainMaker Anti duplication optimization of trading pool transactions
Tips
More Chang'an chain open source projects QA, You can log in to the open source community 、 Technical document library view .
Download the source code
https://git.chainmaker.org.cn/chainmaker/chainmaker-go
Consult the documentation
https://docs.chainmaker.org.cn/
Changan chain ChainMaker Case collection
http://www.wenjuan.com/s/UZBZJvhFGte/
“ Changan chain ChainMaker” It is the first independent and controllable blockchain software and hardware technology system in China , It is jointly developed by microchip Research Institute, enterprises and universities , With full autonomy 、 High performance 、 Strong privacy 、 The outstanding characteristics of wide cooperation . Chang'an chain is oriented to large-scale node networking 、 High transaction processing performance 、 Strong data security, privacy and other next-generation blockchain technology requirements , Integrate the special acceleration chip hardware of blockchain and the bottom software platform that can be assembled , To build high performance 、 High credibility 、 High security digital infrastructure provides new solutions , Provide strong blockchain technical support for Chang'an chain ecological alliance . The name “ Changan chain ”, Metaphorical meaning “ lasting political stability 、 Create brilliance again 、 Link to the world “.
边栏推荐
- 最小二乘系统辨识课 中篇:递归最小二乘
- [untitled]
- Least squares system identification class II: recursive least squares
- Acid of redis
- pybullet机器人仿真环境搭建 5.机器人位姿可视化
- 【力扣刷题】二分查找:4. 寻找两个正序数组的中位数
- Simple use of tensor
- Comprehensive analysis of discord security issues
- Redis顺序排序命令
- Redis Guide (8): principle and implementation of Qianfan Jingfa distributed lock
猜你喜欢
What is the process of switching C # read / write files from user mode to kernel mode?
【力扣刷题】11.盛最多水的容器//42.接雨水
pybullet机器人仿真环境搭建 5.机器人位姿可视化
我把它当副业月入3万多,新手月入过万的干货分享!
油田勘探问题
[from database deletion to running] JDBC conclusion (finish the series in one day!! run as soon as you finish learning!)
Learn about common functional interfaces
Develop operator based on kubebuilder (for getting started)
10 tf. data
NFT contract basic knowledge explanation
随机推荐
Notes on key review of software engineering at the end of the term
【力扣刷题】单调栈:84. 柱状图中最大的矩形
基於Kubebuilder開發Operator(入門使用)
Redis Guide (8): principle and implementation of Qianfan Jingfa distributed lock
Failed to upload hyperf framework using alicloud OSS
牛客小白月赛50
Everyone is a scientist free gas experience Mint love crash
R语言广义线性模型函数GLM、glm函数构建逻辑回归模型(Logistic regression)、分析模型是否过离散(Overdispersion)、使用残差偏差与二项式模型中的剩余自由度的比率评估
心情不好,我就这样写代码
Redis order sorting command
对话长安马自达高层,全新产品将在Q4发布,空间与智能领跑日系
Tsinghua's "magic potion" is published in nature: reversing stem cell differentiation, and the achievements of the Nobel Prize go further. Netizen: life can be created without sperm and eggs
【毕业季】致毕业生的一句话:天高任鸟飞,海阔凭鱼跃
Cookie和Session详解
我把它当副业月入3万多,新手月入过万的干货分享!
How to identify contractual issues
若依打包如何分离jar包和资源文件?
100+数据科学面试问题和答案总结 - 基础知识和数据分析
What is the difference between stm32f1 and gd32f1?
1-12Vmware新增SSH功能