This disclosure relates to the technical field of blockchains, including a smart contract-based data processing method and apparatus, an electronic device, a computer-readable storage medium, and a computer program product.
In a blockchain system, a smart contract is a code that may be understood and executed by each node on a blockchain, and may execute any logic and obtain a result. The smart contract may be understood to be an executable program, while the blockchain may be understood to be an operating system that provides a program running environment. In practice, the smart contract may be managed and tried through transactions on the blockchain.
In the blockchain network, a service object may invoke smart contracts already deployed on the blockchain by initiating a transaction. All the smart contracts are deployed and run on consensus nodes in the blockchain network. Each consensus node respectively runs the smart contract specified by the transaction. For the smart contract required for data reading, each consensus node will access respective account books. Finally, each consensus node will mutually verify whether execution results are consistent (reach a consensus). If yes, the execution results are stored in the respective account books, and the execution results are returned to the service object. The execution results may also be synchronized to other types of nodes. In this way, the number of data storage and the operation workload of the consensus nodes are greater. Furthermore, the consensus nodes are heavily loaded, thereby affecting data processing efficiency.
Embodiments of this disclosure provide a smart contract-based data processing method and apparatus, an electronic device, a computer-readable storage medium, and a computer program product, which can reduce the load of a consensus node and improve data processing efficiency.
In some examples, a method of contract-based data processing includes obtaining, by an electronic device at a service node in a service network, an initial contract invocation request for executing a transaction service. The initial contract invocation request includes a first contract identifier of a target chain contract that is deployed on a consensus node in a core consensus network. The method further includes determining, according to the first contract identifier of the target chain contract, a target local contract that is deployed at the service node and is associated with the target chain contract deployed at the consensus node, invoking the target local contract that executes a local service associated with the transaction service to obtain a local transaction execution result, and transmitting a target contract invocation request to the consensus node based on the local transaction execution result and the initial contract invocation request. The target contract invocation request causes the consensus node to invoke the target chain contract that executes a consensus service associated with the transaction service.
In some examples, a method for contract-based data processing includes obtaining, by an electronic device at a consensus node in a core consensus network, a target contract invocation request for executing a transaction service. The target contract invocation request indicates that a service node in a service network executes a local service associated with the transaction service to obtain a local transaction execution result in response to an initial contract invocation request. The method further includes invoking a target chain contract based on a first contract identifier in the target contract invocation request to execute a consensus service associated with the transaction service to obtain a chain transaction execution result.
In some examples, an apparatus for contract-based data processing at a service node in a service network includes processing circuitry. The processing circuitry is configured to obtain an initial contract invocation request for executing a transaction service. The initial contract invocation request includes a first contract identifier of a target chain contract that is deployed on a consensus node in a core consensus network. The processing circuitry is further configured to determine, according to the first contract identifier of the target chain contract, a target local contract that is deployed at the service node and is associated with the target chain contract deployed at the consensus node, invoke the target local contract that executes a local service associated with the transaction service to obtain a local transaction execution result, and transmit a target contract invocation request to the consensus node based on the local transaction execution result and the initial contract invocation request. The target contract invocation request causes the consensus node to invoke the target chain contract that executes a consensus service associated with the transaction service.
In the embodiments of this disclosure, a target local contract is deployed on a service node in a service network independent of a core consensus network, and a first mapping relationship between a first contract identifier and a second contract identifier corresponding to the target local contract is set. Before a consensus node of the core consensus network invokes a target chain contract deployed on the consensus node to execute a consensus service indicated by a transaction service, the service node in the service network may first obtain an initial contract invocation request for executing the transaction service, execute a local service indicated by the transaction service, and obtain a local transaction execution result. Furthermore, the service node may determine a target contract invocation request based on the local transaction execution result and the initial contract invocation request, and forward the target contract invocation request to the consensus node to execute the consensus service indicated by the transaction service. That is to say, before executing the consensus service, the service node may perform corresponding processing on the received contract invocation request before the consensus node, so that the local service executed on the consensus node is moved to the service node for processing, thereby reducing the resource consumption of the consensus node for executing the local service, reducing the load of the consensus node, and improving the transaction processing efficiency of a blockchain network.
To describe the technical solutions of the embodiments of this disclosure more clearly, the following briefly introduces the accompanying drawings required for describing the embodiments of this disclosure. The accompanying drawings in the following description show only some embodiments of this disclosure.
The technical solutions in embodiments of this disclosure are described in the following with reference to the accompanying drawings in the embodiments of this disclosure. The described embodiments are merely some rather than all of the embodiments of this disclosure.
Before the embodiments of this disclosure are further described in detail, nouns and terms in the embodiments of this disclosure are described, and the nouns and terms in the embodiments of this disclosure are applicable to the following explanations.
1) Transaction is equivalent to a computer term “transaction”, includes operations to be submitted to a blockchain network for execution, and does not refer solely to transactions in a business context. As the term “transaction” is used conventionally in a blockchain technology, the embodiments of this disclosure follow this convention.
For example, a deploy transaction is used for installing a specified smart contract to a node in the blockchain network, and the smart contract is ready to be invoked. An invoke transaction is used for adding a record of a transaction in a blockchain by invoking a smart contract, and performing operations on a state database of the blockchain, including an update operation (including a write operation (including addition and deletion of key-value pair data) and a delete operation) and a query operation (namely, querying a key-value pair in the state database).
2) The blockchain is a storage structure of encrypted and chained transactions formed by blocks.
For example, a header of each block may include both hash values of all the transactions in the block and hash values of all the transactions in the previous block, so as to realize anti-tampering and anti-forgery of the transactions in the block based on the hash values. After the newly generated transactions are filled into the blocks and reach the consensus of nodes in the blockchain network, the transactions are added to a tail of the blockchain to form a chain growth.
3) The blockchain network incorporates new blocks into a set of nodes of the blockchain in a consensus manner.
4) Smart contracts, also referred to as chaincodes or application codes, are programs deployed in the nodes of the blockchain network. The nodes execute the smart contracts invoked in the received transactions to update or query the key-value pair data of the state database.
Reference is made to
It is to be understood that the number of routing nodes in the routing network 1-3 may be one or more and is not limited herein. This embodiment of this disclosure is illustrated with a routing node 10D. The routing node 10D may be used for network isolation of the service network 1-1 and the core consensus network 1-2. The routing node 10D may be an independent physical server, a server cluster or a distributed system composed of a plurality of physical servers, or a cloud server providing basic cloud computing services, such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a network service, cloud communication, a middleware service, a domain name service, a security service, a content delivery network (CDN), and big data and artificial intelligence platforms. This is not limited herein. The routing node 10D may perform network hierarchy on a peer to peer (P2P) network to form a hierarchical structure of “service network 1-1-core consensus network 1-2”, and thus can improve the confidentiality and security of data on the blockchain.
The service network 1-1 (namely, a witness network) and the core consensus network 1-2 shown in
A blockchain node system (namely, a second blockchain node system) corresponding to the core consensus network 1-2 shown in
It is to be understood that in this embodiment of this disclosure, the routing node, the service node, and the consensus node may be collectively referred to as a blockchain node in the blockchain network 1W. The blockchain node may be a server accessing the blockchain network 1W or a user terminal accessing the blockchain network 1W. The specific form of the blockchain node is not limited herein. It is to be understood that the service network 1-1 and the core consensus network 1-2 shown in
It is to be understood that the blockchain system may include a smart contract. The smart contract is a code that may be understood and executed by each node (including the consensus node) of a blockchain in the blockchain system, and may execute any logic and obtain a result. In this embodiment of this disclosure, smart contracts deployed and running only on the service node of the service network 1-1 may be collectively referred to as a local contract, and smart contracts deployed on the consensus node of the core consensus network 1-2 may be collectively referred to as a chain contract. A service object (which may be a user requesting to execute a transaction service or a user requesting to deploy a smart contract) may invoke the smart contract (which may be the local contract or the chain contract) already deployed in the blockchain system by initiating a contract invocation request (which may also be referred to as a transaction service request) through a client on a user terminal. It is to be understood that the blockchain system may include one or more smart contracts. These smart contracts may be differentiated by a contract identifier (for example, an identity document (ID) or a name, or a contract address or a contract function name (also referred to as a contract method name)). In the contract invocation request initiated by the client, the ID or name of the smart contract may also be carried, thereby specifying a smart contract required to be run by the blockchain. If the smart contract specified by the client is a contract required for data reading, the relevant node will access the local storage to read data. For transactions to be uploaded, finally, various consensus nodes will mutually verify whether execution results are consistent (namely, perform consensus). If yes, the execution results may be stored in respective local accounts, and the execution results may be returned to the client.
In this embodiment of this disclosure, the chain contract specified to be invoked by the service object may be referred to as a target chain contract, and a contract identifier of the target chain contract may be referred to as a first contract identifier. Similarly, the local contract associated with the target chain contract may be referred to as a target local contract, and a contract identifier of the target local contract may be referred to as a second contract identifier. A consensus node and a node memory of a service node deployed with the target local contract both store a mapping relationship between the first contract identifier and the second contract identifier, and the mapping relationship may be referred to as a first mapping relationship. The service node herein specifically refers to a node in the service network 1-1 having an execution permission for the target local contract, and a node (for example, node 110a shown in
In this embodiment of this disclosure, the service node may first obtain an initial contract invocation request transmitted by a first user terminal. The first user terminal herein refers to a user terminal that transmits the initial contract invocation request. The initial contract invocation request includes a first contract identifier which may be used for executing a relevant transaction service. Then, a second contract identifier associated with a target chain contract is queried in a node memory of the service node based on the first contract identifier and a first mapping relationship, a target local contract may then be obtained based on the second contract identifier, and the target local contract may be invoked to execute a local service indicated by the transaction service, so as to obtain a local transaction execution result. Next, the service node may determine a target contract invocation request based on the local transaction execution result and the initial contract invocation request. After executing the local service, the target contract invocation request obtained may be the same as the initial contract invocation request or may be different from the initial contract invocation request. Subsequently, the service node may forward the target contract invocation request to the consensus node. After receiving the target contract invocation request, the consensus node may obtain a target chain contract based on the first contract identifier in the target contract invocation request, and may then invoke the target chain contract to execute a consensus service indicated by the transaction service, so as to obtain a chain transaction execution result. Finally, a block (namely, a to-be-uploaded block) to be added to a blockchain may be generated according to the chain transaction execution result, and the block may be uploaded. The blockchain is a blockchain to which the target chain contract belongs.
The local contract provided in this embodiment of this disclosure is a special contract which is not executed at the consensus node but only executed at the service node. The service node may first invoke the target local contract to execute the corresponding local service by specifying the target chain contract associated with the target local contract in the initial contract invocation request, and then the consensus node invokes the target chain contract to execute the corresponding consensus service. For example, for a blockchain established by the State General Administration, provincial administrations may be accessed as service nodes. In addition to meeting relevant national requirements, each province may have a different policy. At this moment, the service nodes of each province may deploy different local contracts to serve only this province. On the one hand, the local contract may be checked and calculated in advance to relieve the pressure of the consensus node. On the other hand, the local contract may access and utilize local service data, so that the local service data is not required to be uploaded, thereby reducing the storage pressure of the consensus node, while better protecting the privacy thereof.
Reference is made to
It is to be understood that the service node with the local contract deployed in the service network may invoke the local contract to execute a local service indicated by a transaction service, and any consensus node with the chain contract deployed in the core consensus network may invoke the chain contract to execute a consensus service indicated by the transaction service. For example, the transaction service herein may be an asset transfer service. The asset transfer service may be used for transferring virtual assets such as game currency, game diamonds, and electronic bills. The type of virtual assets will not be limited herein. For another example, the transaction service herein may be a file transfer service. The file transfer service may be used for transferring electronic files in various forms such as electronic contracts and electronic official documents. In addition, the transaction service herein may also be a query service, a storage service, or the like. This is not limited in this application. It is to be noted that when the local contract is deployed on the service node, an associated chain contract may be specified so that some data of the chain contract may be multiplexed.
As shown in
It is to be noted that each local contract may establish an association relationship with one or more chain contracts. In an implementation, a mapping relationship between a contract identifier of a local contract and a contract identifier of a chain contract associated with the local contract may be used for representing an association relationship therebetween, and the mapping relationships may be stored in a node memory or other storage modules of the consensus node and the associated service node in the form of a relationship mapping table. Reference is made to
As shown in
In an implementation, before one or more contract invocation requests are forwarded from a service node to a core chain (namely, the core consensus network), the service node may execute corresponding local contracts for pre-checking and filtering the contract invocation requests (referred to as pre-checking processing), and only contract invocation requests satisfying an uploading condition are finally forwarded to the core chain for processing. For example, in a transfer scenario, the contract invocation request D may be a request in the contract invocation request B that satisfies a transfer condition (referred to as an uploading condition). For another example, if the service node 20b checks that the amount of remaining assets of the service object A is greater than 500 yuan, namely, the contract invocation request B satisfies the transfer condition, the contract invocation request B may be forwarded to the consensus node 20c as the contract invocation request D. Then the consensus node 20c executes an operation of transferring 500 yuan to the service object F. On the contrary, if the amount of remaining assets of the service object A is less than 500 yuan, namely, the contract invocation request B does not satisfy the transfer condition, the service node 20b may generate request failure information (for example, information for prompting that the amount of remaining assets of the service object A is insufficient) according to the transaction execution result C, and return the request failure information to the user terminal 20a.
It is to be noted that in addition to the pre-checking processing exemplified above, local services indicated by different transaction services may also contain different contents, such as information completion processing or statistical classification processing. This is not limited by this embodiment of this disclosure.
The process in which the consensus node performs a transaction service is described below. As shown in
Subsequently, the consensus node 20c may return a transaction execution result (such as a transfer success result) to the user terminal 20a and a user terminal 20h bound with the service object F through the service node 20b. When the service object A queries the amount of remaining assets thereof through the user terminal 20a, the amount of remaining assets presented is the latest amount of remaining assets of the service object A. When the service object F queries the amount of remaining assets thereof through the user terminal 20h, the amount of remaining assets presented is the latest amount of remaining assets of the service object F.
It is to be understood that a smart contract-based data processing method according to an embodiment of this disclosure may be applied to service scenarios such as the transfer of virtual assets (for example, game currency, game diamonds, and electronic bills) or the transfer of electronic files (for example, electronic contracts or electronic official documents), or other service scenarios where checking and calculation are performed in advance through local contracts. Since the service node may process the received contract invocation request correspondingly before the consensus node invokes the local contract, it is not necessary to perform all the operations relevant to the contract invocation request on the consensus node. Thus, the data processing pressure of the consensus node can be reduced, the load of the consensus node can be reduced, and the overall transaction processing efficiency of the blockchain network can be improved.
Reference is made to
In step S101, an initial contract invocation request for executing a transaction service is obtained, the initial contract invocation request includes a first contract identifier for invoking a target chain contract, and both the consensus node and the service node storing a first mapping relationship between the first contract identifier and a second contract identifier.
In this embodiment of this disclosure, a target local contract is deployed on a specified service node in a service network, and a target chain contract is deployed on a consensus node of a core consensus network. The core consensus network is independent of the service network, and the two networks are isolated by a routing network. The service node may receive a transaction request (for example, a contract deployment request or an initial contract invocation request) transmitted from a user terminal, and the consensus node may receive the transaction request forwarded via the service node. The transaction request may be a request generated by the user terminal according to a transaction service initiated by a service object. In order to facilitate subsequent understanding and distinguishing, the user terminal transmitting the initial contract invocation request may be referred to as a first user terminal, and the user terminal transmitting the contract deployment request may be referred to as a second user terminal. The first user terminal and the second user terminal may be the same user terminal or may be different user terminals.
It is to be understood that the service object may deploy one or more local contracts on the service node by initiating the contract deployment request. Taking the deployment of a target local contract as an example herein, the service object may initiate a contract deployment request through the second user terminal, and the service object may deploy the target local contract on a specified service node through the contract deployment request. The specified service node may include one or more service nodes in the core consensus network.
It is to be understood that the service object may uniquely identify a smart contract by specifying a contract identifier (for example, an ID or a name) of the smart contract. A blockchain node (the service node or the consensus node) may invoke the corresponding smart contract through the contract identifier. In this embodiment of this disclosure, the contract identifier corresponding to the target chain contract is the first contract identifier, and the contract identifier corresponding to the target local contract is the second contract identifier. In view of this, the service object may also specify, in the contract deployment request, contract identifiers of one or more chain contracts associated with the target local contract. The one or more chain contracts include the target chain contract. Both the consensus node and the node memory or other storage modules (for example, a hard disk, a memory, a database, or the like) of the specified service node may store the first mapping relationship between the first contract identifier and the second contract identifier. It is to be understood that the process of deploying other local contracts is consistent with the process of deploying target local contracts, and the implementation of deploying local contracts may be described with reference to the corresponding step S201 of
It is to be understood that upon successful deployment of the target local contract, the specified service node may return a deployment success result to the second user terminal. Thus, the service object may initiate, by the first user terminal, an initial contract invocation request for executing a transaction service (for example, an asset transfer service, a file transfer service, a query service, a storage service, or the like). The initial contract invocation request may carry a first contract identifier corresponding to a target chain contract specified by the service object. The first user terminal may transmit the initial contract invocation request to one or more service nodes deployed with a target local contract. The one or more service nodes, after receiving the initial contract invocation request, may invoke the target local contract associated with the target chain contract according to the initial contract invocation request. The implementation of invoking the target local contract may be described with reference to step S102. For ease of illustration, the subsequent steps are illustrated with only one service node.
It is to be understood that the first user terminal and the second user terminal may be different user terminals. For example, the second user terminal is user terminal A, the first user terminal is user terminal B, and the service node may transmit a deployment success result to user terminal A after the deployment is completed. The service node may also transmit the deployment success result to user terminal B, whereby user terminal B may transmit the initial contract invocation request to the service node based on the deployment success result. In this embodiment of this disclosure, after receiving the deployment success result transmitted by the service node, user terminal A may transmit a notification to user terminal B that the deployment of the service node is completed, and then user terminal B may transmit the initial contract invocation request to the service node.
In step S102, based on the first contract identifier and the first mapping relationship, the second contract identifier is queried, a target local contract is determined based on the second contract identifier, and by invoking the target local contract, a local service indicated by the transaction service is executed to obtain a local transaction execution result.
It is to be understood that local contract information is stored in the service node (for example, in the node memory). The local contract information refers to information relevant to the local contract (including the target local contract) deployed on the service node. The local contract information may include a mapping relationship between contract identifiers of these local contracts and contract identifiers of the associated chain contracts. For example, a service node A is deployed with local contract A1 and local contract A2, local contract A1 is associated with a specified chain contract B1, and local contract A2 is associated with a specified chain contract B2. Both chain contract B1 and chain contract B2 are deployed on a consensus node B. Then, the service node A may store a mapping relationship between a contract identifier of local contract A1 and a contract identifier of chain contract B1 and a mapping relationship between a contract identifier of local contract A2 and a contract identifier of chain contract B2 in local contract information stored in a node memory thereof. In addition, the consensus node B may also store these mapping relationships in a node memory thereof.
It is to be understood that the mapping relationship may be stored in a relationship mapping table. The relationship mapping table includes the first mapping relationship between the first contract identifier and the second contract identifier. In an example, a form of the relationship mapping table may be described with reference to the relationship mapping table 20e shown in
In this embodiment of this disclosure, the service node may query, in the relationship mapping table, a contract identifier having the first mapping relationship with the first contract identifier, may determine the queried contract identifier as the second contract identifier associated with the target chain contract, and may then determine a local contract corresponding to the second contract identifier as the target local contract.
It is to be understood that one local contract has a unique mapping relationship with one chain contract. The relationship mapping table may include one or more mapping relationship columns. One of the mapping relationship columns may be used for storing one mapping relationship. Therefore, the service node may determine the mapping relationship column having the first contract identifier and the first mapping relationship stored in the relationship mapping table as a target mapping relationship column, and may then determine a contract identifier different from the first contract identifier stored in the target mapping relationship column as the second contract identifier. For example, referring again to
It is to be understood that the local contract information may further include a local contract function corresponding to the target local contract, and the service node may execute the local service indicated by the transaction service by invoking the local contract function. In this embodiment of this disclosure, the service node may first read a local contract function in the local contract information by invoking the target local contract, may access local service data associated with the local service from the node memory of the service node through the local contract function, and may then execute the local service indicated by the transaction service through the local service data to obtain a local transaction execution result.
In an implementation, the local contract information may further include a contract code. The service object may deploy the contract code (namely, a contract program statement) written by the service object in the target local contract. The contract code refers to the contract program statement supporting the target local contract to execute the local service. The contract code may include a contract function name corresponding to the local contract function and a function statement corresponding to the contract function name. The service node may invoke the target local contract to obtain the contract function name corresponding to the local contract function in the local contract information, and may then obtain the function statement corresponding to the contract function name. It is to be understood that the function statement may indicate a storage position where the local service data associated with the local service in the service node (for example, in the node memory) is located. That is, the service node may transmit a data read request to the node memory of the service node through the function statement, and may then obtain the local service data at the storage position. The local service data may be used for executing the local service indicated by the transaction service.
It is to be noted that the local service data may refer to data relevant to the service object served by the service node, and the local service data may be derived from an associated user terminal, or other blockchain nodes in the blockchain network (for example, other service nodes participating in the transaction service, or superior nodes of the service node, or consensus nodes in the core consensus network).
The local service refers to a service that may be executed by the service node using the local service data, for example, checking whether a certain contract invocation request satisfies an uploading condition (referred to as pre-checking processing, for example, checking whether the contract invocation request satisfies relevant policies of the corresponding province), or completing information unique to some service nodes (referred to as information completion processing, for example, allocating an invoice number, completing an official seal or signature, or the like), or performing statistics and classification on relevant transaction data and outputting the data in a specified format (referred to as statistics and classification processing, for example, performing statistics on the number of transactions transferred by a certain company on the current day). This is not limited in this application. The pre-checking processing and the information completion processing are described below as examples, respectively.
In a scenario where the local service is pre-checked, the local contract function may include a pre-checking function associated with the local service. The service node may access first local service data associated with the local service from the service node (for example, in the node memory) through the pre-checking function, and may then perform pre-checking processing on a request parameter in the initial contract invocation request based on the first local service data. At this moment, the local service data includes the first local service data.
For example, enterprise A transfers an electronic bill to enterprise B, thereby generating relevant request parameters. The service node may search historical transaction information of the electronic bill in the node memory thereof, so as to, for example, determine whether an account of enterprise A has the electronic bill, determine whether accounts of enterprise A and enterprise B are incorrect, determine the source of the electronic bill owned by enterprise A, and determine whether the number of the electronic bill is incorrect, or the like. In response to a pre-check result indicating that the request parameter satisfies the uploading condition indicated by the local service, the request parameter satisfying the uploading condition indicated by the local service may be determined as a valid request parameter, and then the valid request parameter may be taken as the local transaction execution result corresponding to the local service. On the contrary, in response to the pre-check result indicating that the request parameter does not satisfy the uploading condition indicated by the local service, the request parameter not satisfying the uploading condition indicated by the local service may be determined as an invalid request parameter, and the invalid request parameter may be taken as the local transaction execution result corresponding to the local service. Then, the service node may generate request failure information according to the invalid request parameter and then return the request failure information to the first user terminal that transmits the initial contract invocation request. That is to say, the service node may filter or intercept contract invocation requests not satisfying the uploading condition. The request failure information is used for indicating that the initial contract invocation request is rejected, and may include a specific reason for rejection, error information, or the like.
It is to be understood that pre-checking the initial contract invocation request on the service node may intercept some malicious or problematic requests, thereby reducing, on the one hand, the amount of calculation on the consensus node, relieving the data processing pressure of the consensus node, and reducing the number of contract invocation requests of the consensus node. On the other hand, when the consensus node does not have relevant determining capability, the service node may use own local service data for determination.
The specific content of the uploading condition is relevant to the transaction service, and will not be limited herein. For example, in an electronic bill scenario, the service node may be a service node having a target area attribute (for example, a province, a city, a region, or the like), the consensus node may be a superior node of the service node, and then the uploading condition may be a policy associated with the target area attribute (for example, a policy of a province, a policy of a city, a policy of a region, or the like). For example, a service node of a province A may pre-check whether a contract invocation request B (namely, the initial contract invocation request) for issuing an electronic bill satisfies a relevant policy of the province A. Only if the contract invocation request B satisfies the relevant policy of the province A (for example, a limit policy for a single transaction amount), the service node of the province A may re-forward the contract invocation request B to a country chain consisting of consensus nodes for subsequent processing. For another example, in a transfer scenario, the uploading condition may be that a transaction initiator has a sufficient amount of remaining assets. That is to say, when the amount of remaining assets of the transaction initiator is greater than or equal to the amount of to-be-transferred assets, the service node may forward a contract invocation request C for transfer to the consensus node, and the consensus node continues to perform the transfer operation. Otherwise, the service node may intercept the contract invocation request C.
It is to be understood that the request parameter may refer to a parameter relevant to the transaction service. The request parameter may contain different specific contents for different transaction services. For example, in an electronic bill scenario, the request parameters may include parameters relevant to circulation logic for the entire life cycle of the electronic bill. For another example, the request parameters may include electronic bill issuing information, electronic bill claim information, bill status of the electronic bill, access permission of data, keywords on the electronic bill, and the like. In the transfer scenario, the request parameter may include the amount of remaining assets of the transaction initiator, signature information, the amount of to-be-transferred assets, an identifier of a transaction receiver (such as an account number of the transaction receiver), and the like. In an electronic document scenario, the request parameter may include official seal information, signature information, status information, and the like of an electronic file.
In a scenario where the local service is information-completed, the local contract function may include an information completion function associated with the local service. The service node may access second local service data associated with the local service from the service node (for example, in the node memory) through the information completion function, and may then perform information completion processing on a request parameter in the initial contract invocation request based on the second local service data. Then, the information-completed request parameter may be taken as the local transaction execution result corresponding to the local service. At this moment, the local service data includes the second local service data. For example, in an electronic bill scenario, a provincial tax service may act as a service node that, when issuing an electronic bill, may complete some information unique to the provincial tax service, such as allocating an invoice number. For another example, in an electronic file scenario, before transferring an electronic file to the Supreme Court (namely, the consensus node) as the service node, a local court may complete official seal or signature, or the like of the local court.
It is to be understood that by deploying the local contract, the blockchain network may store some data originally stored on the consensus node on the service node, so as to use the data owned by the service node or the specific capability (such as the capability not possessed by the chain contract) to perform information completion (namely, data completion). Thus, multi-party interaction can be reduced, the storage pressure and calculation pressure of the consensus node can be relieved, and the privacy security of the data of the service node can also be improved.
In step S103, a target contract invocation request is transmitted to the consensus node based on the local transaction execution result and the initial contract invocation request, and by invoking the target chain contract, a consensus service indicated by the transaction service is executed, the target contract invocation request is used for obtaining, by the consensus node, the target chain contract based on the first contract identifier.
In an implementation, the blockchain network where the service network and the core consensus network are located may further include a routing network for performing network isolation. The service node may determine a target contract invocation request for being transmitted to the consensus node based on the local transaction execution result and the initial contract invocation request, and may then forward the target contract invocation request to the consensus node.
In conjunction with the foregoing step S102, the pre-checking processing and the information completion processing are still described below as examples, respectively.
In a scenario where the local service is pre-checked, when the local transaction execution result is a valid request parameter, the service node may determine an initial contract invocation request containing the valid request parameter as a target contract invocation request. That is to say, when the request parameter in the initial contract invocation request satisfies the uploading condition indicated by the local service, the initial contract invocation request and the target contract invocation request are the same contract invocation request. On the contrary, when the local transaction execution result is an invalid request parameter, the service node may intercept the initial contract invocation request and may return request failure information to the first user terminal. It is to be understood that if the number of initial contract invocation requests is one or more, the service node may determine a contract invocation request satisfying the uploading condition among the one or more initial contract invocation requests as a target contract invocation request. In this embodiment of this disclosure, the service node may forward the target contract invocation request to the consensus node through the routing node in the routing network. In addition, the service node may also transmit the target contract invocation request to the consensus node.
In a scenario where the local service is information-completed, the service node may generate the target contract invocation request according to the local transaction execution result and the initial contract invocation request. The target contract invocation request may include an information-completed request parameter. The information-completed request parameter may include an original request parameter in the initial contract invocation request and an updated request parameter generated after information completion processing (namely, a request parameter added with information of the service node). That is to say, the service node may add the updated request parameter to the request parameter of the initial contract invocation request. Thus, a target contract invocation request containing the information-completed request parameter may be obtained, and then the target contract invocation request may be forwarded to the consensus node through the routing node in the routing network, or the target contract invocation request may be directly transmitted to the consensus node without the aid of the routing node. It is to be understood that the initial contract invocation request and the target contract invocation request are different contract invocation requests at this moment.
For example, when issuing an electronic bill, a user terminal X1 (referred to as a first user terminal) may initiate a contract invocation request Y1 (referred to as an initial contract invocation request) for issuing an electronic bill, and the contract invocation request Y1 includes a request parameter Z1. After receiving the contract invocation request Y1, a service node X2 may allocate an invoice number for the electronic bill based on local service data thereof, generate a request parameter Z2 (referred to as an updated request parameter) according to the invoice number, and then add the request parameter Z2 to the request parameter Z1 of the contract invocation request Y1, thus obtaining a request parameter Z3 (referred to as an information-completed request parameter). Here, the contract invocation request Y1 containing the request parameter Z3 may be referred to as a contract invocation request Y2 (referred to as a target contract invocation request). The service node may then transmit the contract invocation request Y2 to a consensus node X4 through a routing node X3. In this embodiment of this disclosure, the service node may also update relevant fields in the initial contract invocation request according to the local transaction execution result to obtain the target contract invocation request containing updated fields, and may then forward the target contract invocation request (through the routing node or not) to the consensus node, so that the consensus node may invoke the target chain contract to parse the updated fields into updated request parameters.
It is to be noted that in this embodiment of this disclosure, the service node in the service network may correspond to different levels, for example, a superior-subordinate relationship (such as a county level, a municipal level, or a provincial level). After receiving an initial contract invocation request, a subordinate node may invoke a local contract deployed on the subordinate node to obtain a first contract invocation request, and then may transmit the first contract invocation request to a superior node. The superior node may invoke a local contract deployed on the superior node to obtain a second contract invocation request. In like manner, the contract invocation request obtained by the last level of service node may be taken as the target contract invocation request transmitted to the consensus node (having the highest level).
In this embodiment of this disclosure, after receiving the target contract invocation request, the consensus node may obtain a target chain contract based on the first contract identifier in the target contract invocation request, and may then invoke the target chain contract to execute a consensus service indicated by the transaction service. The specific implementation of the consensus node executing the consensus service may be described with reference to the corresponding step S302 of
It is to be noted that the target chain contract may be either a contract that has been successfully deployed on the consensus node or a null chain contract. In this embodiment of this disclosure, when the target chain contract is a null contract, the consensus node does not invoke any chain contract. In this embodiment of this disclosure, the service object may also directly specify the target local contract in the contract invocation request through the first user terminal. That is to say, the first user terminal may transmit the contract invocation request containing the second contract identifier to the service node deployed with the target local contract. The service node may obtain the target local contract based on the second contract identifier, may invoke the target local contract to execute the local service so as to obtain a local transaction execution result, and may then return the local transaction execution result to the first user terminal.
For example, when a service object A obtains a tax amount payable of the service object A within a time period, a contract invocation request B for calculating the tax amount may be initiated by a user terminal A1 (referred to as a first user terminal), and a contract identifier C1 (referred to as a second contract identifier) corresponding to a local contract C (referred to as a target local contract) relevant to the calculation of the tax amount may be specified in the contract invocation request B. Then the user terminal A1 may transmit the contract invocation request B to a service node A2, the service node A2 may obtain the local contract C through the contract identifier C1, and local service data D relevant to the calculation of the tax amount (for example, a tax payment policy, a tax payment formula, the income of the service object A, various expenditures, an occupied cultivated land area, or the like) may be obtained from a node memory of the service node A2 through the local contract C. Finally, the service node A2 may calculate a tax amount payable E (referred to as a local transaction execution result) of the service object A based on the local service data D, and return the tax amount payable E to the user terminal A1.
It is to be understood that the data processing load on the core consensus network caused by the deployment of new programs/services/processes on the core consensus network is reduced by performing some operations such as data statistics, query or calculation on the local contract (for example, writing some internally used codes in the local contract).
It is to be understood that other functions of the local contract may be customized by receiving custom requests from the service object for other functions of the local contract to accommodate different service scenarios in this embodiment of this disclosure. This is not limited in this application. In addition, the contract invocation method provided by this embodiment of this disclosure can reduce the error rate of contract invocation and facilitate the management of the smart contract, thereby improving the invocation efficiency of the smart contract. For example, each province has a different policy, and a local contract deployed by a service node of province A only serves province A, thus solving the problem that a person in province B erroneously invokes the local contract of province A.
Reference is made to
In step S201, a contract deployment request that is transmitted by a second user terminal and used for deploying one or more preset local contracts is obtained, and the contract deployment request is forwarded to a consensus node.
In this embodiment of this disclosure, a service object may initiate a contract deployment request used for deploying one or more preset local contracts through a second user terminal. The contract deployment request may be used for adding a contract function (for example, a local contract function corresponding to a target local contract) to each preset local contract so as to realize a corresponding function, and may also be used for specifying a node identifier corresponding to a service node (referred to as a service node deploying the preset local contract) which may execute each preset local contract in a service network. In addition, the contract deployment request is also used for specifying an associated chain contract (which may be an already deployed chain contract or a null chain contract on the consensus node) for the preset local contract. It is to be noted that information specified by the contract deployment request may be represented by a contract key field, and the second user terminal may generate a corresponding contract deployment request based on the contract key field and may then transmit the contract deployment request to any one service node in the service network.
In this embodiment of this disclosure, after receiving the contract deployment request, the service node may forward the contract deployment request to any consensus node in a core consensus network through a routing node in a routing network, or directly transmit the contract deployment request to any consensus node without the aid of the routing node. After receiving the contract deployment request, the consensus node may perform consensus on the contract deployment request. When the contract deployment request reaches the consensus, the consensus node may generate local contract summary information corresponding to the one or more preset local contracts according to the contract deployment request. The local contract summary information includes information corresponding to each preset local contract. Then the local contract summary information may be stored in the consensus node (for example, in a node memory). At this moment, the one or more preset local contracts on a core chain are successfully deployed. It is to be understood that the one or more preset local contracts include the target local contract. Accordingly, the local contract summary information generated by the consensus node includes information corresponding to the target local contract. The implementation for the consensus node to perform consensus on the contract deployment request and generate local contract summary information may be described with reference to the corresponding step S401 of
It is to be noted that the local contract summary information may be stored in the consensus node (for example, in the node memory) in the form of table storage, key-value (KV) storage, file storage, or the like. This is not limited in this application. In an implementation, the local contract summary information may be stored in the form of KV storage. In this way, during subsequent synchronization or invocation of a local contract, a corresponding value (for example, a contract identifier of a local contract in a relationship mapping table) may be queried quickly through a set Key (for example, a contract identifier of a chain contract in the relationship mapping table).
For ease of understanding, reference is made to
As shown in
As shown in
In step S202, a contract synchronization request is transmitted to the consensus node so that the consensus node performs consensus on the contract synchronization request, local contract information transmitted by the consensus node is obtained in a case that the contract synchronization request reaches the consensus, the local contract information is stored into a node memory of a service node, and a target local contract is deployed based on the local contract information.
It is to be understood that only when the preset local contract is actually deployed to the corresponding service node, the local contract can be invoked subsequently. Any service node in the service network may transmit a contract synchronization request to the consensus node in the core consensus network through the routing node in the routing network, or directly transmit the contract synchronization request to the consensus node in the core consensus network without the aid of the routing node, so as to synchronize contract information corresponding to the preset local contract required to be deployed on the service node. After receiving the contract synchronization request, any consensus node in the core consensus network may broadcast the contract synchronization request to other consensus nodes, so that the consensus node may perform consensus on the contract synchronization request. The contract synchronization request includes a service node identifier corresponding to the service node. Thus, when the contract synchronization request reaches the consensus, the consensus node may obtain local contract information relevant to the service node identifier from the local contract summary information stored in the node memory thereof based on the service node identifier, and may return (or directly return) the local contract information to the service node via the routing node. At this moment, the service node may store the received local contract information in the node memory of the service node, and may create a corresponding preset local contract (for example, a target local contract) based on the local contract information.
It is to be noted that for a preset local contract, only a contract synchronization request transmitted by a service node having an execution permission for the preset local contract can reach the consensus. That is to say, the consensus node is required to verify whether each service node that transmits the contract synchronization request has a permission to deploy a certain preset local contract. The implementation for the consensus node to perform consensus on the contract synchronization request and obtain local contract information may be described with reference to the corresponding step S402 of
This is illustrated with a service node specified to deploy a target local contract. When the contract synchronization request transmitted by the service node to the consensus node reaches the consensus, local contract information transmitted by the consensus node may be obtained. The local contract information may include information of the target local contract and other local contracts also deployed on the service node. Therefore, the local contract information may include a relationship mapping table and a local contract information table. The relationship mapping table may store a first mapping relationship between a first contract identifier and a second contract identifier, and a second mapping relationship between the second contract identifier and a service node identifier (namely, a node identifier of the service node). The local contract information table may include a contract information column corresponding to the target local contract.
In this embodiment of this disclosure, for the purpose of distinguishing, the service node which obtains and forwards the contract deployment request may be referred to as a first service node (for example, service node 301b in
To facilitate understanding, reference is made to
In step S203, an initial contract invocation request for executing a transaction service is obtained; in the relationship mapping table, a contract identifier having the first mapping relationship with the first contract identifier is queried; the queried contract identifier is determined as the second contract identifier associated with the target chain contract; a local contract corresponding to the second contract identifier is determined as the target local contract; the target local contract is invoked to execute a local service indicated by the transaction service to obtain a local transaction execution result; a target contract invocation request for being transmitted to the consensus node is determined based on the local transaction execution result and the initial contract invocation request, and the target contract invocation request is forwarded to the consensus node.
It is to be noted that the implementation process of step S203 is similar to the implementation process of step S103, and will not be repeated herein.
In a scenario where the local service is pre-checked, reference is made to
The local contract-based data processing method according to this embodiment of this disclosure may be applied to a blockchain system with unequal nodes. And, in this embodiment of this disclosure, the local contract may be executed on service nodes at different levels. Moreover, the service node may perform corresponding processing (for example, pre-checking processing, information completion processing, or the like) on the received contract invocation request before the consensus node invokes the local contract, and it is not necessary to perform all the operations relevant to the contract invocation request on the consensus node. Thus, the operation pressure of the consensus node can be reduced, and the overall transaction processing efficiency of the blockchain network can be improved. In addition, when the local contract is executed, the service node uses data thereof (referred to as local service data), so that the resource consumption caused by uploading of the local service data can be reduced, the resource consumption caused by multi-party interaction can be reduced, the data privacy security can be improved, and the storage pressure of the consensus node can be reduced.
Reference is made to
In step S301, a target contract invocation request for executing a transaction service is obtained.
In this embodiment of this disclosure, a consensus node may receive a target contract invocation request for performing a transaction service. The target contract invocation request refers to a request determined by a service node in a service network independent of a core consensus network based on a local transaction execution result and an initial contract invocation request. The local transaction execution result is obtained by the service node invoking a target local contract to execute a local service indicated by the transaction service. The target local contract is obtained by the service node based on a second contract identifier. The second contract identifier is a contract identifier that is queried by the service node in the service node (for example, in a node memory) based on a first contract identifier and a first mapping relationship and is associated with a target chain contract. The first contract identifier refers to a contract identifier for invoking the target chain contract in the initial contract invocation request. The initial contract invocation request is used for executing the transaction service. The target chain contract is deployed on the consensus node. Both the consensus node and the service node (for example, the node memory) store the first mapping relationship between the first contract identifier and the second contract identifier. The second contract identifier is a contract identifier of the target local contract deployed on the service node. The process of performing, by the service node, smart contract-based data processing may be described with reference to the corresponding description of
In step S302, a target chain contract is invoked based on a first contract identifier in the target contract invocation request, and by invoking the target chain contract, a consensus service indicated by the transaction service is executed to obtain a chain transaction execution result.
It is to be understood that the consensus node may search a plurality of deployed chain contracts based on the first contract identifier, and may then determine the chain contract corresponding to the first contract identifier as the target chain contract. Thus, the consensus node may invoke the target chain contract to read a chain contract function in the consensus node (for example, in the node memory), may access consensus service data associated with the consensus service in the consensus node (for example, in the node memory) through the chain contract function, and may then execute the consensus service indicated by the transaction service through the consensus service data to obtain a chain transaction execution result. The consensus service refers to a service executed by the consensus node (such as transferring virtual assets or issuing an electronic bill), and the content of the consensus service is relevant to the transaction service. This is not limited in this application. In addition, for a chain contract required for data reading, each consensus node may read data by accessing a corresponding account book during service execution.
In step S303, a block to be added to a target blockchain is generated according to the chain transaction execution result, and the block is uploaded, the target blockchain is a blockchain to which the target chain contract belongs.
In this embodiment of this disclosure, the consensus node may generate target transaction data according to the chain transaction execution result, and may broadcast the target transaction data to other consensus nodes. Subsequently, each consensus node may put the target transaction data into a respective transaction pool for subsequent packaging processing. It is to be understood that a node may be selected from a plurality of consensus nodes as a first consensus node (also referred to as a packing node and a block generation node) through a consensus algorithm (for example, leader block generation, round-robin block generation, computing power competition block generation, or the like). After obtaining an accounting right, the first consensus node may extract a certain amount of transaction data from the transaction pool thereof for packaging. When the target transaction data is packaged into a new block (referred to as a to-be-uploaded block), the first consensus node may broadcast the to-be-uploaded block to the second consensus node (namely, a node other than the first consensus node in the core consensus network). Subsequently, the second consensus node may perform block consensus on the to-be-uploaded block to obtain a block consensus result, and may return a block consensus result to the first consensus node. If the block consensus result is a consensus reaching result, the first consensus node may add the to-be-uploaded block to the blockchain to which the target chain contract belongs.
It is to be understood that the target local contract is required to be deployed on the service node before performing steps S301-S303. Reference is made to
In step S401, a contract deployment request that is transmitted by a second user terminal and forwarded by a service node is obtained, consensus is performed on the contract deployment request, in a case that the contract deployment request reaches the consensus, local contract summary information corresponding to one or more preset local contracts is generated according to the contract deployment request, and the local contract summary information is stored into a consensus node.
In this embodiment of this disclosure, the second user terminal may transmit a contract deployment request for deploying one or more preset local contracts to the service node. After being successfully received by the service node, the contract deployment request may be forwarded (or directly transmitted) to the consensus node through a routing node in a routing network, and then the consensus node may receive the contract deployment request. The one or more preset local contracts include a target local contract. It is to be understood that the contract deployment request may include a contract key field respectively corresponding to each preset local contract. The contract key field may include at least the following fields: a local contract identifier (local contract ID, or referred to as a local contract number), a local contract version number (version), a local contract type (type), a local contract code (code), local contract description information (Desc), an associated contract identifier (chain contract ID), and an executable node identifier list (executable node list). The local contract type may be used for marking invocation timing of each preset local contract. For example, a local contract of which the local contract type is type A may be invoked before data is forwarded to the core consensus network, and a local contract of which the local contract type is type B may be invoked after the data is synchronized back to the service node. The local contract description information may be used for describing the function of each preset local contract. Certainly, the contract keyword field may also not include the local contract description information. The associated contract identifier refers to a contract identifier of a chain contract associated with each preset local contract deployed on the consensus node. The executable node identifier list may include one or more executable node identifiers. The executable node identifiers refer to node identifiers corresponding to nodes having an execution permission for each preset local contract (namely, a service object specifies a service node required to deploy each preset local contract). The executable node identifier list corresponding to the target local contract includes service node identifiers.
In addition, the contract deployment request may also include common fields such as terminal signature information, terminal identifiers, and request timestamps corresponding to the second user terminal (namely, a request initiator). Based on this, the consensus node may perform consensus on both the terminal signature information and the terminal identifiers. Here, the consensus node may recalculate expected signature information of the contract deployment request based on a private key used by the second user terminal when signing the contract deployment request, and may then compare the signature information with the terminal signature information. If a comparison result is consistent, it is determined that the contract deployment request passes security verification (referred to as consensus reaching), and it is indicated that the contract deployment request has not been tampered with in the network transmission process. Otherwise, the consensus node may reject the contract deployment request, and may return request rejection information to the second user terminal according to the comparison result. In addition, the consensus node may also obtain a deployment permission of the second user terminal through the terminal identifier, and identify the deployment permission. If it is identified that the deployment permission is a valid permission, it may be determined that the contract deployment request passes permission verification (referred to as consensus reaching), and it is indicated that the second user terminal has a permission to deploy a local contract to a specified service node. Otherwise, the consensus node may reject the contract deployment request, and may return request rejection information to the second user terminal according to an identification result. It is to be understood that there may be different levels of deployment of local contracts in different service scenarios, and therefore the deployment permission of the second user terminal may be relevant to the level thereof.
In this embodiment of this disclosure, when both the terminal signature information and the terminal identifiers reach the consensus, the consensus node may generate a summary relationship mapping table according to the local contract identifiers, the associated contract identifiers, and the executable node identifier lists corresponding to all the preset local contracts in the contract deployment request. The summary relationship mapping table may include mapping relationship columns respectively corresponding to each preset local contract. Each mapping relationship column may be used for storing a mapping relationship between the local contract identifier and the associated contract identifier of the preset local contract corresponding thereto, and a mapping relationship between the local contract identifier and the corresponding executable node identifier. For example, reference is made to
Meanwhile, the consensus node may generate a summary contract information table according to the local contract identifiers, the local contract codes, the associated contract identifiers, and the executable node identifier lists corresponding to all the preset local contracts. The summary contract information table may include contract information columns respectively corresponding to each preset local contract. As shown in
In this embodiment of this disclosure, the consensus node may determine the foregoing summary relationship mapping table and summary contract information table as local contract summary information (for example, the local contract summary information 30d shown in
In step S402, a contract synchronization request transmitted by the service node is obtained, consensus on the contract synchronization request is performed, in a case that the contract synchronization request reaches the consensus, local contract information is obtained from the local contract summary information based on the service node identifier, and the local contract information is transmitted to the service node.
It is to be understood that the consensus node is configured to synchronize a local contract to a service node that may execute this local contract. At the time of synchronization, the consensus node may quickly calculate the service node which may obtain the local contract information by accessing the executable node identifier list at the time of local contract deployment, including: The consensus node may obtain a contract synchronization request transmitted by the service node. The contract synchronization request may include a service node identifier and node signature information of the service node. Then, consensus may be performed on the node signature information and the service node identifier. Here, the consensus node may recalculate expected signature information of the contract synchronization request based on a private key used by the service node when signing the contract synchronization request, and may then compare the signature information with the node signature information. If a comparison result is consistent, it is determined that the contract synchronization request passes security verification, and it is indicated that the contract synchronization request has not been tampered with in the network transmission process. Otherwise, the consensus node may reject the contract synchronization request, and may return request rejection information to the service node according to the comparison result. In addition, the consensus node may also obtain an execution permission of the service node through the service node identifier, and identify the execution permission. It is to be understood that the consensus node may query whether the service node identifier exists in the executable node identifier list respectively corresponding to one or more preset local contracts. If the service node identifier is queried, the execution permission may be identified as a valid permission. That is, it is determined that the contract synchronization request passes permission verification, and it is indicated that the service node has a permission to deploy and execute a specified local contract. Otherwise, the consensus node may reject the contract synchronization request, and may return request rejection information to the service node according to an identification result.
In this embodiment of this disclosure, in a case that both the node signature information and the service node identifier reach the consensus, the consensus node may perform querying in the summary relationship mapping table based on the service node identifier, and determine a queried mapping relationship column of a node identifier which is the same as the service node identifier as a relationship mapping table. Thus, the consensus node may determine a local contract identifier in the relationship mapping table as a key contract identifier, perform querying in the summary contract information table based on the key contract identifier, and determine a queried contract information column of a contract identifier which is the same as the key contract identifier as a local contract information table. Subsequently, the consensus node may determine the relationship mapping table and the local contract information table as the local contract information, and may transmit the local contract information to the service node. The relationship mapping table stores a first mapping relationship between a first contract identifier and a second contract identifier, and a second mapping relationship between the second contract identifier and the service node identifier. The local contract information table may include a contract information column corresponding to the target local contract. After receiving the local contract information, the service node may store the local contract information in the node memory of the service node, and may then deploy one or more local contracts including the target local contract based on the local contract information.
For example, reference may be made to
In this embodiment of this disclosure, a long connection may be established between the service node and the consensus node, and then the consensus node may actively push corresponding local contract information to a service node having an execution permission (namely, a service node corresponding to an executable node identifier stored in local contract summary information) at intervals, so that these service nodes may store the local contract information into a node memory of the service node, and deploy a specified local contract based on the local contract information.
It is to be noted that after the local contract information is successfully synchronized, the consensus node may delete the local contract information in the node memory thereof, so as to reduce the pressure of data storage. In addition, the service node is in a public network (referred to as a service network) and may be accessed by other network terminals to cause tampering of the local contract information. Therefore, after the local contract information is successfully synchronized, the consensus node may still retain the local contract information in the node memory thereof, and may subsequently perform relevant verification based on the stored local contract information.
It is to be understood that when an already deployed local contract is modified (updated or deleted), the execution logic of the local contract may also be changed by initiating a request. The process is similar to the process of deploying the local contract.
In step S403, a target contract invocation request for executing a transaction service is obtained, a target chain contract is invoked based on a first contract identifier in the target contract invocation request, by invoking the target chain contract, a consensus service indicated by the transaction service is executed to obtain a chain transaction execution result, a block to be added to a target blockchain is generated according to the chain transaction execution result, and the block is uploaded.
It is to be noted that the implementation process of step S403 may be described with reference to the corresponding step S303 of
Reference is made to
In step S1, a remote procedure call (RPC) layer of each consensus node (for example, node 1 to node N) obtains a user request (for example, a target contract invocation request). The user request is also referred to as a transaction. The RPC layer is an external interface provided by consensus nodes, which may be configured to obtain the target contract invocation request.
In step S2, each consensus node broadcasts a transaction to each other, and one of the consensus nodes packages a plurality of transactions into a block (referred to as a to-be-uploaded block) and broadcasts to the other consensus nodes. The selection of a block generation node (referred to as a first consensus node) may vary depending on a consensus algorithm, and may include leader block generation, round-robin block generation, computing power competition block generation, and the like. A blockchain consensus network in
In step S3, after each consensus node receives the block, the transaction in the block is started. A transaction parameter is parsed at a logic calculation layer, and a contract (referred to as a target chain contract) is executed. The execution process includes a process of reading data in a memory (such as a node memory). As illustrated in
In step S4, after the execution of the contract is completed, each consensus node verifies an execution result (namely, the foregoing chain transaction execution result) with each other. The verification method may be that the execution result or the memory change is organized into a result tree (such as Merkle), and the root of the result tree is stored into a block header through result tree root hashing. Finally, the block hash of each consensus node is verified to be consistent.
In step S5, after the consensus is successful, each consensus node writes data relevant to this block into the memory. The data includes the block header, all transactions contained in the block, execution results, and the like.
The detailed process of steps S1-S5 may be described with reference to the corresponding steps S301-S303 of
It is to be understood that the consensus node may quickly implement the deployment and synchronization of local contracts in conjunction with the service node.
Reference is made to
The first obtaining module 11 is configured to obtain an initial contract invocation request for executing a transaction service. The initial contract invocation request includes a first contract identifier for invoking a target chain contract. The target chain contract is deployed on a consensus node of a core consensus network, and the core consensus network is independent of the service network. Both the consensus node and the service node store a first mapping relationship between the first contract identifier and a second contract identifier. The second contract identifier is a contract identifier of a target local contract deployed on the service node.
The first execution module 12 is configured to query, based on the first contract identifier and the first mapping relationship, the second contract identifier, determine the target local contract based on the second contract identifier, and execute, by invoking the target local contract, a local service indicated by the transaction service to obtain a local transaction execution result.
The forwarding module 13 is configured to transmit a target contract invocation request to the consensus node based on the local transaction execution result and the initial contract invocation request, and execute, by invoking the target chain contract, a consensus service indicated by the transaction service, the target contract invocation request being used for obtaining, by the consensus node, the target chain contract based on the first contract identifier.
In an implementation, a blockchain network where the service network and the core consensus network are located further includes a routing network for performing network isolation.
The forwarding module 13 is further configured to transmit the target contract invocation request to the consensus node through a routing node in the routing network based on the local transaction execution result and the initial contract invocation request.
Referring to
The request feedback module 14 is configured to: determine, in response to the pre-check result indicating that the request parameter does not satisfy the uploading condition, the request parameter not satisfying the uploading condition as an invalid request parameter, and take the invalid request parameter as the local transaction execution result corresponding to the local service; and generate request failure information according to the invalid request parameter, and return the request failure information to a first user terminal that transmits the initial contract invocation request.
Referring to
The first contract deployment module 15 is configured to forward a contract deployment request transmitted by a second user terminal to the consensus node. The contract deployment request is used for generating, by the consensus node, local contract information corresponding to one or more preset local contracts. The one or more preset local contracts include the target local contract.
The first contract synchronization module 16 is configured to: transmit a contract synchronization request to the consensus node, the contract synchronization request being used for performing, by the consensus node, consensus on the contract synchronization request; the contract synchronization request including a service node identifier corresponding to the service node; receive local contract information transmitted by the consensus node in a case that the contract synchronization request reaches the consensus, the local contract information referring to information obtained by the consensus node in local contract summary information based on the service node identifier; and deploy the target local contract based on the local contract information.
Referring to
In an implementation, the service node stores local contract information. The local contract information includes a relationship mapping table. The relationship mapping table includes the first mapping relationship.
The third query unit 121 is configured to query, in the relationship mapping table, a contract identifier having the first mapping relationship with the first contract identifier, determining the queried contract identifier as the second contract identifier, and determine a local contract corresponding to the second contract identifier as the target local contract.
The reading unit 122 is configured to: read the local contract information by invoking the target local contract; and
obtain local service data associated with the local service by reading the local contract information.
The execution unit 123 is configured to execute, through the local service data, the local service indicated by the transaction service to obtain the local transaction execution result.
Referring to
In an implementation, in a case that the local service data includes first local service data, the pre-check subunit 1231 is configured to: pre-check a request parameter in the initial contract invocation request based on the first local service data; and determine, in response to a pre-check result indicating that the request parameter satisfies an uploading condition, the request parameter satisfying the uploading condition as a valid request parameter, and take the valid request parameter as the local transaction execution result corresponding to the local service, the uploading condition being a condition for uploading indicated by the local service.
In an implementation, in a case that the local service data includes second local service data, the information completion subunit 1232 is configured to: perform information completion on a request parameter in the initial contract invocation request based on the second local service data; and take the information-completed request parameter as the local transaction execution result corresponding to the local service.
Reference is made to
The second obtaining module 21 is configured to obtain a target contract invocation request for executing a transaction service. The target contract invocation request is transmitted by a service node based on a local transaction execution result and an initial contract invocation request, and the service node is located in a service network of the core consensus network. The local transaction execution result is obtained by invoking a target local contract by the service node to execute a local service indicated by the transaction service. The target local contract is obtained by the service node based on a second contract identifier. The second contract identifier is queried by the service node based on a first contract identifier and a first mapping relationship. The first contract identifier refers to a contract identifier for invoking a target chain contract in the initial contract invocation request. The initial contract invocation request is used for executing the transaction service. The target chain contract is deployed on the consensus node. Both the consensus node and the service node store the first mapping relationship between the first contract identifier and the second contract identifier. The second contract identifier is a contract identifier of the target local contract deployed on the service node.
The second execution module 22 is configured to invoke the target chain contract based on the first contract identifier in the target contract invocation request, and execute, by invoking the target chain contract, a consensus service indicated by the transaction service to obtain a chain transaction execution result.
Referring to
The second contract deployment module 24 is configured to perform consensus on a contract deployment request forwarded by the service node, and generate, in a case that the contract deployment request reaches the consensus, local contract summary information corresponding to one or more preset local contracts according to the contract deployment request. The contract deployment request is transmitted to the service node by a second user terminal, and the one or more preset local contracts include the target local contract.
The second contract synchronization module 25 is configured to: perform consensus on a contract synchronization request transmitted by the service node, the contract synchronization request including a service node identifier corresponding to the service node; and obtain, in a case that the contract synchronization request reaches the consensus, local contract information from the local contract summary information based on the service node identifier, and transmit the local contract information to the service node, the local contract information being used for deploying the target local contract by the service node.
In an implementation, the contract deployment request includes a contract key field respectively corresponding to each preset local contract, and the contract key field includes a local contract identifier, a local contract version number, a local contract type, a local contract code, local contract description information, an associated contract identifier, and an executable node identifier list. The associated contract identifier refers to a contract identifier of a chain contract associated with each preset local contract deployed on the consensus node. The executable node identifier list includes one or more executable node identifiers. The executable node identifier refers to a node identifier corresponding to a node having an execution permission for each preset local contract. The executable node identifier list corresponding to the target local contract includes the service node identifier.
In an implementation, the contract deployment request further includes terminal signature information and a terminal identifier corresponding to the second user terminal. Referring to
The first consensus unit 241 is configured to perform consensus on the terminal signature information and the terminal identifier.
The mapping table generation unit 242 is configured to generate, in a case that both the terminal signature information and the terminal identifier reach the consensus, a summary relationship mapping table according to the local contract identifier, the associated contract identifier, and the executable node identifier list. The summary relationship mapping table includes mapping relationship columns respectively corresponding to the one or more preset local contracts. The mapping relationship column is used for storing a mapping relationship between the local contract identifier and the associated contract identifier, and a mapping relationship between the local contract identifier and the executable node identifier.
The information table generation unit 243 is configured to generate a summary contract information table according to the local contract identifier, the local contract code, the associated contract identifier, and the executable node identifier list. The summary contract information table includes contract information columns respectively corresponding to the one or more preset local contracts.
The determination and storage unit 244 is configured to determine the summary relationship mapping table and the summary contract information table as the local contract summary information corresponding to the one or more preset local contracts.
In an implementation, the contract synchronization request may further include node signature information.
Referring to
The second consensus unit 251 is configured to perform consensus on the node signature information and the service node identifier.
The first query unit 252 is configured to perform, in a case that both the node signature information and the service node identifier reach the consensus, querying in the summary relationship mapping table based on the service node identifier, and determine a queried mapping relationship column of a node identifier which is the same as the service node identifier as a relationship mapping table. The relationship mapping table stores the first mapping relationship and a second mapping relationship between the second contract identifier and the service node identifier.
The second query unit 253 is configured to determine a local contract identifier in the relationship mapping table as a key contract identifier, perform querying in the summary contract information table based on the key contract identifier, and determine a queried contract information column of a contract identifier which is the same as the key contract identifier as a local contract information table. The local contract information table includes a contract information column corresponding to the target local contract.
The determination and transmission unit 254 is configured to determine the relationship mapping table and the local contract information table as the local contract information, and transmit the local contract information to the service node.
In this embodiment of this disclosure, the uploading module 23 is configured to generate a block to be added to a target blockchain according to the chain transaction execution result, and upload the block. The target blockchain is a blockchain to which the target chain contract belongs.
Reference is made to
In the computer device 1000 as shown in
An embodiment of this disclosure also provides a computer-readable storage medium (e.g., non-transitory computer readable storage medium). The computer-readable storage medium stores a computer program executed by the above-mentioned smart contract-based first data processing apparatus 9-1 or smart contract-based second data processing apparatus 10-2, and the computer program includes program instructions. When the processor executes the program instructions, the smart contract-based data processing method according to the foregoing embodiment of this disclosure can be performed. Therefore, the description will not be repeated herein. In addition, the description of the beneficial effects using the same method will not be repeated. As an example, the program instructions may be deployed to be executed on one electronic device, or on a plurality of electronic devices located at one site, or on a plurality of electronic devices distributed across a plurality of sites and interconnected by a communication network. The plurality of electronic devices distributed across the plurality of sites and interconnected by the communication network may form a blockchain system.
The computer-readable storage medium may be the smart contract-based data processing apparatus according to the foregoing embodiment of this disclosure or an internal storage unit of the computer device, such as a hard disk or an internal memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, or a flash card provided on the computer device. In this embodiment of this disclosure, the computer-readable storage medium may further include both the internal storage unit and the external storage device of the computer device. The computer-readable storage medium is configured to store the computer program and other programs and data required by the computer device. The computer-readable storage medium may be further configured to temporarily store data that has been outputted or is to be outputted.
An embodiment of this disclosure also provides a computer program product or a computer program. The computer program product or the computer program includes computer instructions. The computer instructions are stored in a computer-readable storage medium. A processor of an electronic device such as a computer device reads the computer instructions from the computer-readable storage medium. The processor executes the computer instructions, so as to enable the electronic device to perform the smart contract-based data processing method according to the foregoing embodiment of this disclosure.
It is to be understood that data relevant to transaction services is involved in the embodiments of this disclosure. When the embodiments of this disclosure are applied to a particular product or technology, user approval or consent is required, and collection, use and processing of the relevant data is required to comply with relevant national and regional laws and regulations and standards.
It is noted that units and algorithm steps of the examples described in the disclosed embodiments in this specification may be implemented by electronic hardware, computer software, or a combination thereof. To clearly describe the interchangeability between the hardware and the software, the foregoing has generally described compositions and steps of the examples based on functions. Whether these functions are executed in the manner of hardware or software depends on particular applications and design constraint conditions of the technical solutions. It is also noted that different methods may be used to implement the described functions for each particular application, the implementation is not considered as going beyond the scope of this disclosure.
The term module (and other similar terms such as unit, submodule, etc.) in this disclosure may refer to a software module, a hardware module, or a combination thereof. A software module (e.g., computer program) may be developed using a computer programming language. A hardware module may be implemented using processing circuitry and/or memory. Each module can be implemented using one or more processors (or processors and memory). Likewise, a processor (or processors and memory) can be used to implement one or more modules. Moreover, each module can be part of an overall module that includes the functionalities of the module.
What is disclosed above is merely exemplary embodiments of this disclosure, and certainly is not intended to limit the scope of the claims of this disclosure. Therefore, equivalent variations made in accordance with the claims of this disclosure shall fall within the scope of this disclosure.
Number | Date | Country | Kind |
---|---|---|---|
202110923438.7 | Aug 2021 | CN | national |
The present application is a continuation of International Application No. PCT/CN2022/104894, entitled “SMART CONTRACT-BASED DATA PROCESSING METHOD AND APPARATUS, ELECTRONIC DEVICE, COMPUTER-READABLE STORAGE MEDIUM, AND COMPUTER PROGRAM PRODUCT ” and filed on Jul. 11, 2022, which claims priority to Chinese Patent Application No. 202110923438.7, filed on Aug. 12, 2021. The entire disclosures of the prior applications are hereby incorporated by reference in their entirety.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2022/104894 | Jul 2022 | US |
Child | 18196878 | US |