TW202109292A - Method and device for concurrently executing transactions in block chain - Google Patents

Method and device for concurrently executing transactions in block chain Download PDF

Info

Publication number
TW202109292A
TW202109292A TW109110268A TW109110268A TW202109292A TW 202109292 A TW202109292 A TW 202109292A TW 109110268 A TW109110268 A TW 109110268A TW 109110268 A TW109110268 A TW 109110268A TW 202109292 A TW202109292 A TW 202109292A
Authority
TW
Taiwan
Prior art keywords
transaction
variable
execution
read operation
write
Prior art date
Application number
TW109110268A
Other languages
Chinese (zh)
Other versions
TWI759708B (en
Inventor
劉曉建
張兆勇
Original Assignee
開曼群島商創新先進技術有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 開曼群島商創新先進技術有限公司 filed Critical 開曼群島商創新先進技術有限公司
Publication of TW202109292A publication Critical patent/TW202109292A/en
Application granted granted Critical
Publication of TWI759708B publication Critical patent/TWI759708B/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/08Payment architectures
    • G06Q20/085Payment architectures involving remote charge determination or related payment systems
    • G06Q20/0855Payment architectures involving remote charge determination or related payment systems involving a third party
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3829Payment protocols; Details thereof insuring higher security of transaction involving key management

Abstract

The embodiment of the invention provides a method and device for concurrently executing transactions in a block chain. The method is executed at a first node in a block chain, wherein a plurality of transactions are executed concurrently at present in the first node; including a first transaction therein, wherein the first transaction comprises a reading operation on a first variable; the method comprises the following steps of: ; after the code of the reading operation in the first transaction is started to be executed, whether a second transaction is about to write in the first variable or not is inferred, the second transaction is a transaction with the transaction number smaller than that of the first transaction in the multiple transactions, and the transaction number corresponds to the preset submission sequence of the transactions; in a case where it is inferred that a second transaction is to write to the first variable, execution of the read operation in the first transactions suspended.

Description

在區塊鏈中同時執行交易的方法和裝置及電腦可讀儲存媒體與計算設備Method and device for simultaneously executing transactions in block chain, computer readable storage medium and computing equipment

本說明書實施例涉及區塊鏈技術領域,更具體地,涉及一種在區塊鏈中同時執行交易的方法和裝置。 The embodiments of this specification relate to the field of blockchain technology, and more specifically, to a method and device for simultaneously executing transactions in a blockchain.

區塊鏈技術是構建在點對點(P2P)網路上,利用鏈式資料結構來驗證與儲存資料,利用分散式節點共識演算法來產生和更新資料,利用密碼學的方式保證資料傳輸和存取的安全,利用由自動化腳本代碼組成的智慧合約來編程和操作資料的一種全新的分散式基礎架構與計算範式。區塊鏈技術也被稱之為分散式帳本技術,是一種去中心化的分散式資料庫技術,其特點是去中心化、公開透明、不可篡改、可信任。區塊鏈的每筆資料,都會廣播到全網的區塊鏈節點,每個全節點都有全量的、一致的資料。區塊鏈中的節點透過發送交易而進行轉帳、存入資料等業務,區塊鏈中的記帳節點在交易池中收集區塊鏈中的交易,執行所述交易,並在執行所述交易之後,將這些交易打包到區塊中並擴散到區塊鏈中。區塊鏈中的驗證節點會對從記帳節點發出的區塊進行驗證,在驗證通過之後,每個節點在接收到該區塊時,都會執行該區塊中包括的每個交易。為了保證各個節點的資料一致性,各個節點中在執行區塊中的多個交易時,對該多個交易的提交順序需要是一致的,這樣才能得到一致的執行結果。因此,在現有技術中,記帳節點在執行交易之前會按照預定規則對將要執行的多個交易進行編號,並按照編號的順序依次執行多個交易,也即依次提交多個交易,並且其它節點在接收到該區塊之後,也是按照上述交易編號順序依次執行並提交所述多個交易。然而,所述多個交易並不一定都是相互依賴的,在兩個交易之間不存在依賴性的情況中,同時執行這兩個交易並不影響最終的結果。而如果同時執行的兩個交易存在依賴性,則該同時執行將影響到最終的結果。 因此,需要一種更有效的在區塊鏈中同時執行多個交易的方法。 Blockchain technology is built on a peer-to-peer (P2P) network. It uses a chained data structure to verify and store data, uses a distributed node consensus algorithm to generate and update data, and uses cryptography to ensure data transmission and access. Security, a new decentralized infrastructure and computing paradigm that uses smart contracts composed of automated script codes to program and manipulate data. Blockchain technology is also called decentralized ledger technology, which is a decentralized decentralized database technology, which is characterized by decentralization, openness and transparency, non-tampering, and trustworthiness. Every piece of data in the blockchain will be broadcast to the blockchain nodes of the entire network, and each full node has a full amount of consistent information. The nodes in the blockchain conduct transactions such as transfers and deposit data by sending transactions. The accounting nodes in the blockchain collect transactions in the blockchain in the transaction pool, execute the transaction, and execute the transaction after the transaction is executed. , Pack these transactions into blocks and spread them to the blockchain. The verification node in the blockchain will verify the block sent from the accounting node. After the verification is passed, each node will execute each transaction included in the block when it receives the block. In order to ensure the consistency of the data of each node, when multiple transactions in the block are executed in each node, the order of submission of the multiple transactions needs to be consistent, so that consistent execution results can be obtained. Therefore, in the prior art, the billing node will number multiple transactions to be executed according to predetermined rules before executing the transaction, and execute multiple transactions in sequence in the order of the numbers, that is, submit multiple transactions in turn, and other nodes After the block is received, the multiple transactions are executed and submitted in sequence according to the above-mentioned transaction number sequence. However, the multiple transactions are not necessarily mutually dependent, and in the case that there is no dependency between the two transactions, executing the two transactions at the same time does not affect the final result. If there are dependencies between two transactions executed at the same time, the simultaneous execution will affect the final result. Therefore, there is a need for a more effective method of simultaneously executing multiple transactions in the blockchain.

本說明書實施例旨在提供一種更有效的同時執行多個交易的方法,以解決現有技術中的不足。 為實現上述目的,本說明書一個方面提供一種在區塊鏈中同時執行多個交易的方法,所述方法在區塊鏈中的第一節點執行,所述多個交易中包括第一交易,所述第一交易中包括對第一變數的讀取操作,所述方法包括: 在開始執行所述第一交易中的所述讀取操作的代碼之後,推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二交易為所述多個交易中交易編號小於所述第一交易的交易,其中,所述交易編號與交易的預定提交順序相對應; 在推斷第二交易將要對所述第一變數進行寫入的情況中,暫停執行所述第一交易中的所述讀取操作。 在一個實施例中,所述第一節點中預設有變數衝突表,所述變數衝突表中記錄了第一變數為衝突變數,其中,推斷第二交易是否將要對所述第一變數進行寫入包括,基於所述變數衝突表,推斷第二交易將要對所述第一變數進行寫入。 在一個實施例中,所述方法還包括,在暫停執行所述第一交易中的所述讀取操作之後,確定所述第二交易是否根據提交順序為所述第一交易的前一個交易,在確定所述第二交易根據提交順序為所述第一交易的前一個交易的情況中,基於第二交易的執行,恢復執行所述讀取操作。 在一個實施例中,所述讀取操作的讀取對象為共享記憶體中儲存的交易提交結果,其中,基於第二交易的執行,恢復執行所述讀取操作包括,在第二交易提交之後,恢復執行所述讀取操作。 在一個實施例中,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料,其中,基於第二交易的執行,恢復執行所述讀取操作包括,基於在執行第二交易的過程中在共享記憶體預定位址中的聲明,恢復執行所述讀取操作,所述聲明指示所述第二交易的執行將不再對所述第一變數進行寫入。 在一個實施例中,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料,其中,基於第二交易的執行,恢復執行所述讀取操作包括,在確定所述中間資料中包括第二交易中對第一變數的寫入值之後,恢復執行所述讀取操作,並在共享記憶體中對該讀取操作的執行進行記錄。 在一個實施例中,推斷第二交易是否將要對所述第一變數進行寫入包括,獲取第二交易的交易資料;基於第二交易的交易資料,推斷第二交易是否將要對所述第一變數進行寫入。 在一個實施例中,基於第二交易的交易資料,推斷第二交易是否將要對所述第一變數進行寫入包括,透過將第二交易中調用的函數名稱和第一變數輸入預定判定模型,推斷第二交易是否將要對所述第一變數進行寫入。 在一個實施例中,所述方法還包括,在暫停執行所述第一交易中的所述讀取操作之後,確定是否存在交易編號在所述第二交易與第一交易之間的衝突交易,其中,所述衝突交易為被推斷將要對所述第一變數進行寫入的交易,以及,在不存在所述衝突交易的情況中,基於第二交易的執行,恢復執行所述讀取操作。 在一個實施例中,所述第一節點中預設有變數衝突表,所述變數衝突表中記錄了第一變數的衝突機率,其中,在開始執行所述第一交易中的所述讀取操作的代碼之後,推斷第二交易是否將要對所述第一變數進行寫入包括,在開始執行所述第一交易中的所述讀取操作的代碼之後,在第一預定數值範圍內產生隨機數,以及透過確定所述隨機數是否在第二預定數值範圍內,推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二預定數值範圍在所述第一預定數值範圍之內、並基於所述衝突機率確定。 本說明書另一方面提供一種在區塊鏈中同時執行多個交易的裝置,所述裝置部署在區塊鏈中的第一節點中,所述多個交易中包括第一交易,所述第一交易中包括對第一變數的讀取操作,所述裝置包括: 第一確定單元,配置為,在開始執行所述第一交易中的所述讀取操作的代碼之後,推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二交易為所述多個交易中交易編號小於所述第一交易的交易,其中,所述交易編號與交易的預定提交順序相對應; 暫停單元,配置為,在推斷第二交易將要對所述第一變數進行寫入的情況中,暫停執行所述第一交易中的所述讀取操作。 在一個實施例中,所述第一節點中預設有變數衝突表,所述變數衝突表中記錄了第一變數為衝突變數,其中,所述第一確定單元還配置為,基於所述變數衝突表,推斷第二交易將要對所述第一變數進行寫入。 在一個實施例中,所述裝置還包括,第二確定單元,配置為,在暫停執行所述第一交易中的所述讀取操作之後,確定所述第二交易是否根據提交順序為所述第一交易的前一個交易,以及第一恢復單元,配置為,在確定所述第二交易根據提交順序為所述第一交易的前一個交易的情況中,基於第二交易的執行,恢復執行所述讀取操作。 在一個實施例中,所述讀取操作的讀取對象為共享記憶體中儲存的交易提交結果,其中,所述恢復單元還配置為,在第二交易提交之後,恢復執行所述讀取操作。 在一個實施例中,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料,其中,所述恢復單元還配置為,基於在執行第二交易的過程中在共享記憶體預定位址中的聲明,恢復執行所述讀取操作,所述聲明指示所述第二交易的執行將不再對所述第一變數進行寫入。 在一個實施例中,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料,所述恢復單元還配置,在確定所述中間資料中包括第二交易中對第一變數的寫入值之後,恢復執行所述讀取操作,並在共享記憶體中對該讀取操作的執行進行記錄。 在一個實施例中,所述第一確定單元還包括,獲取子單元,配置為,獲取第二交易的交易資料;以及第一確定子單元,配置為,基於第二交易的交易資料,推斷第二交易是否將要對所述第一變數進行寫入。 在一個實施例中,所述第一確定子單元還配置為,透過將第二交易中調用的函數名稱和第一變數輸入預定判定模型,推斷第二交易是否將要對所述第一變數進行寫入。 在一個實施例中,所述裝置還包括,第三確定單元,配置為,在暫停執行所述第一交易中的所述讀取操作之後,確定是否存在交易編號在所述第二交易與第一交易之間的衝突交易,其中,所述衝突交易為被推斷將要對所述第一變數進行寫入的交易,以及,第二恢復單元,配置為,在不存在所述衝突交易的情況中,基於第二交易的執行,恢復執行所述讀取操作。 在一個實施例中,所述第一節點中預設有變數衝突表,所述變數衝突表中記錄了第一變數的衝突機率,其中,所述第一確定單元還包括,產生子單元,配置為,在開始執行所述第一交易中的所述讀取操作的代碼之後,在第一預定數值範圍內產生隨機數,以及第二確定子單元,配置為,透過確定所述隨機數是否在第二預定數值範圍內,而推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二預定數值範圍在所述第一預定數值範圍之內、並基於所述衝突機率確定。 本說明書另一方面提供一種電腦可讀儲存媒體,其上儲存有電腦程式,當所述電腦程式在電腦中執行時,令電腦執行上述任一項方法。 本說明書另一方面提供一種計算設備,包括記憶體和處理器,其特徵在於,所述記憶體中儲存有可執行代碼,所述處理器執行所述可執行代碼時,實現上述任一項方法。 透過根據本說明書實施例的在區塊鏈中同時執行交易的方案,透過確定交易之間的衝突機率,從而確定是否暫停對變數的讀取操作,從而可使得對於沒有相互依賴性的多個交易,可同時執行這些交易,對於具有相互依賴性的多個交易,可串列執行這些交易,從而大機率避免了交易之間的衝突和交易的回撤,從而在保證計算結果一致性的同時,加快了處理速度,提高了處理性能。 The embodiments of the present specification aim to provide a more effective method for executing multiple transactions at the same time, so as to solve the deficiencies in the prior art. In order to achieve the above objective, one aspect of this specification provides a method for simultaneously executing multiple transactions in a blockchain. The method is executed at a first node in the blockchain, and the multiple transactions include the first transaction. The first transaction includes a reading operation of the first variable, and the method includes: After starting to execute the code of the read operation in the first transaction, it is inferred whether the second transaction will write the first variable, wherein the second transaction is a transaction among the plurality of transactions A transaction with a serial number smaller than the first transaction, wherein the transaction serial number corresponds to a predetermined submission order of the transaction; In the case where it is inferred that the second transaction will write the first variable, the execution of the read operation in the first transaction is suspended. In one embodiment, a variable conflict table is preset in the first node, and the variable conflict table records that the first variable is a conflict variable, wherein it is inferred whether the second transaction will write the first variable Inclusion includes, based on the variable conflict table, inferring that the second transaction will write the first variable. In one embodiment, the method further includes, after suspending execution of the read operation in the first transaction, determining whether the second transaction is the previous transaction of the first transaction according to the order of submission, In the case where it is determined that the second transaction is the previous transaction of the first transaction according to the submission order, the execution of the read operation is resumed based on the execution of the second transaction. In one embodiment, the read object of the read operation is the transaction submission result stored in the shared memory, wherein, based on the execution of the second transaction, resuming execution of the read operation includes, after the second transaction is submitted , Resume the execution of the read operation. In one embodiment, the read object of the read operation is the intermediate data that is written into the shared memory during the processing of the second transaction, and the execution of the read operation is resumed based on the execution of the second transaction Including, based on the statement in the predetermined address of the shared memory during the execution of the second transaction, resuming the execution of the read operation, the statement indicating that the execution of the second transaction will no longer affect the first variable To write. In one embodiment, the read object of the read operation is the intermediate data that is written into the shared memory during the processing of the second transaction, and the execution of the read operation is resumed based on the execution of the second transaction This includes, after determining that the intermediate data includes the write value of the first variable in the second transaction, resume execution of the read operation, and record the execution of the read operation in the shared memory. In one embodiment, inferring whether the second transaction will write the first variable includes obtaining transaction data of the second transaction; based on the transaction data of the second transaction, inferring whether the second transaction will affect the first variable. Variables are written. In one embodiment, based on the transaction data of the second transaction, inferring whether the second transaction will write the first variable includes, by inputting the name of the function called in the second transaction and the first variable into a predetermined determination model, Infer whether the second transaction will write the first variable. In one embodiment, the method further includes, after suspending execution of the reading operation in the first transaction, determining whether there is a conflicting transaction with a transaction number between the second transaction and the first transaction, Wherein, the conflicting transaction is a transaction that is inferred to be written to the first variable, and, in a case where the conflicting transaction does not exist, the execution of the reading operation is resumed based on the execution of the second transaction. In one embodiment, a variable conflict table is preset in the first node, and the conflict probability of the first variable is recorded in the variable conflict table. After the operation code, inferring whether the second transaction will write the first variable includes, after starting to execute the read operation code in the first transaction, generating a random value within a first predetermined value range Number, and by determining whether the random number is within a second predetermined value range, infer whether the second transaction will write the first variable, wherein the second predetermined value range is within the first predetermined value Within the range and determined based on the probability of conflict. Another aspect of this specification provides a device for simultaneously executing multiple transactions in a blockchain. The device is deployed in a first node in the blockchain, and the multiple transactions include a first transaction. The transaction includes a reading operation of the first variable, and the device includes: The first determining unit is configured to, after starting to execute the code of the read operation in the first transaction, infer whether the second transaction will write the first variable, wherein the second transaction Is a transaction with a transaction number smaller than the first transaction among the plurality of transactions, wherein the transaction number corresponds to a predetermined submission order of the transaction; The suspending unit is configured to suspend the execution of the read operation in the first transaction when it is inferred that the second transaction will write the first variable. In an embodiment, a variable conflict table is preset in the first node, and the variable conflict table records that the first variable is a conflict variable, wherein the first determining unit is further configured to, based on the variable Conflict table, inferring that the second transaction will write the first variable. In one embodiment, the device further includes a second determining unit configured to, after suspending the execution of the read operation in the first transaction, determine whether the second transaction is the same according to the order of submission. The previous transaction of the first transaction and the first restoration unit are configured to, in the case of determining that the second transaction is the previous transaction of the first transaction according to the submission order, resume execution based on the execution of the second transaction The read operation. In one embodiment, the read object of the read operation is the transaction submission result stored in the shared memory, wherein the recovery unit is further configured to resume execution of the read operation after the second transaction is submitted . In one embodiment, the read object of the read operation is the intermediate data written into the shared memory during the processing of the second transaction, wherein the recovery unit is further configured to be based on the execution of the second transaction The statement in the predetermined address of the shared memory during the process resumes the execution of the read operation, and the statement indicates that the execution of the second transaction will no longer write the first variable. In one embodiment, the read object of the read operation is the intermediate data written into the shared memory during the processing of the second transaction, and the recovery unit is further configured to determine that the intermediate data includes the first After the value of the first variable is written in the second transaction, the execution of the read operation is resumed, and the execution of the read operation is recorded in the shared memory. In an embodiment, the first determining unit further includes an obtaining subunit configured to obtain transaction data of the second transaction; and a first determining subunit configured to infer the first transaction based on the transaction data of the second transaction. 2. Whether the transaction will write the first variable. In one embodiment, the first determining subunit is further configured to infer whether the second transaction will write the first variable by inputting the name of the function called in the second transaction and the first variable into a predetermined determination model. Into. In one embodiment, the device further includes a third determining unit configured to, after suspending the execution of the reading operation in the first transaction, determine whether there is a transaction number between the second transaction and the first transaction. A conflicting transaction between transactions, wherein the conflicting transaction is a transaction that is inferred to be written to the first variable, and the second recovery unit is configured to, in the case where the conflicting transaction does not exist , Based on the execution of the second transaction, resume execution of the read operation. In one embodiment, a variable conflict table is preset in the first node, and the conflict probability of the first variable is recorded in the variable conflict table, wherein the first determining unit further includes a generating subunit, and configuring Is, after starting to execute the code of the read operation in the first transaction, a random number is generated within a first predetermined value range, and a second determining subunit is configured to determine whether the random number is in Is within a second predetermined numerical range, and it is inferred whether the second transaction will write the first variable, wherein the second predetermined numerical range is within the first predetermined numerical range and is based on the conflict probability determine. Another aspect of this specification provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed in a computer, the computer is made to execute any of the above methods. Another aspect of this specification provides a computing device, including a memory and a processor, characterized in that executable code is stored in the memory, and when the processor executes the executable code, any one of the above methods is implemented . Through the simultaneous execution of transactions in the blockchain according to the embodiment of this specification, by determining the probability of conflicts between transactions, it is determined whether to suspend the reading operation of variables, so that multiple transactions without interdependence can be , These transactions can be executed at the same time, and for multiple transactions with interdependence, these transactions can be executed in tandem, so as to avoid conflicts between transactions and retracements of transactions, so as to ensure the consistency of calculation results. Speed up the processing speed and improve the processing performance.

下面將結合附圖描述本說明書實施例。 圖1示出根據本說明書實施例的區塊鏈系統示意圖。如圖1所示,所述系統中包括構成區塊鏈的多個節點(圖中示意示出6個節點),這些節點兩兩相連,其中例如包括節點11、節點12和節點13。如本領域技術人員所知,在區塊鏈中,一些節點會收集區塊鏈中的多個交易放入交易池中並競爭記帳權。例如圖中的節點11透過獲取記帳權而成為記帳節點。節點11在成為記帳節點之後會執行其交易池中的多個交易,並將該多個交易打包成區塊發送給其它節點,例如發送給節點12。節點12將會對該區塊進行驗證,並同樣地執行該區塊中的多個交易。在預定數目個節點對該區塊進行驗證之後,也即對該區塊達到了共識,區塊鏈中的其它節點(例如節點13)將不需要繼續對該區塊進行驗證,而是直接對該區塊中的交易進行執行,以更新本地的相關資料。 在同時執行多個交易的過程中,所述多個交易中可能涉及到對多個變數的計算,在兩個交易中不涉及相同的變數的情況中,其執行順序並不會影響最終的計算結果,而在例如第一交易包括對變數k1的寫入、第二交易包括對變數k1的讀取、並且第一交易的編號在第二交易之前的情況中,第一交易成為第二交易的衝突交易,也就是說,第二交易必須在確定第一交易對其即將讀取的k1值不再寫入的情況中,才能進行對該k1值的讀取,否則其讀取的k1值是錯誤的值。其中,所述交易的編號對應於交易的提交順序,在同時執行交易時,為了保證最終的交易執行結果相同,必須保證交易的提交順序與串列執行交易時的提交順序是相同的。同時,在本說明書實施例中,為了保證各個節點對多個交易的執行結果是相同的,在同時執行多個交易的同時,考慮交易之間對存取變數的衝突,從而使得平行執行的交易的衝突機率較大的情況下進行等待,以避免衝突的發生。例如,如圖1中所示,每個節點都可以根據本節點的交易執行歷史預設變數衝突表,該變數衝突表中記錄了容易引起交易衝突的變數。從而,例如,在節點11中,當在執行第二交易時開始進行對變數k1的讀取操作之後,將參考節點11中的變數衝突表,以確定k1是否為衝突變數,在確定k1為衝突變數的情況中,也就是說,第二交易與其之前的交易之間存在衝突的機率較大,因此暫停第二交易中對k1的讀取,而等其之前一個交易提交之後再進行該讀取。 可以理解,上文對圖1的描述只是示意性地,而不是用於限制本說明書實施例的範圍。例如,在節點中,也可以透過其他方式獲取交易之間的衝突機率,或者所述第二交易也可以在其之前的交易進行其它執行之後再進行讀取。下文將詳細描述根據本說明書實施例的同時執行交易的過程。 圖2示出根據本說明書一個實施例的一種在區塊鏈中同時執行交易的方法流程圖,所述方法在區塊鏈中的第一節點執行,所述第一節點中目前同時執行多個交易,其中包括第一交易,所述第一交易中包括對第一變數的讀取操作,所述方法包括: 在步驟S202,在開始執行所述第一交易中的所述讀取操作的代碼之後,推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二交易為所述多個交易中交易編號小於所述第一交易的交易,其中,所述交易編號與交易的預定提交順序相對應; 在步驟S204,在推斷第二交易將要對所述第一變數進行寫入的情況中,暫停執行所述第一交易中的所述讀取操作。 首先,在步驟S202,在開始執行所述第一交易中的所述讀取操作的代碼之後,推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二交易為所述多個交易中交易編號小於所述第一交易的交易,其中,所述交易編號與交易的預定提交順序相對應。 如上文中參考圖1中所述,該方法在區塊鏈中的一個節點執行。該節點在打包區塊時,或者該節點在接收到新產生的區塊之後,都會對相關的多個交易進行執行提交。例如,一個區塊中可包括幾千筆交易,而這幾千筆交易可能涉及幾百個變數,其中,多個交易可能存取不同的變數,或者,多個交易可能存取相同的變數。在現有技術中,在記帳節點中,已經根據預定規則確定了將打包到一個區塊中的多個交易各自的交易編號,該交易編號的順序指示了交易的執行順序和提交順序。在本說明書實施例中,為了使得最後的計算結果與現有技術中的串列計算結果相同,對區塊中的多個交易保留預定好的提交順序,即,以各個交易的編號順序作為其各自的提交順序,同時,透過預先確定交易之間的衝突機率,使得沒有依賴關係的各個交易可同時執行,並使得具有依賴關係的各個交易依據其編號的先後串列執行,從而避免交易衝突,其中,對於先後編號的交易1和交易2,如果在交易1中對第一變數進行寫入,在交易2中對第一變數進行讀取,則交易2依賴於交易1的結果,交易1是交易2的衝突交易。 在一個實施例中,如上文所述,在區塊鏈每個節點中預設有變數衝突表,該衝突變數記錄了多個變數中的衝突變數。圖3示出了變數衝突表的示意形式。如圖3所示,該變數衝突表中對執行多個交易過程中的多個變數k1、k2、…kn進行列表,並將所述多個變數中的衝突變數對應的值設定為1,將多個變數中的非衝突變數的值設定為0。從而,透過查詢該變數衝突表,可確定特定變數是否為衝突變數。所述衝突變數例如為容易引起交易衝突的變數。例如,可根據程式員的先驗經驗確定多個變數中的衝突變數,從而預設變數衝突表。或者,可根據節點中的已有的執行交易的歷史資料進行確定,例如,在歷史資料中的一個交易中包括對例如變數k1的讀取時,根據該歷史資料確定在該交易之前的交易對該變數k1進行寫入的平均機率。如果該平均機率大於預定臨限值時,可確定該變數k1為衝突變數。在一個實施例中,可對圖3所示表中各個變數增加時間戳,例如對於變數k1,每次發現對變數k1的存取衝突時,更新一下時間戳,在查詢該表時如果發現時間戳距離目前時間非常遠,則將變數k1的值修改為0。在一個實施例中,可基於每個預定時段的歷史資料,定期更新該表。 在一個實施例中,在基於預設的變數衝突表確定k1為衝突變數之後,根據悲觀策略,如果目前執行的第一交易中包括對變數k1的讀取,則認為目前同時執行的交易中編號小於第一交易的各個交易都是第一交易的衝突交易,也就是說,認為所述各個交易都將要對變數k1進行寫入。這裡,交易編號對應於交易的提交順序,交易的提交順序越靠前,交易編號越小。 在一個實施例中,可在節點中預設各個變數的變數衝突表,該變數衝突表中包括各個變數的衝突機率。圖4示出了變數衝突表的示意形式。如圖4中所示,該變數衝突表中對執行多個交易過程中的多個變數k1、k2、…kn進行列表,該表中各個變數ki對應的值為該變數的衝突機率。該衝突機率例如可基於歷史交易執行資料確定。圖4所示的變數衝突表可定期更新。例如,在所述變數衝突表中,k1的衝突機率為20%。如果目前執行的第一交易中包括對變數k1的讀取,k1的衝突機率表示,同時執行的多個交易中的在第一交易之前的交易對k1進行寫入的平均機率為20%,從而,可根據樂觀策略確定第一交易的衝突交易。具體是,例如可產生0到100之間的隨機數,假設基於20%的機率設定0到40為預定範圍,則,當該隨機數在0到40(包括40)範圍內時,認為該第一交易的在前交易將要對第一變數進行寫入,當該隨機數在40到100(包括100)範圍內時,認為該第一交易的在前交易將不會對第一變數進行寫入,其中,在前交易為與第一交易同時執行的、交易編號小於第一交易的交易。可基於重做和等待各自造成的損失參數確定用於進行推斷的隨機數的預定範圍,比如:假設“等待”會造成中央處理單元(cpu)空閒2ms、“重做”會造成cpu浪費10ms,則當衝突機率為20%時,可將所述預定範圍確定為0到20之間,若“等待”會造成cpu空閒1ms,“重做”會造成cpu浪費10ms,則當衝突機率時20%時,可將所述預定範圍設定為更大,例如0到80等等。 在一個實施例中,可在節點中預設結合圖3和圖4的變數衝突表,在該表中,當變數的衝突機率大於預定臨限值時,將該變數的衝突值設為1,當變數的衝突機率小於等於預定臨限值時,將該變數的衝突值設為其實際衝突機率。從而,在變數的衝突機率大於預定臨限值時,可透過該變數衝突表,直接確定該變數為衝突變數,在變數的衝突機率小於等於預定臨限值時,可透過上述產生隨機數的方式確定該變數是否為衝突變數。從而融合了悲觀策略和樂觀策略。 在一個實施例中,如果目前執行的第一交易中包括對變數k1的讀取,假設目前由第一執行緒執行第一交易,第一執行緒可查詢第一交易的各個在前交易的交易資料,並根據該交易資料確定該在前交易對變數k1進行寫入的機率,從而確定該在前交易是否為第一交易的衝突交易。具體是,例如第一交易的在前交易中包括第二交易,第一執行緒可查詢到第二交易的調用函數的名稱,並透過將該函數名稱和變數k1輸入預定判定模型,以推斷第二交易是否將要對變數k1進行寫入。在一個實施例中,所述預定判定模型例如包括各個調用函數與各個變數之間的寫機率表,所述寫機率表根據歷史交易執行資料、或者根據函數的具體代碼,確定了在調用函數時對各個變數進行寫入的機率。例如,在調用函數中包括對變數k[n]的寫入,n由交易執行中輸入,例如n為1、2或3,則該函數對k[1]的寫入機率可為1/3。從而,透過將第二交易的調用函數的名稱和變數k1輸入該判定模型,在模型中可基於所述寫機率表確定第二交易對變數k1的寫機率是否大於預定臨限值,從而推斷第二交易是否將對k1進行寫入。在一個實施例中,所述判定模型例如為透過歷史交易執行資料訓練的判定模型,在對該判定模型輸入第二交易的調用函數名稱和第一交易讀取的變數k1之後,該判定模型便可以推斷第二交易是否將對變數k1進行寫入。 在步驟S204,在推斷第二交易將要對所述第一變數進行寫入的情況中,暫停執行所述第一交易中的所述讀取操作。 在如上所述推斷第二交易將要對第一變數進行寫入的情況中,也就是說,第二交易是第一交易的衝突交易,第一交易需要暫停執行所述讀取操作,即進行等待,以讀取到第二交易對k1的寫入值,否則,第一交易讀取的k1值將是錯誤的值,在執行了錯誤的讀取之後,在後續將要重新進行讀取操作,並對交易進行相應的重做。 在一個實施例中,在基於上述變數衝突表或變數衝突表推斷第二交易將要對變數k1進行寫入之後,還需要確定該第二交易是否為第一交易的前一個交易,在第二交易為第一交易的前一個交易的情況中,則基於第二交易的執行,恢復執行所述第一交易中的讀取。也就是說,在該實施例中,在確定變數k1為衝突變數之後,則認為第一交易之前的每個同時執行的交易都是第一交易的衝突交易,因此,需要等到第一交易的前一個交易進行了相應操作之後,再恢復第一交易中的讀取操作。 具體是,在一個實施例中,假設第二交易為第一交易的前一個交易,所述讀取操作的讀取對象為共享記憶體中儲存的第二交易的提交結果,也就是說,只有等到第二交易提交之後,第一交易才能讀取到該第二交易對變數k1的寫入值。在該情況中,在第二交易提交之後,可恢復第一交易中的讀取操作。 在一個實施例中,假設第二交易為第一交易的前一個交易,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料。例如,目前透過第二執行緒在執行第二交易,第二執行緒在執行第二交易的過程中在進行對k1的寫入之後,在共享記憶體中記錄對k1進行寫入的動作、和該寫入的k1值作為中間資料。在進行該寫入之後,第二執行緒基於預設代碼或者對代碼的編譯可確定,在後續將不再對k1進行寫入,從而,第二執行緒可在共享記憶體預定位址中聲明:第二交易的執行將不再寫入變數k1,從而執行第一交易的第一執行緒在預定位址讀取到該聲明之後,可結束上述等待,從所述中間資料中讀取由第二執行緒寫入的變數k1的值。 在一個實施例中,假設第二交易為第一交易的前一個交易,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料。例如,目前透過第二執行緒在執行第二交易,第二執行緒在執行第二交易的過程中在進行對k1的寫入之後,在共享記憶體中記錄對k1進行寫入的動作、和該寫入的k1值作為中間資料。執行第一交易的第一執行緒在基於所述中間資料確定第二執行緒對k1進行寫入之後,可結束上述等待,從所述中間資料中讀取由第二執行緒寫入的變數k1的值。所述第一執行緒在進行上述讀取之後,在共享記憶體中記錄其執行了第一交易中的對變數k1的讀取。後續例如在第二執行緒再次執行對變數k1的寫入的情況中,第二執行緒根據第一執行緒在共享記憶體中的記錄,將通知例如交易調度器重新執行第一交易中的所述讀取及後續相關操作、或者回撤第一交易。 在一個實施例中,如上所述,透過查詢各個在前交易的交易資料確定該在前交易是否為第一交易的衝突交易的情況中,在確定第二交易為第一交易的衝突交易的情況中,還需要確定在第一交易與第二交易之間是否還有第一交易的衝突交易,也就是說,確定第二交易是否是離第一交易最近的衝突交易。從而,在確定第二交易為離第一交易最近的衝突交易之後,可基於第二交易的執行,恢復第一交易中的所述讀取操作的執行。 圖5示出根據本說明書一個實施例的一種在區塊鏈中同時執行交易的裝置500,所述裝置部署在區塊鏈中的第一節點中,所述第一節點中目前同時執行多個交易,其中包括第一交易,所述第一交易中包括對第一變數的讀取操作,所述裝置包括: 第一確定單元51,配置為,在開始執行所述第一交易中的所述讀取操作的代碼之後,推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二交易為所述多個交易中交易編號小於所述第一交易的交易,其中,所述交易編號與交易的預定提交順序相對應; 暫停單元52,配置為,在推斷第二交易將要對所述第一變數進行寫入的情況中,暫停執行所述第一交易中的所述讀取操作。 在一個實施例中,所述第一節點中預設有變數衝突表,所述變數衝突表中記錄了第一變數為衝突變數,其中,所述第一確定單元51還配置為,基於所述變數衝突表,推斷第二交易將要對所述第一變數進行寫入。 在一個實施例中,所述裝置還包括,第二確定單元53,配置為,在暫停執行所述第一交易中的所述讀取操作之後,確定所述第二交易是否根據提交順序為所述第一交易的前一個交易,以及第一恢復單元54,配置為,在確定所述第二交易根據提交順序為所述第一交易的前一個交易的情況中,基於第二交易的執行,恢復執行所述讀取操作。 在一個實施例中,所述讀取操作的讀取對象為共享記憶體中儲存的交易提交結果,其中,所述第一恢復單元54還配置為,在第二交易提交之後,恢復執行所述讀取操作。 在一個實施例中,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料,其中,所述第一恢復單元54還配置為,基於在執行第二交易的過程中在共享記憶體預定位址中的聲明,恢復執行所述讀取操作,所述聲明指示所述第二交易的執行將不再對所述第一變數進行寫入。 在一個實施例中,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料,所述第一恢復單元54還配置,在確定所述中間資料中包括第二交易中對第一變數的寫入值之後,恢復執行所述讀取操作,並在共享記憶體中對該讀取操作的執行進行記錄。 在一個實施例中,所述第一確定單元51還包括,獲取子單元511,配置為,獲取第二交易的交易資料;以及第一確定子單元512,配置為,基於第二交易的交易資料,推斷第二交易是否將要對所述第一變數進行寫入。 在一個實施例中,所述第一確定子單元512還配置為,透過將第二交易中調用的函數名稱和第一變數輸入預定判定模型,推斷第二交易是否將要對所述第一變數進行寫入。 在一個實施例中,所述裝置還包括,第三確定單元55,配置為,在暫停執行所述第一交易中的所述讀取操作之後,確定是否存在交易編號在所述第二交易與第一交易之間的衝突交易,其中,所述衝突交易為被推斷將要對所述第一變數進行寫入的交易,以及,第二恢復單元56,配置為,在不存在所述衝突交易的情況中,基於第二交易的執行,恢復執行所述讀取操作。 在一個實施例中,所述第一節點中預設有變數衝突表,所述變數衝突表中記錄了第一變數的衝突機率,其中,所述第一確定單元51還包括,產生子單元513,配置為,在開始執行所述第一交易中的所述讀取操作的代碼之後,在第一預定數值範圍內產生隨機數,以及第二確定子單元514,配置為,透過確定所述隨機數是否在第二預定數值範圍內,而推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二預定數值範圍在所述第一預定數值範圍之內、並基於所述衝突機率確定。 本說明書另一方面提供一種電腦可讀儲存媒體,其上儲存有電腦程式,當所述電腦程式在電腦中執行時,令電腦執行上述任一項方法。 本說明書另一方面提供一種計算設備,包括記憶體和處理器,其特徵在於,所述記憶體中儲存有可執行代碼,所述處理器執行所述可執行代碼時,實現上述任一項方法。 透過根據本說明書實施例的在區塊鏈中同時執行交易的方案,透過確定交易之間的衝突機率,從而確定是否暫停對變數的讀取操作,從而可使得對於沒有相互依賴性的多個交易,可同時執行這些交易;對於具有相互依賴性的多個交易,可串列執行這些交易,從而大機率避免了交易之間的衝突和交易的重做;對於交易之間具有一定衝突機率的情形,本發明方法可在樂觀預期和悲觀預期之間進行平滑過渡,在串列執行浪費cpu和交易重做浪費cpu之間取得平衡,從而在保證計算結果一致性的同時,加快了處理速度,提高了處理性能。 需要理解,本文中的“第一”,“第二”等描述,僅僅為了描述的簡單而對相似概念進行區分,並不具有其他限定作用。 本說明書中的各個實施例均採用漸進的方式描述,各個實施例之間相同相似的部分互相參見即可,每個實施例重點說明的都是與其他實施例的不同之處。尤其,對於系統實施例而言,由於其基本相似於方法實施例,所以描述的比較簡單,相關之處參見方法實施例的部分說明即可。 上述對本說明書特定實施例進行了描述。其它實施例在所附申請專利範圍的範圍內。在一些情況下,在申請專利範圍中記載的動作或步驟可以按照不同於實施例中的順序來執行並且仍然可以實現期望的結果。另外,在附圖中描繪的過程不一定要求示出的特定順序或者連續順序才能實現期望的結果。在某些實施方式中,多任務處理和平行處理也是可以的或者可能是有利的。 本領域普通技術人員應該還可以進一步意識到,結合本文中所公開的實施例描述的各示例的單元及演算法步驟,能夠以電子硬體、電腦軟體或者二者的結合來實現,為了清楚地說明硬體和軟體的可互換性,在上述說明中已經按照功能一般性地描述了各示例的組成及步驟。這些功能究竟以硬體還是軟體方式來執行,取決於技術方案的特定應用和設計約束條件。本領域普通技術人員可以對每個特定的應用來使用不同方法來實現所描述的功能,但是這種實現不應認為超出本申請的範圍。 結合本文中所公開的實施例描述的方法或演算法的步驟可以用硬體、處理器執行的軟體模組,或者二者的結合來實施。軟體模組可以置於隨機記憶體(RAM)、記憶體、唯讀記憶體(ROM)、電可編程ROM、電可抹除可編程ROM、暫存器、硬碟、可移動磁碟、CD-ROM、或技術領域內所公知的任意其它形式的儲存媒體中。 以上所述的具體實施方式,對本發明的目的、技術方案和有益效果進行了進一步詳細說明,所應理解的是,以上所述僅為本發明的具體實施方式而已,並不用於限定本發明的保護範圍,凡在本發明的精神和原則之內,所做的任何修改、等同替換、改進等,均應包含在本發明的保護範圍之內。 The embodiments of this specification will be described below in conjunction with the drawings. Fig. 1 shows a schematic diagram of a blockchain system according to an embodiment of the present specification. As shown in FIG. 1, the system includes multiple nodes (six nodes are schematically shown in the figure) constituting a blockchain, and these nodes are connected in pairs, including node 11, node 12, and node 13, for example. As those skilled in the art know, in the blockchain, some nodes collect multiple transactions in the blockchain and put them into the transaction pool and compete for the right to keep accounts. For example, the node 11 in the figure becomes a billing node by acquiring the billing right. After node 11 becomes a billing node, it will execute multiple transactions in its transaction pool, package the multiple transactions into blocks and send them to other nodes, for example, to node 12. The node 12 will verify the block and execute multiple transactions in the block in the same way. After a predetermined number of nodes verify the block, that is, a consensus on the block is reached, other nodes in the blockchain (such as node 13) will not need to continue to verify the block, but directly The transaction in this block is executed to update the local relevant information. In the process of executing multiple transactions at the same time, the calculation of multiple variables may be involved in the multiple transactions. In the case that the same variables are not involved in the two transactions, the order of execution will not affect the final calculation. As a result, for example, in the case where the first transaction includes the writing of variable k1, the second transaction includes the reading of variable k1, and the number of the first transaction is before the second transaction, the first transaction becomes the second transaction. Conflict transaction, that is, the second transaction must read the k1 value when it is determined that the first transaction will no longer write the k1 value that it will read, otherwise the k1 value it reads is Wrong value. Wherein, the number of the transaction corresponds to the submission order of the transaction. In order to ensure that the final transaction execution result is the same when the transaction is executed at the same time, it must be ensured that the submission order of the transaction is the same as the submission order when the transaction is executed serially. At the same time, in the embodiments of this specification, in order to ensure that the execution results of multiple transactions by each node are the same, while multiple transactions are executed at the same time, the conflicts of access variables between the transactions are considered, so that the transactions executed in parallel are If there is a high probability of conflict, wait for it to avoid the occurrence of conflicts. For example, as shown in Figure 1, each node can preset a variable conflict table based on the transaction execution history of the node, and the variable conflict table records variables that are likely to cause transaction conflicts. Thus, for example, in node 11, after the reading operation of variable k1 is started when the second transaction is performed, the variable conflict table in node 11 is referred to to determine whether k1 is a conflicting variable, and k1 is determined to be a conflict. In the case of variables, that is, the probability of conflict between the second transaction and the previous transaction is high, so the reading of k1 in the second transaction is suspended, and the reading is performed after the previous transaction is submitted. . It can be understood that the above description of FIG. 1 is only schematic, and is not used to limit the scope of the embodiments of the present specification. For example, in the node, the probability of conflict between transactions can also be obtained through other methods, or the second transaction can also be read after other executions of the previous transaction. Hereinafter, the process of simultaneously executing transactions according to the embodiment of the present specification will be described in detail. Figure 2 shows a flow chart of a method for simultaneously executing transactions in a blockchain according to an embodiment of the present specification. The method is executed on a first node in the blockchain, and the first node currently executes multiple transactions simultaneously. A transaction, including a first transaction, and the first transaction including a reading operation of a first variable, and the method includes: In step S202, after starting to execute the code of the read operation in the first transaction, infer whether the second transaction will write the first variable, wherein the second transaction is the multiple Transactions in which the transaction number is smaller than the first transaction in each transaction, wherein the transaction number corresponds to a predetermined submission order of the transaction; In step S204, when it is concluded that the second transaction will write the first variable, the execution of the read operation in the first transaction is suspended. First, in step S202, after starting to execute the code of the read operation in the first transaction, infer whether the second transaction will write the first variable, wherein the second transaction is the Among the multiple transactions, the transaction number is smaller than the first transaction, wherein the transaction number corresponds to a predetermined submission order of the transaction. As described above with reference to Figure 1, this method is executed on a node in the blockchain. When the node packs a block, or after the node receives a newly generated block, it will execute and submit multiple related transactions. For example, a block may include thousands of transactions, and these thousands of transactions may involve hundreds of variables. Among them, multiple transactions may access different variables, or multiple transactions may access the same variable. In the prior art, in the accounting node, the respective transaction numbers of multiple transactions to be packaged into a block have been determined according to predetermined rules, and the order of the transaction numbers indicates the execution order and submission order of the transactions. In the embodiment of this specification, in order to make the final calculation result the same as the tandem calculation result in the prior art, the predetermined submission order is reserved for multiple transactions in the block, that is, the serial number sequence of each transaction is used as its respective order. At the same time, by pre-determining the conflict probability between transactions, each transaction without a dependency relationship can be executed at the same time, and each transaction with a dependency relationship is executed according to the serial number of its serial number, thereby avoiding transaction conflicts. For transaction 1 and transaction 2, if the first variable is written in transaction 1, and the first variable is read in transaction 2, transaction 2 depends on the result of transaction 1, and transaction 1 is transaction 2 conflict transactions. In one embodiment, as described above, a variable conflict table is preset in each node of the blockchain, and the conflict variable records the conflict variable among the multiple variables. Figure 3 shows a schematic form of the variable conflict table. As shown in Figure 3, the variable conflict table lists multiple variables k1, k2,...kn in the execution of multiple transactions, and sets the value corresponding to the conflicting variable in the multiple variables to 1, and The value of the non-conflicting variable among the multiple variables is set to 0. Therefore, by querying the variable conflict table, it can be determined whether a specific variable is a conflict variable. The conflicting variable is, for example, a variable that is likely to cause transaction conflicts. For example, a conflicting variable among multiple variables can be determined according to the prior experience of the programmer, so as to preset a variable conflict table. Or, it can be determined based on the historical data of the existing transaction executed in the node. For example, when a transaction in the historical data includes the reading of, for example, the variable k1, the historical data is used to determine the transaction pair before the transaction. The average probability of writing to this variable k1. If the average probability is greater than the predetermined threshold, the variable k1 can be determined to be a conflict variable. In one embodiment, a timestamp can be added to each variable in the table shown in FIG. 3. For example, for variable k1, every time an access conflict to variable k1 is found, the timestamp is updated, and if the time is found when querying the table If the stamp is very far away from the current time, modify the value of the variable k1 to 0. In one embodiment, the table may be updated periodically based on historical data for each predetermined period. In one embodiment, after determining that k1 is a conflict variable based on the preset variable conflict table, according to a pessimistic strategy, if the first transaction currently executed includes the reading of the variable k1, it is considered that the number in the transaction currently executed simultaneously Each transaction that is smaller than the first transaction is a conflicting transaction of the first transaction, that is, it is assumed that the variable k1 will be written in each of the transactions. Here, the transaction number corresponds to the order of transaction submission. The higher the transaction submission order, the smaller the transaction number. In one embodiment, a variable conflict table for each variable may be preset in the node, and the variable conflict table includes the conflict probability of each variable. Figure 4 shows a schematic form of the variable conflict table. As shown in FIG. 4, the variable conflict table lists multiple variables k1, k2,...kn in the process of executing multiple transactions, and the corresponding value of each variable ki in the table is the conflict probability of the variable. The conflict probability can be determined based on historical transaction execution data, for example. The variable conflict table shown in Figure 4 can be updated regularly. For example, in the variable conflict table, the conflict probability of k1 is 20%. If the currently executed first transaction includes the reading of variable k1, the collision probability of k1 indicates that the average probability of writing to k1 in the transaction before the first transaction among multiple transactions executed at the same time is 20%, thus , The conflicting transaction of the first transaction can be determined according to the optimistic strategy. Specifically, for example, a random number between 0 and 100 can be generated. Assuming that 0 to 40 is set as a predetermined range based on a 20% probability, when the random number is in the range of 0 to 40 (including 40), it is considered that the first The previous transaction of a transaction will write the first variable. When the random number is in the range of 40 to 100 (including 100), it is considered that the previous transaction of the first transaction will not write the first variable. , Where the previous transaction is a transaction executed simultaneously with the first transaction and the transaction number is less than the first transaction. The predetermined range of random numbers used for inference can be determined based on the loss parameters caused by redo and waiting. For example, assuming that "waiting" will cause the central processing unit (cpu) to be idle for 2ms, and "redoing" will cause the cpu to waste 10ms. When the probability of conflict is 20%, the predetermined range can be determined to be between 0 and 20. If "waiting" will cause the cpu to be idle for 1ms, "redo" will cause the cpu to waste 10ms, and when the probability of conflict is 20% At this time, the predetermined range can be set to be larger, such as 0 to 80 and so on. In one embodiment, the variable conflict table combined with Fig. 3 and Fig. 4 can be preset in the node. In the table, when the conflict probability of the variable is greater than the predetermined threshold, the conflict value of the variable is set to 1. When the conflict probability of the variable is less than or equal to the predetermined threshold, the conflict value of the variable is set as its actual conflict probability. Therefore, when the conflict probability of a variable is greater than the predetermined threshold, the variable conflict table can be used to directly determine that the variable is a conflict variable. When the conflict probability of the variable is less than or equal to the predetermined threshold, the above method of generating random numbers can be used Determine whether the variable is a conflict variable. Thus it combines pessimistic and optimistic strategies. In one embodiment, if the currently executed first transaction includes the reading of the variable k1, assuming that the first transaction is currently executed by the first thread, the first thread can query the transactions of each previous transaction of the first transaction According to the transaction data, the probability that the previous transaction writes the variable k1 is determined, so as to determine whether the previous transaction is a conflicting transaction of the first transaction. Specifically, for example, the previous transaction of the first transaction includes the second transaction, and the first thread can query the name of the calling function of the second transaction, and input the function name and variable k1 into the predetermined determination model to infer the second transaction. 2. Whether the transaction will write the variable k1. In one embodiment, the predetermined judgment model includes, for example, a writing probability table between each calling function and each variable. The writing probability table determines that when the function is called based on historical transaction execution data or according to the specific code of the function, The probability of writing to each variable. For example, if the calling function includes writing to the variable k[n], and n is input during transaction execution, for example, n is 1, 2 or 3, then the probability of writing k[1] by this function can be 1/3 . Therefore, by inputting the name of the calling function of the second transaction and the variable k1 into the judgment model, the model can determine whether the writing probability of the variable k1 of the second transaction pair is greater than a predetermined threshold based on the writing probability table, thereby inferring the first 2. Whether the transaction will write to k1. In one embodiment, the judgment model is, for example, a judgment model trained through historical transaction execution data. After inputting the call function name of the second transaction and the variable k1 read by the first transaction to the judgment model, the judgment model is It can be inferred whether the second transaction will write the variable k1. In step S204, when it is concluded that the second transaction will write the first variable, the execution of the read operation in the first transaction is suspended. In the case of inferring that the second transaction will write the first variable as described above, that is, the second transaction is a conflicting transaction of the first transaction, and the first transaction needs to suspend the execution of the read operation, that is, wait , In order to read the written value of the second transaction to k1, otherwise, the k1 value read by the first transaction will be the wrong value. After the wrong read is performed, the subsequent read operation will be performed again, and Redo the transaction accordingly. In one embodiment, after inferring that the second transaction will write the variable k1 based on the above-mentioned variable conflict table or the variable conflict table, it is also necessary to determine whether the second transaction is the previous transaction of the first transaction. In the case of the previous transaction of the first transaction, based on the execution of the second transaction, the execution of the reading in the first transaction is resumed. That is to say, in this embodiment, after the variable k1 is determined to be a conflicting variable, it is considered that each concurrently executed transaction before the first transaction is a conflicting transaction of the first transaction. Therefore, it is necessary to wait until the first transaction is in conflict. After a transaction has performed a corresponding operation, the read operation in the first transaction is resumed. Specifically, in one embodiment, it is assumed that the second transaction is the previous transaction of the first transaction, and the read object of the read operation is the submission result of the second transaction stored in the shared memory, that is, only After the second transaction is submitted, the first transaction can read the written value of the variable k1 of the second transaction. In this case, after the second transaction is submitted, the read operation in the first transaction can be resumed. In one embodiment, it is assumed that the second transaction is the previous transaction of the first transaction, and the read object of the read operation is the intermediate data written into the shared memory during the processing of the second transaction. For example, currently the second transaction is executed through the second thread. After the second thread writes to k1 in the process of executing the second transaction, the operation of writing to k1 is recorded in the shared memory, and The written k1 value is used as intermediate data. After the writing is performed, the second thread can be determined based on the preset code or the compilation of the code, and it will no longer be written to k1 in the future, so that the second thread can declare in the predetermined address of the shared memory : The execution of the second transaction will no longer write the variable k1, so that the first thread that executes the first transaction can end the above waiting after reading the statement at the predetermined address, and read from the intermediate data by the first thread. The value of the variable k1 written by the second thread. In one embodiment, it is assumed that the second transaction is the previous transaction of the first transaction, and the read object of the read operation is the intermediate data written into the shared memory during the processing of the second transaction. For example, currently the second transaction is executed through the second thread. After the second thread writes to k1 in the process of executing the second transaction, the operation of writing to k1 is recorded in the shared memory, and The written k1 value is used as intermediate data. After the first thread that executes the first transaction determines that the second thread writes k1 based on the intermediate data, the wait can be ended, and the variable k1 written by the second thread can be read from the intermediate data. Value. After the first thread performs the above-mentioned reading, it is recorded in the shared memory that it has performed the reading of the variable k1 in the first transaction. Subsequent, for example, in the case that the second thread executes the write to the variable k1 again, the second thread will notify the transaction scheduler to re-execute all of the first transaction based on the record of the first thread in the shared memory. Reading and subsequent related operations, or retracement of the first transaction. In one embodiment, as described above, in the case of determining whether the previous transaction is a conflicting transaction of the first transaction by querying the transaction data of each previous transaction, in the case of determining that the second transaction is a conflicting transaction of the first transaction , It is also necessary to determine whether there is a conflicting transaction of the first transaction between the first transaction and the second transaction, that is, to determine whether the second transaction is the closest conflicting transaction to the first transaction. Therefore, after determining that the second transaction is the closest conflict transaction to the first transaction, the execution of the read operation in the first transaction can be resumed based on the execution of the second transaction. FIG. 5 shows a device 500 for simultaneously executing transactions in a blockchain according to an embodiment of the present specification. The device is deployed in a first node in the blockchain, and the first node currently executes multiple transactions simultaneously. A transaction, including a first transaction, and the first transaction including a reading operation of a first variable, and the device includes: The first determining unit 51 is configured to, after starting to execute the code of the read operation in the first transaction, infer whether the second transaction will write the first variable, wherein the second A transaction is a transaction in which a transaction number of the plurality of transactions is smaller than the first transaction, wherein the transaction number corresponds to a predetermined submission order of the transaction; The suspending unit 52 is configured to suspend the execution of the read operation in the first transaction when it is inferred that the second transaction will write the first variable. In one embodiment, a variable conflict table is preset in the first node, and the variable conflict table records that the first variable is a conflict variable, wherein the first determining unit 51 is further configured to, based on the In the variable conflict table, it is inferred that the second transaction will write the first variable. In one embodiment, the device further includes a second determining unit 53 configured to, after suspending the execution of the read operation in the first transaction, determine whether the second transaction is in accordance with the order of submission. The previous transaction of the first transaction, and the first recovery unit 54 are configured to, in the case of determining that the second transaction is the previous transaction of the first transaction according to the submission order, based on the execution of the second transaction, The read operation is resumed. In one embodiment, the read object of the read operation is the transaction submission result stored in the shared memory, wherein the first recovery unit 54 is further configured to resume execution of the transaction after the second transaction is submitted Read operation. In one embodiment, the read object of the read operation is the intermediate data written into the shared memory during the processing of the second transaction, wherein the first recovery unit 54 is further configured to The statement in the predetermined address of the shared memory in the process of the second transaction resumes the execution of the read operation, and the statement indicates that the execution of the second transaction will no longer write the first variable. In one embodiment, the read object of the read operation is the intermediate data written into the shared memory during the processing of the second transaction, and the first recovery unit 54 is further configured to determine the intermediate data After including the value written to the first variable in the second transaction, resume execution of the read operation, and record the execution of the read operation in the shared memory. In an embodiment, the first determining unit 51 further includes an obtaining subunit 511 configured to obtain transaction data of the second transaction; and a first determining subunit 512 configured to obtain transaction data based on the second transaction , Infer whether the second transaction will write the first variable. In one embodiment, the first determining subunit 512 is further configured to input the name of the function called in the second transaction and the first variable into a predetermined determination model to infer whether the second transaction will perform the first variable. Write. In one embodiment, the device further includes a third determining unit 55 configured to, after suspending the execution of the reading operation in the first transaction, determine whether there is a transaction number in the second transaction and A conflicting transaction between the first transaction, wherein the conflicting transaction is a transaction that is inferred to be written to the first variable, and the second recovery unit 56 is configured to, when the conflicting transaction does not exist In this case, based on the execution of the second transaction, the execution of the read operation is resumed. In one embodiment, a variable conflict table is preset in the first node, and the conflict probability of the first variable is recorded in the variable conflict table. The first determining unit 51 further includes a generating subunit 513 , Configured to, after starting to execute the code of the read operation in the first transaction, generate a random number within a first predetermined value range, and the second determining subunit 514 is configured to determine the random number by determining the random number Whether the number is within a second predetermined numerical range, and infer whether the second transaction will write the first variable, wherein the second predetermined numerical range is within the first predetermined numerical range and is based on the The probability of the conflict is determined. Another aspect of this specification provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed in a computer, the computer is made to execute any of the above methods. Another aspect of this specification provides a computing device, including a memory and a processor, characterized in that executable code is stored in the memory, and when the processor executes the executable code, any one of the above methods is implemented . Through the simultaneous execution of transactions in the blockchain according to the embodiment of this specification, by determining the probability of conflicts between transactions, it is determined whether to suspend the reading operation of variables, so that multiple transactions without interdependence can be , These transactions can be executed at the same time; for multiple transactions with interdependence, these transactions can be executed in series, so as to avoid conflicts between transactions and redo transactions; for situations where there is a certain probability of conflict between transactions , The method of the present invention can smoothly transition between optimistic expectations and pessimistic expectations, and achieve a balance between the waste of CPUs in serial execution and the waste of CPUs in transaction redoing, thereby ensuring the consistency of calculation results, speeding up the processing speed and improving Improved processing performance. It should be understood that the descriptions of "first", "second", etc. in this article are merely to distinguish similar concepts for simplicity of description, and do not have other limiting effects. The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, as for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for related parts, please refer to the part of the description of the method embodiment. The foregoing describes specific embodiments of this specification. Other embodiments are within the scope of the attached patent application. In some cases, the actions or steps described in the scope of the patent application may be performed in a different order from the embodiment and still achieve desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or sequential order shown in order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous. Those of ordinary skill in the art should be further aware that the units and algorithm steps of the examples described in the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two, for clarity To illustrate the interchangeability of hardware and software, the composition and steps of each example have been described generally in terms of function in the above description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. A person of ordinary skill in the art may use different methods for each specific application to implement the described functions, but such implementation should not be considered beyond the scope of the present application. The steps of the method or algorithm described in combination with the embodiments disclosed herein can be implemented by hardware, a software module executed by a processor, or a combination of the two. The software module can be placed in random memory (RAM), memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, register, hard disk, removable disk, CD -ROM, or any other form of storage medium known in the technical field. The specific embodiments described above further describe the purpose, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above are only specific embodiments of the present invention, and are not intended to limit the scope of the present invention. The protection scope, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

11:節點 12:節點 13:節點 S202:步驟 S204:步驟 k1~kn:變數 500:同時執行交易裝置 51:第一確定單元 52:暫停單元 53:第二確定單元 54:第一恢復單元 55:第三確定單元 56:第二恢復單元 511:獲取子單元 512:第一確定子單元 513:產生子單元 514:第二確定子單元11: Node 12: Node 13: Node S202: steps S204: Step k1~kn: variable 500: Simultaneous execution transaction device 51: The first determination unit 52: Suspend the unit 53: The second determination unit 54: The first recovery unit 55: The third determination unit 56: second recovery unit 511: Get subunit 512: The first determination subunit 513: Generate subunit 514: second determining subunit

透過結合附圖描述本說明書實施例,可以使得本說明書實施例更加清楚: [圖1] 示出根據本說明書實施例的區塊鏈系統示意圖; [圖2] 示出根據本說明書一個實施例的一種在區塊鏈中同時執行交易的方法流程圖; [圖3] 示出了變數衝突表的示意形式; [圖4] 示出了變數衝突表的示意形式; [圖5] 示出根據本說明書一個實施例的一種在區塊鏈中同時執行交易的裝置。 By describing the embodiments of this specification in conjunction with the accompanying drawings, the embodiments of this specification can be made clearer: [Figure 1] shows a schematic diagram of a blockchain system according to an embodiment of this specification; [Figure 2] shows a flowchart of a method for simultaneously executing transactions in a blockchain according to an embodiment of the present specification; [Figure 3] shows the schematic form of the variable conflict table; [Figure 4] shows the schematic form of the variable conflict table; [Figure 5] shows a device for simultaneously executing transactions in the blockchain according to an embodiment of the present specification.

Claims (22)

一種在區塊鏈中同時執行多個交易的方法,所述方法在區塊鏈中的第一節點執行,所述多個交易中包括第一交易,所述第一交易中包括對第一變數的讀取操作,所述方法包括: 在開始執行所述第一交易中的所述讀取操作的代碼之後,推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二交易為所述多個交易中交易編號小於所述第一交易的交易,其中,所述交易編號與交易的預定提交順序相對應; 在推斷第二交易將要對所述第一變數進行寫入的情況中,暫停執行所述第一交易中的所述讀取操作。A method for simultaneously executing multiple transactions in a blockchain, the method is executed at a first node in the blockchain, the multiple transactions include a first transaction, and the first transaction includes a first variable The read operation, the method includes: After starting to execute the code of the read operation in the first transaction, it is inferred whether the second transaction will write the first variable, wherein the second transaction is a transaction among the plurality of transactions A transaction with a serial number smaller than the first transaction, wherein the transaction serial number corresponds to a predetermined submission order of the transaction; In the case where it is inferred that the second transaction will write the first variable, the execution of the read operation in the first transaction is suspended. 根據請求項1所述的方法,其中,所述第一節點中預設有變數衝突表,所述變數衝突表中記錄了第一變數為衝突變數,其中,推斷第二交易是否將要對所述第一變數進行寫入包括,基於所述變數衝突表,推斷第二交易將要對所述第一變數進行寫入。The method according to claim 1, wherein a variable conflict table is preset in the first node, and the variable conflict table records that the first variable is a conflict variable, wherein it is inferred whether the second transaction will affect the Writing the first variable includes, based on the variable conflict table, inferring that the second transaction will write the first variable. 根據請求項2所述的方法,還包括,在暫停執行所述第一交易中的所述讀取操作之後,確定所述第二交易是否根據提交順序為所述第一交易的前一個交易,在確定所述第二交易根據提交順序為所述第一交易的前一個交易的情況中,基於第二交易的執行,恢復執行所述讀取操作。The method according to claim 2, further comprising, after suspending execution of the read operation in the first transaction, determining whether the second transaction is the previous transaction of the first transaction according to the order of submission, In the case where it is determined that the second transaction is the previous transaction of the first transaction according to the submission order, the execution of the read operation is resumed based on the execution of the second transaction. 根據請求項3所述的方法,其中,所述讀取操作的讀取對象為共享記憶體中儲存的交易提交結果,其中,基於第二交易的執行,恢復執行所述讀取操作包括,在第二交易提交之後,恢復執行所述讀取操作。The method according to claim 3, wherein the read object of the read operation is the transaction submission result stored in the shared memory, wherein, based on the execution of the second transaction, resuming the execution of the read operation includes: After the second transaction is submitted, the read operation is resumed. 根據請求項3所述的方法,其中,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料,其中,基於第二交易的執行,恢復執行所述讀取操作包括,基於在執行第二交易的過程中在共享記憶體預定位址中的聲明,恢復執行所述讀取操作,所述聲明指示所述第二交易的執行將不再對所述第一變數進行寫入。The method according to claim 3, wherein the read object of the read operation is the intermediate data written in the shared memory during the processing of the second transaction, and the execution is resumed based on the execution of the second transaction The reading operation includes restoring the execution of the reading operation based on a statement in a predetermined address in the shared memory during the execution of the second transaction, the statement indicating that the execution of the second transaction will no longer affect the execution of the second transaction. The first variable is written. 根據請求項3所述的方法,其中,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料,其中,基於第二交易的執行,恢復執行所述讀取操作包括,在確定所述中間資料中包括第二交易中對第一變數的寫入值之後,恢復執行所述讀取操作,並在共享記憶體中對該讀取操作的執行進行記錄。The method according to claim 3, wherein the read object of the read operation is the intermediate data written in the shared memory during the processing of the second transaction, and the execution is resumed based on the execution of the second transaction The read operation includes, after determining that the intermediate data includes the write value to the first variable in the second transaction, resume execution of the read operation, and execute the read operation in the shared memory Make a record. 根據請求項1所述的方法,其中,推斷第二交易是否將要對所述第一變數進行寫入包括,獲取第二交易的交易資料;基於第二交易的交易資料,推斷第二交易是否將要對所述第一變數進行寫入。The method according to claim 1, wherein inferring whether the second transaction will write the first variable includes obtaining transaction data of the second transaction; based on the transaction data of the second transaction, inferring whether the second transaction will Write the first variable. 根據請求項7所述的方法,其中,基於第二交易的交易資料,推斷第二交易是否將要對所述第一變數進行寫入包括,透過將第二交易中調用的函數名稱和第一變數輸入預定判定模型,推斷第二交易是否將要對所述第一變數進行寫入。The method according to claim 7, wherein, based on the transaction data of the second transaction, inferring whether the second transaction will write the first variable includes, by combining the name of the function called in the second transaction and the first variable Input a predetermined judgment model to infer whether the second transaction will write the first variable. 根據請求項7所述的方法,還包括,在暫停執行所述第一交易中的所述讀取操作之後,確定是否存在交易編號在所述第二交易與第一交易之間的衝突交易,其中,所述衝突交易為被推斷將要對所述第一變數進行寫入的交易,以及,在不存在所述衝突交易的情況中,基於第二交易的執行,恢復執行所述讀取操作。The method according to claim 7, further comprising, after suspending the execution of the reading operation in the first transaction, determining whether there is a conflicting transaction with a transaction number between the second transaction and the first transaction, Wherein, the conflicting transaction is a transaction that is inferred to be written to the first variable, and, in a case where the conflicting transaction does not exist, the execution of the reading operation is resumed based on the execution of the second transaction. 根據請求項1所述的方法,其中,所述第一節點中預設有變數衝突表,所述變數衝突表中記錄了第一變數的衝突機率,其中,在開始執行所述第一交易中的所述讀取操作的代碼之後,推斷第二交易是否將要對所述第一變數進行寫入包括,在開始執行所述第一交易中的所述讀取操作的代碼之後,在第一預定數值範圍內產生隨機數,以及透過確定所述隨機數是否在第二預定數值範圍內,推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二預定數值範圍在所述第一預定數值範圍之內、並基於所述衝突機率確定。The method according to claim 1, wherein a variable conflict table is preset in the first node, and the conflict probability of the first variable is recorded in the variable conflict table, wherein, in the beginning of the execution of the first transaction After the code of the read operation in the first transaction, inferring whether the second transaction will write the first variable includes, after starting to execute the code of the read operation in the first transaction, in the first predetermined A random number is generated within a numerical range, and by determining whether the random number is within a second predetermined numerical range, it is inferred whether the second transaction will write the first variable, wherein the second predetermined numerical range is within the second predetermined numerical range. Within the first predetermined numerical range and determined based on the probability of conflict. 一種在區塊鏈中同時執行多個交易的裝置,所述裝置部署在區塊鏈中的第一節點中,所述多個交易中包括第一交易,所述第一交易中包括對第一變數的讀取操作,所述裝置包括: 第一確定單元,配置為,在開始執行所述第一交易中的所述讀取操作的代碼之後,推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二交易為所述多個交易中交易編號小於所述第一交易的交易,其中,所述交易編號與交易的預定提交順序相對應; 暫停單元,配置為,在推斷第二交易將要對所述第一變數進行寫入的情況中,暫停執行所述第一交易中的所述讀取操作。A device for simultaneously executing multiple transactions in a blockchain, the device is deployed in a first node in the blockchain, the multiple transactions include a first transaction, and the first transaction includes a pair of For a variable reading operation, the device includes: The first determining unit is configured to, after starting to execute the code of the read operation in the first transaction, infer whether the second transaction will write the first variable, wherein the second transaction Is a transaction with a transaction number smaller than the first transaction among the plurality of transactions, wherein the transaction number corresponds to a predetermined submission order of the transaction; The suspending unit is configured to suspend the execution of the read operation in the first transaction when it is inferred that the second transaction will write the first variable. 根據請求項11所述的裝置,其中,所述第一節點中預設有變數衝突表,所述變數衝突表中記錄了第一變數為衝突變數,其中,所述第一確定單元還配置為,基於所述變數衝突表,推斷第二交易將要對所述第一變數進行寫入。The device according to claim 11, wherein a variable conflict table is preset in the first node, and the variable conflict table records that the first variable is a conflict variable, wherein the first determining unit is further configured to , Based on the variable conflict table, infer that the second transaction will write the first variable. 根據請求項12所述的裝置,還包括,第二確定單元,配置為,在暫停執行所述第一交易中的所述讀取操作之後,確定所述第二交易是否根據提交順序為所述第一交易的前一個交易,以及第一恢復單元,配置為,在確定所述第二交易根據提交順序為所述第一交易的前一個交易的情況中,基於第二交易的執行,恢復執行所述讀取操作。The device according to claim 12, further comprising: a second determining unit configured to, after suspending the execution of the reading operation in the first transaction, determine whether the second transaction is the The previous transaction of the first transaction and the first restoration unit are configured to, in the case of determining that the second transaction is the previous transaction of the first transaction according to the submission order, resume execution based on the execution of the second transaction The read operation. 根據請求項13所述的裝置,其中,所述讀取操作的讀取對象為共享記憶體中儲存的交易提交結果,其中,所述第一恢復單元還配置為,在第二交易提交之後,恢復執行所述讀取操作。The device according to claim 13, wherein the read object of the read operation is a transaction submission result stored in the shared memory, and the first recovery unit is further configured to, after the second transaction is submitted, Resume the execution of the read operation. 根據請求項13所述的裝置,其中,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料,其中,所述第一恢復單元還配置為,基於在執行第二交易的過程中在共享記憶體預定位址中的聲明,恢復執行所述讀取操作,所述聲明指示所述第二交易的執行將不再對所述第一變數進行寫入。The device according to claim 13, wherein the read object of the read operation is intermediate data written into the shared memory during the processing of the second transaction, wherein the first recovery unit is further configured to , Based on the statement in the predetermined address of the shared memory during the execution of the second transaction, resume the execution of the read operation, the statement indicating that the execution of the second transaction will no longer perform the first variable Write. 根據請求項13所述的裝置,其中,所述讀取操作的讀取對象為第二交易在處理過程中被寫入共享記憶體中的中間資料,所述第一恢復單元還配置,在確定所述中間資料中包括第二交易中對第一變數的寫入值之後,恢復執行所述讀取操作,並在共享記憶體中對該讀取操作的執行進行記錄。The device according to claim 13, wherein the read object of the read operation is intermediate data written into the shared memory during the processing of the second transaction, and the first recovery unit is further configured to determine After the intermediate data includes the written value of the first variable in the second transaction, the read operation is resumed, and the execution of the read operation is recorded in the shared memory. 根據請求項11所述的裝置,其中,所述第一確定單元還包括,獲取子單元,配置為,獲取第二交易的交易資料;以及第一確定子單元,配置為,基於第二交易的交易資料,推斷第二交易是否將要對所述第一變數進行寫入。The device according to claim 11, wherein the first determining unit further includes an obtaining subunit configured to obtain transaction data of the second transaction; and the first determining subunit configured to obtain transaction data based on the second transaction Transaction data to infer whether the second transaction will write the first variable. 根據請求項17所述的裝置,其中,所述第一確定子單元還配置為,透過將第二交易中調用的函數名稱和第一變數輸入預定判定模型,推斷第二交易是否將要對所述第一變數進行寫入。The device according to claim 17, wherein the first determining subunit is further configured to infer whether the second transaction will affect the second transaction by inputting the name of the function called in the second transaction and the first variable into a predetermined determination model. The first variable is written. 根據請求項17所述的裝置,還包括,第三確定單元,配置為,在暫停執行所述第一交易中的所述讀取操作之後,確定是否存在交易編號在所述第二交易與第一交易之間的衝突交易,其中,所述衝突交易為被推斷將要對所述第一變數進行寫入的交易,以及,第二恢復單元,配置為,在不存在所述衝突交易的情況中,基於第二交易的執行,恢復執行所述讀取操作。The device according to claim 17, further comprising a third determining unit configured to, after suspending the execution of the reading operation in the first transaction, determine whether there is a transaction number between the second transaction and the first transaction. A conflicting transaction between transactions, wherein the conflicting transaction is a transaction that is inferred to be written to the first variable, and the second recovery unit is configured to, in the case where the conflicting transaction does not exist , Based on the execution of the second transaction, resume execution of the read operation. 根據請求項11所述的裝置,其中,所述第一節點中預設有變數衝突表,所述變數衝突表中記錄了第一變數的衝突機率,其中,所述第一確定單元還包括,產生子單元,配置為,在開始執行所述第一交易中的所述讀取操作的代碼之後,在第一預定數值範圍內產生隨機數,以及第二確定子單元,配置為,透過確定所述隨機數是否在第二預定數值範圍內,而推斷第二交易是否將要對所述第一變數進行寫入,其中,所述第二預定數值範圍在所述第一預定數值範圍之內、並基於所述衝突機率確定。The device according to claim 11, wherein a variable conflict table is preset in the first node, and the conflict probability of the first variable is recorded in the variable conflict table, wherein the first determining unit further includes: The generating subunit is configured to generate a random number within a first predetermined value range after starting to execute the code of the read operation in the first transaction, and the second determining subunit is configured to determine through Whether the random number is within a second predetermined numerical range, and inferring whether the second transaction will write the first variable, wherein the second predetermined numerical range is within the first predetermined numerical range, and Determined based on the probability of conflict. 一種電腦可讀儲存媒體,其上儲存有電腦程式,當所述電腦程式在電腦中執行時,令電腦執行請求項1-10中任一項的所述的方法。A computer-readable storage medium has a computer program stored thereon, and when the computer program is executed in a computer, the computer is caused to execute the method described in any one of the request items 1-10. 一種計算設備,包括記憶體和處理器,其特徵在於,所述記憶體中儲存有可執行代碼,所述處理器執行所述可執行代碼時,實現請求項1-10中任一項所述的方法。A computing device, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, it implements any one of request items 1-10 Methods.
TW109110268A 2019-08-30 2020-03-26 Method and apparatus for concurrently executing transactions in a blockchain and computer-readable storage medium and computing device TWI759708B (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910818227.XA CN110648124B (en) 2019-08-30 2019-08-30 Method and apparatus for concurrently executing transactions in a blockchain
CN201910818227.X 2019-08-30

Publications (2)

Publication Number Publication Date
TW202109292A true TW202109292A (en) 2021-03-01
TWI759708B TWI759708B (en) 2022-04-01

Family

ID=68991382

Family Applications (1)

Application Number Title Priority Date Filing Date
TW109110268A TWI759708B (en) 2019-08-30 2020-03-26 Method and apparatus for concurrently executing transactions in a blockchain and computer-readable storage medium and computing device

Country Status (3)

Country Link
CN (2) CN110648124B (en)
TW (1) TWI759708B (en)
WO (1) WO2021036260A1 (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110648124B (en) * 2019-08-30 2021-06-29 创新先进技术有限公司 Method and apparatus for concurrently executing transactions in a blockchain
CN112001798B (en) * 2020-10-28 2021-01-26 支付宝(杭州)信息技术有限公司 Method and apparatus for concurrently executing transactions in a blockchain
CN113127212B (en) * 2020-12-04 2024-03-29 支付宝(杭州)信息技术有限公司 Method and device for processing transaction in blockchain
CN113656507B (en) * 2021-08-26 2024-03-08 支付宝(杭州)信息技术有限公司 Method and device for executing transaction in block chain system

Family Cites Families (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5701480A (en) * 1991-10-17 1997-12-23 Digital Equipment Corporation Distributed multi-version commitment ordering protocols for guaranteeing serializability during transaction processing
US20090138890A1 (en) * 2007-11-21 2009-05-28 Arm Limited Contention management for a hardware transactional memory
CN104572506B (en) * 2013-10-18 2019-03-26 阿里巴巴集团控股有限公司 A kind of method and device concurrently accessing memory
US20160098723A1 (en) * 2014-10-01 2016-04-07 The Filing Cabinet, LLC System and method for block-chain verification of goods
US20180329900A1 (en) * 2015-11-19 2018-11-15 Entit Software Llc Prediction models for concurrency control types
US20180158034A1 (en) * 2016-12-07 2018-06-07 International Business Machines Corporation Dynamic reordering of blockchain transactions to optimize performance and scalability
US10762479B2 (en) * 2017-04-05 2020-09-01 Samsung Sds Co., Ltd. Method and system for processing blockchain-based real-time transaction
CN107688999B (en) * 2017-08-11 2020-11-13 杭州溪塔科技有限公司 Block chain-based parallel transaction execution method
CN109636592B (en) * 2017-10-20 2023-02-28 北京航空航天大学 High performance intelligent contract design
CN108874372B (en) * 2018-06-20 2020-01-24 北京连琪科技有限公司 Scale-based block chain contract implementation method and system
CN109598504B (en) * 2018-10-25 2020-09-01 阿里巴巴集团控股有限公司 Transaction processing method and device based on block chain and electronic equipment
CN109508337A (en) * 2018-11-12 2019-03-22 杭州秘猿科技有限公司 A kind of transaction is parallel to execute method, apparatus, electronic equipment and system
CN109784930B (en) * 2019-02-18 2023-07-18 深圳市迅雷网络技术有限公司 Block chain transaction data processing method and device, electronic equipment and medium
CN110135985B (en) * 2019-04-04 2021-07-27 杭州抖音科技有限公司 Parallel execution method and system for transactions on block chain
CN110163609B (en) * 2019-05-28 2024-02-27 深圳前海微众银行股份有限公司 Method and device for processing data in block chain
CN110648124B (en) * 2019-08-30 2021-06-29 创新先进技术有限公司 Method and apparatus for concurrently executing transactions in a blockchain

Also Published As

Publication number Publication date
TWI759708B (en) 2022-04-01
CN113421073A (en) 2021-09-21
CN110648124A (en) 2020-01-03
CN110648124B (en) 2021-06-29
WO2021036260A1 (en) 2021-03-04

Similar Documents

Publication Publication Date Title
WO2021036260A1 (en) Method and apparatus for concurrently executing transactions in blockchain
JP6499986B2 (en) Fault tolerant batch processing
TWI733390B (en) Method and device for simultaneously executing transactions in block chain, computer readable storage medium and computing equipment
TWI737152B (en) Block chain-based hierarchical storage method and device, and electronic equipment
CN110737664A (en) block link point synchronization method and device
TWI743719B (en) Method and device for simultaneously executing transactions in block chain, computer readable storage medium and computing equipment
TWI730690B (en) Method and device for simultaneously executing transactions in block chain, computer readable storage medium and computing equipment
CN108140028A (en) The method and framework of Access and control strategy of database are provided in the network with distributed data base system
CN110704438B (en) Method and device for generating bloom filter in blockchain
CN112748993A (en) Task execution method and device, storage medium and electronic equipment
TWI732501B (en) Method and device for parallel execution of transactions in block chain, computer readable storage medium and computing equipment
CN113869902A (en) Block chain transaction execution method and device
CN110706108B (en) Method and apparatus for concurrently executing transactions in a blockchain
US20150150011A1 (en) Self-splitting of workload in parallel computation
WO2020238348A1 (en) Block verification method, apparatus and device
CN114356768A (en) Method and device for reducing transaction read-write conflict through placeholder
CN111523900A (en) Block chain consensus method, device and system based on Byzantine fault-tolerant algorithm
Liu et al. RTeX: an Efficient and Timing-Predictable Multi-threaded Executor for ROS 2
WO2021057165A1 (en) Method for concurrently executing transactions in blockchain, and device
JP7458512B2 (en) Distributed transaction processing method, terminal and computer readable storage medium
CN117408703A (en) Transaction execution method, device and blockchain system
WO2012169080A1 (en) Database management method