Disclosure of Invention
The application provides a method and a device for debugging an intelligent contract, which are used for solving the problem of how to conveniently and efficiently debug the intelligent contract.
In a first aspect, an embodiment of the present application provides a method for debugging an intelligent contract, including:
a block chain node acquires a debugging request, and the block chain node is preset with an intelligent contract to be debugged and each debugging strategy;
the block chain node determines a contract function of an intelligent contract to be debugged, transaction information to be operated and a debugging strategy to be used according to the debugging request;
the block chain node calls a contract function of the intelligent contract to be debugged to execute the transaction information to be operated;
and the block chain node executes the debugging strategy to be used in the executing process of the transaction information to be operated so as to obtain the debugging result of the intelligent contract to be debugged.
According to the scheme, the debugging results are debugged after the intelligent contract is deployed in the system, the debugging request is analyzed and then debugged according to the preset debugging strategy, and a local source code is not needed, so that remote debugging is facilitated; meanwhile, the operation code of the intelligent contract is not required to be operated, a newly added debugging channel is not required, the intelligent contract is only required to be deployed, the debugging can be realized through an open API, and the intelligent contract debugging method is simple, efficient and easy to operate.
Optionally, the obtaining, by the blockchain node, a debug request includes:
the block chain node acquires a first sub-debugging request, wherein the first sub-debugging request comprises address information used for indicating a contract function of the intelligent contract to be debugged and transaction parameters of transaction information to be operated;
the block chain node acquires a second sub-debugging request, wherein the second sub-debugging request comprises a strategy identifier of a debugging strategy to be used;
the block chain node determines a contract function of the intelligent contract to be debugged according to the debugging request, and the contract function comprises the following steps:
and the block chain link points analyze the address information and determine a contract function of the intelligent contract to be debugged.
According to the scheme, the debugging request comprises the strategy identification, each debugging strategy is preset on the block chain link point, the strategy identification can be debugged in the debugging process, a special testing channel does not need to be opened up for each intelligent contract to be tested, and the debugging is more convenient and efficient.
Optionally, the method further includes:
the block chain node receives a setting instruction, and the setting instruction is used for setting the intelligent contract to be debugged to be in a debugging state; the debugging state is used for indicating the blockchain node not to process the transaction information of the intelligent contract to be debugged.
According to the scheme, due to the arrangement of the debugging switch, the intelligent contract to be debugged does not influence the transaction of other intelligent contracts during debugging, and the user experience is improved.
Optionally, after the executing the debugging policy to be used to obtain the debugging result of the intelligent contract to be debugged, the method further includes:
the block chain node sets the intelligent contract to be debugged to be in an operating state; the running state is used for indicating the block link nodes to process the transaction information of the intelligent contract to be debugged.
It should be noted that the debugging of the smart contract is performed before the smart contract is used for a formal transaction.
Optionally, the executing the to-be-used debugging policy includes:
and the block chain node executes the debugging strategies to be used in series or in parallel according to the sequence relation among the debugging strategies to be used.
In a second aspect, an embodiment of the present application provides an apparatus for intelligent contract debugging, where the apparatus includes:
the system comprises an acquisition module, a debugging module and a debugging module, wherein the acquisition module is used for acquiring a debugging request and presetting an intelligent contract to be debugged and each debugging strategy;
the processing module is used for determining a contract function of the intelligent contract to be debugged, transaction information to be operated and a debugging strategy to be used according to the debugging request;
calling the intelligent contract to be debugged to execute the transaction information to be operated;
and in the executing process of the transaction information to be operated, executing the debugging strategy to be used so as to obtain a debugging result of the intelligent contract to be debugged.
Optionally, the processing module is specifically configured to:
acquiring a first sub-debugging request, wherein the first sub-debugging request comprises address information used for indicating a contract function of the intelligent contract to be debugged and transaction parameters of transaction information to be run;
acquiring a second sub-debugging request, wherein the second sub-debugging request comprises a strategy identifier of a debugging strategy to be used;
optionally, the processing module is specifically configured to:
and analyzing the address information and determining a contract function of the intelligent contract to be debugged.
Optionally, the processing module is further configured to:
before the block chain node acquires a debugging request, the block chain node receives a setting instruction, wherein the setting instruction is used for setting the intelligent contract to be debugged to be in a debugging state; the debugging state is used for indicating the blockchain node not to process the transaction information of the intelligent contract to be debugged.
Optionally, the processing module is further configured to:
after the debugging strategy to be used is executed so as to obtain a debugging result of the intelligent contract to be debugged, setting the intelligent contract to be debugged to be in a running state; the running state is used for indicating the block link nodes to process the transaction information of the intelligent contract to be debugged.
Optionally, the processing module is specifically configured to:
and executing the debugging strategies to be used in series or in parallel according to the sequence relation among the debugging strategies to be used.
Correspondingly, an embodiment of the present invention further provides a computing device, including:
a memory for storing program instructions;
and the processor is used for calling the program instruction stored in the memory and executing the data storage method of the block chain according to the obtained program.
Accordingly, an embodiment of the present invention further provides a computer-readable non-volatile storage medium, which includes computer-readable instructions, and when the computer-readable instructions are read and executed by a computer, the computer is caused to execute the data storage method of the above block chain.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
First, some terms in the present application are explained so as to be understood by those skilled in the art.
A Smart contract (Smart contract) is a computer protocol intended to propagate, verify or execute contracts in an informational manner. Smart contracts allow trusted transactions to be conducted without third parties, which transactions are traceable and irreversible. The objective is to provide a secure method over traditional contracts and reduce other transaction costs associated with the contracts.
In order to solve the problems in the prior art, an embodiment of the present invention provides an intelligent contract debugging method, which may be applied to a system architecture shown in fig. 1, where the system architecture includes a server 100 and a blockchain node 200.
The intelligent contract to be debugged is deployed on the blockchain node 200.
Specifically, server 100 is configured to send a debug request to block link point 200.
It should be noted that the debug request sent by the server 100 is received by a plurality of different external interfaces of the block link node 200, and the block link node 200 may obtain address information of an access interface of the debug request sent by the server 100. The blockchain node 200 matches a contract function according to the address information to determine a debug result.
After acquiring the debug request sent by the server 100, the blockchain node 200 processes the debug request to generate a debug result.
It should be noted that fig. 1 is only an example of a system architecture according to an embodiment of the present application, and the present application is not limited to this specifically.
Based on the system architecture illustrated in fig. 1, fig. 2 is a schematic flowchart corresponding to a method for intelligent contract debugging according to an embodiment of the present invention, where the process may be executed by an apparatus for intelligent contract debugging, which may be a block link point of the foregoing. As shown in fig. 2, the method includes:
step 201, obtaining a debugging request by a block link point;
it should be noted that the block link points are preset with the intelligent contracts to be debugged and the debugging strategies.
Step 202, the block chain node determines a contract function of the intelligent contract to be debugged, transaction information to be operated and a debugging strategy to be used according to the debugging request.
And step 203, calling the intelligent contract to be debugged by the block chain node to execute the transaction information to be operated.
And 204, executing the debugging strategy to be used by the block chain node in the executing process of the transaction information to be operated so as to obtain the debugging result of the intelligent contract to be debugged.
In the embodiment of the invention, a block chain system is taken as an example, a block chain platform is started, and an intelligent contract is loaded.
Specifically, before the blockchain node obtains the debug request, that is, before step 201, the blockchain node calls the debug interface. That is to say, the block chain node receives a setting instruction, the setting instruction is used for setting the block chain node to be in a debugging state, and the debugging state is used for indicating the block chain node not to process the transaction information of the intelligent contract to be debugged.
As can be seen from the above, in the embodiment of the present invention, the debug switch may be turned on first, for example, the toolendedbagflag is changed to toolean debuggFlag is changed to true, all transactions will go through the debug process after the debug switch is turned on, and the normal transaction process of the user is performed when the debug switch is turned off, and the debug will not be performed. It should be noted that the method for starting debugging is not specifically limited in the present application.
Based on this, in step 201, an intelligent contract is deployed in a block link point of a block link node to obtain a debugging request, since the intelligent contract allows a trusted transaction without a third party, the transaction can be traced, and the block link node can obtain address information of the debugging request.
It should be noted that the block link point may obtain a debugging request of an external server, or may directly and actively call, for example, call a URl address, that is, may generate a debugging request according to a transaction request included in the URl address.
In addition, in one possible implementation manner, the transaction information in the debugging request may directly invoke the transaction information in the real-time transaction request, and in another possible implementation manner, the transaction information in the debugging request may change the transaction parameters in the transaction information for debugging after invoking the transaction information in the real-time transaction request.
In step 201, a block link point obtains a first sub-debugging request, where the first sub-debugging request includes address information used for indicating a contract function of an intelligent contract to be debugged and transaction parameters of transaction information to be run;
and the block chain node acquires a second sub-debugging request, wherein the second sub-debugging request comprises a strategy identifier of a debugging strategy to be used.
Based on this, in step 202, the block link point determines, according to the debugging request, a contract function of the intelligent contract to be debugged, transaction information to be run, and a debugging policy to be used. Such as sending a transfer request from account a to account B for 1 unit of virtual currency or credit, using a debug policy of 1+2+3, such as debug policy "types": "1, 2, 3", wherein typeis a policy parameter.
The transaction information to be operated is virtual currency or credit with the amount of 1 unit, which is transferred from the account A to the account B; the debugging strategy to be used is the debugging strategy 1+2+ 3.
Further, a contract function of the intelligent contract to be debugged, transaction information to be run and a debugging strategy to be used are identified according to a preset rule. In the embodiment of the present application, the preset rule may adopt keyword recognition, for example, the policy parameter is set to type, and when "type" is recognized, a parameter value of "type" is extracted as a parameter value of the policy parameter.
In the embodiment of the present application, determining, by a block link point, a contract function of an intelligent contract to be debugged according to a debugging request includes:
and resolving the address information by the block chain link points, and determining a contract function of the intelligent contract to be debugged.
The above block chain node analyzes the address information, and determines a contract function of the intelligent contract to be debugged, specifically, for example, when the called URl address information is as follows:
http:// www.makerorder.com/dev/transorder, the matching contract function is:
transferfunc(String A,String B,Integer 1)。
specifically, in step 204, the specific flow is as shown in fig. 3:
step 301, matching a corresponding strategy according to parameter values of strategy parameters;
step 302, calling a strategy function corresponding to the strategy according to the strategy;
step 303, the debug request is processed according to the policy function.
In the embodiment of the present application, the debugging policy includes or is not limited to the following policy combinations:
collecting access parameters, collecting return values of debugging results, collecting memory and disk occupation conditions, and collecting network traffic data.
It should be noted that the debugging strategy may also be counting the number of exceptions, and the like, which is not specifically limited in the present application.
For example, four debugging strategies are preset, 1 is collecting the input parameters (i.e. the initial input parameters); 2, collecting a debugging result return value; 3, collecting memory and disk occupation conditions; and 4, collecting network traffic data. At this time, in the debug request "types": "1, 2, 3" indicates that the debugging strategy of collecting entry parameters, collecting return values of debugging results and collecting memory and disk occupation conditions is executed in the debugging.
In the embodiment of the application, the block link points provide special interfaces, so that the test user can dynamically increase or decrease the strategy modes except for the preset four strategies for the intelligent contract.
Based on the above, when the matching debugging policy is "types": when the number of the block chain nodes is '1, 2 and 3', a recording function funcRecord () is called to automatically record parameters (namely an account A, an account B and the number 1), a return value, a current node memory and disk information into a log, and transaction parameters are dynamically monitored and updated.
It should be noted that, the block chain nodes execute the debugging strategies to be used in series or in parallel according to the sequential relationship between the debugging strategies to be used.
In the embodiment of the application, after the debugging strategy to be used is executed so as to obtain the debugging result of the intelligent contract to be debugged, the block link point sets the intelligent contract to be debugged to be in the running state; the running state is used for indicating the blockchain node to process the transaction information of the blockchain system. Before setting the intelligent contract to be debugged as a running state, whether the intelligent contract reaches an expected value is judged according to a debugging result.
It should be noted that before determining whether the debugging result is expected, the blockchain node may obtain log information recorded in the debugging process, and format and output the log information to the user.
Further, in a possible implementation manner, the user analyzes whether the expected value is reached according to the output result. In another possible implementation manner, a threshold is preset in the block link point, and if the debugging result shows abnormal or is greater than the threshold, it is determined that the debugging request contains an illegal transaction.
In order to better illustrate the embodiments of the present invention, specific examples are illustrated below.
Firstly, each node in the blockchain system is preset with various debugging strategies, that is, each node can debug the intelligent contract running on the node according to the preset debugging strategies. The preset debugging strategy at the node can be deployed through a preset interface, and meanwhile, the debugging strategy can be modified through the interface. Assume that four debug strategies are preset in a node at present, which are respectively: 1 represents collection of ginseng; 2 represents collecting a debug result return value; 3 represents collecting the disk occupation condition; and 4, collecting network traffic data.
Then, an intelligent contract to be tested, such as a "transaction transfer contract", is deployed on the node, and the function included in the "transaction transfer contract" is transfer function (String from, String to, String from, Integer amount). Wherein, transferfunc is the function name, String and Integer represent the parameter type of the parameter, fromoud represents the transfer account, toUid represents the receiving account, and amount represents the transfer amount.
It should be noted that, a plurality of intelligent contracts may be deployed on a node, and if an a contract that has been debugged to pass is currently deployed on the node and a B contract to be tested is deployed at the same time, the node may continue to execute the a contract when the B contract is debugged, so that the original service of the node is not affected. To implement this function, a feasible way is to set a debug switch for each smart contract, for example, when the debug switch is turned off, the transaction of the smart contract can be directly executed without debugging the smart contract. When the debug switch is turned on, for example, the bootean debug flag is true, the debug is performed first, and the transaction is performed after the test of the intelligent contract to be tested is completed.
In addition, one intelligent contract may contain one or more transactions, and in the embodiment of the application, only one transaction, namely the "transaction transfer contract", in the deployed intelligent contract is taken as an example. Further, when one intelligent contract comprises a plurality of transactions, such as "transaction transfer contract" and "transaction loan contract", the test of "transaction loan contract" can be directly performed after the test of "transaction transfer contract" is completed without redeploying the intelligent contract.
After the deployment of the debugging strategy and the intelligent contract is completed, the subsequent debugging work can be performed, which specifically comprises the following steps:
s101, acquiring a debugging request; the debugging request comprises a field indicating a contract function of the intelligent contract to be debugged, a field indicating transaction parameters and a field indicating debugging strategies.
In particular, the field indicating the contract function of the intelligent contract to be debugged may be a URl address, such ashttp:// 120.92.11729:18321/UChains/dir/umfne_dir/transaction;
Wherein 120.92.11729:18321 is the IP address and the specific address formed by the ports, and UChains/dir/umfnet dir/transaction is the contract function corresponding to the address.
The fields indicating transaction parameters and the fields indicating debugging strategies can be realized by setting parameter fields, for example, the following request bodies can be used:
namely, the account number is changed from account100 to account101, the amount is 1578379035098 units of virtual coins/credits, and the debugging strategy is 1+2+ 3.
It should be noted that one debugging policy may also include a plurality of debugging sub-policies, for example, the debugging policy 1 includes the debugging sub-policies a and b, which is not specifically limited in this application.
In addition, the debugging request can be compiled and sent to the node by a debugging person through a debugging interface; or a debugger can directly write a section of debugging request corresponding code and send the debugging request corresponding code to the node.
S102, identifying strategy parameters and transaction parameters according to preset rules; in the embodiment of the application, the parameter values of the transaction parameters are identified and extracted according to the keywords, and the parameter values comprise: account100, account101, quantity 1578379035098. And identifying and extracting parameter values of the strategy parameters according to the keywords, wherein the parameter values comprise the following parameters: 1. 2 and 3.
It should be noted that the policy parameter and the transaction parameter may also be identified according to preset location information, which is not specifically limited in this application.
S103, identifying that the debugging strategies are 1,2 and 3 according to the keywords;
it should be noted that, in the embodiment of the present application, the transaction parameters and the debugging request are subjected to real-time summary statistics and analysis, for example, the updated results of the transaction parameters are recorded and are counted at different index latitudes, such as the total transfer of the account a within one hour. For another example, the results of the debugging requests are counted, and the transaction success times and the transaction failure times are respectively calculated.
According to the embodiment of the application, the strategy is adjusted in real time according to result data in the debugging process by performing real-time summary statistics and analysis on transaction parameters and debugging requests.
S104, according to the address information of the debugging request, matching a contract function of the debugging request, namely dev/transorder of the content; in the embodiment of the present application, the contract function is transfer func (String a, String B, Integer1) according to URl address matching.
Based on this, the parameter value of the policy parameter "types" matched and debugged is "1, 2, 3", and corresponds to the policy 1: collecting ginseng; strategy 2: collecting a debugging result return value; strategy 3: and collecting the occupation conditions of the memory and the disk. And then processing the debugging request according to the strategy corresponding to the strategy parameter.
Specifically, policy 1 is executed first: collecting the entry references, specifically, calling a recording function funcRecord () to automatically record the entry references (i.e., account100, account101, number 1578379035098).
In one possible implementation, the debug request obtained by the block link point may be input by a developer, such as:
"catalogld": f "," catalogName: "f catalog", "catalogtype": umf ";
from the above, the blockchain node obtains the transaction data from the f directory for debugging.
Policy 2 is then implemented: collecting a debugging result return value;
it should be noted that, after the contract function is called to generate the return value, i.e., the transaction result, the block link point automatically updates the record, i.e., the return value is not recorded or is recorded as a null value when not generated, and when the contract function is called to generate the return value, i.e., the transaction result, the block link point automatically updates the record.
Further, according to different strategies, after logging, such as after collecting the entry references mentioned above, the block link point calls a contract function transferfunc (StringA, StringB, Integer1), and returns a function result as follows:
as can be seen from the above, the "code" 200, the "msg" OK "indicates that the transaction information is successfully transmitted, and meanwhile, the account100 transfers the transaction to the account 101.
S105, collecting log information recorded in the debugging process by using the block chain nodes; specifically, a statistical function may be called, and then formatted recording and output to the user, and the user analyzes whether the contract expectation is reached according to the output result. Based on the above, the following is specific:
wherein, the 'inputData' corresponds to the strategy 1 and is a collected parameter entering result; "meta" indicates that the transaction message was sent successfully; "outData" corresponds to policy 2, and indicates that the transaction is successful in order to return a result; diskMsg is policy 3: and collecting output results of the memory and the disk occupation situation, wherein the embodiment is the specific occupation situation of the disk.
It should be noted that, the block link point may also be compared with a preset threshold to determine whether the debugging result is expected.
Further, if the debugging result shows abnormal or is larger than the threshold value, the debugging request is determined to contain illegal transactions.
For example, if the debugging request includes a transfer transaction, when the transaction parameter value is a negative value, the debugging result displays an abnormal return error indication, which indicates that the debugging request includes an illegal transaction.
In a possible implementation manner, policy 1 collects the input parameters and cannot find the corresponding parameters in the execution process, and the returned result is "code": 2222 "at this time, which indicates that an error occurs.
According to the scheme, the debugging results are debugged after the intelligent contract is deployed in the system, and local debugger mode debugging is not needed, so that remote debugging is facilitated. Meanwhile, the operation code of the intelligent contract is not required to be operated, a newly added debugging channel is not required, the intelligent contract is only required to be deployed, the debugging can be realized through an open API (application program interface), the operation is simple and easy, and the broadband resource is saved. In addition, the invention can flexibly use various debugging strategies to carry out various limit tests on the line for the approximation, and the debugging result based on the online environment is more accurate.
Based on the same inventive concept, fig. 4 exemplarily shows an apparatus for debugging an intelligent contract, which may be used for a flow of an intelligent contract debugging method according to an embodiment of the present invention.
The device for debugging the intelligent contract comprises:
an obtaining module 401, configured to obtain a debugging request, where the obtaining module presets an intelligent contract to be debugged and each debugging policy;
a processing module 402, configured to determine, according to the debugging request, a contract function of the intelligent contract to be debugged, transaction information to be run, and a debugging policy to be used;
calling the intelligent contract to be debugged to execute the transaction information to be operated;
and in the executing process of the transaction information to be operated, executing the debugging strategy to be used so as to obtain a debugging result of the intelligent contract to be debugged.
Optionally, the processing module 402 is specifically configured to:
acquiring a first sub-debugging request, wherein the first sub-debugging request comprises address information used for indicating a contract function of the intelligent contract to be debugged and transaction parameters of transaction information to be run;
acquiring a second sub-debugging request, wherein the second sub-debugging request comprises a strategy identifier of a debugging strategy to be used;
optionally, the processing module 402 is specifically configured to:
and analyzing the address information and determining a contract function of the intelligent contract to be debugged.
Optionally, the processing module 402 is further configured to:
before the block chain node acquires a debugging request, the block chain node receives a setting instruction, wherein the setting instruction is used for setting the block chain node to be in a debugging state; the debug status is used to instruct the blockchain node not to process transaction information of the blockchain system.
Optionally, the processing module 402 is further configured to:
after the debugging strategy to be used is executed so as to obtain a debugging result of the intelligent contract to be debugged, setting the intelligent contract to be debugged to be in a running state; the operating state is used for indicating the blockchain node to process transaction information of the blockchain system.
Optionally, the processing module 402 is specifically configured to:
and executing the debugging strategies to be used in series or in parallel according to the sequence relation among the debugging strategies to be used.
Based on the same inventive concept, an embodiment of the present invention further provides a computing device, including:
a memory for storing program instructions;
and the processor is used for calling the program instruction stored in the memory and executing the data storage method of the block chain according to the obtained program.
Based on the same inventive concept, embodiments of the present invention further provide a computer-readable non-volatile storage medium, which includes computer-readable instructions, and when the computer reads and executes the computer-readable instructions, the computer is caused to execute the data storage method of the above block chain.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.