Method and device for calling smart contracts and calling transaction processing across virtual machines
Through a unified contract calling protocol and encoding conversion processing within the virtual machine module, the security and efficiency problems existing in the virtual machine agent layer are solved, and efficient, safe and simplified development of cross-virtual machine smart contract calls is achieved.
Patent Information
- Application Number
- CN202410786762.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-18
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-06-18
AI Technical Summary
In the existing technology, the virtual machine agent layer has security risks, low processing efficiency and downtime risks in cross-virtual machine smart contract calls, and is difficult to develop and maintain.
Adopt a unified contract calling protocol and perform encoding conversion processing through the virtual machine module in the target smart contract engine to achieve format conversion of input parameters and transaction results, reduce dependence on the intermediate agent layer, and improve processing efficiency and security.
It enhances the interoperability between different virtual machine modules, simplifies the development process, reduces system complexity and maintenance costs, and improves the processing efficiency and security of contract calls.
Smart Images

Figure CN118350942B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of blockchain and virtual machines, and in particular to a method and device for invoking smart contracts and invoking transaction processing across virtual machines. Background Art
[0002] Blockchain technology is based on encryption algorithms to ensure that data cannot be tampered with and that transactions are secure. Currently, blockchain technology is widely used in finance, logistics, product traceability, digital evidence storage and other fields. As an important component of blockchain technology, smart contracts are a set of automatically executed scripts or program codes that trigger the automatic execution of the program in the contract when the set conditions are met. With the development of blockchain technology, smart contracts corresponding to new development languages and virtual machines that support their operation have emerged. However, it is difficult for smart contracts running in different virtual machine environments to interact with each other.
[0003] In the process of realizing the concept of the present disclosure, it was found that there are at least the following technical problems in the related technologies: some technologies realize the mutual calling of smart contracts between multiple virtual machines by building a virtual machine proxy layer (VMProxy); however, in the above method, the virtual machine proxy layer serves as a transit layer and is likely to be attacked, resulting in security risks; when the processing logic is more complex, the processing time efficiency of the above method needs to be improved, and there may be a risk of downtime in the case of high concurrent access; and the development and maintenance of smart contracts is difficult and the workload is large. Summary of the invention
[0004] In order to solve the above technical problems or at least partially solve the above technical problems, the embodiments of the present disclosure provide a method and device for calling smart contracts and calling transaction processing across virtual machines.
[0005] In the first aspect, an embodiment of the present disclosure provides a method for calling a smart contract across virtual machines. The above method includes: obtaining a predefined contract call protocol for a target smart contract engine; receiving or creating a contract call transaction based on the above contract call protocol; the above contract call transaction includes: a sub-call transaction in which the first smart contract calls the second smart contract; the first virtual machine module where the above first smart contract is located and the second virtual machine module where the above second smart contract is located are different virtual machine modules; based on the above target smart contract engine, calling an adapted target virtual machine module to process the above contract call transaction; in the processing of the above contract call transaction, the above target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the above contract call transaction are converted into a format that conforms to the specification of the above target virtual machine module and the transaction result conforms to the format of the above contract call protocol specification.
[0006] According to an embodiment of the present disclosure, there are type differences among the multiple virtual machine modules included in the above-mentioned target smart contract engine, and the above-mentioned contract calling protocol is a protocol of a unified format for different types of virtual machine modules in the above-mentioned target smart contract engine; the above-mentioned first virtual machine module and the above-mentioned second virtual machine module are of different types.
[0007] According to an embodiment of the present disclosure, the above-mentioned contract call transaction also includes: a user call transaction in which a user calls a target smart contract; in the process of responding to a first contract call instruction initiated by a user for a target smart contract, the above-mentioned user call transaction based on the above-mentioned contract call protocol is created; or, the above-mentioned user call transaction based on the above-mentioned contract call protocol sent from a requesting device is received. In the process of processing the above-mentioned user call transaction, a second contract call instruction in which the first smart contract calls the second smart contract is generated, and the creation of the above-mentioned sub-call transaction is triggered.
[0008] According to an embodiment of the present disclosure, the target smart contract is one of the following situations: the target smart contract is the first smart contract; or, the target smart contract is the direct caller for calling the first smart contract; or, the target smart contract is the indirect caller for calling the first smart contract.
[0009] According to an embodiment of the present disclosure, the above-mentioned contract call transaction carries a target data object in a standard format that complies with the above-mentioned contract call protocol; the above-mentioned target data object contains the following information: call method, return result and parameter list. Among them, in the processing of the above-mentioned contract call transaction, before the execution of the smart contract, the above-mentioned target virtual machine module performs code conversion processing on the input parameters in the contract call transaction to obtain a call code in a standard format that complies with the above-mentioned target virtual machine module, and the above-mentioned input parameters include: the above-mentioned call method and the above-mentioned parameter list; the corresponding smart contract is executed based on the above-mentioned call code. After the smart contract is executed, the above-mentioned target virtual machine module performs code conversion processing on the contract execution result to obtain a transaction result returned in the standard format of the above-mentioned return result.
[0010] According to an embodiment of the present disclosure, creating a contract call transaction based on the above-mentioned contract call protocol includes: parsing the call information for the smart contract to be called; assembling the above-mentioned call information into a target data object that conforms to the format specified by the above-mentioned contract call protocol; generating a contract call transaction based on the above-mentioned target data object. Based on the above-mentioned target smart contract engine, calling the adapted target virtual machine module to process the above-mentioned contract call transaction includes: based on the above-mentioned target smart contract engine, obtaining the contract type of the smart contract to be called in the above-mentioned contract call transaction; calling the target virtual machine module adapted to the above-mentioned contract type; processing the above-mentioned contract call transaction based on the above-mentioned target virtual machine module.
[0011] In the second aspect, the embodiment of the present disclosure provides a method for processing a call transaction. The method for processing the call transaction includes: receiving or creating a user call transaction for a target smart contract; the user call transaction is created based on a contract call protocol, and the contract call protocol is a unified protocol predefined for the target smart contract engine; based on the target smart contract engine, calling the first target virtual machine module adapted to process the user call transaction; in the process of processing the user call transaction, triggering the creation of a sub-call transaction based on the contract call protocol, and calling the second target virtual machine module adapted to process the sub-call transaction; the sub-call transaction is a transaction in which the target smart contract directly or indirectly calls other smart contracts. In the process of processing the contract call transaction, the adapted target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the contract call transaction are converted into a format that conforms to the specification of the adapted target virtual machine module and the transaction result conforms to the specification of the contract call protocol; the contract call transaction is at least one of the following: the user call transaction and the sub-call transaction.
[0012] According to an embodiment of the present disclosure, the target smart contract engine includes multiple virtual machine modules of different types, and the contract call protocol is a unified format protocol for different types of virtual machine modules in the target smart contract engine; the sub-call transaction is a transaction in which the first smart contract calls the second smart contract; wherein the first virtual machine module in which the first smart contract is located is of a different type from the second virtual machine module in which the second smart contract is located. The target smart contract is one of the following situations: the target smart contract is the first smart contract; or, the target smart contract is the direct caller for calling the first smart contract; or, the target smart contract is the indirect caller for calling the first smart contract.
[0013] According to an embodiment of the present disclosure, the above-mentioned contract call transaction carries a target data object in a standard format that complies with the above-mentioned contract call protocol; the above-mentioned target data object contains the following information: a call method, a return result, and a parameter list; wherein, during the processing of the above-mentioned contract call transaction, before the corresponding smart contract is executed, the adapted target virtual machine module performs encoding conversion processing on the input parameters in the contract call transaction to obtain a call code in a standard format that complies with the adapted target virtual machine module, and the above-mentioned input parameters include: the above-mentioned call method and the above-mentioned parameter list; the corresponding smart contract is executed based on the above-mentioned call code.
[0014] After the smart contract is executed, the adapted target virtual machine module encodes and converts the contract execution result to obtain the transaction result returned in the standard format of the above-mentioned return result.
[0015] According to an embodiment of the present disclosure, in the process of processing the above-mentioned user call transaction, triggering the creation of a sub-call transaction based on the above-mentioned contract call protocol includes: in the process of processing the above-mentioned user call transaction, parsing the second call information of the smart contract to be called directly or indirectly required for the execution of the above-mentioned target smart contract; assembling the above-mentioned second call information into a second target data object that conforms to the format specified by the above-mentioned contract call protocol; generating a sub-call transaction based on the above-mentioned second target data object; wherein the above-mentioned first target virtual machine module matches the contract type of the above-mentioned target smart contract; and the above-mentioned second target virtual machine module matches the contract type of other smart contracts to be called. Receiving or creating a user call transaction of a user to a target smart contract includes: receiving a user call transaction of a user to a target smart contract, or creating a user call transaction of a user to a target smart contract. Among them, the above-mentioned receiving a user call transaction of a user to a target smart contract includes: receiving a user call transaction of a user to a target smart contract sent by a requesting device. The above-mentioned creation of a user call transaction of a user to a target smart contract includes: receiving a first contract call instruction initiated by a user for a target smart contract; and creating a user call transaction based on the above-mentioned contract call protocol according to the above-mentioned first contract call instruction.
[0016] In the third aspect, an embodiment of the present disclosure provides a device for calling a smart contract across virtual machines. The above-mentioned device includes: a protocol acquisition module, a first call transaction receiving or creating module, and a target smart contract engine. The above-mentioned protocol acquisition module is used to obtain a predefined contract call protocol for the target smart contract engine. The above-mentioned first call transaction receiving or creating module is used to receive or create a contract call transaction based on the above-mentioned contract call protocol; the above-mentioned contract call transaction includes: a sub-call transaction in which the first smart contract calls the second smart contract; the first virtual machine module where the above-mentioned first smart contract is located and the second virtual machine module where the above-mentioned second smart contract is located are different virtual machine modules. The above-mentioned target smart contract engine is used to call the adapted target virtual machine module to process the above-mentioned contract call transaction; in the processing process of the above-mentioned contract call transaction, the above-mentioned target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the above-mentioned contract call transaction are converted into a format that conforms to the specification of the above-mentioned target virtual machine module, and the transaction result conforms to the format of the above-mentioned contract call protocol specification.
[0017] In a fourth aspect, an embodiment of the present disclosure provides a device for processing a call transaction. The processing device includes: a second call transaction receiving or creating module and a target smart contract engine. The second call transaction receiving or creating module is used to receive or create a user call transaction for a user to call a target smart contract; the user call transaction is created based on a contract call protocol, and the contract call protocol is a unified protocol predefined for the target smart contract engine. The target smart contract engine is used to call the adapted first target virtual machine module to process the user call transaction; in the process of processing the user call transaction, the creation of a sub-call transaction based on the contract call protocol is triggered, and the adapted second target virtual machine module is called to process the sub-call transaction; the sub-call transaction is a transaction in which the target smart contract directly or indirectly calls other smart contracts. In the process of processing the contract call transaction, the adapted target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the contract call transaction are converted into a format that conforms to the specifications of the adapted target virtual machine module and the transaction results conform to the format of the contract call protocol specification; wherein the contract call transaction is at least one of the following: the user call transaction and the sub-call transaction.
[0018] In a fifth aspect, an embodiment of the present disclosure provides an electronic device. The electronic device includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; the memory is used to store computer programs; and the processor is used to implement the method of calling a smart contract across virtual machines or the method of calling transaction processing as described above when executing the program stored in the memory.
[0019] In a sixth aspect, an embodiment of the present disclosure provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for calling a smart contract across virtual machines or the method for calling transaction processing as described above is implemented.
[0020] The above technical solution provided by the embodiments of the present disclosure has at least some or all of the following advantages:
[0021] A solution is provided for calling smart contracts across multiple virtual machines based on a unified contract calling protocol to support an extensible architecture. In the scenario where smart contracts in multiple virtual machine modules contained in a target smart contract engine are called across virtual machines, a unified contract calling protocol is predefined for the target smart contract engine, which means that cross-virtual machine calls can be made in a commonly followed format, thereby enhancing the interoperability between different virtual machine modules. This standardization helps to simplify the work of developers, so that developers only need to focus on protocol specifications rather than a variety of different calling mechanisms. Setting the encoding conversion processing logic within the virtual machine is more direct and customizable. Therefore, developers do not need to write corresponding smart contracts based on the caller and the callee separately as in the solution based on the intermediate proxy layer in the related technology. They only need to develop the corresponding encoding conversion processing logic for the virtual machine where the call occurs, thereby reducing the development workload and difficulty. Moreover, after the newly added virtual machine module is added to the blockchain network corresponding to the above-mentioned target smart contract engine, the overall The contract call protocol and transaction processing framework can be used, and only the corresponding encoding conversion processing logic needs to be customized for the newly added virtual machine module, which is easier to adapt to new blockchain technologies and standards and provides better compatibility and scalability. At the same time, in the process of processing contract call transactions, the virtual machine module performs encoding conversion processing to realize the conversion of input parameters to the target virtual machine module specification format and the conversion of transaction results to the contract call protocol specification format. The encoding conversion processing operation is performed by the calling and called virtual machine modules, which can reduce the dependence and interaction on external modules (such as the intermediate proxy layer), improve processing timeliness, and effectively avoid all calling transactions and forwarding logic concentrated in the intermediate proxy layer to generate high concurrent access pressure, which may cause downtime, and the intermediate proxy layer is easy to be attacked. Security risks and other issues; since there is no need to set up an intermediate proxy layer, the complexity and maintenance cost of the system architecture can be reduced. At the same time, since setting the encoding and decoding logic inside the virtual machine is more direct and customizable, it helps to improve the processing efficiency of contract calls compared to the solution through the intermediate proxy layer. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0023] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or related technical descriptions are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0024] Figure 1AThe system architecture of the method for calling a smart contract across virtual machines and the method for calling transaction processing applicable to an embodiment of the present disclosure is schematically shown;
[0025] Figure 1B The system architecture of a method for calling a smart contract across virtual machines and a method for calling transaction processing applicable to another embodiment of the present disclosure is schematically shown;
[0026] Figure 2 A flowchart of a method for calling a smart contract across virtual machines according to an embodiment of the present disclosure is schematically shown;
[0027] Figure 3 A schematic diagram of a calling path for calling a smart contract during the implementation of a method for calling a smart contract across virtual machines according to an embodiment of the present disclosure is schematically shown;
[0028] Figure 4 The flowchart of the method for invoking transaction processing according to an embodiment of the present disclosure is schematically shown;
[0029] Figure 5 The structure block diagram of the apparatus for calling a smart contract across virtual machines according to an embodiment of the present disclosure is schematically shown;
[0030] Figure 6 The structure block diagram of the device for invoking transaction processing according to an embodiment of the present disclosure is schematically shown;
[0031] Figure 7 The structural block diagram of the electronic device provided by the embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0032] Smart contracts are generally run in blockchain nodes or blockchain ledgers, and the smart contract engine (ContractEngine) provides a simple, deterministic, efficient and secure execution environment for smart contracts. Generally speaking, smart contract engines run smart contracts by building virtual machines. Virtual machines are software implementations used to simulate physical computers. They can create multiple isolated execution environments on physical hardware. Different virtual machines have their own instruction sets, execution models and security mechanisms. Each virtual machine usually has its own characteristics and advantages, but the differences between them also lead to interoperability issues in smart contracts. Interoperability refers to the ability of different systems and components to interact and work together effectively. In the context of blockchain smart contracts, interoperability usually refers to the ability of different smart contract platforms or virtual machines to effectively exchange information and trigger contract execution.
[0033] Smart contract M developed in a certain coding language can run in virtual machine X, but not in virtual machine Y. This limitation restricts the development of cross-chain applications and makes it difficult to combine the advantages of different blockchain networks. For example, the distributed ledger blockchain (Hyperledger Fabric) supports Docker (an open source application container engine) container as the execution environment of smart contract M under the blockchain architecture, but smart contract M may not run in the Ethereum virtual machine (EVM, another example of a virtual machine).
[0034] Therefore, in order to combine the advantages of multiple blockchain architectures, attempts are made to develop cross-chain technology to allow communication and interaction between different blockchain networks. However, cross-chain communication in related technologies mainly focuses on communication between blockchain networks, rather than communication between virtual machines where smart contracts are located. During research and development, it was found that if a smart contract needs to use the functions or data of another smart contract, it usually needs to communicate through events or messages. If the two smart contracts run in different virtual machine modules, it becomes more complicated to achieve the above communication between different virtual machine modules because different virtual machine modules may have different instruction sets, data formats, and execution models.
[0035] In related technologies, some methods are to realize mutual calls of smart contracts between multiple virtual machines by building a virtual machine proxy layer (VMProxy); VMProxy, as an intermediate proxy layer, exists between various virtual machines on the blockchain platform. Its main function is to act as an intermediary to handle and coordinate communications and contract calls between virtual machines.
[0036] However, the virtual machine proxy layer constructed in the above manner is at risk of being attacked. If the attacker successfully attacks, the contract call across virtual machines may be tampered with or interrupted, weakening the security advantage of blockchain technology. Moreover, as a transit layer, the virtual machine proxy layer has a slower processing time when the processing logic is more complex, and there may be a risk of downtime in the case of high concurrent access. In addition, in the process of writing smart contracts, the solution based on the virtual machine proxy layer needs to write the smart contract of the callee in the cross-virtual machine call process based on the language rules of the callee's virtual machine, and write the smart contract of the caller based on the language rules of the caller's virtual machine. The development and maintenance are difficult and labor-intensive. If a new smart contract corresponds to a virtual machine that is connected and needs to call other contracts or be called, the new smart contract needs to be rewritten and deployed, and the development workload during the expansion process is large.
[0037] In view of this, the embodiments of the present disclosure provide a method and device for cross-virtual machine calling smart contracts and call transaction processing. The above method and device provide a solution for cross-virtual machine calling smart contracts between multiple virtual machines based on a unified contract call protocol to support an extensible architecture. In the scenario where a cross-virtual machine call occurs in a smart contract in multiple virtual machine modules contained in a target smart contract engine, a unified contract call protocol is predefined for the target smart contract engine, which means that cross-virtual machine calls can be performed in a commonly followed format, thereby enhancing the interoperability between different virtual machine modules. At the same time, in the process of processing a contract call transaction, the virtual machine module performs a code conversion process to realize the conversion of the input parameter to the target virtual machine module specification format and the conversion of the transaction result to the contract call protocol specification format. The code conversion process is performed by the virtual machine module that calls or is called, which can reduce the dependence and interaction on external modules (such as the intermediate proxy layer). After the newly added virtual machine module is added to the blockchain network corresponding to the above target smart contract engine, the overall contract call protocol and transaction processing framework can be used, and only the corresponding code conversion processing logic needs to be customized for the newly added virtual machine module, which is easier to adapt to new blockchain technologies and standards, and provides better compatibility and scalability.
[0038] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present disclosure.
[0039] Figure 1A The system architecture of a method for calling a smart contract across virtual machines and a method for calling transaction processing applicable to an embodiment of the present disclosure is schematically shown. Figure 1B The system architecture of a method for calling a smart contract across virtual machines and a method for calling transaction processing applicable to another embodiment of the present disclosure is schematically shown.
[0040] Reference Figure 1A Example system architecture 100a and Figure 1B As shown in the exemplary system architecture 100b, the method for calling a smart contract across virtual machines and the method for calling transaction processing provided by the embodiment of the present disclosure can be executed by one or more blockchain nodes 110 in the blockchain network. In an exemplary system architecture 100a, refer to Figure 1A As shown, the blockchain node 110 can be a device operated by a user, such as a terminal device. In another exemplary system architecture 100b, referring to Figure 1BAs shown, data can be exchanged between the blockchain node 110 and the requesting device 120. The blockchain node 110 is used to provide service support such as data processing or data storage for the requesting device 120. The requesting device 120 can be a terminal device or a server.
[0041] Reference Figure 1A and Figure 1B As shown, the blockchain node 110 includes a target smart contract engine 111, which is used to read the contract type, initialize and call the corresponding type of virtual machine module to process the smart contract. In the embodiment of the present disclosure, multiple virtual machine modules can be built in the target smart contract engine, and these virtual machine modules are physically isolated, such as the example virtual machine module A, virtual machine module B and virtual machine module C. Virtual machine module A supports the operation of smart contract 1, virtual machine module B supports the operation of smart contract 2 and smart contract 3, and virtual machine module C supports the operation of smart contract 4.
[0042] In some embodiments, there are type differences among the multiple virtual machine modules included in the above-mentioned target smart contract engine 111. Specifically, it may be the following situations: the type of one or some virtual machine modules is different from the type of other virtual machine modules, and there are some virtual machine modules of the same type; or, the types of each virtual machine module are different.
[0043] A corresponding contract call protocol 101 is defined for the target smart contract engine. When the target smart contract engine calls a smart contract across virtual machines, the contract call protocol is a unified format specification for different virtual machine modules. This format specification is still used after a new virtual machine module is added. When a smart contract is called between virtual machine modules, for example, another smart contract needs to be called during the execution of a smart contract, a contract call transaction is generated based on the contract call protocol, and the transaction result is constructed as format data that complies with the contract call protocol. Encoding conversion is performed inside each virtual machine module, so that the input parameters in the contract call transaction are converted into a format that complies with the corresponding processing virtual machine module specification and the transaction result complies with the format of the contract call protocol specification.
[0044] It should be noted that in order to highlight the key points, Figure 1A and Figure 1BIn the example, a blockchain node contains multiple virtual machine modules, and cross-virtual machine smart contract calls are implemented between multiple virtual machine modules in the same blockchain node; in other embodiments, there is no limit on the number of virtual machine modules contained in the blockchain node, nor is there a limit on whether the blockchain node where the target smart contract is located and the blockchain node where the smart contract corresponding to the sub-call transaction is located are located on the same node, that is, there is no limit on whether the blockchain nodes where multiple virtual machine modules with mutual calling relationships are located are the same, and they can be located on the same node or on different nodes; these blockchain nodes can implement cross-virtual machine smart contract calls based on the logic of the same target smart contract engine.
[0045] The first exemplary embodiment of the present disclosure provides a method for calling a smart contract across virtual machines. The method provided in this embodiment can be applied to Figure 1A The blockchain node 110 in the exemplary system architecture 100a may be applied to Figure 1B Blockchain node 110 in the example system architecture 100b.
[0046] Figure 2 A flowchart of a method for calling a smart contract across virtual machines according to an embodiment of the present disclosure is schematically shown.
[0047] Reference Figure 2 As shown, the method for calling a smart contract across virtual machines provided by an embodiment of the present disclosure includes the following steps: S210, S220 and S230.
[0048] In step S210, a contract calling protocol predefined for the target smart contract engine is obtained.
[0049] In some embodiments, there are type differences among the multiple virtual machine modules included in the above-mentioned target smart contract engine. The types of all virtual machine modules may be different, or the types of some virtual machine modules may be different.
[0050] The above-mentioned contract call protocol is a protocol of a unified format for different types of virtual machine modules in the above-mentioned target smart contract engine. The contract call protocol uniformly describes the general transaction request format for smart contract calls between multiple virtual machine modules, such as the format of JSON (a syntax for storing and exchanging text information, which can be used to transmit data) objects, including the following fields: call method (Method), return result (Return) and parameter list (Params), among which the data types supported by the above-mentioned contract call protocol include but are not limited to the following types: 32-bit integer type (int32), 64-bit integer type (int64), 256-bit integer type (int256), Boolean type (bool), string type (string), etc.
[0051] The multiple virtual machine modules included in the target smart contract engine or the virtual machine modules that are subsequently expanded by more virtual machine modules are all based on the contract call protocol in this unified format for contract call processing. In some embodiments, the correspondence between the target smart contract engine and the virtual machine module can be one-to-one or one-to-many. In view of the fact that different virtual machine modules in the related art (such as the common blockchain virtual machines V8, EVM, WASM, JVM, etc.) have their own ABI (specification for defining smart contract interfaces) coding specifications and cannot communicate with each other, the embodiment of the present disclosure constructs a coding specification that can be followed by virtual machine modules that are called in the same target smart contract engine, and cross-virtual machine contract calls are made based on this coding specification. As an example of each virtual machine module making a cross-virtual machine smart contract call based on this coding specification GF0, the coding specification followed by virtual machine module A is GFA, the coding specification followed by virtual machine module B is GFB, and the coding specification followed by virtual machine module C is GFC. The two virtual machine modules initially included in the target smart contract engine are the above-mentioned virtual machine module A and virtual machine module B. For the scenario where the smart contract 1 in virtual machine module A needs to make a cross-virtual machine call to the smart contract 2 in virtual machine module B, virtual machine module A needs to call smart contract 2 during the execution of smart contract 1 (for example, the execution of smart contract 1 is the process of the user calling the contract), so it automatically triggers the creation of sub-call transaction 1 (the sub-call transaction is used to call smart contract 2), specifically, the creation of sub-call transaction 1 based on the above-mentioned coding specification GF0. After the target smart contract engine receives this sub-call transaction 1, it determines that it is processed by virtual machine module B according to the contract type in sub-call transaction 1 (corresponding to the contract type of smart contract 2), and then calls virtual machine module B to process the sub-call transaction based on coding specification GF0. Inside virtual machine module B, the sub-call transaction based on coding specification GF0 is first converted to obtain a call code that complies with coding specification GFB, and then the corresponding smart contract 2 is executed based on this call code to obtain the contract execution result. Virtual machine module B performs code conversion processing on the above contract execution result, obtains transaction result 1 that complies with coding specification GF0, and returns the transaction result 1 to virtual machine module A. After virtual machine module A obtains the above transaction result based on coding specification GF0, it performs code conversion processing again, converts transaction result 1 into a format that complies with coding specification GFA, and records it in the data processing record corresponding to virtual machine module A, and continues to perform subsequent processing operations related to this transaction result.
[0052] Assuming that the architecture of the target smart contract engine is expanded, a virtual machine module C is added, and during the execution of smart contract 2, it is necessary to further call smart contract 4 in virtual machine module C, then the expanded architecture still uses the previous contract call protocol (based on coding specification GF0), and only needs to adapt and add the corresponding coding conversion logic inside the newly added virtual machine module C. Similarly, for at least one of the newly added callers or callees, the call logic can be expanded in the above manner. There is no need to rewrite and deploy the newly introduced new smart contract as in the related technology, which effectively reduces the difficulty of expansion and the workload of development.
[0053] For example, virtual machine module B needs to call smart contract 4 during the execution of smart contract 2, so it automatically triggers the creation of another sub-call transaction 2 (the sub-call transaction is used to call smart contract 4), specifically, another sub-call transaction 2 based on the above coding specification GF0. After the target smart contract engine receives the sub-call transaction 2, it determines that it is processed by virtual machine module C according to the contract type in the sub-call transaction (corresponding to the contract type of smart contract 4), and then calls virtual machine module C to process the sub-call transaction 2 based on coding specification GF0. Inside virtual machine module C, the sub-call transaction 2 based on coding specification GF0 is first converted to obtain a call code that conforms to coding specification GFC, and then the corresponding function code of smart contract 4 is executed based on this call code to obtain the contract execution result. Virtual machine module C converts the above contract execution result to obtain transaction result 2 that conforms to coding specification GF0, and returns the transaction result 2 to virtual machine module B. After the virtual machine module B obtains the transaction result 2 based on the coding specification GF0, it performs coding conversion processing again, converts the transaction result into a format that complies with the coding specification GFB, and records it in the data processing record corresponding to the virtual machine module B, and continues to execute subsequent processing operations related to this transaction result.
[0054] By predefining a unified contract calling protocol for the target smart contract engine, this means that cross-virtual machine calls can be made through a commonly followed format, enhancing the interoperability between different virtual machine modules; this standardization helps to simplify the work of developers, so that developers only need to focus on protocol specifications rather than a variety of different calling mechanisms. Setting the encoding conversion processing logic within the virtual machine is more direct and customizable. Therefore, developers do not need to write corresponding smart contracts based on the caller and the callee separately as in the solution based on the intermediate proxy layer in the related technology. They only need to develop the corresponding encoding conversion processing logic for the virtual machine where the call occurs, reducing the workload and difficulty of development.
[0055] In step S220, a contract call transaction based on the above-mentioned contract call protocol is received or created; the above-mentioned contract call transaction includes: a sub-call transaction in which the first smart contract calls the second smart contract; the first virtual machine module where the above-mentioned first smart contract is located and the second virtual machine module where the above-mentioned second smart contract is located are different virtual machine modules.
[0056] In some embodiments, there are two calling scenarios: user calling contract and contract calling contract. The above-mentioned contract calling contract refers to one smart contract calling another smart contract. In the embodiment of the present disclosure, the above-mentioned sub-call transaction occurs in the process of the user calling the target smart contract. The above-mentioned sub-call transaction is a transaction in which the above-mentioned target smart contract directly or indirectly calls other smart contracts. Since the smart contract called in the above-mentioned sub-call transaction and the called smart contract are in different virtual machine modules, the sub-call transaction corresponds to the cross-virtual machine call scenario.
[0057] In some embodiments, the above contract call transaction includes not only the above sub-call transaction, but also: a user call transaction for the target smart contract to be called by the user. Figure 1A As shown, this user call transaction can be created by the blockchain node 110, for example, in the process of responding to the first contract call instruction initiated by the user for the target smart contract, the above-mentioned user call transaction based on the above-mentioned contract call protocol is created.
[0058] Or, in other embodiments, referring to Figure 1B As shown, this user call transaction can be created on the side of the requesting device 120, and the blockchain node 110 receives the user call transaction based on the contract call protocol sent by the requesting device 120. The user call transaction complies with the specification of the contract call protocol.
[0059] In the process of processing the above-mentioned user call transaction, a second contract call instruction is generated by the first smart contract to call the second smart contract, and the creation of the above-mentioned sub-call transaction is triggered.
[0060] In some embodiments, creating a contract call transaction based on the above-mentioned contract call protocol includes: parsing the call information for the smart contract to be called; assembling the above-mentioned call information into a target data object that conforms to the format specified by the above-mentioned contract call protocol; and generating a contract call transaction based on the above-mentioned target data object.
[0061] In step S230, based on the target smart contract engine, the adapted target virtual machine module is called to process the contract call transaction. During the processing of the contract call transaction, the target virtual machine module performs encoding conversion before and after executing the smart contract, so that the input parameters in the contract call transaction are converted into a format that complies with the target virtual machine module specification and the transaction result complies with the format of the contract call protocol specification.
[0062] In some embodiments, based on the above-mentioned target smart contract engine, calling the adapted target virtual machine module to process the above-mentioned contract call transaction, including: based on the above-mentioned target smart contract engine, obtaining the contract type of the smart contract to be called in the above-mentioned contract call transaction; calling the target virtual machine module adapted to the above-mentioned contract type; processing the above-mentioned contract call transaction based on the above-mentioned target virtual machine module.
[0063] In the process of processing contract call transactions, the corresponding target virtual machine module performs encoding conversion processing to realize the conversion of input parameters to the target virtual machine module specification format and the conversion of transaction results to the contract call protocol specification format. The workload of encoding conversion processing is performed by the calling and called virtual machine modules, which can reduce dependence on and interaction with external modules (such as the intermediate proxy layer), improve processing timeliness, and effectively avoid all call transactions and forwarding logic concentrated in the intermediate proxy layer, resulting in high concurrent access pressure that may cause downtime and security risks caused by the intermediate proxy layer being easily attacked.
[0064] In the scenario where smart contracts call each other, the two virtual machine modules that make the smart contract call can be of the same type or different types.
[0065] The above-mentioned contract call transaction carries a target data object in a standard format that complies with the above-mentioned contract call protocol; the above-mentioned target data object includes the following information: call method, return result and parameter list.
[0066] In the process of processing the above-mentioned contract call transaction, before the smart contract is executed, the above-mentioned target virtual machine module performs encoding conversion processing on the input parameters in the contract call transaction to obtain a call code that conforms to the standard format of the above-mentioned target virtual machine module. The corresponding smart contract is executed based on the above-mentioned call code to obtain the contract execution result. The above-mentioned input parameters include: the above-mentioned call method and the above-mentioned parameter list.
[0067] After the smart contract is executed, the target virtual machine module performs encoding conversion on the contract execution result to obtain a transaction result returned in the standard format of the return result.
[0068] In some embodiments, the first virtual machine module and the second virtual machine module are of different types; based on the contract call protocol, when smart contracts are called between virtual machine modules of different types, contract call transactions and transaction results are transmitted in a unified manner, and encoding conversion processing is performed inside the virtual machine module, so that the input parameters in the contract call transaction are converted into a format that complies with the specification of the target virtual machine module, and the transaction results comply with the format of the contract call protocol specification.
[0069] In the embodiment including steps S210~S230, a solution is provided for calling smart contracts between multiple virtual machines based on a unified contract call protocol to support an extensible architecture. In the scenario where a cross-virtual machine call occurs in a smart contract in multiple virtual machine modules included in the target smart contract engine, a unified contract call protocol is predefined for the target smart contract engine, which means that the cross-virtual machine call can be performed in a commonly followed format, thereby enhancing the interoperability between different virtual machine modules. This standardization helps to simplify the work of developers, so that developers only need to focus on protocol specifications rather than a variety of different call mechanisms. Setting the encoding conversion processing logic inside the virtual machine is more direct and customizable. Therefore, developers do not need to write corresponding smart contracts based on the caller and the callee separately as in the solution based on the intermediate proxy layer in the related technology. It is only necessary to develop the matching encoding conversion processing logic for the virtual machine where the call occurs, which reduces the workload and difficulty of development. Moreover, after the newly added virtual machine module is added to the blockchain network corresponding to the above-mentioned target smart contract engine, the overall contract call protocol and transaction processing framework can be used, and only the corresponding encoding conversion processing logic needs to be customized for the newly added virtual machine module, which is easier to adapt to new blockchain technologies and standards, and provides better compatibility and scalability. At the same time, in the process of processing contract call transactions, the virtual machine module performs encoding conversion processing to realize the conversion of input parameters to the target virtual machine module specification format and the conversion of transaction results to the contract call protocol specification format. The encoding conversion processing operation is performed by the calling and called virtual machine modules, which can reduce the dependence and interaction on external modules (such as the intermediate proxy layer), improve processing timeliness, and effectively avoid all call transactions and forwarding logic concentrated in the intermediate proxy layer to generate high concurrent access pressure, which may cause downtime, and the intermediate proxy layer is easy to be attacked. Security risks and other issues; since there is no need to set up an intermediate proxy layer, the complexity and maintenance cost of the system architecture can be reduced. At the same time, since setting the encoding and decoding logic inside the virtual machine is more direct and customizable, it helps to improve the processing efficiency of contract calls compared to the solution through the intermediate proxy layer.
[0070] Figure 3The figure schematically shows a calling path diagram of calling a smart contract during the implementation of the method for calling a smart contract across virtual machines according to an embodiment of the present disclosure.
[0071] In some embodiments, the target smart contract is one of the following situations: the target smart contract is the first smart contract; or, the target smart contract is the direct caller for calling the first smart contract; or, the target smart contract is the indirect caller for calling the first smart contract.
[0072] In an exemplary scenario, the target smart contract is the first smart contract, and the following calling path is constructed: user or requesting device → target smart contract (ie, the first smart contract, such as smart contract 1) → second smart contract (such as smart contract 2), and the arrow represents the call.
[0073] For example, refer to Figure 3 As shown in the solid line box, the user or requesting device calls smart contract 301 (as an example of the target smart contract). During the execution of smart contract 301, it is necessary to further call smart contract 311 and smart contract 312 (as an example of the second smart contract). In some embodiments, during the execution of the processing logic corresponding to calling smart contract 311 or smart contract 312 (for example, corresponding to the processing period t1~t2), the code execution inside smart contract 301 has one of the following two situations: the code or code segment related to the call result is suspended and waits for the result to be returned before executing (for example, it is executed after the t2 period); the code or code segment unrelated to the call result can be executed in parallel (for example, it can be executed within the processing period t1~t2).
[0074] Combination Figure 3 and Figure 1A , Figure 1B As shown, the target virtual machine module where the smart contract 301 is located (for example Figure 1AThe example virtual machine module A) creates sub-call transactions JY11 and JY12 respectively, and the target smart contract engine calls the corresponding target virtual machine module according to the above sub-call transactions JY11 and JY12. For example, the target virtual machine module corresponding to the sub-call transaction JY11 is virtual machine module B, and the target virtual machine module corresponding to the sub-call transaction JY12 is virtual machine module C. In virtual machine module B, in response to receiving the sub-call transaction JY11 based on the contract call protocol, the input parameters of the sub-call transaction JY11 are subjected to a first encoding conversion process. The above input parameters include a calling method and a parameter list, and the input parameters in the sub-call transaction JY11 are converted into a standard format corresponding to virtual machine module B, that is, a call code BM11 that conforms to the standard format of virtual machine module B is obtained; based on the call code BM11, the corresponding smart contract 311 is executed to obtain a contract execution result HR11; then after the smart contract is executed, virtual machine module B performs encoding conversion processing on the contract execution result HR11 to obtain a transaction result R11 returned in accordance with the standard format of the return result specified in the contract call protocol, and the above transaction result R11 is returned from virtual machine module B to virtual machine module A.
[0075] After obtaining the returned transaction result R11, virtual machine module A continues to execute subsequent related program codes; and returns the transaction result after executing the program code of smart contract 301. This transaction result can be presented to the user through the visual interface of the blockchain node, or the blockchain node returns the transaction result to the requesting device.
[0076] Similar to the processing logic of virtual machine module B, in virtual machine module C, in response to receiving a sub-call transaction JY12 based on a contract call protocol, a first encoding conversion process is performed on the input parameters of the sub-call transaction JY12, and the above-mentioned input parameters include a calling method and a parameter list. The input parameters in the sub-call transaction JY12 are converted into the standard format corresponding to the virtual machine module C, that is, a call code BM12 that conforms to the standard format of the virtual machine module C is obtained; based on the call code BM12, the corresponding smart contract 312 is executed to obtain a contract execution result HR12; then after the smart contract is executed, virtual machine module C performs encoding conversion processing on the contract execution result HR12 to obtain a transaction result R12 returned in the standard format of the return result specified in the contract call protocol, and the above-mentioned transaction result R12 is returned from virtual machine module C to virtual machine module A.
[0077] After obtaining the returned transaction result R12, virtual machine module A continues to execute subsequent related program codes; and returns the transaction result after executing the program code of smart contract 301. This transaction result can be presented to the user through the visual interface of the blockchain node, or the blockchain node returns the transaction result to the requesting device.
[0078] Although the above example uses the same call level including calls to two smart contracts as an example, in fact, there is no limit on the number of calls to smart contracts in the same call level, which can be one or more (≥2). These parallel-called smart contracts can be called in any order or in a specified order, depending on the execution trigger logic; the transaction results of each of these called smart contracts can be associated (for example, they are commonly used for the judgment of a certain logic of the target smart contract 301) or not. The specific call relationship, call order, and whether there is an association between the returned transaction results and other call information are pre-set in the smart contract of the caller role.
[0079] In another exemplary scenario, the target smart contract is the direct caller for calling the first smart contract, and the following calling path is constructed: user → target smart contract → first smart contract → second smart contract. Figure 3 As shown in the solid line frame and the single-dot dashed line frame, the user or requesting device calls smart contract 301 (taking smart contract 301 as an example of the target smart contract); during the execution of smart contract 301, it is necessary to further call smart contract 311 and smart contract 312 (taking smart contracts 311 and 312 as examples of the first smart contract); during the execution of smart contract 311, it is necessary to further call smart contract 321 (as an example of the second smart contract), and during the execution of smart contract 312, it is necessary to further call smart contract 322 (as an example of the second smart contract). The processing logic of the calling process can be understood by referring to the processing logic of the sub-call transactions JY11 and JY12. Specifically, the smart contract 321 and the corresponding virtual machine module D can be compared with the smart contract 311 and the corresponding virtual machine module B, the sub-call transaction JY21 can be compared with the sub-call transaction JY11, and the transaction result R21 can be compared with the transaction result R11. Similarly, the smart contract 322 and the corresponding virtual machine module E can be compared with the smart contract 312 and the corresponding virtual machine module C, the sub-call transaction JY22 can be compared with the sub-call transaction JY12, and the transaction result R22 can be compared with the transaction result R12. No further details will be given here.
[0080] In another exemplary scenario, the target smart contract is an indirect caller for calling the first smart contract, and the following calling path is constructed: user → target smart contract → smart contract X (smart contract X indicates that the number and number of smart contracts are not limited, it can be one or more smart contracts, and the number of smart contracts called at each layer is also not limited, it can be one or more) → first smart contract → second smart contract. For example, refer to Figure 3As shown in the solid-line frame, the dashed-line frame and the dotted-line frame, the user or the requesting device calls the smart contract 301 (taking the smart contract 301 as an example of the target smart contract); during the execution of the smart contract 301, it is necessary to further call the smart contract 311 and the smart contract 312 (taking the smart contracts 311 and 312 as examples of the first smart contract); during the execution of the smart contract 311, it is necessary to further call the smart contract 321 (as an example of the smart contract X), and during the execution of the smart contract 312, it is necessary to further call the smart contract 322 (as an example of the smart contract X); during the execution of the smart contract 321, it is necessary to further call the smart contract 331 (as an example of the second smart contract), and during the execution of the smart contract 322, it is necessary to further call the smart contract 332 (as an example of the second smart contract). The multi-layer call processing logic of the call process can be understood by referring to the two-layer or three-layer call processing logic in the previous example. For example, the detailed processing processes corresponding to the sub-call transactions JY31, JY32 and the corresponding transaction results R31, R32 of the specific virtual machine module F and virtual machine module G respectively can also be understood by referring to the previous description and will not be explained in detail here.
[0081] Reference Figure 1A As shown, in an exemplary implementation scenario, for a case involving a user calling a contract, the blockchain node 110 creates a user calling transaction TX1 (an example of a contract calling transaction) based on the above-mentioned contract calling protocol in response to receiving the first contract creation instruction. For a case involving a contract calling a contract, the virtual machine module A in the blockchain node 110 generates a second contract calling instruction for smart contract 1 (as an example of the first smart contract) to call smart contract 2 (as an example of the second smart contract) during the processing of the above-mentioned user calling transaction TX1, and automatically triggers the creation of a sub-calling transaction TX2 based on the above-mentioned contract calling protocol.
[0082] Reference Figure 1B As shown, in another implementation scenario, for a situation involving a user calling a smart contract, the blockchain node 110 receives a user call transaction TX1 (an example of a contract call transaction) based on a contract call protocol initiated by the requesting device 120; for a situation involving a contract calling a contract, the blockchain node 110 generates a second contract call instruction for a first smart contract to call a second smart contract during the process of processing the above user call transaction TX1, and triggers the creation of a sub-call transaction TX2 based on the above contract call protocol.
[0083] Whether the user calls a contract or the contract calls a contract, the corresponding contract call transaction complies with the specifications of the contract call protocol. Therefore, in the process of contract calls between different virtual machine modules, the request process and response process of the contract call transaction can shield the differences between the internal specifications of each virtual machine module and support flexible call architecture expansion. Compared with the method based on the intermediate proxy layer, after the new virtual machine module is added to the blockchain network corresponding to the above-mentioned target smart contract engine, the overall contract call protocol and transaction processing framework can be used. Only the corresponding encoding conversion processing logic needs to be customized for the new virtual machine module, which is easier to adapt to new blockchain technologies and standards and provides better compatibility and scalability.
[0084] As an example implementation scenario, refer to Figure 1B As shown, in the user call contract, the request device 120 used by the user side first creates a user call transaction TX1 according to the predefined contract call protocol. The user call transaction TX1 contains relevant information and parameters of the smart contract. The request device 120 sends the user call transaction TX1 to the blockchain node 110 of the blockchain system. Or, refer to Figure 1A As shown, the user operates the blockchain node to generate a first contract creation instruction, and the blockchain node 110 creates a user call transaction TX1 (an example of a contract call transaction) based on the contract call protocol.
[0085] The target smart contract engine of the blockchain node receives and processes the above transaction TX1, analyzes the smart contract type and calls the corresponding virtual machine module A. In virtual machine module A, the input parameters are encoded and converted according to the contract call protocol, and then the contract call function is executed. During this process, virtual machine module A may need to call another smart contract and create a sub-call transaction TX2 (another example of a contract call transaction) according to the smart contract call protocol.
[0086] In the execution logic of the contract calling contract, the target smart contract engine starts to process the above transaction TX2 and calls the corresponding virtual machine module B according to its smart contract type. In virtual machine module B, the input parameter is also converted after encoding and processing to start the contract calling function. After the contract execution result is obtained, the execution result is converted according to the contract calling protocol to obtain a transaction result J2 in the standard format of the return result specified in the contract calling protocol. The transaction result J2 is returned to virtual machine module A, and virtual machine module A continues to execute the subsequent smart contract logic. After the virtual machine module completes the execution of all contract logic, the obtained execution result is converted to obtain the final transaction result J1.
[0087] Based on the same technical concept, the second exemplary embodiment of the present disclosure provides a method for invoking transaction processing. The method provided in this embodiment can be applied to Figure 1A The blockchain node 110 in the exemplary system architecture 100a may be applied to Figure 1B Blockchain node 110 in the example system architecture 100b.
[0088] Figure 4 The flowchart of the method for invoking transaction processing according to an embodiment of the present disclosure is schematically shown.
[0089] Reference Figure 4 As shown, the method for calling transaction processing provided by the embodiment of the present disclosure includes the following steps: S410 and S420.
[0090] In step S410, a user call transaction of a user to a target smart contract is received or created, wherein the user call transaction is created based on a contract call protocol, which is a unified protocol predefined for the target smart contract engine.
[0091] Receiving or creating a user call transaction of a user to a target smart contract includes: receiving a user call transaction of a user to a target smart contract, or creating a user call transaction of a user to a target smart contract.
[0092] The receiving of a user call transaction to a target smart contract includes: receiving a user call transaction to a target smart contract sent by a requesting device.
[0093] The above-mentioned creation of a user call transaction for a target smart contract includes: receiving a first contract call instruction initiated by a user for the target smart contract; and creating a user call transaction based on the above-mentioned contract call protocol according to the above-mentioned first contract call instruction.
[0094] In the scenario where cross-virtual machine calls occur in smart contracts within multiple virtual machine modules contained in the target smart contract engine, a unified contract call protocol is predefined for the target smart contract engine, which means that cross-virtual machine calls can be made in a commonly followed format, enhancing the interoperability between different virtual machine modules; this standardization helps to simplify the work of developers, so that developers only need to focus on protocol specifications rather than a variety of different call mechanisms. Setting the encoding conversion processing logic inside the virtual machine is more direct and customizable. Therefore, developers do not need to write corresponding smart contracts based on the caller and the callee separately as in the solution based on the intermediate proxy layer in the related technology. They only need to develop the matching encoding conversion processing logic for the virtual machine where the call occurs, reducing the workload and difficulty of development. Moreover, after the new virtual machine module is added to the blockchain network corresponding to the above-mentioned target smart contract engine, the overall contract call protocol and transaction processing framework can be used, and only the corresponding encoding conversion processing logic needs to be customized for the new virtual machine module, which is easier to adapt to new blockchain technologies and standards and provides better compatibility and scalability.
[0095] In step S420, based on the above-mentioned target smart contract engine, the adapted first target virtual machine module is called to process the above-mentioned user call transaction; in the process of processing the above-mentioned user call transaction, the creation of a sub-call transaction based on the above-mentioned contract call protocol is triggered, and the adapted second target virtual machine module is called to process the above-mentioned sub-call transaction; the above-mentioned sub-call transaction is a transaction in which the above-mentioned target smart contract directly or indirectly calls other smart contracts.
[0096] In the embodiments of the present disclosure, in order to distinguish and describe the corresponding target virtual machine modules in the calling process of a user calling a contract and a contract calling a contract, a first target virtual machine module is used to describe the virtual machine module used to process user call transactions; and a second target virtual machine module is used to describe the virtual machine module used to process sub-call transactions.
[0097] Among them, in the processing of the contract call transaction, the adapted target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the above-mentioned contract call transaction are converted into a format that conforms to the specifications of the adapted target virtual machine module and the transaction results conform to the format of the above-mentioned contract call protocol specifications; wherein the above-mentioned contract call transaction is at least one of the following: the above-mentioned user call transaction, the above-mentioned sub-call transaction.
[0098] For example, in the process of processing user call transactions, the adapted first target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the above-mentioned user call transaction are converted into a format that complies with the specifications of the adapted first target virtual machine module, and the transaction results comply with the format of the above-mentioned contract call protocol specifications; in the process of processing sub-call transactions, the adapted second target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the above-mentioned sub-call transaction are converted into a format that complies with the specifications of the adapted second target virtual machine module, and the transaction results comply with the format of the above-mentioned contract call protocol specifications.
[0099] In the process of processing contract call transactions, the virtual machine module performs encoding conversion processing to realize the conversion of input parameters to the target virtual machine module specification format and the conversion of transaction results to the contract call protocol specification format. The workload of encoding conversion processing is performed by the calling and called virtual machine modules, which can reduce the dependence and interaction on external modules (such as the intermediate proxy layer), improve processing timeliness, and effectively avoid all calling transactions and forwarding logic concentrated in the intermediate proxy layer to generate high concurrent access pressure, which may cause downtime, and the intermediate proxy layer is easy to be attacked. Security risks and other issues; since there is no need to set up an intermediate proxy layer, the complexity and maintenance cost of the system architecture can be reduced. At the same time, since setting the encoding and decoding logic inside the virtual machine is more direct and customizable, it helps to improve the processing efficiency of contract calls compared to the solution through the intermediate proxy layer.
[0100] In some embodiments, the target smart contract engine includes multiple virtual machine modules of different types, and the contract call protocol is a protocol of a unified format for different types of virtual machine modules in the target smart contract engine.
[0101] The above-mentioned sub-call transaction is a transaction in which the first smart contract calls the second smart contract; wherein the first virtual machine module in which the above-mentioned first smart contract is located is of a different type from the second virtual machine module in which the above-mentioned second smart contract is located.
[0102] The target smart contract is one of the following: the target smart contract is the first smart contract; or the target smart contract is the direct caller for calling the first smart contract; or the target smart contract is the indirect caller for calling the first smart contract. For details, please refer to the description of the first embodiment.
[0103] In some embodiments, the above-mentioned contract call transaction carries a target data object in a standard format that complies with the above-mentioned contract call protocol; the above-mentioned target data object includes the following information: call method, return result and parameter list.
[0104] Among them, in the processing of the above-mentioned contract call transaction, before the corresponding smart contract is executed, the adapted target virtual machine module will encode and convert the input parameters in the contract call transaction to obtain a call code that conforms to the standard format of the adapted target virtual machine module, and the above-mentioned input parameters include: the above-mentioned calling method and the above-mentioned parameter list; the corresponding smart contract is executed based on the above-mentioned calling code.
[0105] After the smart contract is executed, the adapted target virtual machine module encodes and converts the contract execution result to obtain the transaction result returned in the standard format of the above-mentioned return result.
[0106] Whether the user calls a contract or the contract calls a contract, the corresponding contract call transaction complies with the specifications of the contract call protocol. Therefore, in the process of contract calls between different virtual machine modules, the request process and response process of the contract call transaction can shield the differences between the internal specifications of each virtual machine module and support flexible call architecture expansion. Compared with the method based on the intermediate proxy layer, after the new virtual machine module is added to the blockchain network corresponding to the above-mentioned target smart contract engine, the overall contract call protocol and transaction processing framework can be used. Only the corresponding encoding conversion processing logic needs to be customized for the new virtual machine module, which is easier to adapt to new blockchain technologies and standards and provides better compatibility and scalability.
[0107] According to an embodiment of the present disclosure, in the process of processing the above-mentioned user call transaction, the creation of a sub-call transaction based on the above-mentioned contract call protocol is triggered, including: in the process of processing the above-mentioned user call transaction, parsing the second call information of the smart contract to be called that is required to be directly called or indirectly called by the execution of the above-mentioned target smart contract; assembling the above-mentioned second call information into a second target data object that conforms to the format specified by the above-mentioned contract call protocol; generating a sub-call transaction based on the above-mentioned second target data object; wherein the above-mentioned first target virtual machine module matches the contract type of the above-mentioned target smart contract; and the above-mentioned second target virtual machine module matches the contract type of other smart contracts to be called.
[0108] This embodiment may include more details or beneficial effects, and reference may be made to the relevant description of the first embodiment.
[0109] A third exemplary embodiment of the present disclosure provides a device for invoking a smart contract across virtual machines.
[0110] Figure 5 The structure block diagram of the apparatus for calling a smart contract across virtual machines according to an embodiment of the present disclosure is schematically shown;
[0111] Reference Figure 5As shown, the device 500 for calling a smart contract across virtual machines provided by an embodiment of the present disclosure includes: a protocol acquisition module 501, a first call transaction receiving or creating module 502, and a target smart contract engine 503.
[0112] The above-mentioned protocol acquisition module 501 is used to obtain the contract call protocol predefined for the target smart contract engine.
[0113] The above-mentioned first call transaction receiving or creating module 502 is used to receive or create a contract call transaction based on the above-mentioned contract call protocol; the above-mentioned contract call transaction includes: a sub-call transaction in which the first smart contract calls the second smart contract; the first virtual machine module where the above-mentioned first smart contract is located and the second virtual machine module where the above-mentioned second smart contract is located are different virtual machine modules.
[0114] The above-mentioned target smart contract engine 503 is used to call the adapted target virtual machine module to process the above-mentioned contract call transaction; during the processing of the above-mentioned contract call transaction, the above-mentioned target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the above-mentioned contract call transaction are converted into a format that complies with the specifications of the above-mentioned target virtual machine module and the transaction results comply with the format of the above-mentioned contract call protocol specifications.
[0115] According to an embodiment of the present disclosure, the above-mentioned contract call transaction also includes: a user call transaction in which a user calls a target smart contract; in the process of responding to a first contract call instruction initiated by a user for a target smart contract, the above-mentioned user call transaction based on the above-mentioned contract call protocol is created; or, the above-mentioned user call transaction based on the above-mentioned contract call protocol sent from a requesting device is received. In the process of processing the above-mentioned user call transaction, a second contract call instruction in which the first smart contract calls the second smart contract is generated, and the creation of the above-mentioned sub-call transaction is triggered.
[0116] According to an embodiment of the present disclosure, the target smart contract is one of the following situations: the target smart contract is the first smart contract; or, the target smart contract is the direct caller for calling the first smart contract; or, the target smart contract is the indirect caller for calling the first smart contract.
[0117] According to an embodiment of the present disclosure, the above-mentioned contract call transaction carries a target data object in a standard format that complies with the above-mentioned contract call protocol; the above-mentioned target data object contains the following information: call method, return result and parameter list. Among them, in the processing of the above-mentioned contract call transaction, before the execution of the smart contract, the above-mentioned target virtual machine module performs code conversion processing on the input parameters in the contract call transaction to obtain a call code in a standard format that complies with the above-mentioned target virtual machine module, and the above-mentioned input parameters include: the above-mentioned call method and the above-mentioned parameter list; the corresponding smart contract is executed based on the above-mentioned call code. After the smart contract is executed, the above-mentioned target virtual machine module performs code conversion processing on the contract execution result to obtain a transaction result returned in the standard format of the above-mentioned return result.
[0118] According to an embodiment of the present disclosure, creating a contract call transaction based on the above-mentioned contract call protocol includes: parsing the call information for the smart contract to be called; assembling the above-mentioned call information into a target data object that conforms to the format specified by the above-mentioned contract call protocol; generating a contract call transaction based on the above-mentioned target data object. Based on the above-mentioned target smart contract engine, calling the adapted target virtual machine module to process the above-mentioned contract call transaction includes: based on the above-mentioned target smart contract engine, obtaining the contract type of the smart contract to be called in the above-mentioned contract call transaction; calling the target virtual machine module adapted to the above-mentioned contract type; processing the above-mentioned contract call transaction based on the above-mentioned target virtual machine module.
[0119] For more details of this embodiment, please refer to the relevant description of the first embodiment, which will not be repeated here.
[0120] A fourth exemplary embodiment of the present disclosure provides an apparatus for invoking transaction processing.
[0121] Figure 6 The structure block diagram of the device for invoking transaction processing according to an embodiment of the present disclosure is schematically shown.
[0122] Reference Figure 6 As shown, the device 600 for call transaction processing provided by the embodiment of the present disclosure includes: a second call transaction receiving or creating module 601, and a target smart contract engine 602.
[0123] The second call transaction receiving or creating module 601 is used to receive or create a user call transaction for a user to call a target smart contract; the user call transaction is created based on a contract call protocol, and the contract call protocol is a unified protocol predefined for the target smart contract engine.
[0124] The target smart contract engine 602 is used to call the adapted first target virtual machine module to process the user call transaction; in the process of processing the user call transaction, the creation of a sub-call transaction based on the contract call protocol is triggered, and the adapted second target virtual machine module is called to process the sub-call transaction; the sub-call transaction is a transaction in which the target smart contract directly or indirectly calls other smart contracts. In the process of processing the contract call transaction, the adapted target virtual machine module performs encoding conversion before and after executing the smart contract, so that the input parameters in the contract call transaction are converted into the format that conforms to the specifications of the adapted target virtual machine module and the transaction results conform to the format of the contract call protocol specifications; the contract call transaction is at least one of the following: the user call transaction and the sub-call transaction.
[0125] For more details of this embodiment, please refer to the relevant description of the second embodiment, which will not be repeated here.
[0126] Any multiple of the functional modules included in the above-mentioned device 600 or device 700 can be combined into one module for implementation, or any one of the modules can be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules can be combined with at least part of the functions of other modules and implemented in one module. At least one of the functional modules included in the device 600 or device 700 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application-specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware and firmware or in any appropriate combination of any of them. Alternatively, at least one of the functional modules included in the device 600 or device 700 can be at least partially implemented as a computer program module, and when the computer program module is run, the corresponding function can be executed.
[0127] A fifth exemplary embodiment of the present disclosure provides an electronic device.
[0128] Figure 7 The structural block diagram of the electronic device provided by the embodiment of the present disclosure is schematically shown.
[0129] Reference Figure 7As shown, the electronic device 700 provided by the embodiment of the present disclosure includes a processor 701, a communication interface 702, a memory 703 and a communication bus 704, wherein the processor 701, the communication interface 702 and the memory 703 communicate with each other through the communication bus 704; the memory 703 is used to store computer programs; the processor 701 is used to implement the method of calling a smart contract across virtual machines or calling a transaction processing method as described above when executing the program stored in the memory.
[0130] The sixth exemplary embodiment of the present disclosure further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for calling a smart contract across virtual machines or the method for calling transaction processing as described above.
[0131] The computer-readable storage medium may be included in the device or apparatus described in the above embodiment; or it may exist independently without being assembled into the device or apparatus. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present disclosure is implemented.
[0132] According to an embodiment of the present disclosure, a computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, apparatus, or device.
[0133] It should be noted that the collection, collection, update, analysis, processing, use, transmission, storage and other aspects of user personal information involved in the technical solution provided by the embodiments of the present disclosure are in compliance with the provisions of relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken for user personal information to prevent illegal access to user personal information data and maintain the security of user personal information, network security and national security.
[0134] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0135] The foregoing is merely a specific embodiment of the present disclosure, which enables those skilled in the art to understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features applied herein.
Claims
1. A method for calling a smart contract across virtual machines, characterized in that: include: Get the predefined contract calling protocol for the target smart contract engine; Receiving or creating a contract call transaction based on the contract call protocol; The contract call transaction includes: a sub-call transaction in which the first smart contract calls the second smart contract; the first virtual machine module in which the first smart contract is located and the second virtual machine module in which the second smart contract is located are virtual machine modules of different types; Based on the target smart contract engine, call the adapted target virtual machine module to process the contract call transaction; in the process of processing the contract call transaction, the target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the contract call transaction are converted into a format that conforms to the specification of the target virtual machine module and the transaction result conforms to the format of the contract call protocol specification; Among them, there are types of differences in the multiple virtual machine modules included in the target smart contract engine, and the contract calling protocol is a protocol of a unified format for different types of virtual machine modules in the target smart contract engine.
2. The method according to claim 1, characterized in that The contract call transaction also includes: a user call transaction for a target smart contract to be called by a user; In the process of responding to the first contract call instruction initiated by the user for the target smart contract, creating the user call transaction based on the contract call protocol; or receiving the user call transaction based on the contract call protocol sent from the requesting device; In the process of processing the user call transaction, a second contract call instruction is generated for the first smart contract to call the second smart contract, and the creation of the sub-call transaction is triggered.
3. The method according to claim 2, characterized in that The target smart contract is one of the following: The target smart contract is the first smart contract; or, The target smart contract is a direct caller for calling the first smart contract; or, The target smart contract is an indirect caller for calling the first smart contract.
4. The method according to claim 1, characterized in that The contract call transaction carries a target data object in a standard format that complies with the contract call protocol; the target data object includes the following information: call method, return result, and parameter list; Wherein, in the processing of the contract call transaction, before the smart contract is executed, the target virtual machine module performs encoding conversion processing on the input parameters in the contract call transaction to obtain a call code that conforms to the standard format of the target virtual machine module, wherein the input parameters include: the call method and the parameter list; and executes the corresponding smart contract based on the call code; After the smart contract is executed, the target virtual machine module performs encoding conversion processing on the contract execution result to obtain a transaction result returned in accordance with the standard format of the return result.
5. The method according to any one of claims 1 to 4, characterized in that Creating a contract call transaction based on the contract call protocol, including: parsing the call information for the smart contract to be called; assembling the call information into a target data object that conforms to the format specified by the contract call protocol; generating a contract call transaction based on the target data object; Based on the target smart contract engine, calling the adapted target virtual machine module to process the contract call transaction, including: based on the target smart contract engine, obtaining the contract type of the smart contract to be called in the contract call transaction; calling the target virtual machine module adapted to the contract type; processing the contract call transaction based on the target virtual machine module.
6. A method for invoking transaction processing, characterized in that: include: Receive or create a user call transaction to the target smart contract; The user call transaction is created based on a contract call protocol, where the contract call protocol is a unified protocol predefined for a target smart contract engine; Based on the target smart contract engine, calling the adapted first target virtual machine module to process the user call transaction; in the process of processing the user call transaction, triggering the creation of a sub-call transaction based on the contract call protocol, and calling the adapted second target virtual machine module to process the sub-call transaction; the sub-call transaction is a transaction in which the target smart contract directly or indirectly calls other smart contracts; Wherein, in the process of processing the contract call transaction, the adapted target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the contract call transaction are converted into a format that conforms to the specification of the adapted target virtual machine module and the transaction result conforms to the format of the contract call protocol specification; wherein, the contract call transaction is at least one of the following: the user call transaction, the sub-call transaction; There are differences in the types of multiple virtual machine modules included in the target smart contract engine, and the contract calling protocol is a protocol of a unified format for different types of virtual machine modules in the target smart contract engine; The sub-call transaction is a transaction in which the first smart contract calls the second smart contract; wherein the first virtual machine module where the first smart contract is located is of a different type from the second virtual machine module where the second smart contract is located.
7. The method according to claim 6, characterized in that The target smart contract is one of the following: The target smart contract is the first smart contract; or, The target smart contract is a direct caller for calling the first smart contract; or, The target smart contract is an indirect caller for calling the first smart contract.
8. The method according to claim 6, characterized in that The contract call transaction carries a target data object in a standard format that complies with the contract call protocol; the target data object includes the following information: call method, return result, and parameter list; Wherein, in the processing of the contract call transaction, before the corresponding smart contract is executed, the adapted target virtual machine module performs encoding conversion processing on the input parameters in the contract call transaction to obtain a call code in a standard format that conforms to the adapted target virtual machine module, wherein the input parameters include: the call method and the parameter list; and the corresponding smart contract is executed based on the call code; After the smart contract is executed, the adapted target virtual machine module encodes and converts the contract execution result to obtain a transaction result returned in the standard format of the return result.
9. The method according to claim 6, characterized in that In the process of processing the user call transaction, triggering the creation of a sub-call transaction based on the contract call protocol, including: in the process of processing the user call transaction, parsing the second call information of the smart contract to be called that is directly or indirectly called by the target smart contract execution; assembling the second call information into a second target data object that conforms to the format specified by the contract call protocol; generating a sub-call transaction based on the second target data object; wherein the first target virtual machine module matches the contract type of the target smart contract; and the second target virtual machine module matches the contract type of other smart contracts to be called; Receiving or creating a user call transaction of a user to a target smart contract includes: receiving a user call transaction of a user to a target smart contract, or creating a user call transaction of a user to a target smart contract; The receiving a user call transaction of the target smart contract includes: receiving a user call transaction of the target smart contract sent by the requesting device; The creating of a user call transaction for a target smart contract includes: receiving a first contract call instruction initiated by a user for the target smart contract; and creating a user call transaction based on the contract call protocol according to the first contract call instruction.
10. A device for calling a smart contract across virtual machines, characterized in that: include: The protocol acquisition module is used to obtain the predefined contract call protocol for the target smart contract engine; A first call transaction receiving or creating module, used to receive or create a contract call transaction based on the contract call protocol; The contract call transaction includes: a sub-call transaction in which the first smart contract calls the second smart contract; the first virtual machine module in which the first smart contract is located and the second virtual machine module in which the second smart contract is located are virtual machine modules of different types; The target smart contract engine is used to call the adapted target virtual machine module to process the contract call transaction; during the processing of the contract call transaction, the target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the contract call transaction are converted into a format that conforms to the specification of the target virtual machine module and the transaction result conforms to the format of the contract call protocol specification; Among them, there are types of differences in the multiple virtual machine modules included in the target smart contract engine, and the contract calling protocol is a protocol of a unified format for different types of virtual machine modules in the target smart contract engine.
11. A device for invoking transaction processing, characterized in that: include: The second call transaction receiving or creating module is used to receive or create a user call transaction for a user to call a target smart contract; The user call transaction is created based on a contract call protocol, where the contract call protocol is a unified protocol predefined for a target smart contract engine; The target smart contract engine is used to call the adapted first target virtual machine module to process the user call transaction; in the process of processing the user call transaction, trigger the creation of a sub-call transaction based on the contract call protocol, and call the adapted second target virtual machine module to process the sub-call transaction; the sub-call transaction is a transaction in which the target smart contract directly or indirectly calls other smart contracts; Wherein, in the process of processing the contract call transaction, the adapted target virtual machine module performs encoding conversion processing before and after executing the smart contract, so that the input parameters in the contract call transaction are converted into a format that conforms to the specification of the adapted target virtual machine module and the transaction result conforms to the format of the contract call protocol specification; wherein, the contract call transaction is at least one of the following: the user call transaction, the sub-call transaction; There are differences in the types of multiple virtual machine modules included in the target smart contract engine, and the contract calling protocol is a protocol of a unified format for different types of virtual machine modules in the target smart contract engine; The sub-call transaction is a transaction in which the first smart contract calls the second smart contract; wherein the first virtual machine module where the first smart contract is located is of a different type from the second virtual machine module where the second smart contract is located.
12. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory, used to store computer programs; A processor, for implementing the method according to any one of claims 1 to 9 when executing a program stored in a memory.
13. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 9 is implemented.
