Multi-channel transaction processing method and device based on smart contract

By configuring connection pool information in the external contract image file and establishing a multi-channel connection pool, the problem of low communication efficiency between nodes and containers is solved, and high-throughput and high concurrent transaction requests are efficiently handled.

CN120263871APending Publication Date: 2025-07-04CHENGDU PRIME STARK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410008756.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-04
Publication Date
2025-07-04

AI Technical Summary

Technical Problem

The communication efficiency between nodes and containers in existing blockchain networks is not high, and it is difficult to efficiently handle transaction requests with high throughput and high concurrent volume.

Method used

Configure preset connection pool configuration information in the mirror file of the external contract, build an external contract container and establish multiple communication channel connection pools, and send multiple transaction requests through the channel connection pool, so that the external contract container polls and receives and processes transaction requests in turn.

Benefits of technology

It improves the communication efficiency between the accounting node and the external contract container, and can efficiently handle high throughput and high concurrency transaction scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120263871A_ABST
    Figure CN120263871A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a multi-channel transaction processing method and device based on a smart contract, and relates to the technical field of contract communication. The method comprises the following steps: configuring preset connection pool configuration information in a mirror image file of an external contract in advance, and constructing an external contract container according to the mirror image file of the external contract; then the external contract container is started, so that the external contract container establishes a channel connection pool according to preset connection pool configuration information, and the channel connection pool comprises a plurality of communication channels; and finally, a plurality of transaction requests are sent to the external contract container through the channel connection pool, so that the external contract container sequentially polls and receives the transaction requests in the plurality of communication channels, and an external contract is operated to respond to the plurality of transaction requests. According to the invention, parallel communication between the bookkeeping node and the external contract container can be realized through the plurality of communication channels in the channel connection pool, so that the communication efficiency between the bookkeeping node and the external contract container is improved, and transaction scenes with high throughput and high concurrency demands can be efficiently processed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of contract communication, and particularly to a multi-channel transaction processing method and device based on a smart contract. Background Art

[0002] Smart contracts can perform various tasks, such as verifying and executing contracts, managing digital assets, and executing financial transactions. Smart contracts are usually deployed to run inside the nodes of a blockchain network. At the same time, a Docker container can also be created and started to deploy the smart contract to run in the container. Therefore, a smart contract deployed to run inside a node is called an internal contract, and a smart contract deployed to run in a container is called an external contract.

[0003] At present, after the container finishes executing the external contract, the execution result is returned to the node through a pre-set communication channel. However, currently, single-channel communication is adopted between the container and the node. Although it can reduce the communication overhead of the node, when processing multiple transaction requests, the communication efficiency between the node and the container is not high, and it is difficult to efficiently process application scenarios with high throughput and high concurrency requirements. Summary of the Invention

[0004] The purpose of the embodiments of the present invention is to provide a multi-channel transaction processing method and device based on a smart contract to solve the problem of low communication efficiency between nodes and containers in the existing blockchain network.

[0005] The specific technical solution of the present invention is as follows: In the first aspect of the embodiments of the present invention, a multi-channel transaction processing method based on a smart contract is provided, which is applied to a bookkeeping node in a blockchain network and includes: Pre-configure preset connection pool configuration information in the mirror file of the external contract, and construct an external contract container according to the mirror file of the external contract; Start the external contract container, so that the external contract container establishes a channel connection pool according to the preset connection pool configuration information, and the channel connection pool contains multiple communication channels; Send multiple transaction requests to the external contract container through the channel connection pool, so that the external contract container sequentially polls to receive the transaction requests in multiple communication channels and runs the external contract in response to the multiple transaction requests.

[0006] Further, the step of pre-configuring preset connection pool configuration information in the mirror file of the external contract and constructing an external contract container according to the mirror file of the external contract includes: The bookkeeping node adds preset connection pool configuration information to the mirror file of the external contract; the preset connection pool configuration information includes the size of the connection pool; Start the external contract engine, pull the mirror file of the external contract from the local contract mirror repository to build the corresponding external contract container, and deploy the external contract in the external contract container; the external contract contains multiple sub-contracts, and each sub-contract is configured with a sub-contract ID and a constructor method.

[0007] Further, starting the external contract container so that the external contract container establishes a channel connection pool according to the preset connection pool configuration information includes: After the external contract is deployed, the accounting node sends a start instruction to the external contract container to start the external contract container; The external contract container reads the size of the connection pool in the preset connection pool configuration information, determines the number of channels of the channel connection pool according to the size of the connection pool, and establishes the corresponding number of communication channels with the accounting node according to the number of channels of the channel connection pool.

[0008] Further, the external contract container sequentially polls to receive transaction requests in multiple communication channels and runs the external contract in response to the multiple transaction requests, including: The external contract container sequentially polls to obtain the status of each communication channel in the channel connection pool and receives the transaction requests sent by the accounting node through the communication channels in the idle state; the transaction requests carry the sub-contract ID, the constructor method, and the transaction parameters; After the external contract container receives the transaction request, it calls the constructor method declared in the corresponding sub-contract in the external contract according to the sub-contract ID and the constructor method carried in the transaction request to simulate the execution of the transaction processing according to the transaction parameters.

[0009] Further, the simulating the execution of the transaction processing according to the transaction parameters includes: Construct a simulated transaction environment according to the transaction request; Read the corresponding business basic data from the database according to the transaction parameters; Based on the business basic data, simulate the execution of the transaction processing in the simulated transaction environment, construct a transaction read-write set, and obtain transaction business data.

[0010] Further, the method further includes: After the transaction processing is completed, the external contract container returns the transaction business data to the accounting node through the communication channel.

[0011] Further, the method further includes: After the accounting node receives the transaction business data corresponding to the transaction request, it signs the transaction business data to obtain the corresponding transaction execution result; Perform desensitization processing on the transaction business data to obtain the first transaction data; Package the first transaction data and the corresponding transaction execution result and upload them to the global network.

[0012] In the second aspect of the embodiments of the present invention, a multi-channel transaction processing device based on a smart contract is provided, which is applied to a bookkeeping node in a blockchain network and includes: A container construction module, configured to pre-configure preset connection pool configuration information in the mirror file of an external contract, and construct an external contract container according to the mirror file of the external contract; A channel connection module, configured to start the external contract container, so that the external contract container establishes a channel connection pool according to the preset connection pool configuration information, and the channel connection pool includes multiple communication channels; A transaction processing module, configured to send multiple transaction requests to the external contract container through the channel connection pool, so that the external contract container sequentially polls and receives transaction requests in multiple communication channels, and runs the external contract in response to the multiple transaction requests.

[0013] The beneficial effect of the present invention is that: by configuring preset connection pool configuration information in the mirror file of the external contract, the method can start the external contract container after the external contract container is constructed, and establish a channel connection pool according to the preset connection pool configuration information, so that the bookkeeping node and the external contract container can perform parallel communication through multiple communication channels in the channel connection pool, improving the communication efficiency between the bookkeeping node and the external contract container, and being able to efficiently process transaction scenarios with high throughput and high concurrency requirements. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention, and those of ordinary skill in the art can also obtain other drawings without creative efforts based on these drawings.

[0015] Figure 1 is a flowchart of a multi-channel transaction processing method based on a smart contract proposed in an embodiment of the present invention; Figure 2 is a schematic diagram of the module structure of a multi-channel transaction processing device based on a smart contract proposed in an embodiment of the present invention. EMBODIMENTS

[0016] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0017] Embodiment 1: Figure 1 is a flowchart of a multi-channel transaction processing method based on a smart contract proposed in an embodiment of the present invention. Refer to Figure 1 As shown, a multi-channel transaction processing method based on a smart contract in an embodiment of the present invention can be applied to a bookkeeping node in a blockchain network, and mainly includes the following steps: S1: Pre-configure preset connection pool configuration information in the mirror file of the external contract, and construct an external contract container based on the mirror file of the external contract; S2: Start the external contract container, so that the external contract container establishes a channel connection pool according to the preset connection pool configuration information, and the channel connection pool contains multiple communication channels; S3: Send multiple transaction requests to the external contract container through the channel connection pool, so that the external contract container sequentially polls and receives transaction requests in multiple communication channels, and runs the external contract in response to the multiple transaction requests.

[0018] Further, in one embodiment, pre-configuring preset connection pool configuration information in the mirror file of the external contract and constructing an external contract container based on the mirror file of the external contract in step S1 of the embodiment of the present invention includes, but is not limited to, the following sub-steps: S101: The bookkeeping node adds preset connection pool configuration information to the mirror file of the external contract; the preset connection pool configuration information includes the size of the connection pool; S102: Start the external contract engine, pull the mirror file of the external contract from the local contract mirror repository to construct the corresponding external contract container, and deploy the external contract in the external contract container. Among them, the external contract contains multiple sub-contracts, and each sub-contract is configured with a sub-contract ID and a constructor method.

[0019] In the specific implementation process, the mirror files of the external contracts used to construct the external contract containers in the embodiments of the present invention include Java external contract mirror files and GO external contract mirror files. Correspondingly, the external contract engines are respectively Java contract engines and GO contract engines.

[0020] Specifically, developers first write the corresponding external contract code using development languages such as Java, GO, and NODEJS. When writing the external contract code, the external contract can be split into multiple sub-contracts, and different constructor methods are configured in each sub-contract to implement different business logics, such as purchase logic, selling logic, transfer logic, etc. At the same time, a corresponding sub-contract ID (or sub-contract name) is configured for each sub-contract to facilitate the invocation and execution of the corresponding sub-contract according to the ID (name).

[0021] After the external contract code is written, it is compiled into an executable external contract file, and based on the external contract file, the Dockerfile tool is used to create a corresponding external contract image to obtain the image file of the corresponding external contract.

[0022] At the same time, in order to facilitate the maintenance of the communication channel for subsequent contract containers, the embodiment of the present invention pre-configures connection pool configuration information for multi-channel communication according to information such as node computing power and resources, and adds the connection pool configuration information to the image file of the external contract, so that after the external contract container is started, it can establish a channel connection pool according to the connection pool configuration information to achieve multi-channel communication between the external contract container and the accounting node. After the addition of the connection pool configuration information is completed, the image file of the external contract at this time is stored in the local contract image repository of the node.

[0023] Further, in one embodiment, starting the external contract container in step S2 of the embodiment of the present invention so that the external contract container establishes a channel connection pool according to the preset connection pool configuration information includes, but is not limited to, the following sub-steps: S201. After the external contract is deployed, the accounting node sends a start instruction to the external contract container to start the external contract container; S202. The external contract container reads the size of the connection pool in the preset connection pool configuration information, determines the number of channels of the channel connection pool according to the size of the connection pool, and establishes a corresponding number of communication channels with the accounting node according to the number of channels of the channel connection pool.

[0024] Specifically, after the external contract is deployed, the accounting node can send a Docker run instruction to the external contract container to start the external contract container. In addition, an automatic start instruction can also be set in the image file of the external contract, so that the external contract container can be automatically started and run after it is built, without the accounting node sending a start instruction.

[0025] Further, in one embodiment, the external contract container in step S3 of the embodiment of the present invention sequentially polls and receives transaction requests in multiple communication channels and runs the external contract in response to the multiple transaction requests, including, but is not limited to, the following sub-steps: S301. The external contract container sequentially polls to obtain the status of each communication channel in the channel connection pool, and receives the transaction requests sent by the accounting nodes through the communication channels in the idle state. Among them, the transaction requests carry the sub-contract ID, construction method, and transaction parameters.

[0026] S302. After receiving the transaction requests, the external contract container calls the construction method declared in the corresponding sub-contract in the external contract according to the sub-contract ID and construction method carried in the transaction requests, so as to simulate the execution of transaction processing according to the transaction parameters.

[0027] Specifically, the embodiment of the present invention adopts a polling method to obtain the status of each communication channel in the channel connection pool, such as the idle state or the used state. The purpose is to ensure that there is only one transaction request in transmission processing on the communication channel, avoiding further causing communication process blockage and affecting communication efficiency.

[0028] Further, the process of simulating the execution of transaction processing according to the transaction parameters in step S302 specifically includes: (1) First, construct a simulated transaction environment according to the transaction requests; (2) According to the transaction parameters, read the corresponding business basic data from the database; where the business basic data includes the accounts of both parties to the transaction and the asset information under the accounts, etc.; (3) Based on the business basic data, simulate the execution of transaction processing in the simulated transaction environment, construct a transaction read-write set, and obtain transaction business data.

[0029] Among them, when the external contract container simulates the execution of transaction processing, a read-write set in the plaintext state will be generated. Among them, the read set is the state of both parties to the transaction before the transaction, and the write set is the state of both parties to the transaction after the transaction.

[0030] Taking the first transfer transaction where the transaction request is for Organization A to transfer 10 to Organization B as an example, the business description of this transaction is, for example, "A from to B, 10; or A transfers 10 to B"; before the transfer, "the account balance of Organization A is 100, and the account balance of Organization B is X", then the read-write set of the first transfer transaction includes: read set "<A, tx0>, <B, X>", where "tx0" is the transaction version number of the first partition network, and write set "<A, 90>, <B, X + 10>".

[0031] Further, the method provided by the embodiment of the present invention further includes: After the transaction processing is completed, the external contract container returns the transaction business data to the accounting nodes through the communication channels. The communication channels change to the idle state after completing the transaction requests and can process the next transaction request.

[0032] Further, the method provided by the embodiment of the present invention further includes: After receiving the transaction service data corresponding to the transaction request, the accounting node signs the transaction service data to obtain the corresponding transaction execution result; Perform desensitization processing on the transaction service data to obtain the first transaction data; Package and upload the first transaction data and the corresponding transaction execution result to the global network.

[0033] Specifically, the desensitization processing is based on desensitization rules. The desensitization rules include desensitization methods and desensitization content. The desensitization content includes full data desensitization and target field desensitization; based on the desensitization rules, determine the data to be desensitized in the target read-write set corresponding to the target transaction, and then perform hash calculation on the data to be desensitized to obtain the target hash of the data to be desensitized. The target hash and other transaction data generated by the target transaction are used as transaction service data together; it should be noted that: if the data to be desensitized includes multiple discontinuous fields, the target hash includes multiple hash values corresponding to each character segment.

[0034] In the embodiment of the present invention, by configuring preset connection pool configuration information in the mirror file of the external contract, after the external contract container is constructed, the external contract container can be started, and a channel connection pool can be established according to the preset connection pool configuration information, so that the accounting node and the external contract container can communicate in parallel through multiple communication channels in the channel connection pool, improving the communication efficiency between the accounting node and the external contract container, and being able to efficiently process transaction scenarios with high throughput and high concurrency requirements.

[0035] Embodiment 2: Refer to Figure 2 As shown, on the basis of Embodiment 1, the embodiment of the present invention provides a multi-channel transaction processing device based on a smart contract, which can be applied to an accounting node in a blockchain network. The device includes: A container construction module, configured to pre-configure preset connection pool configuration information in the mirror file of the external contract, and construct an external contract container according to the mirror file of the external contract; A channel connection module, configured to start the external contract container, so that the external contract container establishes a channel connection pool according to the preset connection pool configuration information, and the channel connection pool contains multiple communication channels; A transaction processing module, configured to send multiple transaction requests to the external contract container through the channel connection pool, so that the external contract container sequentially polls and receives transaction requests in multiple communication channels, and runs the external contract in response to the multiple transaction requests.

[0036] In an embodiment, the device described in the embodiment of the present invention further includes a data feedback module, configured to, after the transaction processing is completed, the external contract container returns the transaction service data to the accounting node through the communication channel.

[0037] In one embodiment, the device according to the embodiment of the present invention further includes an identity signature module, configured to sign the transaction service data after the accounting node receives the transaction service data corresponding to the transaction request, so as to obtain a corresponding transaction execution result; a desensitization processing module, configured to perform desensitization processing on the transaction service data to obtain first transaction data; a data upload module, configured to package and upload the first transaction data and the corresponding transaction execution result to the global network.

[0038] The multi-channel transaction processing device based on a smart contract provided by the embodiment of the present invention can, by configuring preset connection pool configuration information in the mirror file of the external contract, start the external contract container after the external contract container is built, and establish a channel connection pool according to the preset connection pool configuration information, so that the accounting node and the external contract container can perform parallel communication through multiple communication channels in the channel connection pool, improving the communication efficiency between the accounting node and the external contract container, and being able to efficiently process transaction scenarios with high throughput and high concurrency requirements.

[0039] In the above embodiment, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the embodiments of the present invention are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired manner (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wirelessly (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer, or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).

[0040] It should be noted that in this text, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising the said element.

[0041] Each embodiment in this specification is described in a related manner. For the same or similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and reference can be made to the corresponding part of the method embodiment for the relevant content.

[0042] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A multi-channel transaction processing method based on smart contracts, which is applied to accounting nodes in a blockchain network, and is characterized in that, Including: Pre-configure preset connection pool configuration information in the mirror file of the external contract, and build an external contract container based on the mirror file of the external contract; Start the external contract container, so that the external contract container establishes a channel connection pool according to the preset connection pool configuration information, and the channel connection pool contains multiple communication channels; Send multiple transaction requests to the external contract container through the channel connection pool, so that the external contract container sequentially polls and receives the transaction requests in multiple communication channels, and runs the external contract in response to the multiple transaction requests.

2. The multi-channel transaction processing method based on a smart contract according to claim 1, wherein The step of pre-configuring preset connection pool configuration information in the mirror file of the external contract and building an external contract container based on the mirror file of the external contract includes: The accounting node adds preset connection pool configuration information to the mirror file of the external contract; the preset connection pool configuration information includes the size of the connection pool; Start the external contract engine, pull the mirror file of the external contract from the local contract image repository to build the corresponding external contract container, and deploy the external contract in the external contract container; the external contract contains multiple sub-contracts, and each sub-contract is configured with a sub-contract ID and a constructor method.

3. The multi-channel transaction processing method based on smart contract according to claim 1, characterized in that, The step of starting the external contract container so that the external contract container establishes a channel connection pool according to the preset connection pool configuration information includes: After the external contract is deployed, the accounting node sends a start instruction to the external contract container to start the external contract container; The external contract container reads the size of the connection pool in the preset connection pool configuration information, determines the number of channels in the channel connection pool according to the size of the connection pool, and establishes the corresponding number of communication channels with the accounting node according to the number of channels in the channel connection pool.

4. The multi-channel transaction processing method based on smart contract according to claim 1, characterized in that, The step that the external contract container sequentially polls and receives the transaction requests in multiple communication channels and runs the external contract in response to the multiple transaction requests includes: The external contract container sequentially polls to obtain the status of each communication channel in the channel connection pool, and receives the transaction requests sent by the accounting node through the communication channels in the idle state; the transaction requests carry sub-contract IDs, constructor methods, and transaction parameters; After the external contract container receives the transaction request, it calls the constructor method declared in the corresponding sub-contract in the external contract according to the sub-contract ID and constructor method carried in the transaction request to simulate and execute transaction processing according to the transaction parameters.

5. The multi-channel transaction processing method based on a smart contract according to claim 4, wherein The step of simulating and executing transaction processing according to the transaction parameters includes: Construct a simulated transaction environment according to the transaction request; Read the corresponding business basic data from the database according to the transaction parameters; Based on the business basic data, simulate and execute transaction processing in the simulated transaction environment, construct a transaction read-write set, and obtain transaction business data.

6. The multi-channel transaction processing method based on smart contract according to claim 5, characterized in that, It also includes: After the transaction processing is completed, the external contract container returns the transaction business data to the accounting node through the communication channel.

7. The multi-channel transaction processing method based on smart contract according to claim 6, wherein It also includes: After the accounting node receives the transaction business data corresponding to the transaction request, it signs the transaction business data to obtain the corresponding transaction execution result; Perform desensitization processing on the transaction business data to obtain the first transaction data; Package the first transaction data and the corresponding transaction execution result and upload them to the global network.

8. A multi-channel transaction processing device based on smart contracts, which is applied to the accounting nodes in the blockchain network, and is characterized in that, Including: A container construction module for pre-configuring preset connection pool configuration information in the mirror file of the external contract and constructing an external contract container based on the mirror file of the external contract; A channel connection module for starting the external contract container, so that the external contract container establishes a channel connection pool according to the preset connection pool configuration information, and the channel connection pool contains multiple communication channels; A transaction processing module for sending multiple transaction requests to the external contract container through the channel connection pool, so that the external contract container sequentially polls and receives the transaction requests in multiple communication channels and runs the external contract in response to the multiple transaction requests.