Data migration method and device of block chain, computer equipment and storage medium
By using the combination of migration auxiliary contract identification and business contract in the blockchain, the problem that the existing technology cannot safely and trustworthyly prove whether blockchain transactions are migration transactions, and a secure and trustworthy data migration process is achieved.
Patent Information
- Application Number
- CN202311567093.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-22
- Publication Date
- 2025-05-23
AI Technical Summary
The existing technology cannot safely and credibly prove whether blockchain transactions are migration transactions from the original chain, resulting in the inability to effectively prevent illegal counterfeit migration transactions.
All migration transactions are marked by using the migration auxiliary contract identifier, and the business contract is called through the migration auxiliary contract, and a new chain transaction is constructed to ensure that the new chain transaction contains the contract identifier of the migration auxiliary contract, thereby proving the source of the transaction.
It realizes a secure and credible proof that the current transaction is a migration transaction from the original chain, prevents illegal counterfeiting, and improves the reliability and security of the data migration process.
Smart Images

Figure CN120029990A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a blockchain data migration method, apparatus, computer equipment, storage medium and computer program product. Background Art
[0002] With the continuous development of computer technology, blockchain technology has also developed rapidly. More and more users will store business data on the blockchain. However, due to insufficient performance and complex architecture of the original chain, the blockchain data of the original chain needs to be migrated to complete the chain change. After completing the data migration, it is usually necessary to prove to the blockchain user whether the current transaction is a migration transaction from the original chain.
[0003] In the related art, an identification field is generally added to the migration transaction to identify whether the current transaction is a migration transaction. However, this method cannot prevent builders who do not have construction permissions from setting the corresponding field in the non-migration transaction as the migration transaction identifier to impersonate a migration transaction, resulting in an inability to safely and reliably prove whether the current transaction is a migration transaction from the original chain. Summary of the invention
[0004] Based on this, it is necessary to provide a blockchain data migration method, device, computer equipment, computer-readable storage medium and computer program product to address the above technical problems, by using a migration auxiliary contract identifier to mark all migration transactions, so as to safely and reliably prove that the current transaction is a migration transaction from the original chain.
[0005] In a first aspect, the present application provides a method for data migration of a blockchain. The method comprises:
[0006] Receive a migration transaction, wherein the migration transaction is constructed according to the transaction data structure of the target blockchain based on the original chain transaction, and the migration transaction includes a contract identifier and an original chain read-write set, wherein the original chain read-write set is generated after the business contract corresponding to the contract identifier on the original blockchain is called to execute the original chain transaction;
[0007] Call the migration assistance contract;
[0008] The business contract corresponding to the contract identifier is called through the migration auxiliary contract, and the new chain read-write set corresponding to the migration transaction is constructed according to the read-write set data structure of the target blockchain and the original chain read-write set through the business contract;
[0009] According to the contract identifier of the migration assistance contract, the migration transaction, and the new chain read-write set corresponding to the migration transaction, a new chain transaction corresponding to the original chain transaction is constructed, wherein the contract identifier of the migration assistance contract is used to mark that the new chain transaction comes from the original blockchain;
[0010] The new chain transaction is stored in the target blockchain.
[0011] In a second aspect, the present application also provides a blockchain data migration device. The device includes:
[0012] A receiving module, used to receive a migration transaction, wherein the migration transaction is constructed according to the transaction data structure of the target blockchain based on the original chain transaction, and the migration transaction includes a contract identifier and an original chain read-write set, wherein the original chain read-write set is generated after the business contract corresponding to the contract identifier on the original blockchain is called to execute the original chain transaction;
[0013] Migration assistance contract calling module, used to call the migration assistance contract;
[0014] A cross-contract calling module, used to call the business contract corresponding to the contract identifier through the migration auxiliary contract, and construct a new chain read-write set corresponding to the migration transaction according to the read-write set data structure of the target blockchain through the business contract and the original chain read-write set;
[0015] A new chain transaction construction module, used to construct a new chain transaction corresponding to the original chain transaction according to the contract identifier of the migration assistance contract, the migration transaction and the new chain read-write set corresponding to the migration transaction, wherein the contract identifier of the migration assistance contract is used to mark that the new chain transaction comes from the original blockchain;
[0016] A storage module is used to store the new chain transaction in the target blockchain.
[0017] Optionally, the device further comprises:
[0018] The world state update module is used to update the world state data of the target blockchain according to the write set in the new chain read-write set corresponding to the new chain transaction; and store the updated world state data in the world state database of the target blockchain.
[0019] Optionally, the device further comprises:
[0020] The authority checking module is used to perform a transaction authority check on the migration transaction through the migration assistance contract before calling the business contract corresponding to the contract identifier through the migration assistance contract; after the transaction authority check passes, calling the business contract corresponding to the contract identifier.
[0021] Optionally, the permission check module is further used to obtain the identity information of the builder of the migration transaction according to the received migration transaction through the migration assistance contract; query whether there is a migration transaction construction permission associated with the identity information; when it is found that the identity information has the corresponding migration transaction construction permission, determine that the transaction permission check has passed, and when it is found that the identity information does not have the corresponding migration transaction construction permission, determine that the transaction permission check has failed.
[0022] Optionally, the device further comprises:
[0023] A transaction parsing module, used to parse the transaction data structure of the migration transaction through the migration auxiliary contract to obtain the original chain read-write set related to each business contract identifier;
[0024] The cross-contract calling module is used to call the corresponding business contract according to the original chain read-write set related to each business contract identifier.
[0025] Optionally, the device further comprises:
[0026] A validity check module, used to extract the read set in the original chain read-write set through the migration assistance contract; and check the validity of the migration transaction according to the extracted read set in the original chain read-write set;
[0027] The cross-contract calling module is used to call the corresponding business contract according to the original chain read-write set related to each business contract after the validity check is passed.
[0028] Optionally, the validity check module is used to obtain the version number of the read set in the extracted original chain read-write set; check whether the version number is consistent with the version number of the read set recorded in the world state database corresponding to the target blockchain; if they are consistent, it is determined that the transaction validity check has passed; if they are inconsistent, it is determined that the transaction validity check has failed.
[0029] Optionally, the device further comprises:
[0030] The new chain read-write set construction module is used to extract key-value pairs from the read-write set through the business contract, and construct a new chain read-write set corresponding to the migration transaction according to the extracted key-value pairs according to the read-write set data structure of the target blockchain.
[0031] Optionally, the storage module is used to add the new chain transaction to a transaction pool associated with the target blockchain; package the new chain transaction into a block to be verified in the transaction pool; determine a target block for writing into the target blockchain based on the block to be verified, and write the target block into the blockchain database of the target blockchain.
[0032] Optionally, the device further comprises:
[0033] A startup module, configured to run the migration assistance contract after receiving a startup instruction for data migration;
[0034] The contract cancellation module is used to cancel the migration assistance contract after receiving the end instruction of data migration.
[0035] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0036] Receive a migration transaction, wherein the migration transaction is constructed according to the transaction data structure of the target blockchain based on the original chain transaction, and the migration transaction includes a contract identifier and an original chain read-write set, wherein the original chain read-write set is generated after the business contract corresponding to the contract identifier on the original blockchain is called to execute the original chain transaction;
[0037] Call the migration assistance contract;
[0038] The business contract corresponding to the contract identifier is called through the migration auxiliary contract, and the new chain read-write set corresponding to the migration transaction is constructed according to the read-write set data structure of the target blockchain and the original chain read-write set through the business contract;
[0039] According to the contract identifier of the migration assistance contract, the migration transaction, and the new chain read-write set corresponding to the migration transaction, a new chain transaction corresponding to the original chain transaction is constructed, wherein the contract identifier of the migration assistance contract is used to mark that the new chain transaction comes from the original blockchain;
[0040] The new chain transaction is stored in the target blockchain.
[0041] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0042] Receive a migration transaction, wherein the migration transaction is constructed according to the transaction data structure of the target blockchain based on the original chain transaction, and the migration transaction includes a contract identifier and an original chain read-write set, wherein the original chain read-write set is generated after the business contract corresponding to the contract identifier on the original blockchain is called to execute the original chain transaction;
[0043] Call the migration assistance contract;
[0044] The business contract corresponding to the contract identifier is called through the migration auxiliary contract, and the new chain read-write set corresponding to the migration transaction is constructed according to the read-write set data structure of the target blockchain and the original chain read-write set through the business contract;
[0045] According to the contract identifier of the migration assistance contract, the migration transaction, and the new chain read-write set corresponding to the migration transaction, a new chain transaction corresponding to the original chain transaction is constructed, wherein the contract identifier of the migration assistance contract is used to mark that the new chain transaction comes from the original blockchain;
[0046] The new chain transaction is stored in the target blockchain.
[0047] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0048] Receive a migration transaction, wherein the migration transaction is constructed according to the transaction data structure of the target blockchain based on the original chain transaction, and the migration transaction includes a contract identifier and an original chain read-write set, wherein the original chain read-write set is generated after the business contract corresponding to the contract identifier on the original blockchain is called to execute the original chain transaction;
[0049] Call the migration assistance contract;
[0050] The business contract corresponding to the contract identifier is called through the migration auxiliary contract, and the new chain read-write set corresponding to the migration transaction is constructed according to the read-write set data structure of the target blockchain and the original chain read-write set through the business contract;
[0051] According to the contract identifier of the migration assistance contract, the migration transaction, and the new chain read-write set corresponding to the migration transaction, a new chain transaction corresponding to the original chain transaction is constructed, wherein the contract identifier of the migration assistance contract is used to mark that the new chain transaction comes from the original blockchain;
[0052] The new chain transaction is stored in the target blockchain.
[0053] The above-mentioned blockchain data migration method, device, computer equipment, storage medium and computer program product receive a migration transaction during the data migration process. The migration transaction is constructed according to the original chain transaction according to the transaction data structure of the target blockchain. The migration transaction includes a contract identifier and an original chain read-write set. The original chain read-write set is generated after calling the business contract corresponding to the contract identifier on the original blockchain to execute the original chain transaction. After receiving the migration transaction, the migration auxiliary contract is called, and then the business contract corresponding to the contract identifier is called through the migration auxiliary contract, so that the new chain read-write set corresponding to the migration transaction is constructed according to the original chain read-write set according to the read-write set data structure of the target blockchain through the business contract. Then, according to the contract identifier of the migration auxiliary contract, the migration transaction and the new chain read-write set corresponding to the migration transaction, a new chain transaction corresponding to the original chain transaction is constructed. The contract identifier of the migration auxiliary contract in the new chain transaction is used to mark that the new chain transaction comes from the original blockchain, and the new chain transaction is stored in the target blockchain to realize the data migration of the blockchain. At the same time, during the migration process, since the migration auxiliary contract is called first when the migration transaction is received, and then the migration auxiliary contract calls the business contract corresponding to the migration transaction, when the new chain transaction corresponding to the original chain transaction is constructed according to the migration transaction, the contract identifier of the called migration auxiliary contract can be marked in the new chain transaction. In this way, it is ensured that the transaction content that includes the contract identifier of the auxiliary migration contract must be a migration transaction, thereby achieving the purpose of safely and reliably proving that the current transaction is a migration transaction from the original chain. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 is a schematic diagram of a block in one embodiment;
[0055] Figure 2A An application environment diagram of a data migration method of a blockchain in one embodiment;
[0056] Figure 2B is a schematic diagram of a blockchain in one embodiment;
[0057] Figure 2C A schematic diagram of information required to generate a block in one embodiment;
[0058] Figure 3 This is an application environment diagram of a data migration method of a blockchain in another embodiment;
[0059] Figure 4 A flowchart of a data migration method of a blockchain in one embodiment;
[0060] Figure 5 A schematic diagram of a data migration process in one embodiment;
[0061] Figure 6A functional schematic diagram of each smart contract for implementing data migration in one embodiment;
[0062] Figure 7 It is a functional diagram of each smart contract for realizing data migration in the relevant technology;
[0063] Figure 8 A flowchart of a data migration method of a blockchain in a specific embodiment;
[0064] Fig. 9 It is a structural block diagram of a data migration device of a blockchain in one embodiment;
[0065] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0066] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0067] First, some key terms appearing in the embodiments of the present application are explained.
[0068] Hyperledger Fabric (an open source blockchain distributed ledger): consists of two different but related parts, namely the world state and the blockchain. The ledger is a series of ordered and tamper-proof records of state transitions, composed of blockchains, which store immutable and ordered records in blocks, and also contains a state database to record the current state. The current state of the ledger is the latest value of all keys recorded in the chain transaction log. Since the current state represents the latest value of all known keys, it is also called the world state.
[0069] World State: records the latest status after all transactions are executed. The world state is actually saved in a non-relational database to facilitate the storage and retrieval of the status. The database saves the latest value of a set of ledger states in the form of key-value pairs. Saving the world state allows the application to quickly obtain the latest value of the current ledger without traversing the entire transaction log. Its value can be a simple value or a complex data consisting of a set of key-value pairs. Each world state has a version number, and the starting version number value is 0. Every time the world state is changed, the version number of the world state will increase. When the world state is updated, a validity check is also performed to ensure that it matches the version number when the transaction was created.
[0070] Blockchain: It is a file system that records transaction logs. It is constructed by N blocks B linked by hash values. Each block contains a series of multiple ordered transactions. The block header contains the hash value of the transaction recorded in this block, as well as the hash value of the previous block header. In this way, all transactions in the ledger are linked together in an orderly and encrypted form. In other words, in a distributed network, the ledger data cannot be tampered with without destroying the hash chain.
[0071] like Figure 1 As shown, each block of the blockchain has: a block header, block data, and block metadata.
[0072] The block header H contains the encrypted hash of all transactions in the block data D and the equivalent hash from the previous block. Through this linking method, the blocks are inextricably linked to each other.
[0073] The block header H2 of the current block (for example, represented by B2) consists of the block number, the hash of the block data D2 of the current block B2, and the hash of the block data D1 from the previous block B1, which are written into the block header H2 when the block B2 is created. Among them, the block number (Block number) is an integer starting from 0, and it will increase by 1 based on the previous value for each new block appended to the blockchain. The hash of the block data of the current block (Current BlockHash) is the hash value of all transactions contained in the block data of the current block. The hash of the block data of the previous block (Previous Block Hash) is a copy of the hash value of all transactions contained in the block data of the previous block in the blockchain.
[0074] The block data B contains multiple transactions T in an orderly arrangement, which are written when the block B is created. Each transaction contains the detailed structure of the transaction, and the transaction records the changes in the world state. The detailed structure of each transaction includes the transaction header, transaction signature, transaction proposal, transaction proposal response and endorsement list. The block metadata M contains the time when the block was written, as well as the corresponding certificate, public key and signature.
[0075] The transaction header includes some basic metadata about the transaction such as the smart contract name and its version.
[0076] The transaction signature contains an encrypted signature created using the client application's private key to check whether the transaction content has been tampered with.
[0077] The transaction proposal contains the name of the smart contract to be called and the input parameters required to call the smart contract. The smart contract can update the ledger based on the submitted transaction proposal.
[0078] The transaction proposal response (Proposal Response), after calling the smart contract to simulate the execution of the transaction, obtains the before and after values of the world state, and returns it to the client as a read-write set (Read-Write Set). After the simulated execution of the transaction, the endorser (Endorser) will generate a read-write set (Read-Write Set). The read set (Read Set) contains the list of keys read by the transaction during the simulated execution and the corresponding submitted values and their submitted version numbers. The write set (Write Set) contains the key list and the new value written after the simulated execution.
[0079] Endorsement list, a transaction contains only one transaction response, but with multiple endorsement signatures from the required organizations to satisfy the required endorsement policy.
[0080] The specific transaction execution process is as follows: the client application creates and sends a transaction proposal (Proposal) to the endorsement node (Endorser Peer) of the target organization. The proposal includes the operations related to the smart contract to be executed (such as reading or writing data) and the necessary parameters. After receiving the proposal, the endorsement node will perform the operations related to the smart contract and verify the validity of the transaction according to the endorsement policy related to the smart contract. The endorsement node endorses the transaction and generates a transaction endorsement result (Endorsement), which contains the read-write set of the operations related to the smart contract and the signature of the endorsement node. The endorsement node returns the transaction endorsement result to the client application. After the client application collects a sufficient number of valid endorsement results, it submits these results as transaction proposals to the sorting service node (Orderer Peer). After receiving the transaction proposal, the sorting service node packages the transaction into blocks in order and generates a block header for the block. Among them, the sorting service node uses a consensus algorithm (such as Kafka) to sort the transactions to ensure that all nodes reach a consensus on the same order. The sorting service node sends the sorted transaction blocks to all the endorsing nodes in the network. The endorsing nodes verify the legitimacy of the transaction blocks, including checking the signature of the transaction and the consistency of the endorsement results. The endorsing node submits the transaction block to its own ledger, updates the world state and transaction log. The endorsing node uses the read set part of the read-write set to check the validity of the transaction, and uses the write set part of the read-write set to update the version number and value of the affected key. The transaction log records all confirmed transactions to achieve the immutability and traceability of transactions. The client application can send a query request to any node to obtain confirmed transaction data or the current world state.
[0081] A smart contract is a computer protocol that, after being developed and deployed, allows trusted transactions to be conducted without a third party, thus achieving self-execution and self-verification. From a technical perspective, a smart contract can be seen as a computer program that can autonomously execute all or part of the operations related to the contract and generate corresponding verifiable evidence to illustrate the validity of the execution of the contract operations. Transactions in smart contracts can be queried and are irreversible. Before the deployment of a smart contract, the logical flow of all terms related to the contract has been established. Smart contracts usually have a user interface for users to interact with the established contract, and these interactions strictly follow the previously established logic. Thanks to cryptographic technology, these interactions can be strictly verified to ensure that the contract can be smoothly executed according to the previously established rules, thereby preventing breach of contract. Compared with traditional contracts, smart contracts improve security and uniqueness, and use commitments defined in digital form to ensure the security and reliability of the agreement of the contract participants. A smart contract can include a set of commitments defined in digital form, as well as protocols on which the contract participants can execute these commitments.
[0082] The migration assistance contract and business contract deployed on the blockchain node mentioned in the embodiments of this application are smart contracts that implement different functions. Smart contracts can be deployed on the nodes of the blockchain network, and the functions of upgrading and canceling smart contracts can also be provided.
[0083] This application will be described by the following examples:
[0084] See also Figure 2A In the application environment shown in the embodiment of the present application, the original blockchain is the blockchain corresponding to the blockchain node system 100 running the blockchain network, the target blockchain is the blockchain corresponding to the blockchain node system 200 running the target blockchain network, and the blockchain node system refers to a system for sharing data between nodes, which may include multiple blockchain nodes, such as Figure 2A As shown, the blockchain node system 100 includes multiple blockchain nodes 1001, 1002, 1003... The blockchain node system 200 includes blockchain nodes 2001, 2002, 2003... Each node can receive input information during normal operation and maintain the shared data in the system based on the received input information. In order to ensure the information intercommunication within the system, there can be an information connection between each node in the system, and the nodes can transmit information through the above information connection. For example, when any node in the system receives input information, other nodes in the system obtain the input information according to the consensus algorithm, and store the input information as data in the shared data, so that the data stored on all nodes in the system are consistent.
[0085] Each node in the blockchain node system has a corresponding node identifier, and each node in the blockchain node system can store the node identifiers of other nodes in the blockchain node system, so that the generated blocks can be broadcast to other nodes in the blockchain node system according to the node identifiers of other nodes. A node identifier list as shown in the following table can be maintained in each node, and the node name and node identifier are stored in the node identifier list accordingly. Among them, the node identifier can be an IP (Internet Protocol, a protocol for interconnection between networks) address and any other information that can be used to identify the node. Table 1 only uses the IP address as an example for illustration.
[0086] Node Name Node ID Node 1 xxx.xxx.xxx.xxx Node 2 xxx.xxx.xxx.xxx … … Node N xxx.xxx.xxx.xxx
[0087] Each node in the blockchain node system stores the same blockchain. The blockchain consists of multiple blocks, see Figure 2B The blockchain consists of multiple blocks. The genesis block includes a block header and a block body. The block header stores the input information characteristic value, version number, timestamp and difficulty value, and the block body stores the input information; the next block of the genesis block takes the genesis block as the parent block, and the next block also includes a block header and a block body. The block header stores the input information characteristic value of the current block, the block header characteristic value, version number, timestamp and difficulty value of the parent block, and so on, so that the block data stored in each block in the blockchain is associated with the block data stored in the parent block, ensuring the security of the input information in the block.
[0088] When generating each block in the blockchain, see Figure 2C When the node where the blockchain is located receives the input information, it verifies the input information. After the verification is completed, the input information is stored in the memory pool and the hash tree used to record the input information is updated. After that, the update timestamp is updated to the time when the input information is received, and different random numbers are tried to calculate the eigenvalue multiple times so that the calculated eigenvalue can satisfy the following formula:
[0089] SHA256(SHA256(version+prev_hash+merkle_root+ntime+nbits+x))<TARGET
[0090] Among them, SHA256 is the eigenvalue algorithm used to calculate the eigenvalue; version (version number) is the version information of the relevant block protocol in the blockchain; prev_hash is the block header eigenvalue of the parent block of the current block; merkle_root is the eigenvalue of the input information; ntime is the update time of the update timestamp; nbits is the current difficulty, which is a fixed value within a period of time and is determined again after exceeding the fixed time period; x is a random number; TARGET is the eigenvalue threshold, which can be determined based on nbits.
[0091] In this way, when the random number that satisfies the above formula is calculated, the information can be stored accordingly, the block header and block body can be generated, and the current block can be obtained. Subsequently, the node where the blockchain is located sends the newly generated block to other nodes in the data sharing system according to the node identification of other nodes in the data sharing system. Other nodes verify the newly generated block and add the newly generated block to the blockchain stored in them after the verification is completed.
[0092] Due to various reasons such as insufficient performance of the original chain and complex architecture, in order to achieve blockchain version upgrades or technical architecture adjustments, it is necessary to migrate the blockchain data of the original chain to the target blockchain to complete the chain change. In the design of the relevant migration transaction execution process, there is no way to safely and reliably prove to blockchain users whether the current transaction is a migration transaction.
[0093] The implementation details of the technical solution of the embodiment of the present application are described in detail below:
[0094] Optionally, the original blockchain and the target blockchain are different types of blockchains. For example, the first blockchain can be a private blockchain and the second blockchain can be a consortium blockchain. It should be understood that the original blockchain in the embodiment of the present application will migrate transactions to the target blockchain due to version upgrades or technical architecture adjustments. The blockchain data migration method provided in the embodiment of the present application can be applied to Figure 2A In the application environment shown, the ledger data is migrated from the original blockchain corresponding to the blockchain node system 100 to the target blockchain corresponding to the blockchain node system 200.
[0095] In some embodiments, the blockchain data migration method provided in the embodiments of the present application can be applied to Figure 3 In the application environment shown, refer to Figure 3The block stored in the blockchain node 302 corresponding to the original blockchain is called the original chain block, and the original chain block includes the original chain transaction. The migration server 304 can obtain the original chain transaction from the blockchain node 302 corresponding to the original blockchain, and construct a migration transaction that can be parsed by the blockchain node 306 corresponding to the target blockchain according to the transaction data structure of the target blockchain and the original chain transaction, and send the migration transaction to the blockchain node 306 corresponding to the target blockchain. The migration transaction includes a contract identifier and an original chain read-write set, and the original chain read-write set is generated after calling the business contract corresponding to the contract identifier on the original blockchain to execute the original chain transaction. After receiving the migration transaction, blockchain node 306 first calls the migration assistance contract, and calls the business contract corresponding to the contract identifier through the migration assistance contract. Through the business contract, according to the read-write set data structure of the target blockchain, the new chain read-write set corresponding to the migration transaction is constructed according to the original chain read-write set. According to the contract identifier of the migration assistance contract, the migration transaction and the new chain read-write set corresponding to the migration transaction, a new chain transaction corresponding to the original chain transaction is constructed. The contract identifier of the migration assistance contract is used to mark that the new chain transaction comes from the original blockchain, and the new chain transaction is stored in the target blockchain.
[0096] Among them, the blockchain node 302 corresponding to the original blockchain communicates with the migration server 304 through the network, and the migration server 304 communicates with the blockchain node 306 corresponding to the target blockchain through the network. The blockchain node 302 corresponding to the original blockchain, the migration server 304, and the blockchain node 306 corresponding to the target blockchain can be implemented by an independent server or a server cluster composed of multiple servers.
[0097] It should be noted that after the blockchain data migration is started, the blockchain nodes of the target blockchain will not receive new transactions for the time being, but only support receiving migration transactions sent by the migration server, and call the migration assistance contract when receiving the migration transaction to mark the migration transaction. After the migration is completed, the migration assistance contract can be cancelled. The blockchain nodes of the target blockchain receive new transactions and cannot use the migration assistance contract, so they will not be marked with the contract logo of the migration assistance contract, thereby achieving a safe and reliable distinction between migration transactions and new transactions.
[0098] In one embodiment, Figure 4 As shown, a blockchain data migration method is provided, which can be executed by a blockchain node corresponding to a target blockchain, and includes the following steps:
[0099] Step 402, receiving a migration transaction, which is constructed according to the transaction data structure of the target blockchain based on the original chain transaction. The migration transaction includes a contract identifier and an original chain read-write set, which is generated after calling the business contract corresponding to the contract identifier on the original blockchain to execute the original chain transaction.
[0100] Specifically, the migration transaction may be received by a blockchain node in the blockchain network corresponding to the target blockchain. The blockchain node may be any one of the numerous blockchain nodes in the blockchain network corresponding to the target blockchain to implement blockchain migration. Optionally, the blockchain administrator of the target blockchain pre-configures a node selected from the numerous blockchain nodes as a node for executing blockchain migration. Optionally, a node may be selected from the numerous blockchain nodes as a node for executing blockchain migration by voting.
[0101] In the embodiment of the present application, the original blockchain and the target blockchain can be different types of blockchains, also known as heterogeneous blockchains, that is, the original blockchain and the target blockchain have different chain structures, mainly including different data structures and access methods. The goal of data migration for heterogeneous blockchains is to realize the conversion of transactions matching the chain structure of the original blockchain into transactions matching the chain structure of the target blockchain, and store them on the target blockchain. For example, the original blockchain is the Fabric blockchain, and the target blockchain is the Changan chain (chainmaker). The current blockchain system is replaced with a new blockchain system, while retaining the original block data of the current blockchain system, that is, migrating from Fabric to Chainmaker, which has the problem of incompatibility of read-write set data structures. In the embodiment of the present application, the original blockchain and the target blockchain can also be blockchains of the same type, but with different versions. For example, in some cases, you want to upgrade the version of the current blockchain system, but the data structures of blocks, read-write sets, etc. between the new and old versions are incompatible, such as migrating from Chainmaker 1.x to Chainmaker 2.x. Data structures such as read-write sets are incompatible, such as the data structures of the read-write sets of the original chain and the target chain are stored in key-value pairs, but the design of the key or version number is different.
[0102] The original blockchain and the target blockchain are the data provider and receiver respectively, which is equivalent to opening a secure channel between two heterogeneous blockchains, allowing secure data migration, which can well ensure the confidentiality, integrity and security of the migrated data.
[0103] The original chain transaction can be a transaction in any block on the original blockchain, and the transaction data structure of the original chain transaction matches the original blockchain. The migration server can obtain the block on the original blockchain, extract the original chain transaction from it, and parse the original chain transaction according to the transaction data structure of the original blockchain to obtain the parsing result, and then construct the migration transaction according to the transaction data structure of the target blockchain based on the parsing result. The migration transaction is constructed according to the transaction data structure of the target blockchain, so it matches the target blockchain. After the blockchain node corresponding to the target blockchain receives the migration transaction, it can call the migration transaction auxiliary contract to parse it and obtain the specific content of the migration transaction.
[0104] Optionally, the migration server may start from the first block on the original blockchain and read each block in sequence until the last block is read. For each block read, each transaction recorded in the block is read in sequence according to the order of each transaction recorded in the block. For each transaction read, that is, the original chain transaction, the original chain transaction is parsed, and a migration transaction matching the transaction data structure of the target blockchain is constructed according to the parsing result.
[0105] The previous article introduced the composition of the block. The detailed structure of each transaction in the block includes: the chain ID to which the contract belongs, the name of the smart contract to be called, the transaction type, the calling method, the input parameters required to call the smart contract, and the before and after values of the world state obtained after calling the smart contract to simulate the execution of the transaction, that is, the read-write set. The migration server can parse at least the contract identifier and the original chain read-write set from the original chain transaction, thereby constructing the migration transaction including the contract identifier and the original chain read-write set. The original chain read-write set is generated after calling the business contract corresponding to the contract identifier on the original blockchain to execute the original chain transaction.
[0106] Step 404: call the migration assistance contract.
[0107] The migration transaction constructed according to the contract identifier and the original chain read-write set is a type of transaction that can be processed by the blockchain node corresponding to the target blockchain by calling the migration auxiliary contract. In this way, after the blockchain node of the target blockchain receives the migration transaction, it will first call the migration transaction auxiliary contract, and after parsing, obtain its contract identifier and the original chain read-write set on the original blockchain. Then, the migration transaction auxiliary contract calls the business contract across contracts according to the business contract identifier, and updates the business read-write set to the corresponding new chain transaction read-write set through the business contract.
[0108] That is to say, after starting data migration, all transactions received by the blockchain node corresponding to the target blockchain are considered to be migration transactions, and the migration auxiliary contract is used first to process them. The blockchain node can first call the migration auxiliary contract to process the migration transaction, that is, the migration transaction is used as the input parameter of the migration auxiliary contract to process the migration transaction. In the related art, the business contract corresponding to the migration transaction is directly called, and then the business contract extracts the original chain read-write set and writes the original chain read-write set to the current business database. When there are multiple business contracts on the blockchain, such a function needs to be deployed for each business contract, which is complex and redundant for the implementation of the business contract. In comparison, in the embodiment of the present application, by uniformly calling the migration auxiliary contract first to process the migration transaction, the problem of complex and redundant implementation of the business contract is cleverly avoided, and a highly elegant and clear development experience is brought to the developer, which can enable the business contract to focus on processing the format conversion of the read-write set contained in the migration transaction. At the same time, by reducing the implementation complexity, the maintainability and scalability in the blockchain application development process are improved, and the goal of better meeting business needs in various application scenarios is further promoted.
[0109] If after migrating the data of the original blockchain to the target blockchain, the new blockchain still needs to continue running, which will generate additional data, these additional data will also be recorded on the target blockchain. In order to distinguish the migration transaction from the new transaction, both need to be marked. In the embodiment of the present application, by using a migration assistance contract, the contract identifier of the migration assistance contract is carried in the generated new chain transaction, which realizes a more convenient and clear migration transaction marking method, and provides a credible proof for the migration transaction, ensuring the reliability and security of the migration process. After the migration is completed, the migration assistance contract can be cancelled. In this way, the subsequent new transactions cannot call the migration assistance contract when they are uploaded to the chain, and will not be processed by the migration assistance contract, and will not be marked with the contract identifier of the migration assistance contract, thereby achieving the distinction and marking of the two.
[0110] Step 406: The business contract corresponding to the contract identifier is called through the migration auxiliary contract, and the new chain read-write set corresponding to the migration transaction is constructed according to the read-write set data structure of the target blockchain and the original chain read-write set through the business contract.
[0111] As mentioned above, the migration transaction contains the contract identifier and the original chain read-write set. The original chain read-write set is generated by calling the business contract corresponding to the contract identifier on the original blockchain to execute the original chain transaction. Considering the isolation of transaction data corresponding to different business contracts, the corresponding business contracts need to handle the corresponding transactions. The blockchain node can first call the migration auxiliary contract, and then the migration auxiliary contract uses a cross-contract call to call the corresponding business contract. Through the business contract, according to the read-write set data structure of the target blockchain, the new chain read-write set corresponding to the migration transaction is constructed according to the original chain read-write set.
[0112] In one embodiment, calling the business contract corresponding to the contract identifier through the migration assistance contract includes: parsing the transaction data structure of the migration transaction through the migration assistance contract to obtain the original chain read-write set related to each business contract identifier; calling the corresponding business contract according to the original chain read-write set related to each business contract identifier.
[0113] Optionally, the business contract identifier included in the migration transaction may be one or more, that is, the execution of the original chain transaction may call one or more business contracts. When the migration transaction includes multiple business contract identifiers, the blockchain node can parse the migration transaction through the migration auxiliary contract, obtain the original chain read-write set related to each business contract identifier, and call the corresponding business contract with the original chain read-write set as a parameter.
[0114] In this embodiment, the parsing task of the migration transaction is uniformly implemented by the migration auxiliary contract, which makes the parsing process more efficient and reduces the risk of data inconsistency during the parsing process. In addition, compared with parsing the migration transaction separately through each business contract, the coding burden of the business contract can be reduced.
[0115] In one embodiment, the method further includes: extracting the read set in the original chain read-write set through the migration auxiliary contract; checking the validity of the migration transaction according to the extracted read set in the original chain read-write set; after the validity check passes, executing the step of calling the corresponding business contract according to the original chain read-write set related to each business contract.
[0116] In one embodiment, the validity of the migration transaction is checked based on the read set in the extracted read-write set of the original chain, including: obtaining the version number of the read set in the extracted read-write set of the original chain; checking whether the version number is consistent with the version number of the read set recorded in the world state database corresponding to the target blockchain; if they are consistent, determining that the transaction validity check has passed; if they are inconsistent, determining that the transaction validity check has failed.
[0117] To ensure the validity of the migration transaction, the blockchain node can verify through the migration auxiliary contract whether the version number of the read set in the original chain read-write set is inconsistent with the version number stored in the world state database corresponding to the local target blockchain. If they are inconsistent, it means that the migration transaction has changed the data and the migration transaction is invalid. If they are consistent, it means that the migration transaction is valid.
[0118] In one embodiment, the migration transaction also includes an endorsement signature. The blockchain node can also call the business contract corresponding to the contract identifier through the migration auxiliary contract, query the corresponding endorsement policy, and verify whether the endorsement signature in the migration transaction is consistent with the endorsement policy corresponding to the query. If it is consistent, it means that the migration transaction is valid, otherwise, it means that the migration transaction is invalid.
[0119] In one embodiment, before calling the business contract corresponding to the contract identifier through the migration assistance contract, the method further includes: performing a transaction authority check on the migration transaction through the migration assistance contract; and calling the business contract corresponding to the contract identifier after the transaction authority check passes.
[0120] In order to ensure the reliability of the source of the migration transaction, the blockchain node can perform permission verification on the received migration transaction. Only after the permission verification is passed, the corresponding business contract will be called according to the migration transaction. In this embodiment, the permission management of the migration transaction is centralized in the migration auxiliary contract, which simplifies the permission management process and improves the management efficiency. It is not necessary to set up redundant migration transaction permission verification functions in the business contract, but to implement them in the migration auxiliary contract, ensuring that the business contract only focuses on the conversion of the read-write set data format related to the current business.
[0121] In one embodiment, the migration transaction is checked for transaction permissions through the migration assistance contract, including: obtaining, through the migration assistance contract, the identity information of the builder of the migration transaction based on the received migration transaction, querying whether there is migration transaction building permission associated with the identity information, and when it is found that the identity information has corresponding migration transaction building permission, determining that the transaction permission check has passed; when it is found that the identity information does not have corresponding migration transaction building permission, determining that the transaction permission check has failed.
[0122] For computer devices that have the ability to obtain original chain transactions from the original blockchain to construct migration transactions, they can attach identity information that can be marked with corresponding permissions when sending migration transactions based on the authorized identity information. When the blockchain node receives the migration transaction, it can call the migration auxiliary contract to verify the identity information, thereby determining whether the builder of the migration transaction has the permission to construct the migration transaction.
[0123] Optionally, the migration auxiliary contract can first perform permission verification, and then perform migration transaction parsing if the permission verification passes. After parsing the original chain read-write set and the contract identifier, the business contract corresponding to the contract identifier is called to specifically execute subsequent steps, that is, construct a new chain read-write set and a new chain transaction based on the original chain read-write set; if the permission verification fails, the processing of the migration transaction is terminated.
[0124] It can be seen that in the above embodiment, by implementing unified transaction parsing and permission management by the migration auxiliary contract, in the scenario where there are cross-contract calls, there is no need to perform transaction parsing and permission verification functions separately after each business contract receives the migration transaction, thereby eliminating repeated transaction parsing and permission management, and significantly improving the blockchain migration performance.
[0125] After the migration auxiliary contract completes the above-mentioned transaction parsing and permission verification, the business contract corresponding to the contract identifier and the original chain read-write set parsed from the migration transaction is called. Through the called business contract, the new chain read-write set corresponding to the migration transaction is constructed to complete the format conversion of the read-write set.
[0126] Step 408: construct a new chain transaction corresponding to the original chain transaction according to the contract identifier of the migration assistance contract, the migration transaction, and the new chain read-write set corresponding to the migration transaction. The contract identifier of the migration assistance contract is used to mark that the new chain transaction comes from the original blockchain.
[0127] Step 410: Store the new chain transaction in the target blockchain.
[0128] Due to the immutable nature of the blockchain system, the data timestamp in the target blockchain will be updated to the timestamp at the time of migration, rather than the timestamp when the original chain transaction was generated. Therefore, after completing the format conversion of the above read-write set, the new chain transaction can be constructed based on the converted new chain read-write set and stored in the target blockchain.
[0129] In one embodiment, the business contract constructs a new chain read-write set corresponding to the migration transaction according to the read-write set data structure of the target blockchain and the original chain read-write set, including: extracting key-value pairs from the read-write set through the business contract, and constructing a new chain read-write set corresponding to the migration transaction according to the extracted key-value pairs according to the read-write set data structure of the target blockchain.
[0130] It can be understood that the blockchain node needs to store the corresponding new chain transaction in the target blockchain according to the execution order of the original chain transaction in the original blockchain. For example, original chain transaction 1, original chain transaction 2 and original chain transaction 3 are converted into new chain transaction 1, new chain transaction 2 and new chain transaction 3 respectively. The execution order of original chain transaction 1, original chain transaction 2 and original chain transaction 3 in the original blockchain is to execute original chain transaction 1 first, then execute original chain transaction 2, and finally execute original chain transaction 3. Then the blockchain node executes in sequence: first generate the corresponding new chain transaction 1 and then store it in the target blockchain, then generate the corresponding new chain transaction 2 and then store it in the target blockchain, and finally generate the corresponding new chain transaction 3 and then store it in the target blockchain.
[0131] Since the new chain transaction stored on the target blockchain is migrated from the original blockchain, the new chain transaction stored on the target blockchain should have such a credible proof. When constructing the new chain transaction corresponding to the migration transaction, the new chain transaction corresponding to the original chain transaction is constructed according to the contract identifier of the migration auxiliary contract, the migration transaction and the new chain read-write set corresponding to the migration transaction. In other words, the contract identifier of the migration auxiliary contract is stored in the new chain transaction to mark that the new chain transaction comes from the original blockchain.
[0132] In some embodiments, in order to further prove the detailed source of the new chain transaction, such as which blockchain the new chain transaction originates from, which block of the original blockchain it originates from, or which original chain transaction it originates from, the business contract may also mark the transaction information of the original chain transaction from which the new chain transaction originates in the new chain transaction, and the transaction information may include at least one of the calling address of the original blockchain where the original chain transaction is located, the block identifier of the block where it is located, and the transaction hash.
[0133] In some embodiments, in order to indicate how to query the new chain transaction corresponding to the original chain transaction, the blockchain node corresponding to the original blockchain can also record the transaction information of the new chain transaction corresponding to the original chain transaction in the original blockchain. The transaction information may include at least one of the calling address of the target blockchain where the new chain transaction is located, the block identifier of the block where it is located, and the transaction hash.
[0134] In one embodiment, storing the new chain transaction to the target blockchain includes: adding the new chain transaction to a transaction pool associated with the target blockchain; packaging the new chain transaction into a block to be verified in the transaction pool; determining a target block for writing into the target blockchain according to the block to be verified, and writing the target block into the blockchain database of the target blockchain.
[0135] Specifically, the new chain transaction submitted by the blockchain node through the business contract will be placed in the transaction pool and wait. Through packaging, the data of different transactions will be combined to form a block to be verified. Then, the block hash corresponding to the block to be verified is generated, and it is combined with the block hash of the previous block to form a target block, and the target block is written into the target blockchain.
[0136] In one embodiment, the method further includes: updating the world state data of the target blockchain according to the write set in the new chain read-write set corresponding to the new chain transaction; and storing the updated world state data in the world state database of the target blockchain.
[0137] Specifically, the new chain read-write set can reflect which data in the state database is read, written, and deleted during the simulation execution of the new chain transaction. The value of the current business contract is stored in the world state database, that is, the data related to different business contracts are isolated, and the value of the current business contract is updated by accessing the world state database corresponding to the business contract.
[0138] The above-mentioned blockchain data migration method receives a migration transaction during the data migration process. The migration transaction is constructed according to the original chain transaction according to the transaction data structure of the target blockchain. The migration transaction includes a contract identifier and an original chain read-write set. The original chain read-write set is generated after calling the business contract corresponding to the contract identifier on the original blockchain to execute the original chain transaction. After receiving the migration transaction, the migration auxiliary contract is called, and then the business contract corresponding to the contract identifier is called through the migration auxiliary contract, so as to construct a new chain read-write set corresponding to the migration transaction according to the original chain read-write set according to the read-write set data structure of the target blockchain through the business contract. Then, according to the contract identifier of the migration auxiliary contract, the migration transaction and the new chain read-write set corresponding to the migration transaction, a new chain transaction corresponding to the original chain transaction is constructed. The contract identifier of the migration auxiliary contract in the new chain transaction is used to mark that the new chain transaction comes from the original blockchain, and the new chain transaction is stored in the target blockchain to realize the data migration of the blockchain. At the same time, during the migration process, since the migration auxiliary contract is called first when the migration transaction is received, and then the migration auxiliary contract calls the business contract corresponding to the migration transaction, when the new chain transaction corresponding to the original chain transaction is constructed according to the migration transaction, the contract identifier of the called migration auxiliary contract can be marked in the new chain transaction. In this way, it is ensured that the transaction content that includes the contract identifier of the auxiliary migration contract must be a migration transaction, thereby achieving the purpose of safely and reliably proving that the current transaction is a migration transaction from the original chain.
[0139] In the related technology, the migration transaction first calls the business contract corresponding to the migration transaction, and then the specific business contract checks the migration transaction permissions. After completing the permission check, the business contract parses the migration transaction to obtain the corresponding original chain transaction data, and then parses the original chain transaction data to obtain the original chain transaction, extracts the original chain transaction read-write set, and writes the original chain transaction write set into the blockchain database corresponding to the target blockchain after converting the format.
[0140] The defects of this method are: 1. Since multiple business contracts may be used in a chain, according to this method, it is necessary to add transaction permission verification logic and original chain transaction parsing function to each business contract. The addition of these codes not only increases the complexity of the business contract, but also makes it inconvenient to uniformly manage the business contract permissions. The transaction permission verification and original chain transaction parsing codes are repeated and redundant for all business contracts. 2. This method cannot safely and reliably prove to blockchain users whether the current transaction is a migration transaction from other blockchains. In the relevant technology, generally only an identification field can be added to the migration transaction to identify whether the current transaction is a migration transaction, but this method cannot prevent builders who do not have the construction authority from setting the corresponding field in the non-migration transaction as the migration transaction identifier to impersonate the migration transaction, resulting in the inability to safely and reliably prove whether the current transaction is a migration transaction from the original chain.
[0141] In the embodiment of the present application, by adding a migration auxiliary contract to the blockchain node corresponding to the target blockchain, all migration transactions first call the migration auxiliary contract, and then the migration auxiliary contract completes the migration transaction authority verification and migration transaction parsing. When the authority verification passes and the original chain read-write set and contract identifier are parsed, the migration auxiliary contract calls the business contract corresponding to the migration transaction through the contract call method, and the business contract only needs to focus on the format conversion operation of the read-write set. Especially in the case of multiple business contracts, there are many cross-contract calls. Compared with the method in which each business contract performs authority verification and transaction parsing by itself, the number of business contract call layers is reduced, and the clarity of the business contract call logic is improved, thereby optimizing the maintainability and scalability of the entire blockchain system, which can significantly improve the execution performance of migration transactions and effectively support the needs of various business scenarios.
[0142] like Figure 5 FIG. 1 is a flow chart of data migration in one embodiment. Figure 5After starting data migration, for the received migration transaction, the migration auxiliary contract is first called, and the transaction authority verification of the received migration transaction is performed through the migration auxiliary contract. If the verification fails, the processing of the received migration transaction is terminated. If the verification passes, the received migration transaction is further parsed through the migration auxiliary contract to obtain the original chain read-write set and contract identifier included in the migration transaction, and the business contract corresponding to the contract identifier is called through a cross-contract call. The business contract then constructs a new chain read-write set that conforms to the target blockchain based on the original chain read-write set, and constructs a new chain transaction based on the contract identifier, the new chain read-write set and the contract identifier of the migration auxiliary contract, and adds the new chain transaction to the target blockchain.
[0143] like Figure 6 FIG. 1 is a functional diagram of each smart contract for implementing data migration in one embodiment. Figure 6 After receiving the migration transaction, the blockchain node corresponding to the target blockchain calls the migration auxiliary contract to verify the transaction authority of the received migration transaction, and parses the received migration transaction to obtain the original chain read-write set and contract identifier included in the migration transaction, and then calls other business contracts through cross-contract calls, and processes the business-related read-write sets through other business contracts.
[0144] like Figure 7 As shown in the figure, it is a functional diagram of each smart contract for realizing data migration in the related technology. Figure 7 After receiving the migration transaction, the blockchain node corresponding to the target blockchain randomly constructs a contract identifier and then calls a business contract to verify the transaction authority of the received migration transaction, and parses the received migration transaction to obtain the original chain read-write set and contract identifier included in the migration transaction. Only then can the subsequent new chain construction transaction be performed and stored on the target blockchain. In addition, the business contract needs to continue to call other business contracts according to the migration transaction through cross-contract calls. Other business contracts also need to repeatedly verify the transaction authority of the received migration transaction, and parse the received migration transaction to obtain the original chain read-write set related to the current business contract included in the migration transaction. Only then can the subsequent new chain construction transaction be performed and stored on the target blockchain.
[0145] In a specific embodiment, Figure 8 As shown, the data migration method of the blockchain includes the following steps:
[0146] Step 802, after receiving the data migration start instruction, running the migration assistance contract;
[0147] Step 804: receiving a migration transaction, which is constructed according to the transaction data structure of the target blockchain and the original chain transaction. The migration transaction includes a contract identifier and an original chain read-write set, which is generated after the business contract corresponding to the contract identifier on the original blockchain is called to execute the original chain transaction;
[0148] Step 806: Call the migration assistance contract to perform a transaction permission check on the migration transaction through the migration assistance contract. After the transaction permission check passes, parse the transaction data structure of the migration transaction to obtain the original chain read-write set related to each business contract identifier;
[0149] Step 808, calling the corresponding business contract according to the original chain read-write set related to each business contract identifier;
[0150] Step 810: extract key-value pairs from the read-write set through the business contract, and construct a new chain read-write set corresponding to the migration transaction according to the extracted key-value pairs according to the read-write set data structure of the target blockchain;
[0151] Step 812: construct a new chain transaction corresponding to the original chain transaction through the business contract according to the contract identifier of the migration assistance contract, the migration transaction, and the new chain read-write set corresponding to the migration transaction. The contract identifier of the migration assistance contract is used to mark that the new chain transaction comes from the original blockchain.
[0152] Step 814, adding the new chain transaction to the transaction pool associated with the target blockchain through the business contract;
[0153] Step 816, packaging the new chain transaction into a block to be verified in the transaction pool;
[0154] Step 818, determining a target block for writing into the target blockchain according to the block to be verified, and writing the target block into the blockchain database of the target blockchain;
[0155] Step 820: Update the world state data of the target blockchain according to the write set in the new chain read-write set corresponding to the new chain transaction;
[0156] Step 822, storing the updated world state data in the world state database of the target blockchain;
[0157] Step 824: After receiving the instruction to end the data migration, cancel the migration assistance contract.
[0158] As described above, there are many problems in the relevant technologies. For example, it is impossible to reliably prove whether the current transaction is a migration transaction, which greatly reduces the security and credibility of the blockchain migration solution. In addition, too much non-business logic is added to the business contract, which not only increases the mental burden of developers, but also makes the migration solution less elegant.
[0159] This embodiment can achieve the following technical effects:
[0160] 1. Clearly marked and proved migration transactions: By using the migration auxiliary contract, a more convenient and clear way of marking migration transactions is achieved, and credible proof is provided for migration transactions to ensure the reliability and security of the migration process.
[0161] 2. Clear migration rules: The clear migration rules provided enable users to better determine migration transactions and improve the completeness of the blockchain migration solution.
[0162] 3. Unified authority management: The authority verification and management of migration transactions are unified and centralized in the migration auxiliary contract, which simplifies the authority management process and improves management efficiency. In other words, the original complex and redundant migration transaction authority verification function for business contracts is implemented in the migration auxiliary contract, which is elegant and clear enough for developers, and also ensures that the business contract only focuses on the format conversion of the write set data related to the current business.
[0163] 4. Centralized business data analysis: The business data analysis tasks are centralized in the migration assistance contract, making the analysis process more efficient, reducing the risk of data inconsistency during the analysis process, and alleviating the coding burden of the business contract.
[0164] 5. Reduce the number of business contract call layers: In business scenarios with multi-layer contract calls, the number of business contract call layers is reduced, the clarity of the contract call logic is improved, and the maintainability and scalability of the entire blockchain system are optimized.
[0165] 6. Improved execution performance of migration transactions: In scenarios with a large number of cross-contract call transactions, the execution performance of migration transactions has been significantly improved, effectively supporting the needs of various business scenarios.
[0166] 7. Improve system performance: By implementing unified transaction parsing and permission management, repeated transaction parsing and permission management are eliminated in transactions with cross-contract calls, significantly improving blockchain migration performance.
[0167] In summary, the embodiments of the present application have brought significant changes in terms of clearly proving migration transactions, unified authority management, centralized business data analysis, reducing the number of business contract call layers, and improving the execution performance of migration transactions. At the same time, by optimizing the logical calls of migration transactions, it not only reduces the amount of code in the business contract, but also ensures the security of the chain and the clarity of the rules, thereby improving the perfection of the entire blockchain migration solution.
[0168] It should be understood that, although the steps in the flowcharts of the embodiments described above are shown in sequence according to the instructions of the arrows, these steps are not necessarily performed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the flowcharts of the embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of the steps or stages in other steps.
[0169] Based on the same inventive concept, the embodiment of the present application also provides a blockchain data migration device for implementing the blockchain data migration method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of the data migration device for one or more blockchains provided below can refer to the limitations of the blockchain data migration method above, and will not be repeated here.
[0170] In one embodiment, Fig. 9 As shown, a blockchain data migration device 900 is provided, including: a receiving module 902, a migration auxiliary contract calling module 904, a cross-contract calling module 906, a new chain transaction construction module 908 and a storage module 910, wherein:
[0171] The receiving module 902 is used to receive a migration transaction, which is constructed according to the transaction data structure of the target blockchain and the original chain transaction. The migration transaction includes a contract identifier and an original chain read-write set, which is generated after the business contract corresponding to the contract identifier on the original blockchain is called to execute the original chain transaction;
[0172] A migration assistance contract calling module 904, used to call a migration assistance contract;
[0173] The cross-contract calling module 906 is used to call the business contract corresponding to the contract identifier through the migration auxiliary contract, and construct the new chain read-write set corresponding to the migration transaction according to the read-write set data structure of the target blockchain and the original chain read-write set through the business contract;
[0174] A new chain transaction construction module 908 is used to construct a new chain transaction corresponding to the original chain transaction according to the contract identifier of the migration assistance contract, the migration transaction and the new chain read-write set corresponding to the migration transaction. The contract identifier of the migration assistance contract is used to mark that the new chain transaction comes from the original blockchain;
[0175] The storage module 910 is used to store the new chain transaction in the target blockchain.
[0176] Optionally, the blockchain data migration device 900 further includes:
[0177] The world state update module is used to update the world state data of the target blockchain according to the write set in the new chain read-write set corresponding to the new chain transaction; and store the updated world state data in the world state database of the target blockchain.
[0178] Optionally, the blockchain data migration device 900 further includes:
[0179] The permission check module is used to perform a transaction permission check on the migration transaction through the migration assistance contract before calling the business contract corresponding to the contract identifier through the migration assistance contract; after the transaction permission check passes, the business contract corresponding to the contract identifier is called.
[0180] Optionally, the permission check module is further used to obtain the identity information of the builder of the migration transaction according to the received migration transaction through the migration assistance contract; query whether there is a migration transaction construction permission associated with the identity information; when it is queried that the identity information has the corresponding migration transaction construction permission, determine that the transaction permission check has passed; when it is queried that the identity information does not have the corresponding migration transaction construction permission, determine that the transaction permission check has failed.
[0181] Optionally, the blockchain data migration device 900 further includes:
[0182] The transaction parsing module is used to parse the transaction data structure of the migration transaction through the migration auxiliary contract to obtain the original chain read-write set related to each business contract identifier;
[0183] The cross-contract calling module 906 is used to call the corresponding business contract according to the original chain read-write set related to each business contract identifier.
[0184] Optionally, the blockchain data migration device 900 further includes:
[0185] A validity check module, used to extract the read set in the original chain read-write set through the migration auxiliary contract; and check the validity of the migration transaction according to the extracted read set in the original chain read-write set;
[0186] The cross-contract calling module 906 is used to call the corresponding business contract according to the original chain read-write set related to each business contract after the validity check is passed.
[0187] Optionally, the validity check module is used to obtain the version number of the read set in the extracted read-write set of the original chain; check whether the version number is consistent with the version number of the read set recorded in the world state database corresponding to the target blockchain; if they are consistent, it is determined that the transaction validity check has passed; if they are inconsistent, it is determined that the transaction validity check has failed.
[0188] Optionally, the blockchain data migration device 900 further includes:
[0189] The new chain read-write set construction module is used to extract key-value pairs from the read-write set through the business contract, and construct the new chain read-write set corresponding to the migration transaction according to the extracted key-value pairs according to the read-write set data structure of the target blockchain.
[0190] Optionally, the storage module 910 is used to add the new chain transaction to a transaction pool associated with the target blockchain; package the new chain transaction into a block to be verified in the transaction pool; determine a target block for writing into the target blockchain based on the block to be verified, and write the target block into the blockchain database of the target blockchain.
[0191] Optionally, the blockchain data migration device 900 further includes:
[0192] A startup module, used to run the migration assistance contract after receiving a startup instruction for data migration;
[0193] The contract cancellation module is used to cancel the migration assistance contract after receiving the end instruction of data migration.
[0194] The data migration device 900 of the above-mentioned blockchain receives a migration transaction during the data migration process. The migration transaction is constructed according to the original chain transaction according to the transaction data structure of the target blockchain. The migration transaction includes a contract identifier and an original chain read-write set. The original chain read-write set is generated after calling the business contract corresponding to the contract identifier on the original blockchain to execute the original chain transaction. After receiving the migration transaction, the migration auxiliary contract is called, and then the business contract corresponding to the contract identifier is called through the migration auxiliary contract, so as to construct a new chain read-write set corresponding to the migration transaction according to the original chain read-write set according to the read-write set data structure of the target blockchain through the business contract. Then, according to the contract identifier of the migration auxiliary contract, the migration transaction and the new chain read-write set corresponding to the migration transaction, a new chain transaction corresponding to the original chain transaction is constructed. The contract identifier of the migration auxiliary contract in the new chain transaction is used to mark that the new chain transaction comes from the original blockchain, and the new chain transaction is stored in the target blockchain to realize the data migration of the blockchain. At the same time, during the migration process, since the migration auxiliary contract is called first when the migration transaction is received, and then the migration auxiliary contract calls the business contract corresponding to the migration transaction, when the new chain transaction corresponding to the original chain transaction is constructed according to the migration transaction, the contract identifier of the called migration auxiliary contract can be marked in the new chain transaction. In this way, it is ensured that the transaction content that includes the contract identifier of the auxiliary migration contract must be a migration transaction, thereby achieving the purpose of safely and reliably proving that the current transaction is a migration transaction from the original chain.
[0195] Each module in the above-mentioned blockchain data migration device 900 can be implemented in whole or in part by software, hardware, or a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0196] In one embodiment, a computer device is provided, which may be a blockchain node, and its internal structure diagram may be as follows: Fig.10As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store block data and status data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a data migration method of a blockchain is implemented.
[0197] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0198] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps of the blockchain data migration method provided in the embodiment of the present application are implemented.
[0199] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the blockchain data migration method provided in the embodiment of the present application are implemented.
[0200] In one embodiment, a computer program product is provided, including a computer program, which, when executed by a processor, implements the steps of the blockchain data migration method provided in the embodiment of the present application.
[0201] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0202] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0203] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0204] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A data migration method for blockchain, It is characterized in that The method comprises: Receive a migration transaction, wherein the migration transaction is constructed according to the transaction data structure of the target blockchain based on the original chain transaction, and the migration transaction includes a contract identifier and an original chain read-write set, wherein the original chain read-write set is generated after the business contract corresponding to the contract identifier on the original blockchain is called to execute the original chain transaction; Call the migration assistance contract; The business contract corresponding to the contract identifier is called through the migration auxiliary contract, and the new chain read-write set corresponding to the migration transaction is constructed according to the read-write set data structure of the target blockchain and the original chain read-write set through the business contract; According to the contract identifier of the migration assistance contract, the migration transaction, and the new chain read-write set corresponding to the migration transaction, a new chain transaction corresponding to the original chain transaction is constructed, wherein the contract identifier of the migration assistance contract is used to mark that the new chain transaction comes from the original blockchain; The new chain transaction is stored in the target blockchain.
2. The method according to claim 1, It is characterized in that The method further comprises: Update the world state data of the target blockchain according to the write set in the new chain read-write set corresponding to the new chain transaction; The updated world state data is stored in the world state database of the target blockchain.
3. The method according to claim 1, It is characterized in that Before calling the service contract corresponding to the contract identifier through the migration assistance contract, the method further includes: Performing a transaction authority check on the migration transaction through the migration assistance contract; After the transaction authority check is passed, the business contract corresponding to the contract identifier is called.
4. The method according to claim 3, It is characterized in that The performing transaction authority check on the migration transaction through the migration assistance contract includes: Acquiring, through the migration assistance contract, the identity information of the builder of the migration transaction according to the received migration transaction; Query whether there is a migration transaction construction permission associated with the identity information; When it is found that the identity information has the corresponding migration transaction building authority, it is determined that the transaction authority check has passed; when it is found that the identity information does not have the corresponding migration transaction building authority, it is determined that the transaction authority check has not passed.
5. The method according to claim 1, It is characterized in that The calling of the business contract corresponding to the contract identifier through the migration assistance contract includes: The transaction data structure of the migration transaction is parsed through the migration auxiliary contract to obtain the original chain read-write set related to each business contract identifier; Call the corresponding business contract according to the original chain read-write set related to each business contract identifier.
6. The method according to claim 5, It is characterized in that The method further comprises: Extracting the read set in the original chain read-write set through the migration assistance contract; Checking the validity of the migration transaction according to the extracted read set in the original chain read-write set; After the validity check is passed, the step of calling the corresponding business contract according to the original chain read-write set related to each business contract is executed.
7. The method according to claim 6, It is characterized in that The checking the validity of the migration transaction according to the extracted read set in the original chain read-write set includes: Obtaining the version number of the read set in the extracted original chain read-write set; Check whether the version number is consistent with the version number of the read set recorded in the world state database corresponding to the target blockchain; If they are consistent, the transaction validity check is determined to have passed; If they are inconsistent, it is determined that the transaction validity check has failed.
8. The method according to claim 1, It is characterized in that The constructing a new chain read-write set corresponding to the migration transaction according to the read-write set data structure of the target blockchain through the business contract and according to the original chain read-write set includes: The key-value pairs are extracted from the read-write set through the business contract, and according to the read-write set data structure of the target blockchain, a new chain read-write set corresponding to the migration transaction is constructed according to the extracted key-value pairs.
9. The method according to claim 1, It is characterized in that The storing the new chain transaction to the target blockchain includes: Adding the new chain transaction to a transaction pool associated with the target blockchain; Packing the new chain transactions into blocks to be verified in the transaction pool; A target block for writing into the target blockchain is determined according to the block to be verified, and the target block is written into the blockchain database of the target blockchain.
10. The method according to any one of claims 1 to 9, It is characterized in that The method further comprises: After receiving the data migration start instruction, running the migration assistance contract; After receiving the end instruction of the data migration, the migration assistance contract is cancelled.
11. A data migration device for blockchain, It is characterized in that The device comprises: A receiving module, used to receive a migration transaction, wherein the migration transaction is constructed according to the transaction data structure of the target blockchain based on the original chain transaction, and the migration transaction includes a contract identifier and an original chain read-write set, wherein the original chain read-write set is generated after the business contract corresponding to the contract identifier on the original blockchain is called to execute the original chain transaction; Migration assistance contract calling module, used to call the migration assistance contract; A cross-contract calling module, used to call the business contract corresponding to the contract identifier through the migration auxiliary contract, and construct a new chain read-write set corresponding to the migration transaction according to the read-write set data structure of the target blockchain through the business contract and the original chain read-write set; A new chain transaction construction module, used to construct a new chain transaction corresponding to the original chain transaction according to the contract identifier of the migration assistance contract, the migration transaction and the new chain read-write set corresponding to the migration transaction, wherein the contract identifier of the migration assistance contract is used to mark that the new chain transaction comes from the original blockchain; A storage module is used to store the new chain transaction in the target blockchain.
12. A computer device comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 10 are implemented.
13. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.
14. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.