当前位置:网站首页>17. how to understand multi version concurrency control and read / write sets of fabric smart contracts? (vernacular version)
17. how to understand multi version concurrency control and read / write sets of fabric smart contracts? (vernacular version)
2022-06-13 07:56:00 【Mingshen special worry】
The previous chapters build step by step Fabric2.2 Version of blockchain network , from 0 Start setting up the server environment 、 To the operation official Demo colony 、 Create channels 、 Installation contract , And complete the development of agricultural product traceability project based on blockchain from zero .
Today, let's have a chat Fabric1.0 Why do we design read / write sets in the future ? What is a read-write set ?
1) Transaction execution process , yes Fabric An important factor in using read-write sets .
Over the years, the alliance chain has developed into two types of transaction processes , and Fabric0.6 And Fabric1.0 Each represents a type of transaction process , This involves the core knowledge points of blockchain , Let's study hard .
Fabric0.6:
1) Suppose the blockchain network has four consensus nodes , The four nodes have the same height , Good network communication .
2) The content of the smart contract is the transfer system , Zhang San's initial account 500 element , Li Si's initial account 0 element .
3) The client sends a transaction to one of the consensus nodes A, The blockchain network broadcasts this transaction to the other three consensus nodes B、C、D, And record to the transaction pool of each node , There is no consensus yet . transaction tx1 Content : Zhang San transfers money to Li Si 20 element .
4) There was another deal at the same time tx2, Zhang San transfers money to Li Si 50 element , The pattern is the same as the steps 3. At this point, each consensus node contains two transactions , Waiting to pack blocks .
5) here A The node is responsible for outputting blocks , take tx1、tx2 Packed in a block , And pre execute to get Zhang San :430 element , Li Si :70 element , And recorded in the blockchain world state .
The above execution process is often perfect , I didn't feel anything wrong , There is no doubt .
Fabric1.0:
1) Suppose the blockchain network has four consensus nodes , The four nodes have the same height , Good network communication .
2) The content of the smart contract is the transfer system , Zhang San's initial account 500 element , Li Si's initial account 0 element .
3)(This step begins to change
) Client sends transaction tx1( Zhang San transfers money to Li Si 20 element ) Give one of the proposal nodes , The proposal node pre executes the smart contract to get the result , Zhang San :480 element , Li Si :20 element , And return the result to the client , During this process, the transaction did not enter the block , The proposal node does not update any databases and caches .
4) There was another deal at the same time tx2( Zhang San transfers money to Li Si 50 element ), The pattern is the same as the steps 3, Zhang San :450 element , Li Si :50 Meta results returned to the client .
5) The client sends the returned results of the two transactions to Orderer node ,Orderer Nodes are only responsible for sorting , Generate blocks , Not responsible for smart contract logic detection , These two transactions are packaged into blocks , Send to commit node
6)commit Node resolution tx1、tx2 Result , Write to the status database in order , Final Zhang San :450 element , Li Si :50 element , There is a problem with the system transaction amount ( Hope the result : Zhang San 430, Li Si 70), And the system does not report an error , Think everything's OK .
Through analysis Fabric1.0 Process discovery , because Fabric1.0 Change the mode to generate blocks after pre execution , And the roles are separated , This leads to transaction execution exceptions in the concurrent scenario , How to solve this problem ? There are two solutions :
1) Front hard rigid , Can make the result Zhangsan 430, Li Si 70, But it's too difficult , There is no good method on the official website .
2) Introducing read / write sets + Multi version concurrency control , Consider one of the deals a failure , Notify the front-end system to resend .( Take a step back and there will be a bigger world in front of you )
2) Read-write set 、 Multi version concurrency control
Assuming the current Key: Zhang San
The version is V1,Key: Li Si
The version is V1, Multi version concurrency control only works with Key of , and Value irrelevant .
1) The client sends tx1( Zhang San transfers money to Li Si 20 element ) To the proposal node , Contract logic : Read the amount of Zhang San , Record Read Zhang San -V1, Read the amount of Li Si , Record Read Li Si -V1, Write Zhang Sanxin's amount , Record Write Zhang San -V2, Write the amount of Li Sixin , Record Write Li Si -V2. And will (Read Zhang San -V1、Read Li Si -V1、Write Zhang San -V2、Write Li Si -V2)
Send to client .
2) The client sends tx2( Zhang San transfers money to Li Si 50 element ) To the proposal node , Contract logic : Read the amount of Zhang San , Record Read Zhang San -V1, Read the amount of Li Si , Record Read Li Si -V1, Write Zhang Sanxin's amount , Record Write Zhang San -V2, Write the amount of Li Sixin , Record Write Li Si -V2. In the same way (Read Zhang San -V1、Read Li Si -V1、Write Zhang San -V2、Write Li Si -V2)
Send to client .
3) The two trade fairs were sent one after the other Orderer node ,Orderer Nodes can ignore the contents , Directly packed into blocks , Send to commit node
4)commit Node parsing block transaction discovery tx1 take Key: Zhang San
Version of Write To V2, analysis tx2 Find out Key: Zhang San
Read The version of is still V1, There are version inconsistencies , Think tx2 Transaction execution failed .
3) If the smart contract has only read sets 、 Only the writeset ?
Suppose a deposit logic , Write data to the blockchain regardless , There is no need to judge whether it has been written , So the contract is only a write set , Only write set contracts are not blocked by multi version concurrency control .
4) Expand
After the subsequent development of blockchain , Changan chain 、BCOS、 Baidu super chain wants to be in Fabric0.6 In this mode, the read / write set is applied to improve the blockchain processing performance , Students who want to know can learn .
边栏推荐
- 平衡二叉树学习笔记------一二熊猫
- Index push down (ICP) for mysql5.6
- [Yu Yue education] econometrics reference materials of Jiujiang University
- [MySQL change master error] slave is not configured or failed to initialize properly
- 19 | establish data path (bottom): instruction + operation =cpu
- Redis underlying data structure -- listpack
- China phosphate market in-depth analysis and investment prospect forecast report 2022-2028
- Web site access excel in IIS
- EF core execute SQL statement
- [an example of MySQL startup error] innodb: failed to create check sector file, errno:13
猜你喜欢
【深度学习】:《PyTorch入门到项目实战》(十二)卷积神经网络:填充(padding)和步幅(stride)
GCC compilation process, function library related compilation process
24 | adventure and prediction (III): thread pool in CPU
Compare advantages and disadvantages of DFS and BFS and name vocabulary
2022 simulated examination question bank and online simulated examination of hoisting machinery command examination questions
The way of distributed system: Lamport logical clock
Redis Cluster - the underlying principle of slot assignment
Redis Cluster - the bottom principle of building clusters
2022年G3锅炉水处理操作证考试题库模拟考试平台操作
基于paddlepaddle的新冠肺炎识别
随机推荐
Redis interview questions
2022年危险化学品经营单位安全管理人员特种作业证考试题库及模拟考试
Redis learning journey - transaction
Redis persistence -- AOF
赋予代码生命力--读代码整洁之道
关于#etl#的问题:io.trino.jdbc.TrinoDriver
Upgrade the project of log4j to log4j2
2021-10-20
A troubleshooting process for database timeout caused by SQL misguided
Index push down (ICP) for mysql5.6
【深度学习】:《PyTorch入门到项目实战》(十二)卷积神经网络:填充(padding)和步幅(stride)
Redis master-slave replication - mentality detection mechanism
思路清晰的软光栅小引擎和四元数结合案例
【Emgu.CV】Emgu. CV. Example\ocr operation reports an error system IO. Filenotfoundexception: "failed to load file or assembly" system.drawing.common "
[MySQL] online lock free delay free DDL artifact GH OST
Precautions for passing parameters with byte array
26 | superscalar and VLIW: how to make the CPU throughput exceed 1
Adding certificates to different systems
【clickhouse专栏】基础数据类型说明
MySQL source code --table_ cache