Smart contract and under-chain service combination method and system
By using the coloring Petri network model and ant colony algorithm, the on-chain smart contract and off-chain services are collaboratively combined, which solves the problem of how to choose the optimal combination solution in complex business scenarios, and achieves efficient and effective service combination.
Patent Information
- Application Number
- CN202411836385.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-05-23
AI Technical Summary
In complex business scenarios, how to effectively model and select the optimal combination solution of on-chain smart contracts and off-chain services, especially in the traditional Internet environment where it cannot be directly extended to on-chain smart contracts.
By obtaining executable services and abstract services, using the colored Petri net model to model the chain-on-chain collaborative combination, designing a description scheme to build an abstract service collaborative combination diagram, and using the ant colony algorithm to optimize and solve based on service quality to obtain the optimal collaborative combination.
It realizes an effective combination of on-chain smart contracts and off-chain services in complex business scenarios, improves the efficiency and effectiveness of the service combination solution, and can more accurately describe and process complex business logic.
Smart Images

Figure CN120034572A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of smart contract technology, and in particular to a smart contract and off-chain service combination method and system. Background Art
[0002] With the development of software technologies in different fields, data as a service (DaaS) in the database field, function as a service (FaaS) in the computing field, and blockchain as a service (BaaS) in the blockchain field have emerged. Various tools and supporting facilities are abstracted in different scenarios to help users obtain solutions to their problems more efficiently. This patent is based on smart contracts as a service, and regards smart contracts as a service. In the scenario of collaboration with off-chain services, the two types of services have their own different attributes and characteristics, so it involves the combination and optimization of the two types of services. Service composition modeling aims to use graphical or mathematical models to rigorously describe the service composition process. It can currently be divided into two categories: process-driven service composition methods and semantic-driven service composition methods. The process-driven service composition method refers to the use of process modeling tools to analogize the business process in the service composition, and the use of components or basic morphemes in the process modeling tools to replace the basic units in the business process. Process-driven service composition solutions include the following three categories: workflow-based service composition, process algebra-based service composition, and state calculus-based service composition. Semantic-driven service composition methods emphasize the generation of automated service composition solutions, and achieve reasoning and selection of composition solutions by adding computer-understandable semantics to services and service compositions. The core lies in the description of the service itself. The currently commonly used solution is the network ontology language OWL-S[6], which describes services from three aspects: service profile, service operation process model, and service grounding that describes the interaction details between services. Using AI reasoning analysis, automatic service composition can be achieved based on OWL-S, and users do not need to declare service processes. However, this model has high requirements for service description, and the results of AI reasoning may deviate from user expectations.
[0003] In actual complex business scenarios, a combination of several on-chain smart contracts and off-chain services is often required. How to model such a combination scenario, design a reasonable combination mechanism, and select the best solution from many on-chain smart contracts and off-chain services with similar functions are issues that need to be considered. So far, there have been rich achievements in the service combination problem, but the achievements are based on traditional web services in the traditional Internet environment and do not have the conditions to be directly extended to on-chain smart contracts. First of all, the services in the collaborative scenario include on-chain smart contract services and off-chain services. The two types of services have different attributes and characteristics. Using the traditional XML method to describe them will make the description scheme too lengthy and complicated. Secondly, when the system contains more than traditional services, the combination model needs to be upgraded and transformed in combination with the characteristics of smart contracts. For example, the call of on-chain smart contracts is asynchronous execution, etc. Such characteristics will affect the construction of the collaborative combination service model. Finally, there are a large number of smart contracts and off-chain services with similar functions provided by different providers on and off the chain. Whether the optimal combination solution that meets the constraints can be selected determines whether the combination model is effective. In order to enable smart contracts and extended services to be combined and coordinated to solve complex business problems, this application mainly solves the service combination problem in the architecture. Summary of the invention
[0004] In view of the above existing problems, the present invention is proposed.
[0005] Therefore, the present invention provides a smart contract and off-chain service combination method and system to solve the problem of how to effectively model and select the optimal combination of on-chain smart contracts and off-chain services in actual complex business scenarios.
[0006] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0007] In a first aspect, the present invention provides a smart contract and off-chain service combination method, comprising:
[0008] Obtain executable services and abstract services, and use the executable services and abstract services to model the synergistic combination of on-chain smart contracts and off-chain services to obtain an on-chain and off-chain synergistic combination model;
[0009] Design a description scheme for the basic control structure in the on-chain and off-chain collaborative composition model, and construct an abstract service collaborative composition diagram based on the description scheme;
[0010] Based on the abstract service synergy combination graph, the service quality is defined, and a first optimization algorithm is used to solve the problem according to the service quality to obtain an optimal synergy combination.
[0011] As a preferred solution of the smart contract and off-chain service combination method described in the present invention, modeling the collaborative combination of on-chain smart contracts and off-chain services includes:
[0012] Define executable services, abstract services, and colored Petri nets;
[0013] According to the definition, the on-chain and off-chain collaborative combination model includes a colored Petri net model isomorphic to the on-chain and off-chain collaborative combination scheme, a set of abstract services for collaborative combination, a set of mapping rules corresponding to the collaborative combination, service selection and optimization strategies, and global constraints for the collaborative combination.
[0014] As a preferred solution of the smart contract and off-chain service combination method described in the present invention, the basic control structure in the on-chain and off-chain collaborative combination model includes: sequence, mutually exclusive selection, loop and concurrent structure, and is constructed through sequential splicing and nesting.
[0015] As a preferred solution of the smart contract and off-chain service combination method described in the present invention, the service quality includes:
[0016] Divide service quality into positive and negative indicators;
[0017] If the difference between the maximum and minimum values of the positive indicator is not zero, the normalized value of the positive indicator is the difference between the maximum value of the positive indicator and the positive indicator value divided by the difference between the maximum and minimum values of the positive indicator;
[0018] If the difference between the maximum and minimum values of the positive indicator is equal to zero, the normalized value of the positive indicator is 1;
[0019] If the difference between the maximum and minimum values of the negative indicator is not zero, the normalized value of the negative indicator is the difference between the negative indicator value and the minimum value of the negative indicator divided by the difference between the maximum and minimum values of the negative indicator;
[0020] If the difference between the maximum and minimum values of the negative indicator is equal to zero, the normalized value of the negative indicator is 1.
[0021] As a preferred solution of the smart contract and off-chain service combination method described in the present invention, it also includes:
[0022] The objective function of the on-chain and off-chain collaborative combination model is to maximize the overall service quality score of the execution service combination, which is equal to each abstract service. The weight vector of the service is multiplied by the normalized service quality to obtain the weighted service quality score of the service, and the weighted service quality scores of all abstract services are summed up.
[0023] The constraint condition is that the overall service quality vector of the collaborative combination is greater than or equal to a preset minimum value and less than or equal to a preset maximum value.
[0024] As a preferred solution of the smart contract and off-chain service combination method described in the present invention, the solution using the first optimization algorithm includes:
[0025] Create an ant colony, initialize the pheromone matrix, information heuristic factor, expected heuristic factor, pheromone volatilization factor and maximum number of iterations;
[0026] Randomly select a starting service for each ant;
[0027] Calculate the probability of transferring to the next service and select the next service;
[0028] Repeat the selection process until the complete service portfolio path is constructed;
[0029] Record the path results of each ant and update the optimal solution and pheromone matrix.
[0030] As a preferred solution of the smart contract and off-chain service combination method described in the present invention, it also includes:
[0031] If the service belongs to the set of services to which the current ant can transfer, the transfer probability is the ratio of the sum of the weighted products of the pheromone concentrations from the service to all optional services and the service scores;
[0032] If the service does not belong to the set of services to which the current ant can transfer, the transfer probability is 0.
[0033] In a second aspect, the present invention provides a smart contract and off-chain service combination system, including:
[0034] A model building module is used to obtain executable services and abstract services, and use the executable services and abstract services to model the synergistic combination of on-chain smart contracts and off-chain services to obtain an on-chain and off-chain synergistic combination model;
[0035] The design scheme module is used to design a description scheme for the basic control structure in the on-chain and off-chain collaborative combination model, and to construct an abstract service collaborative combination diagram based on the description scheme;
[0036] The solution module is used to define the service quality based on the abstract service synergy combination diagram, and solve the problem according to the service quality and by using a first optimization algorithm to obtain an optimal synergy combination.
[0037] In a third aspect, the present invention provides a computing device, comprising:
[0038] Memory and processor;
[0039] The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the steps of the smart contract and off-chain service combination method are implemented.
[0040] In a fourth aspect, the present invention provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the steps of the smart contract and off-chain service combination method.
[0041] Compared with the prior art, the present invention has the following beneficial effects: Aiming at the problem of lack of combination model and service selection mechanism, the present invention proposes a C-CPN collaborative combination model and a heuristic service selection algorithm. Based on the colored Petri net model, the on-chain and off-chain collaborative combination problem in smart contract as a service is modeled, and its mathematical definition and basic control structure are introduced. A collaborative combination scheme description method is designed to simplify the description process. The quality of service (QoS) definition of extended services and smart contracts is explained, and the service selection problem is abstracted into an optimization problem of solving the optimal QoS weighted score under the condition of satisfying constraints. The problem is solved based on the improved ant colony algorithm and the optimal solution is obtained, and the optimal executable service is assigned to each abstract service in the abstract service composition collaborative graph. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0043] Figure 1 A schematic diagram of the overall process logic of a smart contract and off-chain service combination method according to an embodiment of the present invention;
[0044] Figure 2 A basic control structure in a colored Petri net of a smart contract and an off-chain service composition method according to an embodiment of the present invention;
[0045] Figure 3 A schematic diagram of the location flatten of multiple executable service tokens of a smart contract and an off-chain service composition method according to an embodiment of the present invention;
[0046] Figure 4 A colored Petri net model for modeling a collaborative solution of a smart contract and an off-chain service composition method according to an embodiment of the present invention;
[0047] Figure 5 The execution time of different service selection algorithms of the smart contract and off-chain service combination method described in one embodiment of the present invention;
[0048] Figure 6This is a graph showing the trend of the optimal scores of two ant colony algorithms changing with the number of iterations under condition ① of the smart contract and off-chain service combination method described in one embodiment of the present invention;
[0049] Figure 7 This is a trend chart of the optimal scores of the two ant colony algorithms changing with the number of iterations under conditions ② and ③ of the smart contract and off-chain service combination method described in one embodiment of the present invention. DETAILED DESCRIPTION
[0050] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the drawings of the specification. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary persons in the art without creative work should fall within the scope of protection of the present invention.
[0051] Example 1
[0052] Reference Figure 1-Figure 3 Table 1-Table 2 are an embodiment of the present invention, which provides a smart contract and off-chain service combination method, including:
[0053] S100: Obtain executable services and abstract services, use executable services and abstract services to model the synergistic combination of on-chain smart contracts and off-chain services, and obtain an on-chain and off-chain synergistic combination model;
[0054] S200: Design a description scheme for the basic control structure in the on-chain and off-chain collaborative composition model, and construct an abstract service collaborative composition diagram based on the description scheme;
[0055] S300: Based on the abstract service synergy combination graph, define the service quality, and solve the problem using the first optimization algorithm according to the service quality to obtain the optimal synergy combination.
[0056] It should be noted that by proposing a collaborative composition model based on colored Petri nets (C-CPN), a new modeling method is provided for the on-chain and off-chain collaborative composition problem in smart contracts as a service, which enables more accurate description and processing of complex business logic; using an improved heuristic algorithm, the optimal executable service is selected for each abstract service under the premise of meeting the global constraints of quality of service (QoS), thereby improving the efficiency and effectiveness of the service composition solution; through the collaborative work of smart contracts and off-chain services, more complex business problems can be solved, expanding the application scope of smart contracts.
[0057] In the embodiment of the present application, the above step S100 includes the following sub-steps A1-A2;
[0058] In A1: define executable services, abstract services, and colored Petri nets;
[0059] In A2: According to the definition, the on-chain and off-chain collaborative combination model includes a colored Petri net model isomorphic to the on-chain and off-chain collaborative combination scheme, a set of abstract services for collaborative combination, a set of mapping rules corresponding to the collaborative combination, service selection and optimization strategies, and global constraints for the collaborative combination.
[0060] In the embodiment of the present application, the smart contract as a service is based on the two types of services, on-chain smart contracts and off-chain extension services, and can provide collaborative combination solutions to the outside world. After decomposing complex business problems into multiple basic service units with low coupling based on microservices, each basic unit can be matched with multiple specific services with similar functions, and these specific services are defined as executable services, and the basic units are defined as abstract services;
[0061] Specifically, the executable service in Smart Contract as a Service can be an on-chain smart contract service or an off-chain extension service. The specific execution of the collaborative combination solution can be expressed as:
[0062] S exec ={s|s∈S contract ∪s∈S extend}
[0063] Smart contract is the basic service unit that completes a certain function in the service, which can include several executable services, represented as:
[0064] S abstract =(T,{S exec},F,I,S abstract|in ,S abstract|out )
[0065] Where T represents the unique identifier of the abstract service, {S exec} represents the set of executable services matching the abstract service, F represents the functional description of the abstract service, and I represents the basic description information of the abstract service; S abstract|in and S abstract|out They respectively represent the predecessor and successor abstract services of this abstract service.
[0066] Classic Petri net is a commonly used modeling method for constructing composite service models. However, when faced with these two completely heterogeneous basic service units in smart contract as a service, the use of classic Petri net modeling will result in complex and large-scale models. The colored Petri net in the advanced Petri net is used to model the collaborative composition problem in smart contract as a service. Based on the classic Petri net, the colored Petri net is expressed as:
[0067] Σ color=(P,T,F,W,M)
[0068] Among them, (P, T, F) is a network;
[0069] W∶F→{0,1,2,…} k
[0070] M∶P→{0,1,2,…} k
[0071] For t∈T, if p∈t→M(p)≥W(p,t);
[0072] Then transitions t can occur mutually at the mark M, generating a new mark M ′ , expressed as:
[0073]
[0074] Based on the colored Petri net model, the on-chain and off-chain collaborative combination scheme in smart contract as a service is modeled as follows:
[0075] C-CPN=(Σ color ,{S abstract},Fl,St,Bd)
[0076] Among them, Σ color It is a colored Petri net model of the on-chain and off-chain collaborative combination scheme isomorphic, including places, transition sets and workflow relations; color The identification system M in the vector form [m extend ,m contract ], representing the occurrence rights of extended services and smart contracts respectively; {S abstract} represents a set of abstract services that make up the collaborative combination solution; Fl represents the mapping rule set corresponding to the collaborative combination process; St represents the collaborative combination algorithm, that is, the service selection and optimization strategy; Bd represents the global constraint of the collaborative combination problem, which is usually constrained by the service quality proposed by the user.
[0077] It should be noted that by defining executable services and abstract services, a clear division of service roles and responsibilities is provided, so that smart contract services and off-chain extension services can be clearly distinguished and identified; complex business problems are decomposed into low-coupled basic service units, which enhances the flexibility and maintainability of the system and facilitates independent updating and optimization of each service unit; colored Petri nets are used to model the collaborative combination problem in smart contracts as a service, which solves the problem of complex model and large scale of traditional Petri nets when dealing with heterogeneous service units.
[0078] In the embodiment of the present application, the above step S200 includes the following sub-step B1;
[0079] In B1: sequential, mutually exclusive selection, loop and concurrent structures, which are constructed through sequential splicing and nesting.
[0080] Specifically, Figure 2 As shown, it is assumed that the services that make up the basic control structure are S 1 and S 2 (S 1 and S 2 All S abstract ), corresponding to the strain migration T;
[0081] The sequence structure is represented by S 1 →S 2 , the pre- and post-order services are executed in sequence, S 2 Strictly wait for S 1 Execution completed; the mutually exclusive selection structure is represented by According to the current library's condition judgment, select S 1 or S 2 Execution can be generalized as the mapping of condition sets to several mutually exclusive selection branches; the loop structure is represented by μS 1 (μ∈Z * ). represents the execution of S 1 represents the service μ times, each time changing the data state independently; the parallel structure is represented by S 1 |S 2 , S 1 and S 2 There is no conflict in reading and writing data, and it can be executed in parallel;
[0082] It should be noted that when using C-CPN to model the problem of on-chain and off-chain collaborative combination, the library corresponds to the data state of the system, and the transition corresponds to the executable service S exec By modeling the on-chain and off-chain collaborative combination problems as colored Petri nets and using rigorous formal tools of mathematical logic to complete the transformation of complex combination problems, it is helpful for the service selection and optimization of collaborative combination solutions and lays the foundation for exploring the optimal collaborative combination solution.
[0083] In the embodiment of the present application, the above step S300 includes the following sub-steps C1-C5;
[0084] In C1: Service quality is divided into positive indicators and negative indicators;
[0085] In C2: if the difference between the maximum and minimum values of the positive indicator is not zero, the normalized value of the positive indicator is the difference between the maximum value of the positive indicator and the positive indicator value divided by the difference between the maximum and minimum values of the positive indicator;
[0086] In C3: If the difference between the maximum and minimum values of the positive indicator is equal to zero, the normalized value of the positive indicator is 1;
[0087] In C4: if the difference between the maximum and minimum values of the negative indicator is not zero, the normalized value of the negative indicator is the difference between the negative indicator value and the minimum value of the negative indicator divided by the difference between the maximum and minimum values of the negative indicator;
[0088] In C5: if the difference between the maximum and minimum values of the negative indicator is equal to zero, the normalized value of the negative indicator is 1;
[0089] Specifically, Quality of Service (QoS) is an important measure of the quality of service, ensuring that the service can meet the needs and expectations of users. It is an important concept of traditional Web services. Common service qualities include throughput, response time, etc.
[0090] In the embodiment of the present application, the smart contract as a service includes two types of services: on-chain smart contracts and off-chain extended services. Traditional service quality indicators cannot effectively describe them. In order to ensure the description of the service quality of the collaborative combination solution, the service quality in the smart contract as a service is redefined to include:
[0091] Cost: The resources and expenses required to provide the service. Different services have different cost specifications. For example, translation services can be priced according to the number of bytes processed, and storage services can be priced based on the space occupied and storage duration.
[0092] Response time: refers to the time interval from when the user sends a request to when the service completes processing and returns a response. It is usually expressed in milliseconds (ms) to measure the speed of service execution.
[0093] Throughput: The number of requests or transactions processed by a service per unit time, usually expressed in units of requests per second (QPS) or transactions per second (TPS).
[0094] Availability: The ability to continuously provide services to the outside world within a certain time interval, that is, the proportion of time that the service is working normally and providing services to the outside world.
[0095] Reliability: The probability of providing normal services to the outside world within a certain period of time, that is, the probability that the service will not fail or will respond in time after a failure.
[0096] Let MTTF be the mean time to failure, that is, the average time from the start of service provision to the occurrence of failure, and MTTR be the mean time to repair, that is, the average time from the failure state to the recovery of availability. Then the availability and reliability can be calculated according to equations (9) and (10). Assume that the service failure time follows an exponential distribution. The service availability and availability values are both in [0,1].
[0097] Availability:
[0098] reliability: As an automated script running on the blockchain, the on-chain smart contract has the following service qualities:
[0099] Privacy: A quantitative indicator of the private data disclosed by smart contracts. By analyzing the types and quantities of private data that smart contracts rely on, it is quantified into the privacy value of the smart contract.
[0100] Security: The security level of smart contracts. Because smart contracts exist in all blockchain nodes at the same time, their security is particularly important. Security vulnerabilities in smart contracts can be analyzed through tools including formal verification, and the number of detected security vulnerabilities is used as a security indicator of smart contracts.
[0101] The qualities of service unique to off-chain scaling services include:
[0102] Packet loss rate (PLR): refers to the proportion of call failures caused by network congestion jitter or message errors when passing parameters during the service call process. The value is between [0,1].
[0103] For the long-lived transactional execution mode, the following service qualities are also required:
[0104] Compensation Cost: In the compensation-based distributed transaction model, when a subtransaction crashes and reverses compensation, the resources and costs required for each service to perform compensation actions.
[0105] Retry Cost: In the compensation-based distributed transaction mode, when a subtransaction crashes and is retried forward, the resources and costs required for each service to perform compensation actions.
[0106] The quality of service is combined into a unified vector, expressed as:
[0107]
[0108] Construct global constraints around the service quality of the collaborative combination solution. The constraints are based on the user's preference for several QoS and the value range. The preference is expressed as a weight vector and One-to-one correspondence, starting from 1, assigns QoS indicators p according to their importance. i , then
[0109] Specifically, the QoS indicators have different dimensions and need to be normalized. At the same time, in order to make the normalized values represent a positive impact on the solution, QoS is divided into two categories: positive indicators and negative indicators. The larger the normalized value of the positive indicator, the higher the service quality, including throughput, availability, and reliability, expressed as:
[0110]
[0111] The smaller the normalized value of the negative indicator, the higher the service quality, including cost, response time, privacy, security, packet loss rate, compensation cost, and retry cost, expressed as:
[0112]
[0113] in, is the maximum or minimum value of the negative or positive indicator, q i is a negative or positive indicator value;
[0114] It should be noted that by optimizing service quality, faster, more reliable and more secure services can be provided, thereby improving end-user satisfaction and loyalty, helping to allocate resources more reasonably, ensuring that resources are used on services that can best improve user experience, and avoiding waste of resources; dividing service quality indicators into positive indicators and negative indicators provides a clearer service quality evaluation framework, which helps to more accurately measure and compare the performance of different services; through normalization, service quality indicators of different dimensions are converted to the same scale, so that these indicators can be fairly compared and comprehensively considered.
[0115] In the embodiment of the present application, after completing steps C1-C5 in the above step S300, the following steps C6-C7 are also included;
[0116] In C6: The objective function of the on-chain and off-chain collaborative composition model is to maximize the overall service quality score of the execution service composition, which is equal to each abstract service, and multiply its weight vector by the normalized service quality to obtain the weighted service quality score of the service, and sum the weighted service quality scores of all abstract services;
[0117] In C7: the constraint condition is that the overall service quality vector of the collaborative combination is greater than or equal to the preset minimum value and less than or equal to the preset maximum value;
[0118] Specifically, the core of the service selection mechanism is to select a service for each abstract service S in C-CPN under the premise of satisfying global constraints. abstract Selecting executable services to form a globally optimal collaborative combination solution is a conditionally constrained optimization problem. Let the score of the i-th executable service in C-CPN be in is the QoS weight matrix under global constraints, is the normalized QoS vector of the i-th executable service, and the optimization objective function is expressed as:
[0119]
[0120] Let the overall QoS vector of the collaborative combination solution composed of a certain executable service be It is expressed as:
[0121]
[0122] That is, under the QoS requirements of the complex business functions and global constraints corresponding to C-CPN, the set of executable services with the highest total score is explored; the collaborative combination scheme can be abstracted as a combination of several basic control structures, and studying the QoS calculation method of the basic control structure is the prerequisite for exploring the optimal solution.
[0123] For the four basic control structures, the calculation methods of each QoS indicator are shown in Tables 1 and 2;
[0124] Table 1 QoS index calculation table-1
[0125]
[0126] Table 2 QoS index calculation table-2
[0127]
[0128] As shown in Tables 1 and 2, the basic control structure is constructed using the collaborative combination scheme description method to calculate QoS sequentially.
[0129] It should be noted that by ensuring that the QoS vector is within a preset range, the service quality can be guaranteed to meet business requirements. By selecting the optimal service combination, resources can be used more effectively and system performance can be improved.
[0130] In the embodiment of the present application, after completing steps C6-C7 in the above step S300, the following steps C8-C14 are also included;
[0131] In C8: create an ant colony, initialize the pheromone matrix, information heuristic factor, expected heuristic factor, pheromone volatilization factor and maximum number of iterations;
[0132] In C9: Randomly select the starting service for each ant;
[0133] In C10: calculate the probability of transferring to the next service and select the next service;
[0134] In C11: Repeat the selection process until the complete service portfolio path is constructed;
[0135] In C12: Record the path results of each ant and update the optimal solution and pheromone matrix.
[0136] In C13: If the service belongs to the set of services to which the current ant can transfer, the transfer probability is the ratio of the sum of the weighted products of the pheromone concentrations and service scores from the service to all optional services;
[0137] In C14: If the service does not belong to the set of services to which the current ant can transfer, the transfer probability is 0.
[0138] Specifically, the depth-first search based on traversal can accurately find the optimal solution. However, even if pruning can be done through branch-and-bound, when there are many optional services and the scale of the solution space reaches a certain level, it is difficult to find the optimal solution in polynomial time as an NP problem with exponential time complexity. Therefore, a heuristic algorithm is used to solve the service selection problem of the collaborative combination solution.
[0139] In an optional embodiment, the first optimization algorithm may include a genetic algorithm, which initializes an initial population, evaluates its fitness according to the quality of service (QoS) and other global constraints, selects the best solution according to the fitness, randomly pairs the selected solutions, and exchanges some of their features to generate new solutions, randomly changes some features of some solutions with a certain probability to increase the diversity of the population, selects the best solutions from the new and old solutions according to the fitness to form a new generation of population, and repeats the above process until the termination condition is met;
[0140] In an optional embodiment, the first optimization algorithm may also include a particle swarm optimization algorithm, which randomly initializes a group of particles in the search space, updates the speed and position of each particle according to the current speed of the particle, its own best position and the best position of the group, evaluates the fitness of each particle, and for each particle, if the current position is better than the best position recorded before, updates its best position, and repeats the process of speed and position update, fitness evaluation and updating individual and global optimal positions until the termination condition is met;
[0141] In the embodiment of the present application, the first optimization algorithm includes:
[0142] The ant colony algorithm is divided into ant colony initialization and iterative loop. When initializing the ant colony, an ant colony is first created according to the input population size, and the information heuristic factor α, the expected heuristic factor β, and the evaporation factor ρ are initialized. Then, the pheromone matrix τ is initialized. τ records the pheromone concentration of each path accumulated by the ant colony. The abstract service S representing the k-th token of C-CPN abstract The i-th executable service S in exec To the abstract service S of the (k + 1)-th token abstract The j-th executable service S in exec The pheromone value.
[0143] Such as Figure 3 As shown, in the four basic control structures, the mutually exclusive selection structure and the loop structure have two branches. To reduce the complexity of the algorithm, the two-dimensional branches are flattened into a one-dimensional vector. The k-th and (k + 1)-th tokens are the selection structure and the mutually exclusive structure respectively. The token k The two branches correspond to the abstract services S abstract1 And S abstract2 , each corresponding to two executable services, and the first and the second are selected respectively. The token k+1 Similarly, there are two abstract services, each also corresponding to two executable services, and the second is selected respectively. Then, in the pheromone matrix at this layer, the corresponding position is expressed as:
[0144] (i, j) = (0 * size(S abstract2 ) + 1, 1 * size(S abstract4 ) + 1) = (1, 3)
[0145] A total of k - 1 such matrices can be constructed to form a linked list - shaped pheromone matrix τ;
[0146] When performing the iterative loop, first randomly select the starting service, and randomly select the executable service for the starting token. At this time, it is assumed that the executable services corresponding to all abstract services follow a uniform distribution. Then, conduct a global search of the ants, calculate the probability of selecting each executable service / service group in the subsequent tokens, and complete the selection of the executable service based on the roulette wheel algorithm, which is expressed as:
[0147]
[0148] Among them, τ(t) ij Is the pheromone concentration from service i to service j at time t, α is the information heuristic factor, β is the expected heuristic factor, score(t) j Is the service quality score of service j at time t, service j Is the set of services that the current ant can transfer to;
[0149] Specifically, at time t, the probability of the ant choosing from the current i-th executable service in the k-th token to the j-th executable service in the k+1-th token; According to the obtained probability vector Service selection based on roulette algorithm;
[0150] In the embodiment of the present application, the path result of the global search of each ant is recorded, and after reaching the end point, the optimal solution and the highest score are updated as follows:
[0151] τ ij (t+1)=(1-ρ)×τ ij (t)+Δτ ij
[0152] in,
[0153] In order to increase randomness, reduce the probability of falling into the local optimal solution too early, and accelerate convergence and search speed, the maximum and minimum values of pheromone [τ min ,τ max ], the limiting pheromone update is expressed as:
[0154]
[0155]
[0156] Among them, S best is the quality of the current optimal solution, ρ is the volatility factor of the pheromone;
[0157] After a round of iterations to update the optimal solution and pheromone matrix, a starting service is randomly selected and a new round of search begins;
[0158] Specifically, two new definitions are introduced for the synergistic combination scheme:
[0159] Abstract service collaboration graph abstract ; Use tokens to replace the basic control structure of the C-CPN model collaborative combination scheme to form a directed graph composed of tokens, which also includes a global variable table and global constraints.
[0160] Executable Service Collaboration Graph exec ; Use the service selection optimization algorithm of the collaborative composition scheme to select specific executable services that meet the global constraints from each abstract service. At this time, the abstract service collaborative composition graph becomes an executable service collaborative composition graph.
[0161] The collaborative combination solution is divided into Graph abstract and Graph execThere are two major steps in the generation of Graph. First, the control logic and functions required by complex business problems are described using the collaborative combination solution description method, and then the Graph is created. abstract In the process of traversing the description text, the global variable table, tokens and global constraints are filled. Then the improved ant colony algorithm is used to abstract Optimize service selection on the graph, select the globally optimal executable service for each abstract service, and obtain the graph exec for subsequent execution.
[0162] It should be noted that the collaborative combination scheme description method can accurately and concisely describe the execution logic of complex business scenarios. However, in the specific execution process of the abstract service corresponding to the unique identifier, it is necessary to select a specific on-chain smart contract or off-chain extended service for each abstract service according to specific constraints. This process is called service selection or service optimization. Based on the improved ant colony algorithm, a service selection method for the on-chain and off-chain collaborative combination problem is designed, the QoS in the smart contract as a service is refined, and the optimal collaborative combination scheme is selected under the condition of satisfying global constraints to obtain an executable collaborative combination scheme.
[0163] The above is a schematic scheme of a smart contract and off-chain service combination method of this embodiment. It should be noted that the technical solution of the smart contract and off-chain service combination system and the technical solution of the above-mentioned smart contract and off-chain service combination method belong to the same concept. For details not described in detail in the technical solution of the smart contract and off-chain service combination system in this embodiment, please refer to the description of the technical solution of the above-mentioned smart contract and off-chain service combination method.
[0164] In this embodiment, the smart contract and off-chain service combination system includes:
[0165] A model building module is used to obtain executable services and abstract services, and use the executable services and abstract services to model the synergistic combination of on-chain smart contracts and off-chain services to obtain an on-chain and off-chain synergistic combination model;
[0166] The design scheme module is used to design a description scheme for the basic control structure in the on-chain and off-chain collaborative combination model, and to construct an abstract service collaborative combination diagram based on the description scheme;
[0167] The solution module is used to define the service quality based on the abstract service synergy combination diagram, and solve the problem according to the service quality and by using a first optimization algorithm to obtain an optimal synergy combination.
[0168] This embodiment also provides a computing device, which is applicable to the combination of smart contracts and off-chain services, including:
[0169] Memory and processor; the memory is used to store computer-executable instructions, and the processor is used to execute computer-executable instructions to implement the smart contract and off-chain service combination method proposed in the above embodiment.
[0170] This embodiment also provides a storage medium on which a computer program is stored. When the program is executed by a processor, the method for realizing the smart contract and off-chain service combination proposed in the above embodiment is implemented.
[0171] The storage medium proposed in this embodiment and the method for realizing smart contract and off-chain service combination proposed in the above embodiment belong to the same inventive concept. The technical details not fully described in this embodiment can be referred to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.
[0172] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course can also be implemented by hardware. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ReadOnly, Memory, ROM), random access memory (Random Access Memory, RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform the methods of various embodiments of the present invention.
[0173] Example 2
[0174] Refer to Table 3-Table 4, Figure 4-Figure 7 , which is different from the first embodiment, provides a verification test of a smart contract and off-chain service combination method to verify and illustrate the technical effects used in this method.
[0175] The black box testing method is used to test the details of each function. Multiple groups of correct and incorrect use cases are input to detect whether the expected results can be obtained when the input is legal, and whether errors can be stably identified and exceptions can be handled correctly when the input is illegal, so as to verify the correctness and robustness. The experimental results are shown in Table 3.
[0176] Table 3 Functional test table of collaborative combination solution generation method
[0177]
[0178] As shown in Table 3, after testing, each function meets expectations and has effectiveness and correctness;
[0179] The key point of generating on-chain and off-chain collaborative combination solutions is to select the optimal solution based on global constraints among several optional extended services and smart contracts with similar functions after generating the abstract service collaborative combination diagram;
[0180] like Figure 4 As shown, it is assumed that the description text corresponding to the collaborative scheme, the sequential, mutually exclusive selection, loop and parallel structures are connected in series;
[0181] Assuming that each abstract service has 3 / 5 / 10 options, the time to obtain the optimal collaborative combination solution is calculated based on the branch and bound method, the ant colony algorithm, and the improved ant colony algorithm. The ant population in the ant colony algorithm and the improved ant colony algorithm consists of 20 ants, and 100 iterations are set. The time record starts from the first ant's global search until it stabilizes at the optimal solution and iterates for 10 more times. The QoS of each executable service is randomly generated.
[0182] like Figure 5 As shown in the figure, in the experiment, the horizontal axis represents the number of executable services that can be selected in each abstract service, and the vertical axis represents time. Because the solution time in the branch and bound method increases exponentially with the number of services that can be selected, the logarithm of the execution time to 10 is taken as the vertical axis. According to the experimental results, in this case, when the number of executable services is ≥4, the computational efficiency of the heuristic algorithm represented by the ant colony algorithm is significantly better than that of the branch and bound method. This is because the time complexity of the enumeration algorithm represented by the branch and bound method is exponential, while the heuristic algorithm represented by the ant colony algorithm continuously approaches the optimal solution by accumulating information, and the time complexity is linear. Suppose that the collaborative composition service C needs to select n abstract services, and each abstract service provides m executable services. Then for the branch and bound method, the time complexity of the algorithm is O(m n ). Assuming that the ant colony algorithm needs to be executed k times to approach the optimal solution, the time complexity of the algorithm is O(kn). It is easy to know that when m has a certain scale, the ant colony algorithm has faster computing efficiency. At the same time, it can be seen from the experimental results that the ant colony algorithm is based on iterative search, and the solution time does not fluctuate with the scale of the problem. In the experiment, the parameters of the ant colony algorithm and the improved ant colony algorithm are α=1.0, β=2.0, ρ=0.5 respectively;
[0183] In the ant colony algorithm and the maximum minimum ant colony algorithm based on limiting the range of pheromone values, the experimental parameter group composed of information heuristic factor α, expected heuristic factor β and pheromone volatilization efficiency ρ will significantly affect the experimental results. The experiment is designed to explore the execution results of the ant colony algorithm under different experimental parameter conditions. The different experimental conditions are shown in Table 4;
[0184] Table 4 Condition parameter table
[0185]
[0186] The experiments of ant colony algorithm and improved ant colony algorithm were carried out under conditions ① to ③ respectively. The results are as follows Figure 6 and Figure 7 As shown;
[0187] like Figure 6 and Figure 7 The iteration process and the transformation trend of the optimal score of the two heuristic algorithms under the same population parameters (ant colony size = 20, number of iterations = 30) are shown. The ratio between the information heuristic factor α and the expectation heuristic factor β represents whether the ant colony algorithm attaches more importance to the pheromone experience accumulated in the past or the contribution value of the current executable service. The larger the ratio, the more emphasis is placed on the pheromone accumulated in the past. Similarly, the lower the pheromone volatilization efficiency ρ, the higher the contribution of pheromone to the optimal score. Therefore, when the α / β ratio becomes larger and ρ becomes smaller, the algorithm will converge faster. However, at the same time, the system is more likely to fall into the local optimal situation. The experimental results are in line with expectations. Compared with the traditional ant colony algorithm, the improved ant colony algorithm introduces constraints on the pheromone range to improve the efficiency of the search, converge to the optimal solution faster, and avoid stagnation.
[0188] According to the experimental results, the designed heuristic algorithm is both efficient and available in the service selection problem of on-chain and off-chain collaborative combination solutions of smart contract-as-a-service chains, and can obtain the optimal combination solution under global constraints.
[0189] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit the present invention. 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 solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A smart contract and off-chain service combination method, characterized in that: include: Obtain executable services and abstract services, and use the executable services and abstract services to model the synergistic combination of on-chain smart contracts and off-chain services to obtain an on-chain and off-chain synergistic combination model; Design a description scheme for the basic control structure in the on-chain and off-chain collaborative composition model, and construct an abstract service collaborative composition diagram based on the description scheme; Based on the abstract service synergy combination graph, the service quality is defined, and a first optimization algorithm is used to solve the problem according to the service quality to obtain an optimal synergy combination.
2. The smart contract and off-chain service combination method according to claim 1, characterized in that: Modeling the synergistic combination of on-chain smart contracts and off-chain services includes: Define executable services, abstract services, and colored Petri nets; According to the definition, the on-chain and off-chain collaborative combination model includes a colored Petri net model isomorphic to the on-chain and off-chain collaborative combination scheme, a set of abstract services for collaborative combination, a set of mapping rules corresponding to the collaborative combination, service selection and optimization strategies, and global constraints for the collaborative combination.
3. The smart contract and off-chain service combination method according to claim 2, characterized in that: The basic control structures in the on-chain and off-chain collaborative combination model include: sequence, mutually exclusive selection, loop, and concurrent structures, and are constructed through sequential splicing and nesting.
4. The smart contract and off-chain service combination method according to claim 3, characterized in that: Service quality includes: Divide service quality into positive and negative indicators; If the difference between the maximum and minimum values of the positive indicator is not zero, the normalized value of the positive indicator is the difference between the maximum value of the positive indicator and the positive indicator value divided by the difference between the maximum and minimum values of the positive indicator; If the difference between the maximum and minimum values of the positive indicator is equal to zero, the normalized value of the positive indicator is 1; If the difference between the maximum and minimum values of the negative indicator is not zero, the normalized value of the negative indicator is the difference between the negative indicator value and the minimum value of the negative indicator divided by the difference between the maximum and minimum values of the negative indicator; If the difference between the maximum and minimum values of the negative indicator is equal to zero, the normalized value of the negative indicator is 1.
5. The smart contract and off-chain service combination method according to claim 3 or 4, characterized in that: Also includes: The objective function of the on-chain and off-chain collaborative combination model is to maximize the overall service quality score of the execution service combination, which is equal to each abstract service. The weight vector of the service is multiplied by the normalized service quality to obtain the weighted service quality score of the service, and the weighted service quality scores of all abstract services are summed up. The constraint condition is that the overall service quality vector of the collaborative combination is greater than or equal to a preset minimum value and less than or equal to a preset maximum value.
6. The smart contract and off-chain service combination method according to claim 5, characterized in that: Solving using the first optimization algorithm includes: Create an ant colony, initialize the pheromone matrix, information heuristic factor, expected heuristic factor, pheromone volatilization factor and maximum number of iterations; Randomly select a starting service for each ant; Calculate the probability of transferring to the next service and select the next service; Repeat the selection process until the complete service portfolio path is constructed; Record the path results of each ant and update the optimal solution and pheromone matrix.
7. The smart contract and off-chain service combination method according to claim 6, characterized in that: Also includes: If the service belongs to the set of services to which the current ant can transfer, the transfer probability is the ratio of the sum of the weighted products of the pheromone concentrations from the service to all optional services and the service scores; If the service does not belong to the set of services to which the current ant can transfer, the transfer probability is 0.
8. A system using the smart contract and off-chain service combination method as described in any one of claims 1 to 7, characterized in that: include: A model building module is used to obtain executable services and abstract services, and use the executable services and abstract services to model the synergistic combination of on-chain smart contracts and off-chain services to obtain an on-chain and off-chain synergistic combination model; The design scheme module is used to design a description scheme for the basic control structure in the on-chain and off-chain collaborative combination model, and to construct an abstract service collaborative combination diagram based on the description scheme; The solution module is used to define the service quality based on the abstract service synergy combination diagram, and solve the problem according to the service quality and by using a first optimization algorithm to obtain an optimal synergy combination.
9. An electronic device, comprising: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the steps of the smart contract and off-chain service combination method described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the steps of the smart contract and off-chain service combination method described in any one of claims 1 to 7.