Resource calculation method, device, electronic device and readable storage medium

By dividing the bytecode set into bytecode blocks executed sequentially, the resources required for each instruction are calculated, and control instructions are added to the block, the problem of low resource computing efficiency in distributed computing systems is solved, and more efficient resource utilization is achieved.

CN113296837BActive Publication Date: 2025-02-28ALIBABA GROUP HOLDING LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011438548.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-07
Publication Date
2025-02-28
Estimated Expiration
2040-12-07

AI Technical Summary

Technical Problem

In a distributed computing system, the code needs to be run on each device, calculating the resources required for each instruction one by one, resulting in excessive computing volume and low efficiency.

Method used

The bytecode set is divided into bytecode blocks, the instructions within the block are executed sequentially, the resources required for each instruction are calculated, and control instructions are added to the block to form a new set of bytecode blocks.

Benefits of technology

The calculation amount of resource calculation is reduced, the operation efficiency of bytecode is improved, and unnecessary resource calculation is avoided.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113296837B_ABST
    Figure CN113296837B_ABST
Patent Text Reader

Abstract

The disclosed embodiments disclose a resource calculation method, device, electronic device and readable storage medium. The resource calculation method includes: dividing a first bytecode set into a first bytecode block, wherein the instructions in the first bytecode block are executed sequentially; calculating the first resource required to execute the instructions in the first bytecode block; adding a first control instruction to the first bytecode block according to the first resource required to execute the instructions in the first bytecode block to obtain a second bytecode block; obtaining a second bytecode set including the second bytecode block, thereby reducing the amount of computation of resource calculation and improving the running efficiency of the bytecode.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a resource computing method, device, electronic device, and readable storage medium. Background Art

[0002] In some applications of distributed computing systems, code needs to run on every distributed device. However, calculating and controlling the resources required to execute each instruction individually is computationally intensive and inefficient. Summary of the Invention

[0003] In order to solve the problems in the related art, the embodiments of the present disclosure provide a resource calculation method, device, electronic device and readable storage medium.

[0004] In a first aspect, an embodiment of the present disclosure provides a resource calculation method, including:

[0005] dividing a first bytecode set into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially;

[0006] calculating first resources required to execute instructions in the first bytecode block;

[0007] adding a first control instruction to the first bytecode block according to a first resource required to execute the instructions in the first bytecode block to obtain a second bytecode block;

[0008] A second bytecode set including the second bytecode block is obtained.

[0009] In combination with the first aspect, in a first implementation manner of the first aspect of the present disclosure, the first bytecode set is compiled from a first source code.

[0010] In combination with the first aspect, in a second implementation of the first aspect of the present disclosure, the instructions in the first bytecode set and the second bytecode set are executed in a distributed smart contract.

[0011] In combination with the second implementation manner of the first aspect, in a third implementation manner of the first aspect of the present disclosure, the instructions in the first bytecode set and the second bytecode set are executed in a virtual machine.

[0012] In combination with any one of the first aspect to the second implementation manner of the first aspect, in a fourth implementation manner of the first aspect of the present disclosure, the first bytecode set is divided into first bytecode blocks, where instructions in the first bytecode blocks are executed sequentially, including:

[0013] Scanning instructions in the first bytecode set to obtain specific instructions;

[0014] The first bytecode set is divided into a plurality of first bytecode blocks with the specific instructions as boundaries, wherein the instructions in the first bytecode blocks are executed sequentially.

[0015] In conjunction with the fourth implementation of the first aspect, in a fifth implementation of the first aspect of the present disclosure, the specific instruction includes at least one of the following:

[0016] Function entry instruction, loop instruction, branch jump instruction, jump instruction, function call instruction, function return instruction, end instruction.

[0017] In combination with any one of the first aspect to the second implementation manner of the first aspect, in a sixth implementation manner of the first aspect of the present disclosure, the calculating the first resources required to execute the instructions in the first bytecode block includes:

[0018] Scan each instruction in the first bytecode block one by one;

[0019] Acquire a second resource required to execute each instruction in the first bytecode block;

[0020] The first resources required to execute all instructions in the first bytecode block are calculated according to the second resources required to execute each instruction in the first bytecode block.

[0021] In combination with the sixth implementation of the first aspect, in the seventh implementation of the first aspect of the present disclosure,

[0022] The second resource required to execute each instruction in the first bytecode block is a known amount; and / or

[0023] The first resource required to execute the instructions in the first bytecode block is a static quantity.

[0024] In combination with the second implementation manner of the first aspect, in an eighth implementation manner of the first aspect of the present disclosure, the operation executed by the first control instruction includes:

[0025] Calculating a remaining amount of resources based on a total amount of resources and a first resource required to execute instructions in the first bytecode block;

[0026] Based on the remaining amount of resources being lower than a first threshold, execution of the second bytecode set is stopped.

[0027] In combination with any one of the first aspect to the second implementation of the first aspect, the ninth implementation of the first aspect of the present disclosure further includes:

[0028] The second bytecode set is loaded and instructions in the second bytecode set are executed.

[0029] In combination with the ninth implementation manner of the first aspect, in a tenth implementation manner of the first aspect of the present disclosure, loading the second bytecode set and executing instructions in the second bytecode set includes:

[0030] The second bytecode set is loaded into the distributed smart contract and instructions in the second bytecode set are executed.

[0031] In combination with the tenth implementation manner of the first aspect, in an eleventh implementation manner of the first aspect of the present disclosure, loading the second bytecode set and executing instructions in the second bytecode set includes:

[0032] The second bytecode set is loaded into the virtual machine and instructions in the second bytecode set are executed.

[0033] In a second aspect, an embodiment of the present disclosure provides a resource computing device, including:

[0034] a first bytecode block division module configured to divide the first bytecode set into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially;

[0035] a first resource calculation module, configured to calculate first resources required to execute instructions in the first bytecode block;

[0036] a second bytecode block acquisition module configured to add a first control instruction to the first bytecode block according to a first resource required to execute the instruction in the first bytecode block, so as to obtain a second bytecode block;

[0037] The second bytecode set acquisition module is configured to acquire a second bytecode set including the second bytecode block.

[0038] In combination with the second aspect, in a first implementation manner of the second aspect of the present disclosure, the first bytecode set is compiled from a first source code.

[0039] In combination with the second aspect, in a second implementation of the second aspect of the present disclosure, the instructions in the first bytecode set and the second bytecode set are executed in a distributed smart contract.

[0040] In combination with the second implementation manner of the second aspect, in a third implementation manner of the second aspect of the present disclosure, the instructions in the first bytecode set and the second bytecode set are executed in a virtual machine.

[0041] In combination with any one of the second aspect to the second implementation manner of the second aspect, in a fourth implementation manner of the second aspect of the present disclosure, the first bytecode block division module includes:

[0042] a specific instruction acquisition submodule, configured to scan instructions in the first bytecode set to obtain specific instructions;

[0043] The first bytecode block division submodule is configured to divide the first bytecode set into a plurality of first bytecode blocks based on the specific instructions as boundaries, wherein the instructions in the first bytecode blocks are executed sequentially.

[0044] In conjunction with the fourth implementation of the second aspect, in a fifth implementation of the second aspect of the present disclosure, the specific instruction includes at least one of the following:

[0045] Function entry instruction, loop instruction, branch jump instruction, jump instruction, function call instruction, function return instruction, end instruction.

[0046] In combination with any one of the second aspect to the second implementation manner of the second aspect, in a sixth implementation manner of the second aspect of the present disclosure, the first resource calculation module includes:

[0047] an instruction scanning submodule, configured to scan each instruction in the first bytecode block one by one;

[0048] a second resource acquisition submodule, configured to acquire a second resource required to execute each instruction in the first bytecode block;

[0049] The first resource calculation submodule is configured to calculate the first resources required to execute all instructions in the first bytecode block according to the second resources required to execute each instruction in the first bytecode block.

[0050] In combination with the sixth implementation of the second aspect, in the seventh implementation of the second aspect of the present disclosure,

[0051] The second resource required to execute each instruction in the first bytecode block is a known amount; and / or

[0052] The first resource required to execute the instructions in the first bytecode block is a static quantity.

[0053] In combination with the second implementation manner of the second aspect, in an eighth implementation manner of the second aspect of the present disclosure, the operation executed by the first control instruction includes:

[0054] Calculating a remaining amount of resources based on a total amount of resources and a first resource required to execute instructions in the first bytecode block;

[0055] Based on the remaining amount of resources being lower than a first threshold, execution of the second bytecode set is stopped.

[0056] In combination with any one of the second aspect to the second implementation of the second aspect, the ninth implementation of the second aspect of the present disclosure further includes:

[0057] The loading and executing module is configured to load the second bytecode set and execute instructions in the second bytecode set.

[0058] In combination with the ninth implementation manner of the second aspect, in a tenth implementation manner of the second aspect of the present disclosure, loading the second bytecode set and executing instructions in the second bytecode set includes:

[0059] The second bytecode set is loaded into the distributed smart contract and instructions in the second bytecode set are executed.

[0060] In combination with the tenth implementation manner of the second aspect, in an eleventh implementation manner of the second aspect of the present disclosure, loading the second bytecode set and executing instructions in the second bytecode set includes:

[0061] The second bytecode set is loaded into the virtual machine and instructions in the second bytecode set are executed.

[0062] In a third aspect, the present disclosure provides a blockchain resource calculation method, including:

[0063] Dividing a first bytecode set in the blockchain into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially;

[0064] calculating first resources required to execute instructions in the first bytecode block;

[0065] adding a first control instruction to the first bytecode block according to a first resource required to execute the instructions in the first bytecode block to obtain a second bytecode block;

[0066] Obtain a second bytecode set of the blockchain including the second bytecode block.

[0067] In a fourth aspect, an embodiment of the present disclosure provides a method for calculating smart contract resources, including:

[0068] Dividing a first bytecode set in the smart contract into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially;

[0069] calculating first resources required to execute instructions in the first bytecode block;

[0070] adding a first control instruction to the first bytecode block according to a first resource required to execute the instructions in the first bytecode block to obtain a second bytecode block;

[0071] A second bytecode set of the smart contract including the second bytecode block is obtained.

[0072] In a fifth aspect, an embodiment of the present disclosure provides an electronic device, including a memory and a processor; wherein,

[0073] The memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the method as described in any one of the first aspect, the first to the eleventh implementations of the first aspect, the third aspect, and the fourth aspect.

[0074] In the sixth aspect, an embodiment of the present disclosure provides a readable storage medium on which computer instructions are stored. When the computer instructions are executed by a processor, the method described in any one of the first aspect, the first to eleventh implementations of the first aspect, the third aspect, and the fourth aspect is implemented.

[0075] In the seventh aspect, an embodiment of the present disclosure provides a computer program product, including a computer program / instruction, wherein when the computer program / instruction is executed by a processor, it implements the method as described in any one of the first aspect, the first implementation method to the eleventh implementation method of the first aspect, the third aspect, and the fourth aspect.

[0076] The technical solutions provided by the embodiments of the present disclosure may have the following beneficial effects:

[0077] According to the technical solution provided by the embodiment of the present disclosure, a first bytecode set is divided into a first bytecode block, wherein the instructions in the first bytecode block are executed sequentially; the first resources required to execute the instructions in the first bytecode block are calculated; according to the first resources required to execute the instructions in the first bytecode block, a first control instruction is added to the first bytecode block to obtain a second bytecode block; and a second bytecode set including the second bytecode block is obtained, thereby reducing the amount of computational effort in resource calculation and improving the operational efficiency of the bytecode.

[0078] According to the technical solution provided by the embodiment of the present disclosure, a first bytecode block division module is configured to divide a first bytecode set into first bytecode blocks, wherein the instructions in the first bytecode blocks are executed sequentially; a first resource calculation module is configured to calculate the first resources required to execute the instructions in the first bytecode block; a second bytecode block acquisition module is configured to add a first control instruction to the first bytecode block according to the first resources required to execute the instructions in the first bytecode block to obtain a second bytecode block; and a second bytecode set acquisition module is configured to obtain a second bytecode set including the second bytecode block, thereby reducing the amount of resource calculation and improving the operating efficiency of the bytecode.

[0079] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0080] Other features, objectives and advantages of the present disclosure will become more apparent through the following detailed description of non-limiting embodiments in conjunction with the accompanying drawings. In the accompanying drawings:

[0081] Figure 1a An exemplary schematic diagram illustrating an implementation scenario of a resource calculation method according to an embodiment of the present disclosure;

[0082] Figure 1b An exemplary schematic diagram illustrating an implementation scenario of a resource calculation method according to an embodiment of the present disclosure;

[0083] Figure 1c An exemplary schematic diagram illustrating an implementation scenario of a resource calculation method according to an embodiment of the present disclosure;

[0084] Figure 1d An exemplary schematic diagram illustrating an implementation scenario of a resource calculation method according to an embodiment of the present disclosure;

[0085] Figure 2 A flowchart showing a resource calculation method according to an embodiment of the present disclosure is shown;

[0086] Figure 3 Show the basis Figure 2 Flowchart of step S201 in the illustrated embodiment;

[0087] Figure 4 Show the basis Figure 2 Flowchart of step S202 in the illustrated embodiment;

[0088] Figure 5 A structural block diagram showing a resource calculation method according to another embodiment of the present disclosure is shown;

[0089] Figure 6 A structural block diagram of a resource computing device according to an embodiment of the present disclosure is shown;

[0090] Figure 7 A structural block diagram of a resource computing device according to another embodiment of the present disclosure is shown;

[0091] Figure 8 A structural block diagram of an electronic device according to an embodiment of the present disclosure is shown;

[0092] Figure 9 It is a structural diagram of a computer system suitable for implementing the resource calculation method according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0093] Hereinafter, exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings so that those skilled in the art can easily implement them. In addition, for the sake of clarity, parts not related to the description of the exemplary embodiments are omitted in the accompanying drawings.

[0094] In the present disclosure, it should be understood that terms such as "including" or "having" are intended to indicate the presence of labels, numbers, steps, actions, components, parts, or combinations thereof disclosed in the present specification, and are not intended to exclude the possibility that one or more other labels, numbers, steps, actions, components, parts, or combinations thereof exist or are added.

[0095] It should also be noted that, in the absence of conflict, the embodiments and labels in the embodiments of the present disclosure can be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0096] In some applications of distributed computing systems, code needs to run on every distributed device. However, calculating and controlling the resources required to execute each instruction individually is computationally intensive and inefficient.

[0097] For example, in the blockchain space, WebAssembly (WASM) smart contracts must run on every node device, such as a virtual machine. However, with the widespread adoption of blockchain applications, performance has become a prominent issue. Calculating the resources required to run the WASM bytecode in smart contracts requires a significant amount of computation, instruction by instruction, and determining the remaining resources. This results in low efficiency. In particular, for some "bad" smart contracts that are difficult to terminate, the computational resources required to run them are excessive, resulting in slow execution.

[0098] In order to solve the above problems, the present disclosure proposes a resource calculation method, device, electronic device and readable storage medium.

[0099] Figure 1a An exemplary schematic diagram illustrating an implementation scenario of a resource calculation method according to an embodiment of the present disclosure.

[0100] In one embodiment of the present disclosure, Figure 1aThis figure shows a bytecode program module named block, executed within a smart contract in a virtual machine in a blockchain application scenario. Block includes the operation bytecode instructions xxxa, xxxb, ...xxxh, as well as the execution order control bytecode instructions br_if$block, loop$loop, br_if$loop, end;;$loop, end;;$block. The br_if$block instruction controls a jump to the end point of the block module; loop$loop starts a loop; the br_if$loop instruction controls a jump to the start of the loop; end;;$loop ends the loop; and end;;$block terminates the block bytecode program module.

[0101] against Figure 1a The bytecode program module shown can use the bytecode instructions that control the execution order as the boundaries for dividing the bytecode program module into basic blocks (first bytecode blocks), and each basic block (first bytecode block) can contain operation-type bytecode instructions. The first resources required to execute the instructions in each divided basic block (first bytecode block) are calculated. That is, the solution of the embodiment of the present disclosure can calculate the first resources required to execute the instructions in the first bytecode block as a whole based on the basic blocks (first bytecode blocks) divided in this way, without frequently calculating the required resources for each instruction in the bytecode program module as in the related art. Therefore, the amount of computational resources can be reduced and the operating efficiency of the bytecode can be improved. The following will refer to Figure 1b and Figure 1c Further describes how resource calculations are performed.

[0102] Figure 1b An exemplary schematic diagram illustrating an implementation scenario of a resource calculation method according to an embodiment of the present disclosure.

[0103] In one embodiment of the present disclosure, Figure 1b As shown, the bytecode instructions that control the execution order are used as boundaries. Figure 1aThe bytecode program module named block in is divided into 6 basic blocks: basic block 1, basic block 2, ..., basic block 6. Each basic block can be referred to as the first bytecode block in the embodiment of the present disclosure. In each basic block (first bytecode block), except for the bytecode instructions at the boundary that control the execution order, the rest are operation-type bytecode instructions. Therefore, the instructions in each basic block (first bytecode block) are executed sequentially, and there are no jump operations in the basic block (first bytecode block). The resources required to execute each instruction in the basic block (first bytecode block), such as the GAS value, are known constants, so the resources required to execute all instructions in the basic block can be accurately calculated, that is, the first resource in the embodiment of the present disclosure. The GAS value can be the cost of executing instructions of a smart contract in a blockchain. Those skilled in the art will understand that the resources required to execute each instruction in a basic block can also be the number of clock cycles required, or other resources, and this disclosure will not elaborate on this.

[0104] On the basis of dividing each basic block (first bytecode block), the first control instruction for calculating the resources required for each basic block (first bytecode block) can be added to each basic block (first bytecode block), and each second bytecode block can be obtained based on each basic block (first bytecode block). The set of second bytecode blocks obtained by adding the first control instruction to the basic block (first bytecode block) is the second bytecode set. Figure 1c The method of obtaining the second bytecode set is further described.

[0105] Figure 1c An exemplary schematic diagram illustrating an implementation scenario of a resource calculation method according to an embodiment of the present disclosure.

[0106] like Figure 1c As shown, the BB_GAS_COST totalCost(thisBB) instruction (first control instruction) is added before the instruction of basic block 1 (first bytecode block) to obtain basic block 1_2 (second bytecode block). The BB_GAS_COST totalCost(thisBB) instruction calculates the resources consumed by basic block 1 and exits the overall execution of the bytecode program when the total resources are lower than a certain threshold. Figure 1bThe other basic blocks in the bytecode program, such as basic block 2, ..., basic block 6, also add the same BB_GAS_COST totalCost (thisBB) instruction to obtain basic block 2_2 (not shown in the figure), ..., basic block 6_2 (not shown in the figure), which will not be repeated in this disclosure. The bytecode program module that is actually executed is finally composed of basic block 1_2, basic block 2_2, ..., basic block 6_2. In this way, the consumed resources can be calculated only once in each basic block, and the overall operation of the bytecode program can be exited when the total resources are lower than a specific threshold, without the need to perform calculations when executing each instruction, thereby avoiding unnecessary resource calculations, reducing the amount of resource calculation operations, and improving the operating efficiency of the bytecode.

[0107] Figure 1d An exemplary schematic diagram illustrating an implementation scenario of a resource calculation method according to an embodiment of the present disclosure.

[0108] Figure 1d This paper describes the process of calculating resource consumption of smart contracts according to basic blocks, inserting instructions for calculating resource consumption into basic blocks, and obtaining the smart contract code after static compilation transformation. Figure 1d As shown, the smart contract (first bytecode set) 110 is divided into the first bytecode block 1 111, the first bytecode block 2 112, and the first bytecode block 3 113 as basic blocks. It should be understood that dividing the smart contract into three basic blocks that are executed sequentially is only an example, and the present disclosure is not limited thereto. The number of basic blocks divided can be more or less, and the relationship between the basic blocks is not limited to sequential execution, but can be like Figure 1bAs shown. However, it can be understood that the instructions in each basic block (first bytecode block 111, 112, 113) are executed sequentially. The first resources required to execute the instructions in the first bytecode block 1111, the first bytecode block 2112, and the first bytecode block 3113 as basic blocks are calculated respectively. Based on the first resources required to execute the instructions in the first bytecode block 1111 as a basic block, the first control instruction 1 is added to the first bytecode block 1111 to obtain the second bytecode block 1121. Based on the first resources required to execute the instructions in the first bytecode block 2112 as a basic block, the first control instruction 2 is added to the first bytecode block 2112 to obtain the second bytecode block 2122. Based on the first resources required to execute the instructions in the first bytecode block 3113 as a basic block, the first control instruction 3 is added to the first bytecode block 3113 to obtain the second bytecode block 3123. Obtain a compiled smart contract (second bytecode set) including second bytecode block 1121, second bytecode block 2122, and second bytecode block 3123. In one embodiment of the present disclosure, there may be many instructions in a basic block, for example, dozens of instructions. In this case, compared with the method of calculating and controlling the GAS value instruction by instruction, the calculation frequency of the GAS value of the technical solution of the present disclosure is reduced by more than 10 times, requiring less than 1 / 10 of the original additional overhead.

[0109] Moreover, the technical solution disclosed in the present invention avoids the long-term occupation of computing resources of blockchain smart contracts due to dead loop codes or inefficient codes caused by coding errors, thereby reducing the overall working efficiency of the blockchain.

[0110] Figure 2 A flow chart of a resource calculation method according to an embodiment of the present disclosure is shown. As shown in FIG1 , the resource calculation method includes steps S201 , S202 , S203 , and S204 .

[0111] In step S201 , a first bytecode set is divided into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially.

[0112] In step S202 , first resources required to execute instructions in a first bytecode block are calculated.

[0113] In step S203, a first control instruction is added to the first bytecode block according to the first resource required for executing the instruction in the first bytecode block to obtain a second bytecode block.

[0114] In step S204 , a second bytecode set including a second bytecode block is obtained.

[0115] In one embodiment of the present disclosure, a first bytecode set is divided into first bytecode blocks, wherein the instructions in the first bytecode blocks are executed sequentially so that there are no jump instructions in the first bytecode blocks. The first resources required to execute all instructions in the first bytecode block can be calculated and controlled as a whole, without having to calculate and control each instruction in the first bytecode block one by one. Based on the first resources required to execute the instructions in the first bytecode block, a first control instruction is added to the first bytecode block to obtain a second bytecode block. All second bytecode blocks including the first control instruction are concatenated to obtain a second bytecode set including the second bytecode blocks. When executing the second bytecode set, in each second bytecode block, the first control instruction calculates the first resources required to execute all instructions in the first bytecode block, as well as the remaining resources after deducting the first resources required to execute and calculate all instructions in the first bytecode block from the total resources. When the remaining resources are insufficient, the execution of the bytecode program is terminated, thereby reducing the amount of computation required for resource calculation and improving the bytecode execution efficiency.

[0116] According to the technical solution provided by the embodiment of the present disclosure, a first bytecode set is divided into a first bytecode block, wherein the instructions in the first bytecode block are executed sequentially; the first resources required to execute the instructions in the first bytecode block are calculated; according to the first resources required to execute the instructions in the first bytecode block, a first control instruction is added to the first bytecode block to obtain a second bytecode block; and a second bytecode set including the second bytecode block is obtained, thereby reducing the amount of computational effort in resource calculation and improving the operational efficiency of the bytecode.

[0117] In one embodiment of the present disclosure, the first bytecode set is compiled from a first source code.

[0118] In one embodiment of the present disclosure, the first bytecode set is an executable bytecode set compiled from a first source code. Source code writing is relatively convenient, improving development efficiency. After the first bytecode set is compiled from the first source code, the resources required to execute each instruction in the first bytecode set can be accurately calculated. Thus, after the first bytecode set is divided into first bytecode blocks, the resources required to execute the first bytecode blocks can be accurately calculated, reducing the computational complexity of resource calculations and improving the operational efficiency of the bytecodes.

[0119] According to the technical solution provided by the embodiment of the present disclosure, the first bytecode set is compiled from the first source code, thereby accurately calculating the required resources.

[0120] In one embodiment of the present disclosure, instructions in the first bytecode set and the second bytecode set are executed in a distributed smart contract.

[0121] In one embodiment of the present disclosure, the instructions in the first bytecode set and the second bytecode set can be run in a distributed smart contract, thereby reducing the amount of resource calculation in the distributed smart contract application scenario of the blockchain and improving the operating efficiency of the bytecode. In addition to the field of smart contracts, any scenario where blockchain technology is applied can apply the solution of the embodiment of the present disclosure. For example, in high-frequency computing scenarios such as mining digital currency, evidence storage and anti-counterfeiting, and financial asset settlement, the solution of the embodiment of the present disclosure can also be applied to reduce the amount of resource calculation and improve the operating efficiency of the bytecode. Those skilled in the art will know that the instructions in the first bytecode set and the second bytecode set can also be run in scenarios other than distributed smart contracts, and this disclosure will not go into details.

[0122] According to the technical solution provided by the embodiment of the present disclosure, the instructions in the first bytecode set and the second bytecode set are run in the distributed smart contract, thereby reducing the amount of resource calculation in the distributed smart contract and improving the operating efficiency of the bytecode.

[0123] In one embodiment of the present disclosure, instructions in the first bytecode set and the second bytecode set are executed in a virtual machine.

[0124] In one embodiment of the present disclosure, instructions in the first bytecode set and the second bytecode set can be executed in a virtual machine, thereby reducing the amount of resource calculation in the virtual machine application scenario and improving the bytecode operation efficiency. In one embodiment of the present disclosure, a distributed smart contract can be executed in the virtual machine, and the instructions in the first bytecode set and the second bytecode set are executed in the distributed smart contract of the virtual machine. It can be known by those skilled in the art that the instructions in the first bytecode set and the second bytecode set can also be executed in scenarios other than virtual machines, and this disclosure will not elaborate on this.

[0125] According to the technical solution provided by the embodiment of the present disclosure, the instructions in the first bytecode set and the second bytecode set are executed in the virtual machine, thereby reducing the amount of resource calculation in the virtual machine and improving the operating efficiency of the bytecode.

[0126] In one embodiment of the present disclosure, a first bytecode set is divided into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially, including: scanning instructions in the first bytecode set to obtain specific instructions; and dividing the first bytecode set into multiple first bytecode blocks with the specific instructions as boundaries, wherein instructions in the first bytecode blocks are executed sequentially.

[0127] Figure 3 Show the basis Figure 2 Flowchart of step S201 in the illustrated embodiment.

[0128] like Figure 3 As shown, Figure 2 In the illustrated embodiment, step S201 includes steps S301 and S302.

[0129] In step S301, instructions in the first bytecode set are scanned to obtain specific instructions.

[0130] In step S302, the first bytecode set is divided into a plurality of first bytecode blocks with specific instructions as boundaries, wherein the instructions in the first bytecode blocks are executed sequentially.

[0131] In one embodiment of the present disclosure, instructions in a first bytecode set are scanned to obtain specific instructions, such as bytecode instructions that control the execution order. The first bytecode set is divided into a plurality of first bytecode blocks with the specific instructions as the boundary, so that the instructions in the first bytecode are all executed sequentially without any jumps or changes in the execution order. In this way, it is not necessary to calculate and control the resources required to execute each instruction in the first bytecode one by one, but only to calculate and control all the instructions in the first bytecode as a whole, thereby avoiding unnecessary resource calculations, reducing the amount of resource calculation operations, and improving the operating efficiency of the bytecode.

[0132] According to the technical solution provided by the embodiment of the present disclosure, the first bytecode set is divided into first bytecode blocks, wherein the instructions in the first bytecode blocks are executed sequentially, including: scanning the instructions in the first bytecode set to obtain specific instructions; dividing the first bytecode set into multiple first bytecode blocks with the specific instructions as boundaries, wherein the instructions in the first bytecode blocks are executed sequentially, thereby avoiding unnecessary resource calculations, reducing the amount of computational resources, and improving the operating efficiency of the bytecode.

[0133] In one embodiment of the present disclosure, the specific instruction includes at least one of the following: a function entry instruction, a loop instruction, a branch jump instruction, a jump instruction, a function call instruction, a function return instruction, and an end instruction.

[0134] In one embodiment of the present disclosure, the specific instruction may be a bytecode instruction that controls the execution order, and may include at least one of the following: a function entry instruction, a loop instruction, a branch jump instruction, a jump instruction, a function call instruction, a function return instruction, and an end instruction, such as a function entry instruction, a loop instruction, an if instruction, an else instruction, an end instruction, a br instruction, a br_if instruction, a br_table instruction, a call instruction, a call_indirect instruction, a return instruction, and an end marker instruction. It may also be other bytecode instructions that control the execution order, which will not be described in detail in the present disclosure.

[0135] According to the technical solution provided by the embodiment of the present disclosure, the first bytecode block is reasonably divided by including at least one of the following specific instructions: function entry instruction, loop instruction, branch jump instruction, jump instruction, function call instruction, function return instruction, and end instruction, thereby avoiding unnecessary resource calculation.

[0136] In one embodiment of the present disclosure, calculating the first resources required to execute instructions in a first bytecode block includes: scanning each instruction in the first bytecode block one by one; obtaining the second resources required to execute each instruction in the first bytecode block; and calculating the first resources required to execute all instructions in the first bytecode block based on the second resources required to execute each instruction in the first bytecode block.

[0137] Figure 4 Show the basis Figure 2 Flowchart of step S202 in the illustrated embodiment.

[0138] like Figure 3 As shown, Figure 2 In the illustrated embodiment, step S202 includes steps S401 , S402 , and S403 .

[0139] In step S401 , each instruction in the first bytecode block is scanned one by one.

[0140] In step S402 , second resources required for executing each instruction in the first bytecode block are obtained.

[0141] In step S403 , the first resources required to execute all instructions in the first bytecode block are calculated based on the second resources required to execute each instruction in the first bytecode block.

[0142] In one embodiment of the present disclosure, each instruction in a first bytecode block is scanned one by one to obtain the second resource required to execute each instruction in the first bytecode block, such as the gas level (GAS) required to execute each instruction. The second resources are accumulated to accurately calculate the first resource required to execute all instructions in the first bytecode block, i.e., the total gas level. The first resource and the second resource may also be the number of clock cycles required to execute the instructions, or other resources, which will not be further described in this disclosure.

[0143] According to the technical solution provided by the embodiment of the present disclosure, the first resources required to execute the instructions in the first bytecode block are calculated, including: scanning each instruction in the first bytecode block one by one; obtaining the second resources required to execute each instruction in the first bytecode block; and calculating the first resources required to execute all instructions in the first bytecode block based on the second resources required to execute each instruction in the first bytecode block, thereby accurately calculating the resources required to execute the first bytecode block.

[0144] In one embodiment of the present disclosure, the second resource required to execute each instruction in the first bytecode block is a known amount; and / or the first resource required to execute the instructions in the first bytecode block is a static amount.

[0145] In one embodiment of the present disclosure, the second resource required to execute each instruction in the first bytecode block is a known quantity, for example, the GAS value required to execute each instruction in the first bytecode block is a known quantity, for example, a constant, which can be obtained by a simple method such as looking up a fixed table. Under the condition that the GAS value required to execute each instruction in the first bytecode block is a known constant, the GAS value required to execute all instructions in the first bytecode block, that is, the first resource, can be directly accumulated by the GAS value required to execute each instruction in the first bytecode block. The first resource is a static quantity, for example, a constant, and does not need to be dynamically calculated during the bytecode execution process. In this way, the calculation process of the second resource and the first resource is greatly simplified, the amount of computational complexity of resource calculation is reduced, and the operating efficiency of the bytecode is improved.

[0146] According to the technical solution provided by the embodiments of the present disclosure, the second resource required to execute each instruction in the first bytecode block is a known quantity; and / or the first resource required to execute the instructions in the first bytecode block is a static quantity, thereby simplifying the resource calculation process, reducing the amount of computational complexity of resource calculation, and improving the operating efficiency of the bytecode.

[0147] In one embodiment of the present disclosure, the operations executed by the first control instruction include: calculating the remaining resource amount based on the total resource amount and the first resources required to execute the instructions in the first bytecode block; and stopping the execution of the second bytecode set based on the remaining resource amount being lower than the first threshold.

[0148] In one embodiment of the present disclosure, the GAS value required to execute the instructions in the first bytecode block is subtracted from the total GAS value to calculate the remaining GAS value. When the remaining GAS value is lower than a first threshold, for example, lower than 0, execution of the second bytecode set is stopped. In this way, the operating efficiency of the bytecode is improved. It also avoids the long-term occupation of computing resources caused by dead loop code or inefficient code due to coding errors, thereby reducing overall work efficiency. The first threshold can also be other values, and this disclosure is not limited to this.

[0149] According to the technical solution provided by the embodiment of the present disclosure, the operations performed by the first control instruction include: calculating the remaining resource amount based on the total resource amount and the first resources required to execute the instructions in the first bytecode block; stopping the execution of the second bytecode set based on the remaining resource amount being lower than the first threshold, thereby stopping the execution of the bytecode set when resources are insufficient, thereby improving the operating efficiency of the bytecode.

[0150] In one embodiment of the present disclosure, the method further includes: loading a second bytecode set and executing instructions in the second bytecode set.

[0151] Figure 5 A structural block diagram of a resource calculation method according to another embodiment of the present disclosure is shown.

[0152] exist Figure 5 In addition to including and Figure 2 The same steps S201, S202, S203, and S204 as in the embodiment also include step S501.

[0153] In step S501 , a second bytecode set is loaded and instructions in the second bytecode set are executed.

[0154] In one embodiment of the present disclosure, after calculating all the first resources required to execute the first bytecode module, adding a first control instruction to obtain a second bytecode module, and splicing the second bytecode module to obtain a second bytecode set, the second bytecode set is loaded and the instructions in the second bytecode set are executed, thereby reducing the amount of resource calculation and improving the operating efficiency of the bytecode.

[0155] According to the technical solution provided by the embodiment of the present disclosure, the method further includes: loading the second bytecode set and executing the instructions in the second bytecode set, thereby reducing the amount of resource calculation and improving the operating efficiency of the bytecode.

[0156] In one embodiment of the present disclosure, loading the second bytecode set and executing instructions in the second bytecode set includes: loading the second bytecode set in a distributed smart contract and executing instructions in the second bytecode set.

[0157] In one embodiment of the present disclosure, after calculating all the first resources required to execute the first bytecode module, adding a first control instruction to obtain a second bytecode module, and splicing the second bytecode module to obtain a second bytecode set, the second bytecode set is loaded in a distributed smart contract and the instructions in the second bytecode set are executed, the amount of resource calculation in the distributed smart contract is reduced and the operating efficiency of the bytecode is improved.

[0158] According to the technical solution provided by the embodiment of the present disclosure, by loading the second bytecode set and executing the instructions in the second bytecode set, including: loading the second bytecode set in a distributed smart contract and executing the instructions in the second bytecode set, thereby reducing the amount of resource calculation in the smart contract and improving the operating efficiency of the bytecode.

[0159] In one embodiment of the present disclosure, loading the second bytecode set and executing instructions in the second bytecode set includes: loading the second bytecode set in a virtual machine and executing instructions in the second bytecode set.

[0160] In one embodiment of the present disclosure, after calculating all the first resources required to execute the first bytecode module, adding a first control instruction to obtain a second bytecode module, and splicing the second bytecode module to obtain a second bytecode set, the second bytecode set is loaded in a virtual machine and the instructions in the second bytecode set are executed, so as to reduce the amount of resource calculation in the virtual machine and improve the running efficiency of the bytecode.

[0161] According to the technical solution provided by the embodiment of the present disclosure, by loading the second bytecode set and executing the instructions in the second bytecode set, including: loading the second bytecode set in the virtual machine and executing the instructions in the second bytecode set, thereby reducing the amount of resource calculation in the virtual machine and improving the operating efficiency of the bytecode.

[0162] Figure 6 A structural block diagram of a resource computing device according to an embodiment of the present disclosure is shown.

[0163] like Figure 6 As shown, the resource calculation device includes: a first bytecode block division module 601, a first resource calculation module 602, a second bytecode block acquisition module 603, and a second bytecode set acquisition module 604.

[0164] The first bytecode block partitioning module 601 is configured to partition the first bytecode set into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially.

[0165] The first resource calculation module 602 is configured to calculate the first resources required to execute instructions in the first bytecode block.

[0166] The second bytecode block acquisition module 603 is configured to add a first control instruction to the first bytecode block according to the first resource required to execute the instruction in the first bytecode block, so as to obtain a second bytecode block.

[0167] The second bytecode set acquisition module 604 is configured to acquire a second bytecode set including a second bytecode block.

[0168] According to the technical solution provided by the embodiment of the present disclosure, a first bytecode block division module is configured to divide the first bytecode set into first bytecode blocks, wherein the instructions in the first bytecode blocks are executed sequentially; a first resource calculation module is configured to calculate the first resources required to execute the instructions in the first bytecode block; a second bytecode block acquisition module is configured to add a first control instruction to the first bytecode block according to the first resources required to execute the instructions in the first bytecode block to obtain a second bytecode block; and a second bytecode set acquisition module is configured to obtain a second bytecode set including the second bytecode block, thereby reducing the amount of resource calculation and improving the operating efficiency of the bytecode.

[0169] In one embodiment of the present disclosure, the first bytecode set is compiled from a first source code.

[0170] According to the technical solution provided by the embodiment of the present disclosure, the first bytecode set is compiled from the first source code, thereby accurately calculating the required resources.

[0171] In one embodiment of the present disclosure, instructions in the first bytecode set and the second bytecode set are executed in a distributed smart contract.

[0172] According to the technical solution provided by the embodiment of the present disclosure, the instructions in the first bytecode set and the second bytecode set are run in the distributed smart contract, thereby reducing the amount of resource calculation in the distributed smart contract and improving the operating efficiency of the bytecode.

[0173] In one embodiment of the present disclosure, instructions in the first bytecode set and the second bytecode set are executed in a virtual machine.

[0174] According to the technical solution provided by the embodiment of the present disclosure, the instructions in the first bytecode set and the second bytecode set are executed in the virtual machine, thereby reducing the amount of resource calculation in the virtual machine and improving the operating efficiency of the bytecode.

[0175] In one embodiment of the present disclosure, the first bytecode block partitioning module includes: a specific instruction acquisition submodule, configured to scan instructions in the first bytecode set to obtain specific instructions; a first bytecode block partitioning submodule, configured to divide the first bytecode set into multiple first bytecode blocks with specific instructions as boundaries, wherein the instructions in the first bytecode blocks are executed sequentially.

[0176] According to the technical solution provided by the embodiment of the present disclosure, the first bytecode block division module includes: a specific instruction acquisition submodule, which is configured to scan the instructions in the first bytecode set to obtain specific instructions; a first bytecode block division submodule, which is configured to divide the first bytecode set into multiple first bytecode blocks with the specific instructions as the boundary, wherein the instructions in the first bytecode blocks are executed sequentially, thereby avoiding unnecessary resource calculations, reducing the amount of resource calculation operations, and improving the operating efficiency of the bytecode.

[0177] In one embodiment of the present disclosure, the specific instruction includes at least one of the following: a function entry instruction, a loop instruction, a branch jump instruction, a jump instruction, a function call instruction, a function return instruction, and an end instruction.

[0178] According to the technical solution provided by the embodiment of the present disclosure, the first bytecode block is reasonably divided by including at least one of the following specific instructions: function entry instruction, loop instruction, branch jump instruction, jump instruction, function call instruction, function return instruction, and end instruction, thereby avoiding unnecessary resource calculation.

[0179] In one embodiment of the present disclosure, the first resource calculation module includes: an instruction scanning submodule, configured to scan each instruction in the first bytecode block one by one; a second resource acquisition submodule, configured to acquire the second resource required to execute each instruction in the first bytecode block; and a first resource calculation submodule, configured to calculate the first resource required to execute all instructions in the first bytecode block based on the second resource required to execute each instruction in the first bytecode block.

[0180] According to the technical solution provided by the embodiment of the present disclosure, the first resource calculation module includes: an instruction scanning submodule, configured to scan each instruction in the first bytecode block one by one; a second resource acquisition submodule, configured to acquire the second resource required to execute each instruction in the first bytecode block; and a first resource calculation submodule, configured to calculate the first resource required to execute all instructions in the first bytecode block based on the second resource required to execute each instruction in the first bytecode block, thereby accurately calculating the resources required to execute the first bytecode block.

[0181] In one embodiment of the present disclosure, the second resource required to execute each instruction in the first bytecode block is a known amount; and / or the first resource required to execute the instructions in the first bytecode block is a static amount.

[0182] According to the technical solution provided by the embodiments of the present disclosure, the second resource required to execute each instruction in the first bytecode block is a known quantity; and / or the first resource required to execute the instructions in the first bytecode block is a static quantity, thereby simplifying the resource calculation process, reducing the amount of computational complexity of resource calculation, and improving the operating efficiency of the bytecode.

[0183] In one embodiment of the present disclosure, the operations executed by the first control instruction include: calculating the remaining resource amount based on the total resource amount and the first resources required to execute the instructions in the first bytecode block; and stopping the execution of the second bytecode set based on the remaining resource amount being lower than the first threshold.

[0184] According to the technical solution provided by the embodiment of the present disclosure, the operations performed by the first control instruction include: calculating the remaining resource amount based on the total resource amount and the first resources required to execute the instructions in the first bytecode block; stopping the execution of the second bytecode set based on the remaining resource amount being lower than the first threshold, thereby stopping the execution of the bytecode set when resources are insufficient, thereby improving the operating efficiency of the bytecode.

[0185] Figure 7 A structural block diagram of a resource computing device according to another embodiment of the present disclosure is shown.

[0186] like Figure 7 As shown, the resource computing device 700 includes Figure 6 The same first bytecode block division module 601 , first resource calculation module 602 , second bytecode block acquisition module 603 , and second bytecode set acquisition module 604 further include: a loading and execution module 701 .

[0187] The loading and executing module 701 is configured to load the second bytecode set and execute instructions in the second bytecode set.

[0188] According to the technical solution provided by the embodiment of the present disclosure, it also includes: a loading execution module, which is configured to load the second bytecode set and execute the instructions in the second bytecode set, thereby reducing the amount of resource calculation and improving the operating efficiency of the bytecode.

[0189] In one embodiment of the present disclosure, loading the second bytecode set and executing instructions in the second bytecode set includes: loading the second bytecode set in a distributed smart contract and executing instructions in the second bytecode set.

[0190] According to the technical solution provided by the embodiment of the present disclosure, by loading the second bytecode set and executing the instructions in the second bytecode set, including: loading the second bytecode set in a distributed smart contract and executing the instructions in the second bytecode set, thereby reducing the amount of resource calculation in the smart contract and improving the operating efficiency of the bytecode.

[0191] In one embodiment of the present disclosure, loading the second bytecode set and executing instructions in the second bytecode set includes: loading the second bytecode set in a virtual machine and executing instructions in the second bytecode set.

[0192] According to the technical solution provided by the embodiment of the present disclosure, by loading the second bytecode set and executing the instructions in the second bytecode set, including: loading the second bytecode set in the virtual machine and executing the instructions in the second bytecode set, thereby reducing the amount of resource calculation in the virtual machine and improving the operating efficiency of the bytecode.

[0193] In one embodiment of the present disclosure, in a blockchain, a first bytecode set in the blockchain is divided into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially; first resources required to execute the instructions in the first bytecode block are calculated; based on the first resources required to execute the instructions in the first bytecode block, a first control instruction is added to the first bytecode block to obtain a second bytecode block; and a second bytecode set of the blockchain including the second bytecode block is obtained.

[0194] According to the technical solution provided by the embodiments of the present disclosure, a first bytecode set in a blockchain is divided into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially; first resources required to execute the instructions in the first bytecode block are calculated; a first control instruction is added to the first bytecode block based on the first resources required to execute the instructions in the first bytecode block to obtain a second bytecode block; and a second bytecode set of the blockchain including the second bytecode block is obtained, thereby reducing the amount of computational effort for resource calculation in the blockchain and improving the operational efficiency of the bytecode.

[0195] In one embodiment of the present disclosure, in a smart contract, a first bytecode set in the smart contract is divided into a first bytecode block, wherein instructions in the first bytecode block are executed sequentially; a first resource required to execute the instructions in the first bytecode block is calculated; based on the first resource required to execute the instructions in the first bytecode block, a first control instruction is added to the first bytecode block to obtain a second bytecode block; and a second bytecode set of the smart contract including the second bytecode block is obtained.

[0196] According to the technical solution provided by the embodiments of the present disclosure, a first bytecode set in a smart contract is divided into a first bytecode block, wherein the instructions in the first bytecode block are executed sequentially; a first resource required to execute the instructions in the first bytecode block is calculated; a first control instruction is added to the first bytecode block according to the first resource required to execute the instructions in the first bytecode block to obtain a second bytecode block; and a second bytecode set including the second bytecode block of the smart contract is obtained, thereby reducing the amount of resource calculation in the smart contract and improving the operating efficiency of the bytecode.

[0197] Figure 8 A structural block diagram of an electronic device according to an embodiment of the present disclosure is shown.

[0198] The present disclosure also provides an electronic device, such as Figure 8 As shown, the system includes at least one processor 801; and a memory 802 in communication with the at least one processor 801; wherein the memory 802 stores instructions that can be executed by the at least one processor 801, and the instructions are executed by the at least one processor 801 to implement the following steps:

[0199] dividing a first bytecode set into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially;

[0200] calculating first resources required to execute instructions in the first bytecode block;

[0201] adding a first control instruction to the first bytecode block according to a first resource required to execute the instructions in the first bytecode block to obtain a second bytecode block;

[0202] A second bytecode set including the second bytecode block is obtained.

[0203] In one embodiment of the present disclosure, the first bytecode set is compiled from a first source code.

[0204] In one embodiment of the present disclosure, the instructions in the first bytecode set and the second bytecode set are executed in a distributed smart contract.

[0205] In one embodiment of the present disclosure, the instructions in the first bytecode set and the second bytecode set are executed in a virtual machine.

[0206] In one embodiment of the present disclosure, a first bytecode set is divided into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially, including:

[0207] Scanning instructions in the first bytecode set to obtain specific instructions;

[0208] The first bytecode set is divided into a plurality of first bytecode blocks with the specific instructions as boundaries, wherein the instructions in the first bytecode blocks are executed sequentially.

[0209] In one embodiment of the present disclosure, the specific instruction includes at least one of the following:

[0210] Function entry instruction, loop instruction, branch jump instruction, jump instruction, function call instruction, function return instruction, end instruction.

[0211] In one embodiment of the present disclosure, the calculating of the first resources required to execute the instructions in the first bytecode block includes:

[0212] Scan each instruction in the first bytecode block one by one;

[0213] Acquire a second resource required to execute each instruction in the first bytecode block;

[0214] The first resources required to execute all instructions in the first bytecode block are calculated according to the second resources required to execute each instruction in the first bytecode block.

[0215] In one embodiment of the present disclosure, the second resource required to execute each instruction in the first bytecode block is a known amount; and / or

[0216] The first resource required to execute the instructions in the first bytecode block is a static quantity.

[0217] In one embodiment of the present disclosure, the operation executed by the first control instruction includes:

[0218] Calculating a remaining amount of resources based on a total amount of resources and a first resource required to execute instructions in the first bytecode block;

[0219] Based on the remaining amount of resources being lower than a first threshold, execution of the second bytecode set is stopped.

[0220] In one embodiment of the present disclosure, the instructions are executed by at least one processor 801 to implement the following steps:

[0221] The second bytecode set is loaded and instructions in the second bytecode set are executed.

[0222] In one embodiment of the present disclosure, loading the second bytecode set and executing instructions in the second bytecode set includes:

[0223] The second bytecode set is loaded into the distributed smart contract and instructions in the second bytecode set are executed.

[0224] In one embodiment of the present disclosure, loading the second bytecode set and executing instructions in the second bytecode set includes:

[0225] The second bytecode set is loaded into the virtual machine and instructions in the second bytecode set are executed.

[0226] The instructions are further executed by at least one processor 801 to implement the following steps:

[0227] Dividing a first bytecode set in the blockchain into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially;

[0228] calculating first resources required to execute instructions in the first bytecode block;

[0229] adding a first control instruction to the first bytecode block according to a first resource required to execute the instructions in the first bytecode block to obtain a second bytecode block;

[0230] A second bytecode set of the smart contract including the second bytecode block is obtained.

[0231] The instructions are further executed by at least one processor 801 to implement the following steps:

[0232] Dividing a first bytecode set in the smart contract into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially;

[0233] calculating first resources required to execute instructions in the first bytecode block;

[0234] adding a first control instruction to the first bytecode block according to a first resource required to execute the instructions in the first bytecode block to obtain a second bytecode block;

[0235] A second bytecode set of the smart contract including the second bytecode block is obtained.

[0236] Figure 9 It is a structural diagram of a computer system suitable for implementing the message push method according to an embodiment of the present disclosure.

[0237] like Figure 9 As shown, the computer system 900 includes a processing unit 901, which can execute various processes in the embodiments shown in the above figures according to the program stored in the read-only memory (ROM) 902 or the program loaded from the storage unit 908 to the random access memory (RAM) 903. The RAM 903 also stores various programs and data required for the operation of the system 900. The CPU 901, ROM 902, and RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.

[0238] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed so that a computer program read therefrom can be installed into the storage section 908 as needed. Among them, the processing unit 901 can be implemented as a processing unit such as a CPU, a GPU, a TPU, an FPGA, an NPU, etc.

[0239] The present disclosure also discloses a computer program product, which includes a computer program / instruction, wherein the computer program / instruction implements the method steps of the resource calculation method when executed by a processor.

[0240] In particular, according to embodiments of the present disclosure, the methods described above with reference to the accompanying drawings can be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program tangibly embodied on a computer-readable medium, the computer program comprising program code for executing the methods described in the accompanying drawings. In such embodiments, the computer program can be downloaded and installed from a network via the communication portion 909 and / or installed from removable media 911.

[0241] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the diagram or block diagram can represent a module, program segment or part of the code, and the module, program segment or part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, as well as the combination of boxes in the block diagram and / or flow chart, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or can be implemented using a combination of dedicated hardware and computer instructions.

[0242] The units or modules described in the embodiments of the present disclosure may be implemented in software or hardware. The units or modules described may also be provided in a processor, and the names of these units or modules do not, in certain circumstances, limit the units or modules themselves.

[0243] As another aspect, the present disclosure further provides a computer-readable storage medium. This computer-readable storage medium may be included in the node described in the above embodiments, or may be a standalone computer-readable storage medium not incorporated into a device. The computer-readable storage medium stores one or more programs, which are used by one or more processors to execute the methods described in the present disclosure.

[0244] The above description is merely a preferred embodiment of the present disclosure and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of the invention herein is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but also encompasses other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the inventive concept. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this disclosure.

Claims

1. A resource calculation method, comprising: Dividing a first bytecode set into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially; calculating first resources required to execute instructions in the first bytecode block; According to the first resources required to execute the instructions in the first bytecode block, adding a first control instruction to the first bytecode block to obtain a second bytecode block, wherein the first control instruction is used to calculate the first resources required to execute the instructions in the first bytecode block; A second bytecode set including the second bytecode block is obtained.

2. The method according to claim 1, characterized in that: The first bytecode set is compiled from a first source code.

3. The method according to claim 1, characterized in that The instructions in the first bytecode set and the second bytecode set are executed in a distributed smart contract.

4. The method according to claim 3, characterized in that The instructions in the first bytecode set and the second bytecode set are executed in a virtual machine.

5. The method according to any one of claims 1 to 3, characterized in that: Dividing the first bytecode set into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially, comprises: Scanning instructions in the first bytecode set to obtain specific instructions; The first bytecode set is divided into a plurality of first bytecode blocks with the specific instructions as boundaries, wherein the instructions in the first bytecode blocks are executed sequentially.

6. The method according to claim 5, characterized in that The specific instructions include at least one of the following: Function entry instruction, loop instruction, branch jump instruction, jump instruction, function call instruction, function return instruction, end instruction.

7. The method according to any one of claims 1 to 3, characterized in that: The computing of the first resource required to execute the instructions in the first bytecode block includes: Scan each instruction in the first bytecode block one by one; Acquire a second resource required to execute each instruction in the first bytecode block; The first resources required to execute all instructions in the first bytecode block are calculated according to the second resources required to execute each instruction in the first bytecode block.

8. The method according to claim 7, characterized in that The second resource required to execute each instruction in the first bytecode block is a known amount; and / or The first resource required to execute the instructions in the first bytecode block is a static quantity.

9. The method according to claim 3, characterized in that: The operations performed by the first control instruction include: Calculate the remaining amount of resources according to the total amount of resources and the first resources required to execute the instructions in the first bytecode block; Based on the remaining amount of resources being lower than a first threshold, execution of the second bytecode set is stopped.

10. The method according to any one of claims 1 to 3, characterized in that: Also includes: The second bytecode set is loaded and instructions in the second bytecode set are executed.

11. The method according to claim 10, characterized in that The loading of the second bytecode set and executing instructions in the second bytecode set includes: The second bytecode set is loaded in the distributed smart contract and instructions in the second bytecode set are executed.

12. The method according to claim 11, characterized in that The loading of the second bytecode set and executing instructions in the second bytecode set includes: The second bytecode set is loaded in the virtual machine and instructions in the second bytecode set are executed.

13. A resource computing device, comprising: A first bytecode block division module is configured to divide the first bytecode set into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially; A first resource calculation module, configured to calculate a first resource required to execute instructions in the first bytecode block; A second bytecode block acquisition module is configured to add a first control instruction to the first bytecode block according to the first resource required to execute the instructions in the first bytecode block to obtain a second bytecode block, wherein the first control instruction is used to calculate the first resource required to execute the instructions in the first bytecode block; The second bytecode set acquisition module is configured to acquire a second bytecode set including the second bytecode block.

14. The device according to claim 13, characterized in that The first bytecode block division module comprises: A specific instruction acquisition submodule is configured to scan the instructions in the first bytecode set to obtain specific instructions; The first bytecode block division submodule is configured to divide the first bytecode set into a plurality of first bytecode blocks based on the specific instructions as boundaries, wherein the instructions in the first bytecode blocks are executed sequentially.

15. The device according to claim 13, characterized in that The first resource calculation module includes: An instruction scanning submodule, configured to scan each instruction in the first bytecode block one by one; a second resource acquisition submodule, configured to acquire a second resource required to execute each instruction in the first bytecode block; The first resource calculation submodule is configured to calculate the first resources required to execute all instructions in the first bytecode block according to the second resources required to execute each instruction in the first bytecode block.

16. A blockchain resource calculation method, comprising: Dividing a first bytecode set in the blockchain into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially; calculating first resources required to execute instructions in the first bytecode block; According to the first resources required to execute the instructions in the first bytecode block, adding a first control instruction to the first bytecode block to obtain a second bytecode block, wherein the first control instruction is used to calculate the first resources required to execute the instructions in the first bytecode block; Obtain a second bytecode set of the blockchain including the second bytecode block.

17. A smart contract resource calculation method, comprising: Divide a first bytecode set in the smart contract into first bytecode blocks, wherein instructions in the first bytecode blocks are executed sequentially; calculating first resources required to execute instructions in the first bytecode block; According to the first resources required to execute the instructions in the first bytecode block, adding a first control instruction to the first bytecode block to obtain a second bytecode block, wherein the first control instruction is used to calculate the first resources required to execute the instructions in the first bytecode block; Obtain a second bytecode set of the smart contract including the second bytecode block.

18. An electronic device comprising a memory and a processor; wherein: The memory is used to store one or more computer instructions, wherein the one or more computer instructions are executed by the processor to implement the method according to any one of claims 1-12, 16, and 17.

19. A readable storage medium having computer instructions stored thereon, wherein the computer instructions, when executed by a processor, implement the method according to any one of claims 1-12, 16, and 17.

Citation Information

Patent Citations

  • Automatic management of resource sizing

    CN107209682A

  • Blockchain intelligent contract processing system and method

    CN110392052A