Method and system for automatically generating agricultural product contracts based on contract execution status recognition

By visually modeling and optimizing the contract execution process of the smart contract platform, and identifying and optimizing complex paths, the problem of insufficient processing speed and throughput of smart contracts is solved, and execution efficiency and user experience are improved.

CN119048270BActive Publication Date: 2025-02-14SHENZHEN ZHONGNONG NET E-BUSINESS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411557535.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-04
Publication Date
2025-02-14
Estimated Expiration
2044-11-04

AI Technical Summary

Technical Problem

The widespread application of smart contracts in agricultural supply chains and data management has led to their processing speed and throughput being unable to meet the needs of blockchain network expansion and increase in number of users, affecting the user experience.

Method used

By visualizing the contract execution process of the target agricultural product smart contract platform, identifying the contract status diagram, filtering high complexity contract paths, cleaning and optimizing contract execution data, and using pre-trained smart contract optimization model for feature extraction and optimization strategies Classify and generate an optimized contract path collection.

Benefits of technology

It improves the execution efficiency of smart contracts and improves the user's experience of using digital agricultural services.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119048270B_ABST
    Figure CN119048270B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of blockchain smart contracts, and is a method and system for automatically generating agricultural product contracts based on contract execution status identification, comprising: obtaining an agricultural product contract path set of a target agricultural product smart contract platform and screening a highly complex path set; obtaining clean contract execution data of a highly complex path set within a preset time period; using a pre-trained smart contract optimization model to perform feature extraction on the clean contract execution data to obtain a contract execution feature set, and performing a prediction operation based on hotspot paths and performance bottlenecks on the contract execution feature set to obtain a problem path set; performing optimization strategy classification and optimization result prediction operations on the problem contract execution feature set corresponding to the problem path set to obtain an optimized contract path set, and then updating the initial contract execution process to obtain an optimized agricultural product contract. The present invention can reduce the computational complexity of agricultural product contract execution and improve the overall response speed of the contract.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of blockchain smart contracts, and in particular to a method and system for automatically generating agricultural product contracts based on contract execution status identification. Background Art

[0002] With the rapid development and widespread application of blockchain technology, smart contracts, as its core component, are gradually becoming an important force in promoting the digital transformation of various industries. Smart contracts are self-executing contracts running on blockchain, and their codes cannot be changed after deployment, ensuring the transparency and security of transactions.

[0003] However, with the widespread application of smart contracts in agricultural supply chain, agricultural data management and other fields, the processing speed and throughput of smart contracts are gradually unable to meet the needs of blockchain network expansion and the increase in the number of users, affecting the user experience of digital agricultural services. Summary of the invention

[0004] The present invention provides a method for automatically generating agricultural product contracts based on contract execution status identification, the main purpose of which is to improve the execution efficiency of smart contracts.

[0005] To achieve the above-mentioned purpose, the present invention provides a method for automatically generating agricultural product contracts based on contract execution status identification, comprising:

[0006] Visually model the contract execution process of the target agricultural product smart contract platform to obtain a contract state diagram, and perform full path identification on the contract state diagram to obtain a set of agricultural product contract paths;

[0007] Acquire the real-time network environment data of the agricultural product contract path set, and generate a high complexity threshold adapted to the real-time network environment data by using a pre-built high complexity threshold adaptive adjustment service;

[0008] Calculating the complexity of each agricultural product contract path in the agricultural product contract path set, and screening the agricultural product contract paths with complexity higher than the high complexity threshold to obtain a high complexity path set;

[0009] Obtaining smart contract execution data of the highly complex path set within a preset time period, and performing a data cleaning operation on the smart contract execution data based on a preset cleaning strategy to obtain clean contract execution data;

[0010] Using the problem path identification network in the pre-trained smart contract optimization model, feature extraction is performed on the clean contract execution data to obtain a contract execution feature set, and prediction operations based on hot paths and performance bottlenecks are performed on the contract execution feature set to obtain a problem path set, and contract execution features corresponding to the problem path set are obtained from the contract execution feature set to obtain a problem contract execution feature set;

[0011] Using the optimization decision judgment network in the smart contract optimization model to perform a classification operation based on the optimization strategy on the problem contract execution feature set, obtain the optimization strategy corresponding to each problem path in the problem path set, and perform contract optimization on the problem contract execution feature set according to the optimization strategy corresponding to each problem path, to obtain an optimized contract path set;

[0012] The contract execution process is updated according to the optimized contract path set to obtain an optimized agricultural product contract.

[0013] Optionally, the contract execution process of the target agricultural product smart contract platform is visually modeled to obtain a contract state diagram, including:

[0014] Acquire historical contract execution data of the contract execution process, and perform structured processing on the historical contract execution data to obtain structured historical contract data, wherein the structured historical contract data includes code, documents, and execution logs;

[0015] Use the pre-built UML state diagram to perform state diagram modeling operations based on states, transition conditions, actions performed during state transitions, and entry and exit actions to obtain the basic components of the state diagram;

[0016] According to the structured historical contract data, logically define the states, transition conditions, actions executed when states transition, and entry and exit actions in the basic components of the state diagram to obtain a defined basic component of the state diagram;

[0017] The business process in the target agricultural product smart contract platform is obtained, and the basic components of the defined state diagram are sorted according to the business process using a pre-built visualization tool to obtain a contract state diagram.

[0018] Optionally, the full path identification is performed on the contract state graph to obtain a set of agricultural product contract paths, including:

[0019] Using a pre-built depth-first search algorithm, traverse and identify the contract state graph to obtain an initial full path set;

[0020] Performing a deduplication operation on the initial full path set to obtain a unique full path set;

[0021] According to the contract type in the contract execution process, the unique full path set is classified and summarized to obtain the agricultural product contract path set.

[0022] Optionally, the using a pre-built high complexity threshold adaptive adjustment service to generate a high complexity threshold adapted to the real-time network environment data includes:

[0023] Acquire historical network environment change data and manual evaluation samples, perform feature extraction operations based on processing time, error rate, and resource consumption on the historical network environment change data to obtain a historical execution performance feature set, and obtain a partition threshold of the historical execution performance feature set based on the manual evaluation samples, and use the partition threshold as an initial high complexity threshold;

[0024] The historical execution performance features in the historical execution performance feature set are weighted to obtain a historical performance score, and the historical performance score is regressively predicted to obtain an expected execution score, wherein the expected execution score is expressed as:

[0025]

[0026] In the formula, represents the expected execution score, Indicates the processing time, represents the error rate, Indicates resource consumption, All belong to the historical execution performance feature set;

[0027] Perform feature extraction operations based on processing time, error rate and resource consumption on the real-time network environment data to obtain a contract execution performance feature set, and perform performance scoring on the contract execution performance feature set to obtain an execution performance score ;

[0028] Obtain the minimum perceptible change range of the target agricultural product smart contract platform, and evaluate the execution performance score according to the expected execution score, the minimum perceptible change range, and the initial high complexity threshold. A high complexity threshold is calculated to obtain a high complexity threshold, wherein the high complexity threshold is expressed as:

[0029]

[0030]

[0031] In the formula, represents the high complexity threshold, represents the initial high complexity threshold, represents the minimum change, represents the minimum perceptible change range, represents a proportional coefficient, which is used to adjust the minimum perceptible change range according to the size of the initial high complexity threshold, represents the adjustment factor, Represents the execution performance score.

[0032] Optionally, the calculating the complexity of each agricultural product contract path in the agricultural product contract path set includes:

[0033] Obtaining a complexity analysis indicator set, wherein the complexity analysis indicator set includes CPU usage, memory usage, execution time, and function call times;

[0034] The agricultural product contract path set is monitored and operated to obtain operation record data, and a pre-built performance analysis tool is used to perform data analysis on the operation record data based on the complexity analysis index set to obtain an analysis score sequence of each agricultural product contract path in the agricultural product contract path set under the complexity analysis index set;

[0035] The analysis score sequence is weightedly calculated to obtain the complexity of each agricultural product contract path in the agricultural product contract path set.

[0036] Optionally, performing a data cleaning operation based on a preset cleaning strategy on the smart contract execution data to obtain clean contract execution data includes:

[0037] Obtain a preset cleaning strategy, obtain an outlier interval of each business in the target agricultural product smart contract platform according to the preset cleaning strategy, and perform outlier identification on the smart contract execution data according to the outlier interval to obtain an outlier identification result;

[0038] Deleting the portion of the outlier identification result in the smart contract execution data to obtain normal contract execution data, identifying missing values ​​in the normal contract execution data, and filling the missing values ​​according to a preset linear interpolation algorithm to obtain complete contract execution data;

[0039] A standardized format is obtained, and the complete contract execution data is standardized according to the standardized format to obtain clean contract execution data.

[0040] Optionally, before using the problem path identification network in the pre-trained smart contract optimization model, the method further includes:

[0041] Obtain a smart contract optimization model including a problem path identification network and an optimization decision judgment network, and an artificial optimization training sample, wherein the artificial optimization training sample consists of an original path-real optimization strategy label-real optimization result label, and the real optimization strategy label includes three types of optimization strategies: state merging, advance calculation, and conditional optimization;

[0042] According to a preset allocation ratio, the artificially optimized training samples are randomly grouped into a training sample set and a test sample set;

[0043] Configuring the problem path identification network as an intermediate task, and using a pre-trained problem path identification model to perform transfer learning on the problem path identification network;

[0044] Obtain a training sample from the training sample set in turn, perform forward network calculation on the training sample using the smart contract optimization model, and obtain a prediction optimization strategy and a prediction optimization result corresponding to the training sample;

[0045] Using a pre-constructed cross entropy loss algorithm, calculate the first loss value of the true optimization strategy label corresponding to the training sample and the predicted optimization strategy, and using a pre-constructed mean square error algorithm, calculate the second loss value of the true optimization result label corresponding to the training sample and the predicted optimization result;

[0046] Minimize the first loss value and the second loss value respectively, obtain the first network model parameter when the first loss value is minimized and the second network model parameter when the second loss value is minimized, and perform a network reverse parameter update operation on the smart contract optimization model according to the first network model parameter and the second network model parameter to obtain an updated smart contract optimization model;

[0047] Performing weighted calculation on the first loss value and the second loss value to obtain a comprehensive loss value;

[0048] Determining the convergence of the comprehensive loss value;

[0049] When the comprehensive loss value has not converged, returning to the above step of obtaining a training sample from the training sample set in sequence, and iteratively optimizing the updated smart contract optimization model;

[0050] When the comprehensive loss value converges, the updated smart contract optimization model is tested using the test sample set to obtain a test accuracy rate;

[0051] Determine whether the test accuracy is greater than a preset pass threshold;

[0052] When the test accuracy is less than or equal to the qualified threshold, return to the above step of randomly grouping the artificially optimized training samples into a training sample set and a test sample set according to the preset allocation ratio, and reconstruct the training sample set and the test sample set to train the smart contract optimization model;

[0053] When the test accuracy is greater than the qualified threshold, the training process is stopped to obtain a trained smart contract optimization model.

[0054] Optionally, performing a prediction operation based on hotspot paths and performance bottlenecks on the contract execution feature set to obtain a problem path set includes:

[0055] Performing feature recognition and sorting operations based on the number of function calls and resource consumption on the contract execution feature set to obtain hotspot path sorting results, and filtering the hotspot path sorting results according to a preset hotspot threshold to obtain a hotspot path set;

[0056] Perform feature identification and sorting operations based on execution time and Gas consumption on the contract execution feature set to obtain potential bottleneck path sorting results, and filter the potential bottleneck path sorting results according to a preset bottleneck threshold to obtain a performance bottleneck path set;

[0057] The hotspot path set and the performance bottleneck path set are output to obtain a problem path set.

[0058] Optionally, after the contract execution process is updated according to the optimized contract path set to obtain the optimized agricultural product contract, the method further includes:

[0059] Obtaining the performance test results of the optimized agricultural product contract, obtaining the performance test results of the contract execution process, and obtaining the blockchain of the target agricultural product smart contract platform;

[0060] Determining whether the performance test result of the optimized agricultural product contract is higher than the performance test result of the contract execution process;

[0061] When the performance test result of the optimized agricultural product contract is less than or equal to the performance test result of the contract execution process, the optimized agricultural product contract is determined to be unqualified, and the optimized contract path set is sent to a pre-built manual review database;

[0062] When the performance test result of the optimized agricultural product contract is higher than the performance test result of the contract execution process, the optimized agricultural product contract is deployed to the blockchain.

[0063] To achieve the above object, the present invention also provides an automatic generation system of agricultural product contracts based on contract execution status identification, comprising:

[0064] The contract execution process modeling module is used to visually model the contract execution process of the target agricultural product smart contract platform, obtain a contract state diagram, and perform full path identification on the contract state diagram to obtain a set of agricultural product contract paths;

[0065] A high-complexity path screening module is used to obtain the real-time network environment data of the agricultural product contract path set, generate a high-complexity threshold adapted to the real-time network environment data using a pre-built high-complexity threshold adaptive adjustment service, calculate the complexity of each agricultural product contract path in the agricultural product contract path set, and screen the agricultural product contract paths with a complexity higher than the high-complexity threshold to obtain a high-complexity path set;

[0066] A path optimization module, used to obtain the smart contract execution data of the highly complex path set within a preset time period, and perform a data cleaning operation on the smart contract execution data based on a preset cleaning strategy to obtain clean contract execution data, and use the problem path identification network in the pre-trained smart contract optimization model to perform feature extraction on the clean contract execution data to obtain a contract execution feature set, and perform a prediction operation on the contract execution feature set based on hot paths and performance bottlenecks to obtain a problem path set, and obtain the contract execution features corresponding to the problem path set from the contract execution feature set to obtain a problem contract execution feature set, and use the optimization decision judgment network in the smart contract optimization model to perform a classification operation on the problem contract execution feature set based on the optimization strategy to obtain the optimization strategy corresponding to each problem path in the problem path set, and according to the optimization strategy corresponding to each problem path, perform contract optimization on the problem contract execution feature set to obtain an optimized contract path set;

[0067] The contract update module is used to update the contract execution process according to the optimized contract path set to obtain an optimized agricultural product contract. In order to solve the above problem, the present invention also provides an electronic device, which includes:

[0068] a memory storing at least one instruction; and

[0069] The processor executes the instructions stored in the memory to implement the above-mentioned method for automatically generating agricultural product contracts based on contract execution status identification.

[0070] In order to solve the above problems, the present invention also provides a computer-readable storage medium, in which at least one instruction is stored. The at least one instruction is executed by a processor in an electronic device to implement the above-mentioned method for automatically generating agricultural product contracts based on contract execution status identification.

[0071] The present invention solves the problem described in the background technology. The present invention first obtains a contract state diagram by visually modeling the contract execution process of the target agricultural product smart contract platform. Each node in the contract state diagram represents a state, and each edge represents a transfer condition. The business operation logic can be understood through the contract state diagram. The present invention optimizes the contract execution process from the business operation logic by analyzing the complexity of each agricultural product contract path of the contract state diagram itself; in addition, the present invention also obtains the smart contract execution data of the highly complex path, finds the hot path and performance bottleneck from the data characteristics behind the contract state diagram, and optimizes the contract execution process from the code logic of the smart contract to obtain an optimized contract path set, thereby updating the initial contract execution process to obtain an optimized agricultural product contract. Therefore, the present invention can improve the execution efficiency of smart contracts. BRIEF DESCRIPTION OF THE DRAWINGS

[0072] Figure 1 A schematic diagram of a flow chart of a method for automatically generating agricultural product contracts based on contract execution status identification provided by an embodiment of the present invention;

[0073] Figure 2 A functional module diagram of an automatic generation system for agricultural product contracts based on contract execution status identification provided by an embodiment of the present invention;

[0074] Figure 3 A schematic diagram of the structure of an electronic device for implementing the method for automatically generating agricultural product contracts based on contract execution status identification provided by an embodiment of the present invention.

[0075] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0076] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0077] The embodiment of the present application provides a method for automatically generating agricultural product contracts based on contract execution status identification. The execution subject of the method for automatically generating agricultural product contracts based on contract execution status identification includes but is not limited to at least one of the electronic devices such as a server and a terminal that can be configured to execute the method provided by the embodiment of the present application. In other words, the method for automatically generating agricultural product contracts based on contract execution status identification can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc.

[0078] Reference Figure 1FIG. 1 is a flow chart of a method for automatically generating an agricultural product contract based on contract execution status identification according to an embodiment of the present invention. In this embodiment, the method for automatically generating an agricultural product contract based on contract execution status identification includes:

[0079] S1. Visually model the contract execution process of the target agricultural product smart contract platform to obtain a contract state diagram, and perform full path identification on the contract state diagram to obtain a set of agricultural product contract paths.

[0080] In the embodiment of the present invention, the agricultural data management service of the target agricultural product smart contract platform at least includes agricultural product information registration, agricultural product processing, quality inspection, logistics tracking, sales and purchase, and user feedback, etc. Moreover, the contracts corresponding to each data management service are also different. For example, in the agricultural product information registration service, the producer registers the relevant information of the agricultural product (such as variety, origin, planting date, fertilization record, etc.) on the blockchain through a smart contract, and the smart contract verifies the information and records it on the blockchain, generating an unalterable agricultural product identity (such as a hash value); in the sales and purchase service, the seller publishes the agricultural product information on the market, and consumers can query the detailed information of agricultural products through smart contracts. Consumers confirm the purchase through smart contracts, and the contract automatically verifies the agricultural product information and executes the transaction. The smart contract processes the payment to ensure the transfer of funds and updates the product status to sold.

[0081] The present invention obtains a contract state diagram by visually modeling the contract execution process of the target agricultural product smart contract platform, wherein each state in the contract state diagram corresponds to a business stage of the contract execution process, and different states are connected by pre-built transfer conditions. The contract state diagram can enable professional and technical personnel to accurately control the overall business process and operation logic of the enterprise.

[0082] In detail, in the embodiment of the present invention, the contract execution process of the target agricultural product smart contract platform is visually modeled to obtain a contract state diagram, including:

[0083] Acquire historical contract execution data of the contract execution process, and perform structured processing on the historical contract execution data to obtain structured historical contract data, wherein the structured historical contract data includes code, documents, and execution logs;

[0084] Use the pre-built UML state diagram to perform state diagram modeling operations based on states, transition conditions, actions performed during state transitions, and entry and exit actions to obtain the basic components of the state diagram;

[0085] According to the structured historical contract data, logically define the states, transition conditions, actions executed when states transition, and entry and exit actions in the basic components of the state diagram to obtain a defined basic component of the state diagram;

[0086] The business process in the target agricultural product smart contract platform is obtained, and the basic components of the defined state diagram are sorted according to the business process using a pre-built visualization tool to obtain a contract state diagram.

[0087] Specifically, in an embodiment of the present invention, the historical contract execution data includes the underlying code and files corresponding to each transfer condition, and also includes the execution log of the movement of agricultural data objects between various states.

[0088] Furthermore, the UML state diagram is a diagram in the Unified Modeling Language (UML) for describing the dynamic behavior of a system. The present invention uses the UML state diagram to construct the state diagram basic components of the state, transition conditions, actions executed during state transitions, and entry and exit actions.

[0089] Among them, the state represents the different conditions or stages that an object in the contract may be in during its life cycle; the transition condition represents the triggering event or condition for the object to change from one state to another, usually represented by a line with an arrow; the action performed when the state transitions represents the function call executed when the state transitions, such as calculation, sending a message or any other operation; the entry and exit actions represent the actions performed when entering or leaving a state.

[0090] The present invention logically defines the states, transition conditions, actions executed during state transitions, and entry and exit actions in the basic components of the state diagram according to various states, functions, and algorithms involved in the structured historical contract data, and obtains the basic components of the defined state diagram. Then, the basic components are arranged and combined according to the order of the business process to obtain the contract state diagram of the target agricultural product smart contract platform.

[0091] Furthermore, in an embodiment of the present invention, after obtaining the contract status graph, path identification can be performed on the contract status graph to obtain a set of agricultural product contract paths.

[0092] In detail, in the embodiment of the present invention, the full path identification of the contract state graph to obtain the agricultural product contract path set includes:

[0093] Using a pre-built depth-first search algorithm, traverse and identify the contract state graph to obtain an initial full path set;

[0094] Performing a deduplication operation on the initial full path set to obtain a unique full path set;

[0095] According to the contract type in the contract execution process, the unique full path set is classified and summarized to obtain the agricultural product contract path set.

[0096] Among them, the Depth-First Search algorithm (DFS) is an algorithm for traversing or searching a tree or graph, which can traverse the nodes of the tree along the depth of the tree and search the branches of the tree as deeply as possible. The present invention uses the depth-first search algorithm to traverse and identify the contract state graph to obtain an initial full path set. Then, deduplication is performed according to the database duplication plug-in. Finally, it is summarized according to the contract type to obtain the agricultural product contract path set.

[0097] Among them, the contract types include business types such as procurement contracts, sales contracts, lease contracts, and product types such as grain, fruits and vegetables, and livestock products.

[0098] S2. Acquire the real-time network environment data of the agricultural product contract path set, and use the pre-built high-complexity threshold adaptive adjustment service to generate a high-complexity threshold that adapts to the real-time network environment data.

[0099] Specifically, an adaptive threshold mechanism is introduced in the embodiment of the present invention, which can automatically adjust the high complexity threshold according to the characteristics of the data set. The present invention collects the real-time network environment data of the agricultural product contract path set to obtain a high complexity threshold adapted to the real-time network environment data. The real-time network environment data includes but is not limited to network status, system load, peak trading hours, etc.

[0100] In detail, in the embodiment of the present invention, the use of the pre-built high complexity threshold adaptive adjustment service to generate a high complexity threshold adapted to the real-time network environment data includes:

[0101] Acquire historical network environment change data and manual evaluation samples, perform feature extraction operations based on processing time, error rate, and resource consumption on the historical network environment change data to obtain a historical execution performance feature set, and obtain a partition threshold of the historical execution performance feature set based on the manual evaluation samples, and use the partition threshold as an initial high complexity threshold;

[0102] The historical execution performance features in the historical execution performance feature set are weighted to obtain a historical performance score, and the historical performance score is regressively predicted to obtain an expected execution score, wherein the expected execution score is expressed as:

[0103]

[0104] In the formula, represents the expected execution score, Indicates the processing time, represents the error rate, Indicates resource consumption, All belong to the historical execution performance feature set;

[0105] Perform feature extraction operations based on processing time, error rate and resource consumption on the real-time network environment data to obtain a contract execution performance feature set, and perform performance scoring on the contract execution performance feature set to obtain an execution performance score ;

[0106] Obtain the minimum perceptible change range of the target agricultural product smart contract platform, and evaluate the execution performance score according to the expected execution score, the minimum perceptible change range, and the initial high complexity threshold. A high complexity threshold is calculated to obtain a high complexity threshold, wherein the high complexity threshold is expressed as:

[0107]

[0108]

[0109] In the formula, represents the high complexity threshold, represents the initial high complexity threshold, represents the minimum change, represents the minimum perceptible change range, represents a proportionality coefficient, which is used to adjust the minimum perceptible change range according to the size of the initial high complexity threshold, represents the adjustment factor, Represents the execution performance score.

[0110] It should be known that in order to identify the dynamic high complexity threshold, it is first necessary to have some understanding of the historical data. Therefore, the embodiment of the present invention first obtains the historical network environment change data, and then identifies the characteristics of the processing time, error rate and resource consumption in the historical network environment change data through the neural network model, and then trains the historical execution performance feature set obtained by feature identification through manual evaluation samples to obtain a performance scoring model that can score performance. Query the partition threshold used to distinguish between high complexity and low complexity in the performance scoring model, and use the partition threshold as the initial high complexity threshold.

[0111] By recording the performance scores within a preset time period, a performance score change curve can be obtained. The present invention can obtain future performance scores for a future preset time period by performing regression prediction on the performance score change curve, and use the future performance scores as expected execution scores.

[0112] Then, the present invention performs performance scoring on the real-time network environment data based on processing time, error rate and resource consumption according to the performance scoring model to obtain an execution performance score.

[0113] Furthermore, in an embodiment of the present invention, the minimum perceptible change range of the target agricultural product smart contract platform is obtained.

[0114] The minimum perceptible change range is used to determine whether a change is large enough to be perceived by humans or other systems, ensuring that the impact of the performance score on the high complexity threshold is both meaningful and does not cause unnecessary overreaction.

[0115] Specifically, in the embodiment of the present invention, the above formula is substituted into the expected execution score, the minimum perceptible change range and the initial high complexity threshold, and the high complexity threshold is calculated for the execution performance score to obtain the high complexity threshold.

[0116] S3. Calculate the complexity of each agricultural product contract path in the agricultural product contract path set, and screen the agricultural product contract paths whose complexity is higher than the high complexity threshold to obtain a high complexity path set.

[0117] In detail, in the embodiment of the present invention, the calculation of the complexity of each agricultural product contract path in the agricultural product contract path set includes:

[0118] Obtaining a complexity analysis indicator set, wherein the complexity analysis indicator set includes CPU usage, memory usage, execution time, and function call times;

[0119] The agricultural product contract path set is monitored and operated to obtain operation record data, and a pre-built performance analysis tool is used to perform data analysis on the operation record data based on the complexity analysis index set to obtain an analysis score sequence of each agricultural product contract path in the agricultural product contract path set under the complexity analysis index set;

[0120] The analysis score sequence is weightedly calculated to obtain the complexity of each agricultural product contract path in the agricultural product contract path set.

[0121] Specifically, in an embodiment of the present invention, a profiling performance analysis tool is used, and then the indicators to be analyzed are determined, such as CPU usage, memory usage, execution time, and the number of function calls. Then the contract program is run, and the performance analysis tool is used to collect data. The profiling performance analysis tool will provide a method for calculating the complexity of each path on each data. Among them, the profiling performance analysis tool is a software tool for evaluating and monitoring the runtime performance of a program, which can help developers understand the resource consumption of the program during execution, including but not limited to CPU usage, memory usage, disk I / O, network traffic, and function call time.

[0122] Preferably, in the embodiment of the present invention, the execution time of each path is queried through the Profiling performance analysis tool, and which paths take the longest time; the CPU usage of each path is queried, and which paths have the greatest demand for CPU resources are displayed; the memory allocation and consumption of each path are queried, and memory-intensive paths are found; ... Then, the above monitoring conditions are visualized in a graphical visualization manner to obtain the analysis score sequence of each agricultural product contract path in the agricultural product contract path set under the complexity analysis indicator set.

[0123] Then, according to the preset weight configuration coefficient, the scores in the analysis score sequence are weighted and calculated to obtain the complexity of each agricultural product contract path.

[0124] Furthermore, in the embodiment of the present invention, after the complexity of each agricultural product contract path is obtained, it can be compared according to the high complexity threshold obtained above to screen out a high complexity path set.

[0125] S4. Obtain the smart contract execution data of the high-complexity path set within a preset time period, and perform a data cleaning operation on the smart contract execution data based on a preset cleaning strategy to obtain clean contract execution data.

[0126] The present invention not only optimizes the path of the contract state diagram, but also optimizes the code and logic behind the path. Therefore, the embodiment of the present invention also needs to obtain the smart contract execution data of the highly complex path set within a preset time period.

[0127] In detail, in an embodiment of the present invention, the data cleaning operation based on a preset cleaning strategy is performed on the smart contract execution data to obtain clean contract execution data, including:

[0128] Obtain a preset cleaning strategy, obtain an outlier interval of each business in the target agricultural product smart contract platform according to the preset cleaning strategy, and perform outlier identification on the smart contract execution data according to the outlier interval to obtain an outlier identification result;

[0129] Deleting the portion of the outlier identification result in the smart contract execution data to obtain normal contract execution data, identifying missing values ​​in the normal contract execution data, and filling the missing values ​​according to a preset linear interpolation algorithm to obtain complete contract execution data;

[0130] A standardized format is obtained, and the complete contract execution data is standardized according to the standardized format to obtain clean contract execution data.

[0131] The preset cleaning strategy refers to a configuration program for the type and sequence of function calls during data cleaning.

[0132] Furthermore, the outlier interval refers to a range of outliers determined based on business knowledge and statistical characteristics of data.

[0133] The linear interpolation algorithm refers to an algorithm that estimates the values ​​of other unknown data points between or outside the known discrete data points and then interpolates the values.

[0134] In the embodiment of the present invention, the smart contract execution data is first processed for outliers according to the outlier interval according to the preset cleaning strategy, and then the missing values ​​are filled using a linear interpolation algorithm, and finally the data is standardized through a standardized format to obtain clean contract execution data. Among them, data standardization includes converting character data into numeric data, converting date strings into date formats, converting all data into the same measurement unit, unifying the case of text, removing special characters for stem extraction or word form restoration, etc.

[0135] S5. Utilize the problem path identification network in the pre-trained smart contract optimization model to perform feature extraction on the clean contract execution data to obtain a contract execution feature set, perform prediction operations on the contract execution feature set based on hot paths and performance bottlenecks to obtain a problem path set, and obtain the contract execution features corresponding to the problem path set from the contract execution feature set to obtain a problem contract execution feature set.

[0136] In an embodiment of the present invention, the smart contract optimization model is a Transformer-based neural network model used to extract contract execution features, identify problem paths, and identify optimization strategies for problem paths, and optimize according to the optimization strategies to obtain optimization results.

[0137] The present invention first equips the problem path identification network in the smart contract optimization model with a convolution kernel for extracting features such as the number of function calls, gas consumption, execution time, and state variable changes, and uses the convolution kernel to extract features from clean contract execution data. Then, the extracted results are reduced in dimension through an average pooling operation to obtain a contract execution feature set. Then, the model is subsequently analyzed based on the contract execution feature set.

[0138] In detail, in the embodiment of the present invention, the prediction operation based on the hotspot path and the performance bottleneck is performed on the contract execution feature set to obtain the problem path set, including:

[0139] Performing feature recognition and sorting operations based on the number of function calls and resource consumption on the contract execution feature set to obtain hotspot path sorting results, and filtering the hotspot path sorting results according to a preset hotspot threshold to obtain a hotspot path set;

[0140] Perform feature identification and sorting operations based on execution time and Gas consumption on the contract execution feature set to obtain potential bottleneck path sorting results, and filter the potential bottleneck path sorting results according to a preset bottleneck threshold to obtain a performance bottleneck path set;

[0141] The hotspot path set and the performance bottleneck path set are output to obtain a problem path set.

[0142] Specifically, in the embodiment of the present invention, the code path that is most frequently called and consumes the most resources is regarded as the hotspot path, and the function or module with too long execution time and too high gas consumption is regarded as the potential bottleneck. The present invention trains the network part of the hotspot path and the performance bottleneck through a pre-constructed training sample set, so as to accurately obtain the hotspot path set and the performance bottleneck path set, and combine them to obtain the problem path set.

[0143] Among them, the hotspot path is to identify problems from the perspective of the contract state diagram, while the performance bottleneck is to identify problems from the perspective of background data operation. The present invention deeply optimizes the contract execution process through the identification of problems in both front and back aspects. Among them, the hotspot threshold and bottleneck threshold can be flexibly configured according to specific business scenarios.

[0144] Furthermore, in an embodiment of the present invention, before using the problem path identification network in the pre-trained smart contract optimization model, the method further includes:

[0145] Obtain a smart contract optimization model including a problem path identification network and an optimization decision judgment network, and an artificial optimization training sample, wherein the artificial optimization training sample consists of an original path-real optimization strategy label-real optimization result label, and the real optimization strategy label includes three types of optimization strategies: state merging, advance calculation, and conditional optimization;

[0146] According to a preset allocation ratio, the artificially optimized training samples are randomly grouped into a training sample set and a test sample set;

[0147] Configuring the problem path identification network as an intermediate task, and using a pre-trained problem path identification model to perform transfer learning on the problem path identification network;

[0148] Obtain a training sample from the training sample set in turn, perform forward network calculation on the training sample using the smart contract optimization model, and obtain a prediction optimization strategy and a prediction optimization result corresponding to the training sample;

[0149] Using a pre-constructed cross entropy loss algorithm, calculate the first loss value of the true optimization strategy label corresponding to the training sample and the predicted optimization strategy, and using a pre-constructed mean square error algorithm, calculate the second loss value of the true optimization result label corresponding to the training sample and the predicted optimization result;

[0150] Minimize the first loss value and the second loss value respectively, obtain the first network model parameter when the first loss value is minimized and the second network model parameter when the second loss value is minimized, and perform a network reverse parameter update operation on the smart contract optimization model according to the first network model parameter and the second network model parameter to obtain an updated smart contract optimization model;

[0151] Performing weighted calculation on the first loss value and the second loss value to obtain a comprehensive loss value;

[0152] Determining the convergence of the comprehensive loss value;

[0153] When the comprehensive loss value has not converged, returning to the above step of obtaining a training sample from the training sample set in sequence, and iteratively optimizing the updated smart contract optimization model;

[0154] When the comprehensive loss value converges, the updated smart contract optimization model is tested using the test sample set to obtain a test accuracy rate;

[0155] Determine whether the test accuracy is greater than a preset pass threshold;

[0156] When the test accuracy is less than or equal to the qualified threshold, return to the above step of randomly grouping the artificially optimized training samples into a training sample set and a test sample set according to the preset allocation ratio, and reconstruct the training sample set and the test sample set to train the smart contract optimization model;

[0157] When the test accuracy is greater than the qualified threshold, the training process is stopped to obtain a trained smart contract optimization model.

[0158] Specifically, the smart contract optimization model in the embodiment of the present invention includes a problem path identification network and an optimization decision judgment network. The present invention configures the problem path identification network as an intermediate task, and pre-trains the problem path identification network through transfer learning, so that the intermediate layer output results of the problem path identification network are not output in the subsequent training process. Among them, the intermediate tasks refer to auxiliary tasks or subtasks set in the entire cycle of model training in order to achieve the ultimate goal. The subtasks are not the ultimate goals, but they play an important role in optimizing the training process, improving model performance, and accelerating convergence speed. Among them, the problem path identification model refers to a model downloaded or pre-trained from the Internet, which has a relatively simple function and is only used to identify problem paths.

[0159] Furthermore, the optimization strategies of the present invention include three types of optimization strategies: state merging, advance calculation, and conditional optimization. Among them, the state merging refers to merging multiple adjacent states into one state to reduce the number of state transfers; advance calculation refers to caching certain results that can be calculated in advance to reduce the computational burden during contract execution; conditional optimization refers to optimizing the conditional judgment logic to reduce unnecessary conditional checks. It can be seen that the state merging is optimized from the perspective of the contract state diagram, and the advance calculation and conditional optimization are optimized from the perspective of the background code data and logic configuration.

[0160] The present invention uses pre-constructed artificial optimization training samples for training, and the artificial optimization training samples are composed of original path-real optimization strategy label-real optimization result label. The allocation ratio is configured as training set: test sample set is 7:3.

[0161] Furthermore, in the training process of the present invention, training is performed by updating the network reverse parameters through the gradient descent algorithm. Among them, the network that identifies the optimization strategy corresponding to each problem path is a three-classification network, and the present invention uses the cross entropy loss algorithm to calculate the loss value, and the network that identifies the predicted optimization results of each problem path is a regression network, and the present invention uses the mean square error algorithm to calculate the loss value, thereby obtaining a comprehensive loss value. Among them, the cross entropy loss algorithm and the mean square error algorithm are common loss functions, which will not be described in detail here.

[0162] In order to avoid the phenomenon of model overfitting, the present invention controls the training progress by supervising the convergence of the comprehensive loss value. When the comprehensive loss value converges, it indicates that the model training effect has not improved significantly, then the training process can be stopped, and the test sample set can be used for verification to obtain the test accuracy. If the test accuracy is greater than the preset qualified threshold, such as 90%, the training ends and a trained smart contract optimization model is obtained.

[0163] S6. Utilize the optimization decision judgment network in the smart contract optimization model to perform classification operations on the problem contract execution feature set based on the optimization strategy, obtain the optimization strategy corresponding to each problem path in the problem path set, and perform contract optimization on the problem contract execution feature set according to the optimization strategy corresponding to each problem path to obtain the optimized contract path set.

[0164] The embodiment of the present invention identifies the optimization strategy for the problem contract execution feature set based on the above-mentioned trained smart contract optimization model, and generates optimization results according to the optimization strategy to obtain an optimized contract path set. The optimized contract path set effectively reduces the calculation steps in the contract execution process through strategies such as state merging, condition simplification and advance calculation, reduces the consumption of computing resources, and thus improves the overall response speed of the contract.

[0165] S7. Update the contract execution process according to the optimized contract path set to obtain an optimized agricultural product contract.

[0166] In the embodiment of the present invention, the optimized contract path set replaces the corresponding part in the contract state diagram to obtain the optimized agricultural product contract. However, whether the optimized agricultural product contract is qualified still needs to be verified before it can be put into use.

[0167] In detail, in the embodiment of the present invention, after the contract execution process is updated according to the optimized contract path set to obtain the optimized agricultural product contract, the method further includes:

[0168] Obtaining the performance test results of the optimized agricultural product contract, obtaining the performance test results of the contract execution process, and obtaining the blockchain of the target agricultural product smart contract platform;

[0169] Determining whether the performance test result of the optimized agricultural product contract is higher than the performance test result of the contract execution process;

[0170] When the performance test result of the optimized agricultural product contract is less than or equal to the performance test result of the contract execution process, the optimized agricultural product contract is determined to be unqualified, and the optimized contract path set is sent to a pre-built manual review database;

[0171] When the performance test result of the optimized agricultural product contract is higher than the performance test result of the contract execution process, the optimized agricultural product contract is deployed to the blockchain.

[0172] In the embodiment of the present invention, the performance test results include path execution time, Gas Limit, Gas Price, contract complexity and node performance, etc. By comparing the performance test results, the optimized agricultural product contract is evaluated, and when the evaluation is qualified, it is uploaded to the optimized agricultural product contract and deployed in the blockchain.

[0173] In addition, the present invention also pre-constructs a manual review database for recording the optimized contract path set, which is used for tracing on the one hand and for assisting users in manually optimizing the problem path on the other hand.

[0174] The present invention solves the problem described in the background technology. The present invention first obtains a contract state diagram by visually modeling the contract execution process of the target agricultural product smart contract platform. Each node in the contract state diagram represents a state, and each edge represents a transfer condition. The business operation logic can be understood through the contract state diagram. The present invention optimizes the contract execution process from the business operation logic by analyzing the complexity of each agricultural product contract path of the contract state diagram itself; in addition, the present invention also obtains the smart contract execution data of the highly complex path, finds the hot path and performance bottleneck from the data characteristics behind the contract state diagram, and optimizes the contract execution process from the code logic of the smart contract to obtain an optimized contract path set, thereby updating the initial contract execution process to obtain an optimized agricultural product contract. Therefore, the present invention can improve the execution efficiency of smart contracts.

[0175] like Figure 2 , which is a functional module diagram of an automatic generation system for agricultural product contracts based on contract execution status identification provided by an embodiment of the present invention.

[0176] The agricultural product contract automatic generation system 100 based on contract execution status identification of the present invention can be installed in an electronic device. According to the functions implemented, the agricultural product contract automatic generation system 100 based on contract execution status identification can include a contract execution process modeling module 101, a high-complexity path screening module 102, a path optimization module 103 and a contract update module 104. The module of the present invention can also be called a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.

[0177] The contract execution process modeling module 101 is used to perform visual modeling on the contract execution process of the target agricultural product smart contract platform to obtain a contract state diagram, and perform full path identification on the contract state diagram to obtain a set of agricultural product contract paths, wherein each state in the contract state diagram corresponds to a business stage of the contract execution process, and different states are connected by pre-built transfer conditions;

[0178] The high-complexity path screening module 102 is used to obtain the real-time network environment data of the agricultural product contract path set, generate a high-complexity threshold adapted to the real-time network environment data by using a pre-built high-complexity threshold adaptive adjustment service, calculate the complexity of each agricultural product contract path in the agricultural product contract path set, and screen the agricultural product contract paths with a complexity higher than the high-complexity threshold to obtain a high-complexity path set;

[0179] The path optimization module 103 is used to obtain the smart contract execution data of the high-complexity path set within a preset time period, and perform a data cleaning operation on the smart contract execution data based on a preset cleaning strategy to obtain clean contract execution data, and use the problem path identification network in the pre-trained smart contract optimization model to extract features from the clean contract execution data to obtain a contract execution feature set, and perform a prediction operation on the contract execution feature set based on hot paths and performance bottlenecks to obtain a problem path set, and obtain the contract execution features corresponding to the problem path set from the contract execution feature set to obtain a problem contract execution feature set, and use the optimization decision judgment network in the smart contract optimization model to perform a classification operation on the problem contract execution feature set based on the optimization strategy to obtain the optimization strategy corresponding to each problem path in the problem path set, and according to the optimization strategy corresponding to each problem path, perform contract optimization on the problem contract execution feature set to obtain an optimized contract path set;

[0180] The contract updating module 104 is used to update the contract execution process according to the optimized contract path set to obtain an optimized agricultural product contract.

[0181] In detail, the modules in the agricultural product contract automatic generation system 100 based on contract execution status identification in the embodiment of the present invention are used in the same manner as above. Figure 1 The technical means are the same as the method for automatically generating agricultural product contracts based on contract execution status identification described in , and can produce the same technical effects, so they will not be repeated here.

[0182] like Figure 3 , which is a schematic diagram of the structure of an electronic device for implementing a method for automatically generating agricultural product contracts based on contract execution status identification provided by an embodiment of the present invention.

[0183] The electronic device 1 may include a processor 10, a memory 11 and a bus 12, and may also include a computer program stored in the memory 11 and executable on the processor 10, such as a method program for automatically generating agricultural product contracts based on contract execution status identification.

[0184] The memory 11 includes at least one type of readable storage medium, including flash memory, mobile hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 11 may be an internal storage unit of the electronic device 1, such as a mobile hard disk of the electronic device 1. In other embodiments, the memory 11 may also be an external storage device of the electronic device 1, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card, etc. equipped on the electronic device 1. Further, the memory 11 also includes an internal storage unit of the electronic device 1 and an external storage device. The memory 11 can not only be used to store application software and various types of data installed in the electronic device 1, such as the code of the method program for automatically generating agricultural product contracts based on contract execution status identification, but also can be used to temporarily store data that has been output or is to be output.

[0185] The processor 10 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips, etc. The processor 10 is the control core (Control Unit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules stored in the memory 11 (such as a method program for automatically generating agricultural product contracts based on contract execution status identification, etc.), and calls data stored in the memory 11 to execute various functions of the electronic device 1 and process data.

[0186] The bus 12 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus 12 may be divided into an address bus, a data bus, a control bus, etc. The bus 12 is configured to realize connection and communication between the memory 11 and at least one processor 10, etc.

[0187] Figure 3 Only an electronic device with components is shown, and those skilled in the art will understand that Figure 3 The structure shown does not constitute a limitation on the electronic device 1, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.

[0188] For example, although not shown, the electronic device 1 may also include a power source (such as a battery) for supplying power to various components. Preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that the power management device can realize functions such as charging management, discharging management, and power consumption management. The power source may also include one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components. The electronic device 1 may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.

[0189] Furthermore, the electronic device 1 may also include a network interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device 1 and other electronic devices.

[0190] Optionally, the electronic device 1 may further include a user interface, which may be a display, an input unit (such as a keyboard), or a standard wired interface or a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device. The display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device 1 and to display a visual user interface.

[0191] The program of the method for automatically generating agricultural product contracts based on contract execution status identification stored in the memory 11 of the electronic device 1 is a combination of multiple instructions. When running in the processor 10, it can achieve:

[0192] Visually model the contract execution process of the target agricultural product smart contract platform to obtain a contract state diagram, and perform full path identification on the contract state diagram to obtain a set of agricultural product contract paths, wherein each state in the contract state diagram corresponds to a business stage of the contract execution process, and different states are connected through pre-built transfer conditions;

[0193] Acquire the real-time network environment data of the agricultural product contract path set, and generate a high complexity threshold adapted to the real-time network environment data by using a pre-built high complexity threshold adaptive adjustment service;

[0194] Calculating the complexity of each agricultural product contract path in the agricultural product contract path set, and screening the agricultural product contract paths with complexity higher than the high complexity threshold to obtain a high complexity path set;

[0195] Obtaining smart contract execution data of the highly complex path set within a preset time period, and performing a data cleaning operation on the smart contract execution data based on a preset cleaning strategy to obtain clean contract execution data;

[0196] Using the problem path identification network in the pre-trained smart contract optimization model, feature extraction is performed on the clean contract execution data to obtain a contract execution feature set (number of function calls, gas consumption, execution time, state variable changes, etc.), and prediction operations are performed on the contract execution feature set based on hot paths and performance bottlenecks to obtain a problem path set, and contract execution features corresponding to the problem path set are obtained from the contract execution feature set to obtain a problem contract execution feature set;

[0197] Using the optimization decision judgment network in the smart contract optimization model to perform a classification operation based on the optimization strategy on the problem contract execution feature set, obtain the optimization strategy corresponding to each problem path in the problem path set, and perform contract optimization on the problem contract execution feature set according to the optimization strategy corresponding to each problem path, to obtain an optimized contract path set;

[0198] The contract execution process is updated according to the optimized contract path set to obtain an optimized agricultural product contract.

[0199] Specifically, the specific implementation method of the processor 10 for the above instructions can refer to Figures 1 to 3 The description of the relevant steps in the corresponding embodiments will not be repeated here.

[0200] Furthermore, if the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable storage medium can be volatile or non-volatile. For example, the computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).

[0201] The present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor of an electronic device, the computer program can implement:

[0202] Visually model the contract execution process of the target agricultural product smart contract platform to obtain a contract state diagram, and perform full path identification on the contract state diagram to obtain a set of agricultural product contract paths, wherein each state in the contract state diagram corresponds to a business stage of the contract execution process, and different states are connected through pre-built transfer conditions;

[0203] Acquire the real-time network environment data of the agricultural product contract path set, and generate a high complexity threshold adapted to the real-time network environment data by using a pre-built high complexity threshold adaptive adjustment service;

[0204] Calculating the complexity of each agricultural product contract path in the agricultural product contract path set, and screening the agricultural product contract paths with complexity higher than the high complexity threshold to obtain a high complexity path set;

[0205] Obtaining smart contract execution data of the highly complex path set within a preset time period, and performing a data cleaning operation on the smart contract execution data based on a preset cleaning strategy to obtain clean contract execution data;

[0206] Using the problem path identification network in the pre-trained smart contract optimization model, feature extraction is performed on the clean contract execution data to obtain a contract execution feature set (number of function calls, gas consumption, execution time, state variable changes, etc.), and prediction operations are performed on the contract execution feature set based on hot paths and performance bottlenecks to obtain a problem path set, and contract execution features corresponding to the problem path set are obtained from the contract execution feature set to obtain a problem contract execution feature set;

[0207] Using the optimization decision judgment network in the smart contract optimization model to perform a classification operation based on the optimization strategy on the problem contract execution feature set, obtain the optimization strategy corresponding to each problem path in the problem path set, and perform contract optimization on the problem contract execution feature set according to the optimization strategy corresponding to each problem path, to obtain an optimized contract path set;

[0208] The contract execution process is updated according to the optimized contract path set to obtain an optimized agricultural product contract.

[0209] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, systems and methods can be implemented in other ways. For example, the system embodiments described above are only illustrative, and actual implementation may have other division methods.

[0210] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0211] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.

[0212] It is obvious to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.

[0213] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.

Claims

1. A method for automatically generating agricultural product contracts based on contract execution status identification, characterized in that: The method comprises: Visually model the contract execution process of the target agricultural product smart contract platform to obtain a contract state diagram, and perform full path identification on the contract state diagram to obtain a set of agricultural product contract paths; Acquire the real-time network environment data of the agricultural product contract path set, and generate a high complexity threshold adapted to the real-time network environment data by using a pre-built high complexity threshold adaptive adjustment service; Calculating the complexity of each agricultural product contract path in the agricultural product contract path set, and screening the agricultural product contract paths with complexity higher than the high complexity threshold to obtain a high complexity path set; Obtaining smart contract execution data of the highly complex path set within a preset time period, and performing a data cleaning operation on the smart contract execution data based on a preset cleaning strategy to obtain clean contract execution data; Using the problem path identification network in the pre-trained smart contract optimization model, feature extraction is performed on the clean contract execution data to obtain a contract execution feature set, and prediction operations based on hot paths and performance bottlenecks are performed on the contract execution feature set to obtain a problem path set, and contract execution features corresponding to the problem path set are obtained from the contract execution feature set to obtain a problem contract execution feature set; Using the optimization decision judgment network in the smart contract optimization model to perform a classification operation based on the optimization strategy on the problem contract execution feature set, obtain the optimization strategy corresponding to each problem path in the problem path set, and perform contract optimization on the problem contract execution feature set according to the optimization strategy corresponding to each problem path, to obtain an optimized contract path set; The contract execution process is updated according to the optimized contract path set to obtain an optimized agricultural product contract.

2. The method for automatically generating agricultural product contracts based on contract execution status identification according to claim 1, characterized in that: The contract execution process of the target agricultural product smart contract platform is visually modeled to obtain a contract state diagram, including: Acquire historical contract execution data of the contract execution process, and perform structured processing on the historical contract execution data to obtain structured historical contract data, wherein the structured historical contract data includes code, documents, and execution logs; Use the pre-built UML state diagram to perform state diagram modeling operations based on states, transition conditions, actions performed during state transitions, and entry and exit actions to obtain the basic components of the state diagram; According to the structured historical contract data, logically define the states, transition conditions, actions executed when states transition, and entry and exit actions in the basic components of the state diagram to obtain a defined basic component of the state diagram; The business process in the target agricultural product smart contract platform is obtained, and the basic components of the defined state diagram are sorted according to the business process using a pre-built visualization tool to obtain a contract state diagram.

3. The method for automatically generating agricultural product contracts based on contract execution status identification according to claim 2, characterized in that: The full path identification of the contract state graph is performed to obtain a set of agricultural product contract paths, including: Using a pre-built depth-first search algorithm, traverse and identify the contract state graph to obtain an initial full path set; Performing a deduplication operation on the initial full path set to obtain a unique full path set; According to the contract type in the contract execution process, the unique full path set is classified and summarized to obtain the agricultural product contract path set.

4. The method for automatically generating agricultural product contracts based on contract execution status identification according to claim 3, characterized in that: The method of utilizing the pre-built high complexity threshold adaptive adjustment service to generate a high complexity threshold adapted to the real-time network environment data includes: Acquire historical network environment change data and manual evaluation samples, perform feature extraction operations based on processing time, error rate, and resource consumption on the historical network environment change data to obtain a historical execution performance feature set, and obtain a partition threshold of the historical execution performance feature set based on the manual evaluation samples, and use the partition threshold as an initial high complexity threshold; The historical execution performance features in the historical execution performance feature set are weighted to obtain a historical performance score, and the historical performance score is regressively predicted to obtain an expected execution score, wherein the expected execution score is expressed as: In the formula, represents the expected execution score, Indicates the processing time, represents the error rate, Indicates resource consumption, All belong to the historical execution performance feature set; Perform feature extraction operations based on processing time, error rate and resource consumption on the real-time network environment data to obtain a contract execution performance feature set, and perform performance scoring on the contract execution performance feature set to obtain an execution performance score ; Obtain the minimum perceptible change range of the target agricultural product smart contract platform, and evaluate the execution performance score according to the expected execution score, the minimum perceptible change range, and the initial high complexity threshold. A high complexity threshold is calculated to obtain a high complexity threshold, wherein the high complexity threshold is expressed as: In the formula, represents the high complexity threshold, represents the initial high complexity threshold, represents the minimum change, represents the minimum perceptible change range, represents a proportionality coefficient, which is used to adjust the minimum perceptible change range according to the size of the initial high complexity threshold, represents the adjustment factor, Represents the execution performance score.

5. The method for automatically generating agricultural product contracts based on contract execution status identification according to claim 4, characterized in that: The calculating the complexity of each agricultural product contract path in the agricultural product contract path set includes: Obtaining a complexity analysis indicator set, wherein the complexity analysis indicator set includes CPU usage, memory usage, execution time, and function call times; The agricultural product contract path set is monitored and operated to obtain operation record data, and a pre-built performance analysis tool is used to perform data analysis on the operation record data based on the complexity analysis index set to obtain an analysis score sequence of each agricultural product contract path in the agricultural product contract path set under the complexity analysis index set; The analysis score sequence is weightedly calculated to obtain the complexity of each agricultural product contract path in the agricultural product contract path set.

6. The method for automatically generating agricultural product contracts based on contract execution status identification according to claim 5, characterized in that: The performing a data cleaning operation on the smart contract execution data based on a preset cleaning strategy to obtain clean contract execution data includes: Obtain a preset cleaning strategy, obtain an outlier interval of each business in the target agricultural product smart contract platform according to the preset cleaning strategy, and perform outlier identification on the smart contract execution data according to the outlier interval to obtain an outlier identification result; Deleting the portion of the outlier identification result in the smart contract execution data to obtain normal contract execution data, identifying missing values ​​in the normal contract execution data, and filling the missing values ​​according to a preset linear interpolation algorithm to obtain complete contract execution data; A standardized format is obtained, and the complete contract execution data is standardized according to the standardized format to obtain clean contract execution data.

7. The method for automatically generating agricultural product contracts based on contract execution status identification according to claim 6, characterized in that: Before using the problem path identification network in the pre-trained smart contract optimization model, the method further includes: Obtain a smart contract optimization model including a problem path identification network and an optimization decision judgment network, and an artificial optimization training sample, wherein the artificial optimization training sample consists of an original path-real optimization strategy label-real optimization result label, and the real optimization strategy label includes three types of optimization strategies: state merging, advance calculation, and conditional optimization; According to a preset allocation ratio, the artificially optimized training samples are randomly grouped into a training sample set and a test sample set; Configuring the problem path identification network as an intermediate task, and using a pre-trained problem path identification model to perform transfer learning on the problem path identification network; Obtain a training sample from the training sample set in turn, perform forward network calculation on the training sample using the smart contract optimization model, and obtain a prediction optimization strategy and a prediction optimization result corresponding to the training sample; Using a pre-constructed cross entropy loss algorithm, calculate the first loss value of the true optimization strategy label corresponding to the training sample and the predicted optimization strategy, and using a pre-constructed mean square error algorithm, calculate the second loss value of the true optimization result label corresponding to the training sample and the predicted optimization result; Minimize the first loss value and the second loss value respectively, obtain the first network model parameter when the first loss value is minimized and the second network model parameter when the second loss value is minimized, and perform a network reverse parameter update operation on the smart contract optimization model according to the first network model parameter and the second network model parameter to obtain an updated smart contract optimization model; Performing weighted calculation on the first loss value and the second loss value to obtain a comprehensive loss value; Determining the convergence of the comprehensive loss value; When the comprehensive loss value has not converged, returning to the above step of obtaining a training sample from the training sample set in sequence, and iteratively optimizing the updated smart contract optimization model; When the comprehensive loss value converges, the updated smart contract optimization model is tested using the test sample set to obtain a test accuracy rate; Determine whether the test accuracy is greater than a preset pass threshold; When the test accuracy is less than or equal to the qualified threshold, return to the above step of randomly grouping the artificially optimized training samples into a training sample set and a test sample set according to the preset allocation ratio, and reconstruct the training sample set and the test sample set to train the smart contract optimization model; When the test accuracy is greater than the qualified threshold, the training process is stopped to obtain a trained smart contract optimization model.

8. The method for automatically generating agricultural product contracts based on contract execution status identification according to claim 7, characterized in that: The contract execution feature set is subjected to a prediction operation based on hotspot paths and performance bottlenecks to obtain a problem path set, including: Performing feature recognition and sorting operations based on the number of function calls and resource consumption on the contract execution feature set to obtain hotspot path sorting results, and filtering the hotspot path sorting results according to a preset hotspot threshold to obtain a hotspot path set; Perform feature identification and sorting operations based on execution time and Gas consumption on the contract execution feature set to obtain potential bottleneck path sorting results, and filter the potential bottleneck path sorting results according to a preset bottleneck threshold to obtain a performance bottleneck path set; The hotspot path set and the performance bottleneck path set are output to obtain a problem path set.

9. The method for automatically generating agricultural product contracts based on contract execution status identification according to claim 8, characterized in that: After the contract execution process is updated according to the optimized contract path set to obtain the optimized agricultural product contract, the method further includes: Obtaining the performance test results of the optimized agricultural product contract, obtaining the performance test results of the contract execution process, and obtaining the blockchain of the target agricultural product smart contract platform; Determining whether the performance test result of the optimized agricultural product contract is higher than the performance test result of the contract execution process; When the performance test result of the optimized agricultural product contract is less than or equal to the performance test result of the contract execution process, the optimized agricultural product contract is determined to be unqualified, and the optimized contract path set is sent to a pre-built manual review database; When the performance test result of the optimized agricultural product contract is higher than the performance test result of the contract execution process, the optimized agricultural product contract is deployed to the blockchain.

10. An automatic generation system for agricultural product contracts based on contract execution status recognition, characterized in that: The system comprises: The contract execution process modeling module is used to visually model the contract execution process of the target agricultural product smart contract platform, obtain a contract state diagram, and perform full path identification on the contract state diagram to obtain a set of agricultural product contract paths; A high-complexity path screening module is used to obtain the real-time network environment data of the agricultural product contract path set, generate a high-complexity threshold adapted to the real-time network environment data using a pre-built high-complexity threshold adaptive adjustment service, calculate the complexity of each agricultural product contract path in the agricultural product contract path set, and screen the agricultural product contract paths with a complexity higher than the high-complexity threshold to obtain a high-complexity path set; A path optimization module, used to obtain the smart contract execution data of the highly complex path set within a preset time period, and perform a data cleaning operation on the smart contract execution data based on a preset cleaning strategy to obtain clean contract execution data, and use the problem path identification network in the pre-trained smart contract optimization model to perform feature extraction on the clean contract execution data to obtain a contract execution feature set, and perform a prediction operation on the contract execution feature set based on hot paths and performance bottlenecks to obtain a problem path set, and obtain the contract execution features corresponding to the problem path set from the contract execution feature set to obtain a problem contract execution feature set, and use the optimization decision judgment network in the smart contract optimization model to perform a classification operation on the problem contract execution feature set based on the optimization strategy to obtain the optimization strategy corresponding to each problem path in the problem path set, and according to the optimization strategy corresponding to each problem path, perform contract optimization on the problem contract execution feature set to obtain an optimized contract path set; The contract updating module is used to update the contract execution process according to the optimized contract path set to obtain an optimized agricultural product contract.

Citation Information

Patent Citations

  • Block chain smart contract generation method and device, and electronic equipment

    CN115268847A

  • Automatic generation method of intelligent contract

    CN115659919A