Method for Invoking between Blockchain Smart Contracts

Contract logic splitting and security checking are performed through inter-contract call trees, which solves the problem of contract logic coupling in the blockchain system, realizes contract flexibility and security, reduces development difficulty and prevents resource consumption.

CN115016959BActive Publication Date: 2025-07-29BEIJING LIANDAO TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210718483.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-23
Publication Date
2025-07-29
Estimated Expiration
2042-06-23

AI Technical Summary

Technical Problem

The logical coupling of smart contracts in blockchain systems leads to difficulties in maintenance, inconvenient upgrades, difficult to expand and optimize, and contract problems affect the entire system, lacking flexible inter-contract call methods.

Method used

The inter-contract call tree is used for security check control, and the contract logic is split through the contract call tree. Contract developers register contracts in the blockchain node and set inter-contract call control components, create contract call trees, and conduct legality checks to prevent excessive consumption of resources.

Benefits of technology

It realizes flexible splitting of contract logic, reduces development difficulty, ensures the security and reliability of the contract calling process, and prevents excessive resource consumption from affecting transaction performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115016959B_ABST
    Figure CN115016959B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for invoking between blockchain smart contracts. Contract developers register the developed contracts to blockchain nodes, and a control component for invoking between contracts is set in the blockchain nodes. The blockchain nodes receive a transaction request sent by a client, send an invocation request to the contract corresponding to the first contract method to be invoked, and carry the identifier of the transaction request. The control component for invoking between contracts creates a contract invocation tree for the transaction request, uses the contract corresponding to the first contract method as the root node of the contract invocation tree. The blockchain nodes sequentially complete the invocation of other contract methods associated in this invocation according to the contract method logic, and simultaneously update the contract invocation tree. After each update, it is judged whether the contract invocation tree is legal. If it is illegal, the transaction request is terminated; if it is legal, the invocation continues until the entire transaction request is executed. The present invention performs security check control through the contract invocation tree, improving the flexibility and security of contract invocation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of blockchain, and more specifically, relates to a method for calling between blockchain smart contracts. Background Art

[0002] With the application expansion of blockchain, especially consortium blockchain, in actual scenarios, the external business systems connected to the blockchain are becoming increasingly complex, and the business logic carried by the smart contracts running on the blockchain system is also becoming more complex. Figure 1 It is a schematic diagram of a blockchain application scenario. As Figure 1 shown, a blockchain node is any node in the blockchain network, a smart contract is a contract instance controlled by this blockchain node, and a client is a system or terminal device accessing the blockchain, which can send requests to the blockchain network. The requests sent to the blockchain system carry information such as the name, version, method name, and parameters of the calling contract, and will initiate a call to the specified contract method through the node.

[0003] In the blockchain system, since more and more business logic is carried in the contract, a single contract is getting larger and larger, making it difficult to maintain and upgrade. Traditional business systems can split the business into different business modules for modular management, or further microservice each business to improve the scalability of the system. However, the blockchain system itself does not directly provide capabilities such as the above-mentioned business modularization and scalability. As the business carrier of the blockchain system, smart contracts have the following problems in the docking of complex businesses:

[0004] 1. The logic of a single contract is coupled, and the large amount of contract code is not conducive to maintenance.

[0005] 2. If it is necessary to change the business logic of a certain small module, the entire contract needs to be deactivated and updated.

[0006] 3. It is difficult to horizontally expand the business modules with high resource consumption, which hinders performance optimization.

[0007] 4. When there is a problem in a certain part of the contract, it will affect the entire system.

[0008] For smart contracts, relying on the characteristics of multiple replicas of the blockchain itself, which meet the main characteristics of high-availability system facilities, each contract can be used as a service for a module of business implementation, and the decoupling of the business can be achieved through the call between contracts. Therefore, it is necessary to propose a flexible and reliable method for calling between contracts to facilitate the logical splitting of smart contracts, thereby promoting the expansion and upgrade of the blockchain system when docking with businesses and promoting the implementation and application of the blockchain system. Summary of the Invention

[0009] The purpose of the present invention is to overcome the deficiencies of the prior art and provide a method for calling between blockchain smart contracts, which realizes the calling between contracts and conducts security check control through a contract call tree, improving the flexibility and security of contract calls.

[0010] To achieve the above-mentioned invention purpose, the method for calling between blockchain smart contracts of the present invention includes the following steps:

[0011] S1: The contract developer registers the developed contract to the blockchain node. The registered contract SDK provides an interface for calling between contracts for contract calls; a contract call control component is set in the blockchain node to manage contract calls.

[0012] S2: The blockchain node receives a transaction request sent by the client, creates transaction context information, parses the information carried in the transaction request, and sends a call request to the contract corresponding to the first contract method to be called, carrying the identifier of the transaction request in the call request; the contract call control component creates a contract call tree for the received transaction request, uses the contract corresponding to the first contract method as the root node of the contract call tree, and completes the initialization of the contract call tree; then sets the number of layers n of the contract call tree to 1.

[0013] S3: The blockchain node puts the methods corresponding to each contract in the nth layer of the contract call tree into the context of the transaction request corresponding to the call request, and executes the contract method according to the received call request.

[0014] S4: Judge whether the methods corresponding to each contract in the nth layer of the contract call tree need to call other contract methods. If so, enter step S5; otherwise, enter step S9.

[0015] S5: For the methods corresponding to each contract in the nth layer of the contract call tree, when there is a contract method that needs to call other contract methods, the contract sends a call request for the contract method to be called to the blockchain node, carrying the identifier of the transaction request in the call request; after the blockchain node receives the call request for the contract method to be called, the contract call control component adds the contract to be called as a child node of the call request source contract to the contract call tree corresponding to the transaction request.

[0016] S6: Check whether the current contract call tree is legal. If it is legal, enter step S7; otherwise, enter step S8. The specific method for checking the legality of the contract call tree is as follows:

[0017] First, obtain the depth of the current contract call tree as the call depth, and determine whether the call depth is greater than a preset call depth threshold. If it is greater, the contract call tree is illegal; otherwise, obtain the maximum value among the number of contracts in each layer of the contract call tree as the call width, and determine whether the call width is greater than a preset call width threshold. If it is greater, the contract call tree is illegal; otherwise, further count the number of times each contract in the contract call tree is called, and use the ratio of the call count to the total number of contracts in the current contract call tree as the repetition rate of the contract. If the repetition rate of a certain contract is greater than a preset repetition rate threshold, the contract call tree is illegal; otherwise, the contract call tree is legal;

[0018] S7: Let n = n + 1, and return to step S3;

[0019] S8: The blockchain node terminates the execution of the transaction request corresponding to the illegal contract call tree, marks this transaction request as an invalid transaction, and feeds back a prompt message to the client;

[0020] S9: The method corresponding to the contract in the nth layer of the contract call tree feeds back the execution result to the method corresponding to the upper-layer contract. The method corresponding to the upper-layer contract executes according to the received feedback execution result, and feeds back the obtained execution result to the method corresponding to the next upper-layer contract, and so on, until the method of the contract corresponding to the root node in the contract call tree executes to obtain the execution result of this transaction request. The blockchain conducts consensus on the execution result of this transaction request and finally stores it in the blockchain ledger for the client to obtain.

[0021] In the method for inter-contract calls of the blockchain intelligent contract of the present invention, the contract developer registers the developed contract to the blockchain node, sets an inter-contract call control component in the blockchain node. The blockchain node receives the transaction request sent by the client, sends a call request to the contract corresponding to the first contract method to be called, and carries the identifier of the transaction request in the call request. The inter-contract call control component creates a contract call tree for the received transaction request, uses the contract corresponding to the first contract method as the root node of this contract call tree. The blockchain node sequentially completes the calls of other contract methods associated in this call according to the contract method logic, and simultaneously updates the contract call tree. After each update, it determines whether the contract call tree is legal. If it is illegal, it terminates the transaction request; if it is legal, it continues the call until the entire transaction request is executed.

[0022] The present invention has the following beneficial effects:

[0023] 1) In the present invention, the blockchain node adopts inter-contract calls, which helps to split the contract logic in complex business scenarios and reduces the development difficulty;

[0024] 2) During the contract call process, the present invention realizes dynamic security check and control through a contract call tree, preventing excessive call depth and call width from consuming too many node resources, affecting transaction performance, and ensuring the reliability and security of contract calls between contracts. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] Figure 1 is a schematic diagram of a blockchain application scenario;

[0026] Figure 2 is a flowchart of a specific implementation manner of the method for calling between blockchain smart contracts of the present invention;

[0027] Figure 3 is an example diagram of a contract call tree in this embodiment. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0028] The following describes the specific implementation manner of the present invention with reference to the accompanying drawings, so that those skilled in the art can better understand the present invention. It should be particularly noted that in the following description, when the detailed description of known functions and designs may obscure the main content of the present invention, these descriptions will be omitted here.

[0029] Embodiment

[0030] Figure 2 is a flowchart of a specific implementation manner of the method for calling between blockchain smart contracts of the present invention. As Figure 2 shown, the specific steps of the method for calling between blockchain smart contracts of the present invention include:

[0031] S201: Contract registration:

[0032] Contract developers register the developed contracts to the blockchain nodes. The registered contract SDK (Software Development Kit) provides an interface for calling between contracts, which is used for calling between contracts. A contract call control component is set in the blockchain nodes to manage contract calls.

[0033] S202: Receive and parse the transaction request:

[0034] The blockchain node receives the transaction request sent by the client, creates transaction context information, parses the information carried in the transaction request, and sends a call request to the contract corresponding to the first contract method to be called, carrying the identifier of the transaction request in the call request. The contract call control component creates a contract call tree for the received transaction request, uses the contract corresponding to the first contract method as the root node of the contract call tree, and completes the initialization of the contract call tree. Then, let the number of layers n of the contract call tree be 1.

[0035] In practical applications, because multiple transaction requests can exist simultaneously in a blockchain node, a transaction request identifier must be carried during the call process to distinguish between them. In this embodiment, a hash value is generated for each transaction request as the transaction request identifier. Contract methods can call the target contract by specifying relevant information about the target contract through the inter-contract call interface. The inter-contract call control component can also obtain contract information through this interface.

[0036] S203: Method execution:

[0037] The blockchain node places the methods corresponding to each contract at the nth level in the contract call tree into the context of the transaction request corresponding to the call request, and executes the contract method according to the received call request.

[0038] S204: Determine whether the methods corresponding to the contracts at the nth level in the contract call tree need to call other contract methods. If so, proceed to step S205; otherwise, proceed to step S209.

[0039] S205: Inter-contract call:

[0040] For each contract method at the nth level of the contract call tree, if a contract method needs to call another contract method, the contract initiates a call request to the blockchain node for the desired contract method, carrying the transaction request identifier in the call request. After the blockchain node receives the call request for the desired contract method, the inter-contract call control component adds the desired contract as a child node of the source contract of the call request to the contract call tree corresponding to the transaction request.

[0041] S206: Check whether the current contract call tree is legal. If it is legal, proceed to step S207, otherwise proceed to step S208. In the present invention, the legality of the contract call tree is checked from three aspects: call depth, call width and repetition rate. The specific method is as follows:

[0042] First, obtain the depth of the current contract call tree as the call depth, and determine whether the call depth is greater than the preset call depth threshold. If so, the contract call tree is illegal. Otherwise, obtain the maximum value of the number of contracts in each layer of the current contract call tree as the call width, and determine whether the call width is greater than the preset call width threshold. If so, the contract call tree is illegal. Otherwise, further count the number of times each contract in the current contract call tree is called, and take the ratio of the number of calls to the number of all contracts in the current contract call tree as the repetition rate of the contract. If the repetition rate of a contract is greater than the preset repetition rate threshold, the contract call tree is illegal, otherwise the contract call tree is legal.

[0043] Figure 3This is an example diagram of the contract call tree in this embodiment. As Figure 3 shown, in this embodiment, the call depth of the call tree used is 4, the call width is 2, and the repetition rates of each contract are as follows: Contract 1: 0.2, Contract 2: 0.2, Contract 3: 0.2, Contract 4: 0.4.

[0044] S207: Let n = n + 1, and return to step S203.

[0045] S208: Transaction execution termination:

[0046] The blockchain node terminates the execution of the transaction request corresponding to the illegal contract call tree. This transaction request is marked as an invalid transaction, and a prompt message is fed back to the client.

[0047] S209: Feed back the execution result of the transaction request:

[0048] The method corresponding to the contract in the nth layer of the contract call tree feeds back the execution result to the method corresponding to the contract in the upper layer. The method corresponding to the contract in the upper layer executes according to the received feedback execution result, and feeds back the obtained execution result to the method corresponding to the contract in the layer above it, and so on, until the contract method corresponding to the root node in the contract call tree executes to obtain the execution result of this transaction request. The blockchain conducts consensus on the execution result of this transaction request and finally stores it in the blockchain ledger for the client to obtain.

[0049] Although the above describes the illustrative specific embodiments of the present invention for the convenience of those skilled in the art to understand the present invention, it should be clear that the present invention is not limited to the scope of the specific embodiments. For those of ordinary skill in the art, as long as various changes are within the spirit and scope of the present invention defined and determined by the appended claims, these changes are obvious, and all inventions and creations using the concept of the present invention are within the scope of protection.

Claims

1. A method for calling between blockchain smart contracts, characterized in that, It includes the following steps: S1: The contract developer registers the developed contract to the blockchain node. The registered contract SDK provides an interface for inter - contract calls, which is used for calls between contracts. A control component for inter - contract calls is set in the blockchain node to manage contract calls; S2: The blockchain node receives a transaction request sent by the client, creates transaction context information, parses the information carried in the transaction request, and sends a call request to the contract corresponding to the first contract method to be called, carrying the identifier of the transaction request in the call request; The control component for inter - contract calls creates a contract call tree for the received transaction request, takes the contract corresponding to the first contract method as the root node of the contract call tree, and completes the initialization of the contract call tree. Then, let the number of layers n of the contract call tree be 1; S3: The blockchain node puts the methods corresponding to each contract in the n - th layer of the contract call tree into the context of the call request corresponding to the transaction request, and executes the contract method according to the received call request; S4: Determine whether the methods corresponding to each contract in the n - th layer of the contract call tree need to call other contract methods. If so, go to step S5; otherwise, go to step S9; S5: For the methods corresponding to each contract in the n - th layer of the contract call tree, when there is a method corresponding to a contract that needs to call other contract methods, the contract sends a call request for the contract method to be called to the blockchain node, carrying the identifier of the transaction request in the call request. After the blockchain node receives the call request for the contract method to be called, the control component for inter - contract calls adds the contract to be called as a child node of the contract from which the call request comes to the contract call tree corresponding to the transaction request; S6: Check whether the current contract call tree is legal. If it is legal, go to step S7; otherwise, go to step S8. The specific method for checking the legality of the contract call tree is as follows: First, obtain the depth of the current contract call tree as the call depth, and determine whether the call depth is greater than a preset call depth threshold. If it is greater, the contract call tree is illegal; otherwise, obtain the maximum value among the number of contracts in each layer of the contract call tree as the call width, and determine whether the call width is greater than a preset call width threshold. If it is greater, the contract call tree is illegal; otherwise, further count the number of times each contract in the contract call tree is called, and take the ratio of the call times to the total number of contracts in the current contract call tree as the repetition rate of the contract. If the repetition rate of a certain contract is greater than a preset repetition rate threshold, the contract call tree is illegal; otherwise, the contract call tree is legal; S7: Let n = n + 1, and return to step S3; S8: The blockchain node terminates the execution of the transaction request corresponding to the illegal contract call tree, marks the transaction request as an invalid transaction, and sends a prompt message to the client; S9: The method corresponding to the contract at the nth layer in the contract call tree feeds back the execution result to the method corresponding to the contract in the upper layer. The method corresponding to the contract in the upper layer executes according to the received feedback execution result, and feeds back the obtained execution result to the method corresponding to the contract in the layer above it, and so on, until the contract method corresponding to the root node in the contract call tree executes to obtain the execution result of the transaction request. The blockchain conducts consensus on the execution result of the transaction request and finally stores it in the blockchain ledger for the client to obtain.

Citation Information

Patent Citations

  • Execution method of smart contract in block chain, node and block chain system

    CN114078052A

  • Block chain intelligent contract calling management method

    CN114490874A