CN112017052A - Method and apparatus for deploying and invoking contracts in blockchain - Google Patents

Method and apparatus for deploying and invoking contracts in blockchain Download PDF

Info

Publication number
CN112017052A
CN112017052A CN202011176391.4A CN202011176391A CN112017052A CN 112017052 A CN112017052 A CN 112017052A CN 202011176391 A CN202011176391 A CN 202011176391A CN 112017052 A CN112017052 A CN 112017052A
Authority
CN
China
Prior art keywords
contract
blockchain
blockchains
transaction
corresponds
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN202011176391.4A
Other languages
Chinese (zh)
Inventor
周晨辉
闫莺
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Alipay Hangzhou Information Technology Co Ltd
Original Assignee
Alipay Hangzhou Information Technology Co Ltd
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 Alipay Hangzhou Information Technology Co Ltd filed Critical Alipay Hangzhou Information Technology Co Ltd
Priority to CN202011176391.4A priority Critical patent/CN112017052A/en
Publication of CN112017052A publication Critical patent/CN112017052A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING; COUNTING
    • G06QDATA PROCESSING SYSTEMS OR METHODS, SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL, SUPERVISORY OR FORECASTING PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL, SUPERVISORY OR FORECASTING PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Exchange, e.g. stocks, commodities, derivatives or currency exchange
    • GPHYSICS
    • G06COMPUTING; CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/64Protecting data integrity, e.g. using checksums, certificates or signatures

Abstract

The embodiment of the specification provides a method and a device for deploying contracts in a blockchain system, wherein the blockchain system comprises N independent blockchains, and the method comprises the following steps: receiving a first request to deploy a first contract; determining, based on a predetermined rule, that a first contract corresponds to a first blockchain of the N blockchains; sending a first transaction to the first blockchain to deploy the first contract into the first blockchain.

Description

Method and apparatus for deploying and invoking contracts in blockchain
Technical Field
The embodiment of the specification relates to the technical field of blockchains, in particular to a method and a device for deploying contracts in a blockchain and a method and a device for calling the contracts in the blockchain.
Background
The block chain technology is also called as distributed book technology, is decentralized distributed database technology and is characterized by decentralized, transparent disclosure, no tampering and trusty. Each transaction of the blockchain is broadcast to the blockchain nodes of the whole network, and each whole node has full and consistent data. In a federation chain, a user terminal typically uses a blockchain to perform service processing, such as processing for certificate storage and transfer, through a blockchain platform. However, in a single chain scenario, long runs accumulate large amounts of stored data, and accounts are becoming larger and larger, so that the processing power of the single chain is reduced. In addition, during periods of more concurrent transactions (e.g., twenty-one periods), the access pressure of a single chain increases, so that the processing of the single chain cannot meet the traffic demand.
Disclosure of Invention
The embodiments of the present specification aim to provide a more efficient scheme for deploying and invoking contracts in a blockchain, so as to solve the deficiencies in the prior art.
To achieve the above object, one aspect of the present specification provides a method for deploying contracts in a blockchain system, where the blockchain system includes N independent blockchains, the method including:
receiving a first request to deploy a first contract;
determining, based on a predetermined rule, that a first contract corresponds to a first blockchain of the N blockchains;
sending a first transaction to the first blockchain to deploy the first contract into the first blockchain.
In one embodiment, the method further includes, after determining that a first contract corresponds to a first blockchain of the N blockchains based on a predetermined rule, recording a correspondence of the first contract to the first blockchain.
In one embodiment, recording the correspondence of the first contract to the first blockchain includes recording the correspondence of the unique identifier of the first contract to the first blockchain.
In one embodiment, the unique identification of the first contract is a combination of the account sending the first request and the name of the first contract.
In one embodiment, the method is performed by a blockchain platform that is connected to the N blockchains, respectively, wherein receiving the first request to deploy the first contract comprises receiving a first transaction to deploy the first contract.
In one embodiment, the method further comprises:
receiving a second request for deploying a second contract, wherein the second request comprises the association information of the second contract and the first contract;
determining that a second contract corresponds to the first blockchain based on the correspondence of the first contract to the first blockchain;
sending a second transaction to the first blockchain to deploy the second contract into the first blockchain.
In one embodiment, the method further includes, after determining that a first contract corresponds to a first blockchain of the N blockchains based on a predetermined rule, obtaining an address of the first contract, the predetermined bit of the address of the first contract being used to indicate the first blockchain.
In one embodiment, the first request is sent by a first account, the determining that a first contract corresponds to a first blockchain of the N blockchains based on a predetermined rule includes determining that a first contract corresponds to M blockchains of the N blockchains based on a first predetermined rule, and determining that the first account corresponds to a first blockchain of the M blockchains based on a second predetermined rule.
In one embodiment, the method further includes, after determining that the first account corresponds to a first blockchain of the M blockchains based on a second predetermined rule, recording a first correspondence of the first contract to the M blockchains and a second correspondence of the first account to the first blockchain, wherein the second correspondence is associated with the first correspondence.
Another aspect of the present specification provides a method for invoking contracts in a blockchain system, the blockchain system including N independent blockchains, the method including:
receiving a third request for invoking the first contract;
determining that a first contract corresponds to a first blockchain of the N blockchains;
and sending a third transaction corresponding to the third request to the first blockchain, wherein the first contract is called in the third transaction.
In one embodiment, determining that the first contract corresponds to the first blockchain of the N blockchains includes determining that the first contract corresponds to the first blockchain of the N blockchains by reading a correspondence of a pre-recorded first contract to the first blockchain of the N blockchains.
In one embodiment, the third request includes an address of the first contract, wherein determining that the first contract corresponds to the first of the N blockchains includes determining that the first contract corresponds to the first of the N blockchains based on a predetermined bit in the address of the first contract.
In one embodiment, the first contract is for crediting in the first blockchain, the third transaction causes first data to be credited in the first blockchain after execution, the method further comprising: receiving an identification of the first data from the first blockchain after sending a third transaction corresponding to the third request to the first blockchain.
In one embodiment, the identification of the first data is an identification of the third transaction.
In one embodiment, receiving the third request to invoke the first contract includes receiving a third transaction to invoke the first contract.
Another aspect of the present specification provides an apparatus for deploying contracts in a blockchain system, the blockchain system including N independent blockchains, the apparatus comprising:
a first receiving unit configured to receive a first request for deploying a first contract;
a first determining unit configured to determine that a first contract corresponds to a first blockchain of the N blockchains based on a predetermined rule;
a first sending unit configured to send a first transaction to the first blockchain to deploy the first contract into the first blockchain.
In one embodiment, the apparatus further includes a recording unit configured to record a correspondence relationship between a first contract and a first blockchain of the N blockchains after determining that the first contract corresponds to the first blockchain based on a predetermined rule.
In one embodiment, the recording unit is further configured to record a correspondence between the unique identifier of the first contract and the first block chain.
In one embodiment, the unique identification of the first contract is a combination of the account sending the first request and the name of the first contract.
In one embodiment, the apparatus is disposed in a blockchain platform, and the blockchain platform is respectively connected to the N blockchains, wherein the first receiving unit is further configured to receive a first transaction for deploying a first contract.
In one embodiment, the apparatus further comprises:
a second receiving unit configured to receive a second request for deploying a second contract, the second request including association information of the second contract and the first contract;
a second determining unit configured to determine that a second contract corresponds to the first blockchain based on a correspondence relationship of the first contract and the first blockchain;
a second sending unit configured to send a second transaction to the first blockchain to deploy the second contract into the first blockchain.
In one embodiment, the apparatus further includes an obtaining unit configured to obtain an address of a first contract after determining that the first contract corresponds to a first blockchain of the N blockchains based on a predetermined rule, where a predetermined bit of the address of the first contract is used to indicate the first blockchain.
Another aspect of the present specification provides an apparatus for invoking contracts in a blockchain system, the blockchain system including N independent blockchains, the apparatus comprising:
a first receiving unit configured to receive a third request for invoking the first contract;
a determining unit configured to determine that a first contract corresponds to a first blockchain of the N blockchains;
a sending unit configured to send a third transaction corresponding to the third request to the first blockchain, where the first contract is invoked in the third transaction.
In one embodiment, the determining unit is further configured to determine that the first contract corresponds to the first block chain of the N block chains by reading a correspondence between a pre-recorded first contract and the first block chain of the N block chains.
In one embodiment, the third request includes an address of the first contract, and the determining unit is further configured to determine that the first contract corresponds to a first blockchain of the N blockchains based on a predetermined bit in the address of the first contract.
In one embodiment, the first contract is for crediting in the first blockchain, the third transaction causes first data to be credited in the first blockchain after execution, the apparatus further comprising: a second receiving unit configured to receive an identification of the first data from the first blockchain after sending a third transaction corresponding to the third request to the first blockchain.
In one embodiment, the identification of the first data is an identification of the third transaction.
In one embodiment, the first receiving unit is further configured to receive a third transaction for invoking the first contract.
Another aspect of the present specification provides a computer readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform any one of the above methods.
Another aspect of the present specification provides a computing device comprising a memory having stored therein executable code, and a processor that, when executing the executable code, implements any of the methods described above.
By the scheme for deploying and calling contracts according to the embodiment of the specification, the contracts are averagely deployed into the plurality of block chains, so that the capacity and the processing capacity of parallel expansion can be provided for the block chain system through the plurality of block chains, the read-write pressure is reduced compared with that of a single block chain, the processing efficiency of the block chain system is improved, and particularly the parallel pressure distribution can be realized by fast expansion in a sudden flow increase period.
Drawings
The embodiments of the present specification may be made more clear by describing the embodiments with reference to the attached drawings:
FIG. 1 illustrates a schematic diagram of a blockchain system in accordance with embodiments of the present disclosure;
FIG. 2 illustrates a flow diagram of a method for deploying contracts in a blockchain system in accordance with an embodiment of the present specification;
FIG. 3 shows a content diagram of transaction 1 (Tx 1);
FIG. 4 illustrates a flow diagram of a method for invoking contracts in a blockchain in accordance with an embodiment of the present description;
FIG. 5 shows a content diagram of transaction 2 (Tx 2);
FIG. 6 illustrates an apparatus 600 for deploying contracts in a blockchain system according to an embodiment of the present specification;
fig. 7 illustrates an apparatus 700 for invoking contracts in a blockchain system according to an embodiment of the present description.
Detailed Description
The embodiments of the present specification will be described below with reference to the accompanying drawings.
Fig. 1 shows a schematic diagram of a blockchain system according to an embodiment of the present disclosure. As shown in fig. 1, the blockchain system includes a blockchain platform 11, i.e., a blockchain platform server, and a plurality of user terminals (schematically shown as user terminals 12, 13, and 14). The user terminal is connected to the blockchain platform 11, and operates the blockchain through the blockchain platform 11. The blockchain platform 11 is connected to a plurality of independent blockchains, which are schematically illustrated in fig. 1 as blockchain 1, blockchain 2 and blockchain 3. The blockchain 1, the blockchain 2 and the blockchain 3 can be called as parallel chains of a blockchain system, and operate independently of each other, so as to process user requests respectively and store transaction data respectively, thereby improving the processing capacity and data storage capacity of the system.
The blockchain system including the blockchain 1 to the blockchain 3 is, for example, a system for storing certificates (e.g., a copyright maintenance system), and the user a may send a request to the blockchain platform 11 through, for example, the user terminal 12 to send a transaction to the blockchain system. After receiving the request, the blockchain platform 11 sends the corresponding transaction to one of the blockchains 1 to 3, so as to store the transaction into the corresponding blockchain. Also, blockchain platform 11 may return an identification of the transaction to user terminal 12, where the identification of the transaction may be a hash value of the transaction. Subsequently, when user a wishes to query for the transaction, user a may provide an identification of the transaction to blockchain platform 11 for querying for the transaction.
In case the blockchain system is for example only used for handling a single service, such as copyright maintenance, the form of the transaction in the blockchain system is also relatively single, e.g. the transaction may comprise a transaction of deploying a contract, a transaction of invoking a contract, etc. In this case, blockchain platform 11 may, after receiving the transaction from the user terminal, perform processing by allocating the transaction to blockchain 1, blockchain 2, and blockchain 3, respectively, based on the identity of the contract included in the transaction, thereby achieving an effect of balancing the load.
It is to be understood that the blockchain system shown in fig. 1 is merely exemplary, and the blockchain system according to embodiments of the present disclosure is not limited thereto. For example, each user terminal may assign transactions to and connect with a blockchain through a local client, thereby eliminating the need for assignment through blockchain platform 11. The above-described processing will be described in detail below.
Fig. 2 is a flowchart illustrating a method for deploying contracts in a blockchain system according to an embodiment of the present specification, the method including:
step S202, receiving a request for deploying contract 1;
step S204, determining that contract 1 corresponds to block chain 1 based on a predetermined rule;
step S206, send transaction 1 to blockchain 1 to deploy contract 1 into blockchain 1.
In one embodiment, the method of FIG. 2 is performed by the blockchain platform 11 of FIG. 1.
First, in step S202, the blockchain platform 11 receives a request for deploying the contract 1, for example, from the user terminal 12.
The data that each user wishes to store may be different data, and the processing that needs to be performed on the stored data may also be different, for example, user a may wish to perform qualification processing on the stored data, and user B may wish to perform encryption processing on the stored data. Thus, different users can perform the evidence of their data by invoking the contract by deploying the contract for performing the corresponding processing in the blockchain system.
For example, user a may use his account a to send a request to the blockchain platform 11 through the user terminal 12 for deployment of the contract 1. In one embodiment, the account a may be the only account that user a registered with blockchain platform 11. That is, the account a is managed by the blockchain platform 11 and is not an account in a blockchain. In this embodiment, the request includes, for example, the name "contract 1" of contract 1 and the content of contract 1, where the content of contract 1 is a program for implementing a specific process (e.g., qualification process).
In another embodiment, the account a may also be a blockchain account that the user a applies for, and thus the request for deploying the contract 1 may be transaction 1. Fig. 3 shows a content diagram of transaction 1 (Tx 1). As shown in fig. 3, the sending account of transaction 1 (see "From" field in fig. 3) is account a, where "0 x507a …" is the account address of account a, the receiving account field of transaction 1 (i.e., "To" field in fig. 3) is empty, which indicates that transaction 1 is a transaction for deploying a contract, and the Data field of transaction 1 (i.e., "Data" field in fig. 3) includes the content of contract 1, i.e., a program for implementing a specific process. In addition, as shown in fig. 3, the user terminal 12 also sends the digital signature of transaction 1 through account a to the blockchain platform 11 together. It is To be appreciated that the form of transaction 1 shown in fig. 3 is merely exemplary, and that embodiments of the present specification are not limited in this regard, for example, in another form of transaction 1, the transaction may be indicated in transaction 1 as a contract 1 deployment transaction by a particular field, and the "To" field may be populated with the name of contract 1 (i.e., "contract 1") for deploying contract 1.
In one embodiment, in a case that the account a is a blockchain account, a public key of the account a may be obtained in advance in each blockchain, so that each blockchain may receive the transaction sent by the account a, and each blockchain may locally record status information of the account a after the transaction sent by the account a is first received.
In step S204, the blockchain platform 11 determines that contract 1 corresponds to blockchain 1 based on a predetermined rule.
Various predetermined allocation rules may be set to allocate the contract 1 to one of the blockchains 1 to 3, as long as the predetermined allocation rules substantially uniformly allocate the contracts to the blockchains 1 to 3, thereby load-balancing the blockchains 1 to 3.
In one embodiment, the blockchain platform 11 may number the contracts to be deployed and assign them according to the remainder of dividing the number by 3, for example, when the remainder is 0, it is assigned to blockchain 1, when the remainder is 1, it is assigned to blockchain 2, and when the remainder is 2, it is assigned to blockchain 3.
In another embodiment, the blockchain platform 11 may perform a hash operation on the identification of the contract 1, the hash operation is, for example, some random operation, and the operation result is any value of 1, 2, or 3, so that the contract 1 may be assigned to a blockchain according to the result of the hash operation. Here, the identification of contract 1 may be the identification of the name of contract 1, account a + contract 1, the contract address of contract 1, and so on.
In step S206, blockchain platform 11 sends transaction 1 to blockchain 1 to deploy contract 1 into blockchain 1.
In one embodiment, user a does not send the request to deploy the contract 1 in the form of a transaction, and the blockchain platform 11 generates transaction 1 upon receiving the request, the transaction 1 having substantially the same form as transaction 1 shown in fig. 3, except that the sending account (i.e., the "From" field) is not "account a," but is an account in the blockchain 1 owned by the blockchain platform 11, and further the digital signature of transaction 1 is a signature of the account through the blockchain platform 11, but is a signature over account a. The blockchain platform 11 then sends the generated transaction 1 to any node in the blockchain 1. The nodes in blockchain 1, after receiving transaction 1, broadcast transaction 1 into blockchain 1. The nodes in the blockchain 1 execute the transaction 1 after recognizing the transaction 1, generate a contract address of the contract 1 according to a predetermined rule, and store the contract content of the contract 1 corresponding to the contract address of the contract 1 in the account database, thereby deploying the contract 1 in the blockchain 1.
In another embodiment, as described above, user a sends transaction 1 as shown in fig. 3 to blockchain platform 11 through user terminal 12, so that blockchain platform 11 can directly send transaction 1 to any node in blockchain 1, thereby deploying contract 1 in each node in blockchain 1.
The node in blockchain 1 stores transaction 1 locally after performing transaction 1 as described above, and the node in blockchain 1 may calculate a hash value for transaction 1 and store the hash value in association with the storage location of transaction 1, so that transaction 1 may be found based on the hash value for transaction 1. After deploying contract 1 in blockchain 1 through the above-described procedure, blockchain platform 11 may obtain the hash value of transaction 1 and the contract address of contract 1 from any node in blockchain 1 and return the hash value to user terminal 12 as an identifier of transaction 1, or may also return the contract address of contract 1 to user terminal 12 as an identifier of contract 1.
In one embodiment, after determining that the first contract corresponds to the first blockchain of the N blockchains based on a predetermined rule, the blockchain platform 11 records the correspondence of contract 1 to blockchain 1.
In order to record the correspondence of the contract 1 to the blockchain 1, the blockchain platform 11 needs to record the correspondence of the unique identifier of the contract 1 to the unique identifier of the blockchain 1, and the unique identifier of the contract 1 is known by the user for the purpose of subsequently allocating all transactions related to the contract 1 sent by the user to the blockchain 1.
In one embodiment, the user a includes the name of contract 1, i.e., "contract 1", only in the above-mentioned request to deploy contract 1, the name of the contract 1 being possibly the same as the names of other contracts deployed by other users, and the blockchain platform 11 may uniquely represent the contract 1 (account a, contract 1) in order to uniquely identify the contract 1, where "account a" is the account for requesting to deploy contract 1 and "contract 1" is the name of contract 1. The blockchain platform 11 may record a mapping table of contracts and blockchains as shown in table 1.
TABLE 1
Contract product Block chain
Account A, contract 1 Block chain 1
Account B, contract 2 Block chain 2
Account C, contract 3 Block chain 3
As shown in table 1, the blockchain platform 11 may record the correspondence between the contract 1 and the blockchain 1 in the locally stored table 1, so as to be used for functions such as subsequent calls to the contract 1 and queries for transactions including the contract 1.
In another embodiment, as described above, blockchain 1 may return the address of contract 1 (e.g., 0x487b …) to blockchain platform 11 after contract 1 is deployed, so that blockchain platform 11 may record a table of mappings of contracts to blockchains as shown in table 2.
TABLE 2
Contract product Block chain
0x487b… Block chain 1
0x768a… Block chain 2
0x3876… Block chain 3
As shown in table 2, the blockchain platform 11 may record the correspondence between the contract address of the contract 1 and the blockchain 1 in the locally stored table 2, so as to be used for functions such as subsequent calls to the contract 1 and queries for transactions including the contract 1.
In another way, after determining that the first contract corresponds to the first blockchain of the N blockchains based on a predetermined rule, the blockchain platform 11 may obtain the contract address of contract 1 from any node in the blockchain 1. In this specification embodiment, after acquiring a string of character strings corresponding to a contract 1 according to an existing manner of acquiring a contract address, a node in the blockchain 1 may add a predetermined number of bits to a predetermined position (e.g., a head position or a tail position, etc.) of the string of character strings to generate the contract address of the contract 1, where the predetermined number of bits is used to indicate the blockchain 1, or may modify a predetermined bit included in the string of character strings to generate the contract address of the contract 1, where the predetermined bit is used to indicate the blockchain 1. Thereafter, the blockchain platform 11 and/or the user terminal 12 may obtain a contract address for the contract 1 from any node of the blockchain 1 for making a call to the contract 1. In this case, since the blockchain 1 to which the contract 1 is deployed is indicated in the address of the contract 1, there will be no need to record the mapping relationship table of the contract and the blockchain as described above. Alternatively, the blockchain platform may itself generate the address of contract 1 based on predetermined computational rules. For example, the blockchain platform first calculates a name hash value of contract 1 and modifies a predetermined bit of the name hash value to indicate a blockchain in which contract 1 is deployed (i.e., blockchain 1), thereby obtaining an address of contract 1. The blockchain platform 11 may record the address of contract 1 after obtaining the address of contract 1 for subsequent transmission of the transaction invoking contract 1. Alternatively, blockchain platform 11 may send the address of contract 1 to the user terminal for the user terminal to send a transaction invoking contract 1.
After user a deploys contract 1 in the blockchain system, it may also wish to deploy other contracts, such as contract 2. In one embodiment, contract 2 has no relevance to contract 1, e.g., contract 2 is not associatively called when contract 1 is called, and user A may deploy contract 2 through the same process described above, in which case contract 2 may be deployed into blockchain 1 as contract 1, or contract 2 may be deployed into other blockchains, e.g., blockchain 2.
In another embodiment, the contract 2 has an association with the contract 1, e.g., when invoking the contract 1, the contract 2 needs to be invoked in association, e.g., the contract 2 is invoked in the contract 1. In this case, user a sends a request for deploying contract 2 to blockchain platform 11 through user terminal 12 and includes information in the request that contract 2 be associated with contract 1. After receiving the request for deploying the contract 2, the blockchain platform 11 determines that the contract 1 corresponds to the blockchain 1 based on the mapping table shown in table 1 or table 2, which is locally recorded as described above, so that it may be determined that the contract 2 also corresponds to the blockchain 1, sends a transaction for deploying the contract 2 to the blockchain 1, and records the correspondence of the contract 2 to the blockchain 1 in the mapping table.
In one embodiment, the method illustrated in FIG. 2 may be performed by a user terminal. In this case, the user terminal 12 can directly connect to the respective blockchains 1 to 3 without connecting to the respective blockchains through the blockchain platform 11. After receiving the indication of the user a to deploy the contract 1, the client in the user terminal 12 determines that the contract 1 corresponds to the blockchain 1 based on a predetermined rule, so as to generate a transaction 1 for deploying the contract 1, and sends the transaction 1 to the blockchain 1, and then locally records the corresponding relationship between the contract 1 and the blockchain 1 in the user terminal 12. In the case where other users may invoke the contract 1, the user terminals 12, 13 and 14 may communicate with each other so that the contracts stored by the respective user terminals are consistent with the mapping relationship table of the blockchain. Wherein the user terminals 12, 13 and 14 can communicate directly through the underlying layers. Alternatively, the user terminals 12, 13 and 14 may communicate with each other via the blockchain platform, thereby serving the purpose of unifying the mapping tables, in which case the processing performed by the blockchain platform will be reduced and most of the processing is put into the user terminals.
Fig. 4 is a flowchart illustrating a method for invoking contracts in a blockchain according to an embodiment of the present specification, the method including:
step S402, receiving a request for calling contract 1;
step S404, determining that contract 1 corresponds to block chain 1;
step S406, sends transaction 2, which invokes contract 1, to blockchain 1.
Similarly to the above, the method may be performed by the blockchain platform 11, or may also be performed by the user terminal.
In one embodiment, the method of FIG. 4 is performed by the blockchain platform 11.
At step S402, the blockchain platform 11 receives a request for invoking contract 1 from the user terminal 12.
For example, after the contract 1 is deployed, the user a desires to call the contract 1 to perform predetermined processing on the data 1, and store the processed data 1 in the blockchain system. Thus, user a sends a request to blockchain platform 11 to invoke contract 1. The request indicates a call to contract 1 and includes a parameter to be input when executing contract 1, i.e., data 1.
In one embodiment, the request includes a unique identification of contract 1. For example, as described above, (account a, contract 1) is included in the request as a unique identification for contract 1. Alternatively, the request includes the contract address of contract 1 as the unique identification of contract 1.
In another embodiment, user a's account a is an account in the blockchain system, and user terminal 12 may send transaction 2 invoking contract 1 to the blockchain platform through account a. Fig. 5 shows a content diagram of transaction 2 (Tx 2). As shown in fig. 5, the sending account of transaction 2 is account a, the receiving account is contract 1, where "0 x487b …" represents the account address of contract 1, the data field of transaction 2 represents the call to the STORE function in contract 1, and the data field includes data 1 to be passed into the STORE function. Wherein the transaction 2 is represented in the transaction 2 by the receiving account as a transaction that invokes the contract 1. In addition, as shown in fig. 5, the user terminal 12 also sends the digital signature of transaction 2 through account a to the blockchain platform 11 together.
In step S404, the blockchain platform 11 determines that contract 1 corresponds to blockchain 1.
In one embodiment, as described above, the blockchain platform 11 records a mapping table (as shown in table 1 or table 2 above) of contracts and blockchains. Blockchain platform 11 may determine that contract 1 corresponds to blockchain 1 by reading the mapping table, that is, contract 1 is deployed in blockchain 1.
In another embodiment, the request for invoking contract 1 includes a contract address of contract 1, and at least one predetermined number of bits in the contract address is preset to indicate an identity of a block chain deployed by the contract. For example, the contract address is generated such that the first two bits thereof are set to indicate a block chain, for example, if the first two bits of the contract address are 01, block chain 1 is indicated, if the first two bits of the contract address are 10, block chain 2 is indicated, and if the first two bits of the contract address are 11, block chain 3 is indicated. It is to be understood that although only the first two bits of the contract address are described as being set for indicating the blockchain, in practice, the number of bits for indicating the blockchain may be set according to the number of blockchains included in the blockchain system and the number of blockchains expected to be extended. When generating the contract address of the contract 1, the node in the block chain may add multiple bits for indicating the block chain to a predetermined position (e.g., at a hash head or a hash tail) of the hash value after generating the hash value of the contract according to a predetermined rule (e.g., inputting the name of the contract into a predetermined hash function to generate the hash value of the contract), or replace the multiple bits of the predetermined position of the hash value with multiple bits for indicating the block chain, thereby finally obtaining the contract address of the contract. In this case, blockchain platform 11 may determine that contract 1 corresponds to blockchain 1 based on a predetermined bit (e.g., the first two bits) of the contract address of contract 1 included in the request.
In step S406, blockchain platform 11 sends transaction 2 to blockchain 1 for invoking contract 1.
In one embodiment, the request to invoke contract 1 described above is not in the form of a transaction, and thus, blockchain platform 11 generates transaction 2, which transaction 2 has the same form as transaction 2 shown in FIG. 5, except that its sending account is an account owned by blockchain platform 11, rather than account A, and the digital signature is also a signature of the account of the blockchain platform. Blockchain platform 11 then sends the generated transaction 2 to any node in blockchain 1 to cause contract 1 to be invoked in blockchain 1.
In another embodiment, the request to invoke contract 1 is in the form of transaction 2 shown in fig. 5, whereby blockchain platform 11 sends transaction 2 directly to any node in blockchain 1.
After any node in the blockchain 1 receives the transaction 2, similarly to the above-mentioned transaction 1, after the nodes in the blockchain 1 are identified, the transaction 2 is executed in each whole node in the blockchain 1, so as to execute the contract 1, update the state data of the contract 1, namely, store the data 2 obtained by executing the contract 1 to process the data 1 into the account state of the contract 1, and store the transaction 2 into the blockchain database. Alternatively, the data 2 may be stored in a receipt for transaction 2 for querying. After storing transaction 2 into blockchain 1, the node in blockchain 1 may calculate the hash value of transaction 2 as the identifier of transaction 2, and record the association relationship between the hash value of transaction 2 and the storage location of transaction 2, similarly to transaction 1, so that the transaction content of transaction 2 may be queried based on the hash value.
After each node in blockchain 1 deposits transaction 2, blockchain platform 11 may obtain an identification (e.g., a hash value) of transaction 2 and/or an identification of data 2 from any node in blockchain 1, or after any node in blockchain 1 executes transaction 2 and deposits transaction 2 in blockchain 1, may actively push the identification of transaction 2 and/or the identification of data 2 to blockchain platform 11. The blockchain platform 11 may then send the identification of the transaction 2 and/or the identification of the data 2 to the user terminal 12, so that the user terminal 12 may subsequently perform a query for the data 2 based on the identification of the transaction 2 and/or the identification of the data 2.
In another embodiment, the method shown in fig. 4 may also be performed by the user terminal 12. In this case, the user terminal 12 is directly connected to each blockchain. After receiving a request for invoking contract 1 from user a through the client, the user terminal 12 determines that contract 1 corresponds to blockchain 1 based on a locally recorded mapping table of contracts and blockchains or based on a contract address of contract 1, generates transaction 2, and transmits transaction 2 to any node of blockchain 1, so that transaction 2 is executed in blockchain 1, thereby invoking contract 1, similarly to the above.
Embodiments of assigning transactions to a blockchain by based on contracts in the transactions are described above with reference to fig. 2 and 4, to which embodiments of the specification are not limited. In another embodiment of the present description, in addition to allocating transactions via contracts in transactions, transactions may be allocated a second time based on accounts associated with the transactions. Referring to fig. 2, assuming that the request for deploying contract 1 is sent by account a, at step S204, it may be determined that contract 1 corresponds to M of N blockchains based on a first predetermined rule, and then it may be determined that account a corresponds to blockchain 1 of the M blockchains based on a second predetermined rule, so that transaction 1 may be sent to blockchain at step S206. The second predetermined rule is, for example, to hash account a to determine that account a corresponds to blockchain 1, or to determine that account a corresponds to blockchain 1 based on the registration of account a. After this allocation is made, the correspondence between contracts, blockchains, and accounts may be recorded, for example, by table 3 below.
TABLE 3
As shown in table 3, assuming 0x487B … is the account address of contract 1, table 3 shows that contract 1 corresponds to blockchain 1 and blockchain 2, and blockchain 1 in turn corresponds to accounts a, account B, etc. When blockchain platform 11 sends a transaction to a blockchain that invokes contract 1 sent by account a, it may be determined based on table 3 that the transaction corresponds to blockchain 1 and thus may be sent to blockchain 1.
Fig. 6 illustrates an apparatus 600 for deploying contracts in a blockchain system including N independent blockchains according to an embodiment of the present specification, where the apparatus 600 includes:
a first receiving unit 61 configured to receive a first request for deploying a first contract;
a first determining unit 62 configured to determine that a first contract corresponds to a first blockchain of the N blockchains based on a predetermined rule;
a first sending unit 63 configured to send a first transaction to the first blockchain to deploy the first contract into the first blockchain.
In an embodiment, the apparatus 600 further includes a recording unit 64 configured to record a correspondence relationship between a first contract and a first blockchain of the N blockchains after determining that the first contract corresponds to the first blockchain based on a predetermined rule.
In one embodiment, the recording unit 64 is further configured to record a correspondence between the unique identifier of the first contract and the first block chain.
In one embodiment, the apparatus 600 is deployed on a blockchain platform, and the blockchain platform is connected to the N blockchains, respectively, wherein the first receiving unit 61 is further configured to receive a first transaction for deploying a first contract.
In one embodiment, the apparatus 600 further comprises:
a second receiving unit 65 configured to receive a second request for deploying a second contract, where the second request includes association information of the second contract and the first contract;
a second determining unit 66 configured to determine that a second contract corresponds to the first blockchain based on a correspondence of the first contract to the first blockchain;
a second sending unit 67 is configured to send a second transaction to the first blockchain to deploy the second contract into the first blockchain.
In one embodiment, the apparatus 600 further includes an obtaining unit 68 configured to obtain an address of a first contract after determining that the first contract corresponds to a first blockchain of the N blockchains based on a predetermined rule, where a predetermined bit of the address of the first contract is used to indicate the first blockchain.
Fig. 7 illustrates an apparatus 700 for invoking contracts in a blockchain system including N independent blockchains according to an embodiment of the present specification, the apparatus 700 including:
a first receiving unit 71 configured to receive a third request for invoking the first contract;
a determining unit 72 configured to determine that a first contract corresponds to a first blockchain of the N blockchains;
a sending unit 73, configured to send a third transaction corresponding to the third request to the first blockchain, where the first contract is invoked in the third transaction.
In one embodiment, the determining unit 72 is further configured to determine that the first contract corresponds to the first block chain of the N block chains by reading a correspondence between a pre-recorded first contract and the first block chain of the N block chains.
In one embodiment, the third request includes an address of the first contract, and the determining unit 72 is further configured to determine that the first contract corresponds to a first blockchain of the N blockchains based on a predetermined bit in the address of the first contract.
In one embodiment, the first contract is for crediting the first blockchain, and the third transaction causes first data to be credited in the first blockchain after execution, the apparatus 700 further comprising: a second receiving unit 74 configured to receive an identification of the first data from the first blockchain after sending a third transaction corresponding to the third request to the first blockchain.
In one embodiment, the identification of the first data is an identification of the third transaction.
In one embodiment, the first receiving unit 71 is further configured to receive a third transaction for invoking the first contract.
Another aspect of the present specification provides a computer readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform any one of the above methods.
Another aspect of the present specification provides a computing device comprising a memory having stored therein executable code, and a processor that, when executing the executable code, implements any of the methods described above.
By the scheme for deploying and calling contracts according to the embodiment of the specification, the contracts are averagely deployed into the plurality of block chains, so that the capacity and the processing capacity of parallel expansion can be provided for the block chain system through the plurality of block chains, the read-write pressure is reduced compared with that of a single block chain, the processing efficiency of the block chain system is improved, and particularly the parallel pressure distribution can be realized by fast expansion in a sudden flow increase period.
It is to be understood that the terms "first," "second," and the like, herein are used for descriptive purposes only and not for purposes of limitation, to distinguish between similar concepts.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
It will be further appreciated by those of ordinary skill in the art that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application. The software modules may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are merely exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (32)

1. A method of deploying contracts in a blockchain system comprising N mutually independent blockchains, the method comprising:
receiving a first request to deploy a first contract;
determining, based on a predetermined rule, that a first contract corresponds to a first blockchain of the N blockchains;
sending a first transaction to the first blockchain to deploy the first contract into the first blockchain.
2. The method of claim 1, further comprising, after determining that a first contract corresponds to a first blockchain of the N blockchains based on a predetermined rule, recording a correspondence of the first contract to the first blockchain.
3. The method of claim 2, wherein recording a correspondence of the first contract to the first blockchain comprises recording a correspondence of a unique identification of the first contract to the first blockchain.
4. The method of claim 3, wherein the unique identification of the first contract is a combination of an account sending the first request and a name of the first contract.
5. The method of claim 1, wherein the method is performed by a blockchain platform that is connected to the N blockchains, respectively, and wherein receiving the first request to deploy the first contract comprises receiving a first transaction to deploy the first contract.
6. The method of any of claims 1-5, further comprising:
receiving a second request for deploying a second contract, wherein the second request comprises the association information of the second contract and the first contract;
determining that a second contract corresponds to the first blockchain based on the correspondence of the first contract to the first blockchain;
sending a second transaction to the first blockchain to deploy the second contract into the first blockchain.
7. The method of claim 1, further comprising, after determining, based on a predetermined rule, that a first contract corresponds to a first blockchain of the N blockchains, retrieving an address of the first contract, a predetermined bit of the address of the first contract being used to indicate the first blockchain.
8. The method of claim 1, wherein the first request is sent by a first account, the determining that a first contract corresponds to a first blockchain of the N blockchains based on a predetermined rule comprises determining that a first contract corresponds to M blockchains of the N blockchains based on a first predetermined rule, the determining that the first account corresponds to a first blockchain of the M blockchains based on a second predetermined rule.
9. The method of claim 8, further comprising, after determining that the first account corresponds to a first blockchain of the M blockchains based on a second predetermined rule, recording a first correspondence of the first contract to the M blockchains and a second correspondence of the first account to the first blockchain, wherein the second correspondence is associated with the first correspondence.
10. A method of invoking contracts in a blockchain system comprising N mutually independent blockchains, the method comprising:
receiving a third request for invoking the first contract;
determining that a first contract corresponds to a first blockchain of the N blockchains;
and sending a third transaction corresponding to the third request to the first blockchain, wherein the first contract is called in the third transaction.
11. The method of claim 10, wherein determining that the first contract corresponds to the first blockchain of the N blockchains comprises determining that the first contract corresponds to the first blockchain of the N blockchains by reading a pre-recorded correspondence of the first contract to the first blockchain of the N blockchains.
12. The method of claim 10, wherein the third request includes an address of the first contract, wherein determining that the first contract corresponds to the first of the N blockchains comprises determining that the first contract corresponds to the first of the N blockchains based on a predetermined bit of the address of the first contract.
13. The method of claim 10, wherein the first contract is for crediting in the first blockchain, the third transaction causes first data to be credited in the first blockchain after execution, the method further comprising: receiving an identification of the first data from the first blockchain after sending a third transaction corresponding to the third request to the first blockchain.
14. The method of claim 13, wherein the identification of the first data is an identification of the third transaction.
15. The method of any of claims 10-14, wherein receiving a third request to invoke the first contract comprises receiving a third transaction to invoke the first contract.
16. An apparatus for deploying contracts in a blockchain system comprising N mutually independent blockchains, the apparatus comprising:
a first receiving unit configured to receive a first request for deploying a first contract;
a first determining unit configured to determine that a first contract corresponds to a first blockchain of the N blockchains based on a predetermined rule;
a first sending unit configured to send a first transaction to the first blockchain to deploy the first contract into the first blockchain.
17. The apparatus according to claim 16, further comprising a first recording unit configured to record a correspondence of a first contract with a first blockchain of the N blockchains after determining that the first contract corresponds to the first blockchain based on a predetermined rule.
18. The apparatus according to claim 17, wherein the first recording unit is further configured to record a correspondence of the unique identifier of the first contract to the first blockchain.
19. The apparatus of claim 18, wherein the unique identification of the first contract is a combination of an account sending the first request and a name of the first contract.
20. The apparatus of claim 16, wherein the apparatus is deployed in a blockchain platform, the blockchain platform being connected to the N blockchains, respectively, and wherein the first receiving unit is further configured to receive a first transaction for deploying a first contract.
21. The apparatus of any of claims 16-20, further comprising:
a second receiving unit configured to receive a second request for deploying a second contract, the second request including association information of the second contract and the first contract;
a second determining unit configured to determine that a second contract corresponds to the first blockchain based on a correspondence relationship of the first contract and the first blockchain;
a second sending unit configured to send a second transaction to the first blockchain to deploy the second contract into the first blockchain.
22. The apparatus according to claim 16, further comprising an obtaining unit configured to obtain an address of a first contract after determining that the first contract corresponds to a first blockchain of the N blockchains based on a predetermined rule, the predetermined bit of the address of the first contract being used to indicate the first blockchain.
23. The apparatus of claim 16, wherein the first request is sent by a first account, the first determining unit is further configured to determine that a first contract corresponds to M of the N blockchains based on a first predetermined rule, and the first account corresponds to a first blockchain of the M blockchains based on a second predetermined rule.
24. The apparatus according to claim 23, further comprising a second recording unit configured to record a first correspondence of the first contract with the M blockchains and a second correspondence of the first account with the first blockchain after determining that the first account corresponds to a first blockchain of the M blockchains based on a second predetermined rule, wherein the second correspondence is associated with the first correspondence.
25. An apparatus for invoking contracts in a blockchain system comprising N mutually independent blockchains, the apparatus comprising:
a first receiving unit configured to receive a third request for invoking the first contract;
a determining unit configured to determine that a first contract corresponds to a first blockchain of the N blockchains;
a sending unit configured to send a third transaction corresponding to the third request to the first blockchain, where the first contract is invoked in the third transaction.
26. The apparatus according to claim 25, wherein the determining unit is further configured to determine that the first contract corresponds to the first block chain of the N block chains by reading a correspondence of a pre-recorded first contract to the first block chain of the N block chains.
27. The apparatus of claim 25, wherein the third request includes an address of the first contract, wherein the determination unit is further configured to determine that the first contract corresponds to a first bank chain of the N bank chains based on a predetermined bit of the address of the first contract.
28. An apparatus as defined in claim 25, wherein the first contract is to certify in the first blockchain, the third transaction to cause first data to be deposited in the first blockchain after execution, the apparatus further comprising: a second receiving unit configured to receive an identification of the first data from the first blockchain after sending a third transaction corresponding to the third request to the first blockchain.
29. The apparatus of claim 28, wherein the identification of the first data is an identification of the third transaction.
30. The apparatus of any of claims 25-29, wherein the first receiving unit is further configured to receive a third transaction for invoking the first contract.
31. A computer-readable storage medium, having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method of any of claims 1-15.
32. A computing device comprising a memory having executable code stored therein and a processor that, when executing the executable code, implements the method of any of claims 1-15.
CN202011176391.4A 2020-10-28 2020-10-28 Method and apparatus for deploying and invoking contracts in blockchain Pending CN112017052A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011176391.4A CN112017052A (en) 2020-10-28 2020-10-28 Method and apparatus for deploying and invoking contracts in blockchain

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011176391.4A CN112017052A (en) 2020-10-28 2020-10-28 Method and apparatus for deploying and invoking contracts in blockchain

Publications (1)

Publication Number Publication Date
CN112017052A true CN112017052A (en) 2020-12-01

Family

ID=73527767

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011176391.4A Pending CN112017052A (en) 2020-10-28 2020-10-28 Method and apparatus for deploying and invoking contracts in blockchain

Country Status (1)

Country Link
CN (1) CN112017052A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108805707A (en) * 2018-05-21 2018-11-13 阿里巴巴集团控股有限公司 Works copyright revenue distribution method and device based on block chain
CN110083629A (en) * 2019-04-22 2019-08-02 深圳前海微众银行股份有限公司 A kind of method and device of the event subscription based on block chain
CN110210845A (en) * 2019-06-11 2019-09-06 网易(杭州)网络有限公司 For the method, apparatus of block chain Data Migration, medium and calculate equipment
CN110855701A (en) * 2019-11-21 2020-02-28 清华大学 Block chain-based infrastructure service method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108805707A (en) * 2018-05-21 2018-11-13 阿里巴巴集团控股有限公司 Works copyright revenue distribution method and device based on block chain
CN110083629A (en) * 2019-04-22 2019-08-02 深圳前海微众银行股份有限公司 A kind of method and device of the event subscription based on block chain
CN110210845A (en) * 2019-06-11 2019-09-06 网易(杭州)网络有限公司 For the method, apparatus of block chain Data Migration, medium and calculate equipment
CN110855701A (en) * 2019-11-21 2020-02-28 清华大学 Block chain-based infrastructure service method and device

Similar Documents

Publication Publication Date Title
CN106991334B (en) Data access method, system and device
ES2709436T3 (en) Extensible and programmable multi-company service architecture
US8103767B2 (en) Method and apparatus for distributing requests among a plurality of resources
CN100426242C (en) Method, system and product for identifying, reserving, and logically provisioning resources in provisioning data processing systems
CN1319008C (en) Game virtual-article data processing method, game platform system and game system
KR101213916B1 (en) Method and system for obfuscating data structures by deterministic natural data substitution
US6928459B1 (en) Plurality of file systems using weighted allocation to allocate space on one or more storage devices
CN101197754B (en) Distributed system, distributed service processing method and correlated device
CN105100146B (en) Date storage method, apparatus and system
US7496566B2 (en) Priority based LDAP service publication mechanism
CN102419770B (en) File sharing system, method for realizing file sharing, and file index service equipment
CN104852934A (en) Method for realizing flow distribution based on front-end scheduling, device and system thereof
CN107368259A (en) A kind of method and apparatus that business datum is write in the catenary system to block
CN106325998B (en) Application deployment method and device based on cloud computing
CN108418862B (en) Micro-service management method and system based on artificial intelligence service cloud platform
CN101313495B (en) Method, system and apparatus for data synchronization
EP3432549B1 (en) Method and apparatus for processing user requests
JP4377369B2 (en) Resource allocation arbitration device and resource allocation arbitration method
CN100394726C (en) Method for raising reliability of software system based on strucural member
KR100293795B1 (en) Distributed Database System and Data Entity Access Methods
EP1649387B1 (en) Distributed database system
CN102835067A (en) Method and apparatus for hierarchical management of system resources
CN103095687B (en) metadata processing method and device
CN101247349A (en) Network flux fast distribution method
KR20100126280A (en) System and method for describing applications for manageability and efficient scale-up deployment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination