Transaction processing method and apparatus based on blockchain, and device, medium and product
By using a maintenance array to record contract progress and tag values in blockchain nodes, the problem of high resource consumption in the LRU algorithm is solved, and more efficient smart contract transaction processing is achieved.
Patent Information
- Application Number
- PCT/CN2023/137386
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-04-14
- Filing Date
- 2023-12-08
- Publication Date
- 2024-11-28
AI Technical Summary
In existing technologies, the swapping process of smart contracts uses a linked list operation via the LRU algorithm, which results in high resource consumption and low transaction processing efficiency.
By maintaining an array to record resident contract processes and tag values, the target contract process is determined by the tag value for swapping in and out, reducing resource consumption and improving transaction processing efficiency.
It reduces memory resource consumption, minimizes performance loss, and improves transaction processing efficiency.
Smart Images

Figure CN2023137386_28112024_PF_FP_ABST
Abstract
Description
Blockchain-based transaction processing methods, devices, equipment, media, and products
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on April 14, 2023, with application number 2023104380189 and application name “Blockchain-based transaction processing method and device, electronic device, and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] This application relates to the field of blockchain technology, and specifically to blockchain-based transaction processing. Background Art
[0003] Smart contracts are one of the core technologies of blockchain. A smart contract is a piece of code with business logic that processes blockchain transactions and can be executed within a blockchain's virtual machine. Blockchain virtual machine technology is becoming increasingly mature, especially with the development of container technology (Docker). More and more blockchain technologies support containers as virtual machines for smart contracts, thus removing the limitations of smart contract languages and supporting smart contracts in a variety of development languages.
[0004] Because container technology is isolated from blockchain nodes, smart contract maintenance must be performed within the container. However, containers typically impose limits on resources like memory. Therefore, a maximum number of supported contract processes is typically configured within the container, representing the maximum number of concurrently executing contracts within the container. Within this maximum number of contract processes, contract processes need to be swapped in and out. Swapping in and out involves exiting certain contract processes and adding others.
[0005] In existing implementations, contract processes are swapped in and out using an LRU (Least Recently Used) algorithm. This algorithm requires the use of a linked list to maintain contract processes. However, due to the complexity of linked list operations, it consumes a large amount of container resources. Therefore, improving transaction processing efficiency while using fewer resources is a technical problem that requires continuous research by those skilled in the art.
[0006] Summary of the Invention
[0007] To solve the above technical problems, the embodiments of the present application provide a blockchain-based transaction processing method, a blockchain-based transaction processing device, an electronic device, a computer-readable storage medium, and a computer program product.
[0008] According to one aspect of an embodiment of the present application, a blockchain-based transaction processing method is provided, including: determining a smart contract for processing a transaction; determining a target resident contract process based on a tag value corresponding to each resident contract process recorded in a maintenance array, the tag value being used to identify the execution status of the corresponding resident contract process, and the maximum number of resident contract processes recorded in the maintenance array being the maximum number of contract processes supported by a container deployed in a blockchain node; replacing the target resident contract process in the maintenance array with a target contract process corresponding to the smart contract, and modifying the tag value corresponding to the target contract process to a first value, the first value indicating that the corresponding contract process is in an executed state; and sending the transaction to the target contract process for processing.
[0009] According to one aspect of an embodiment of the present application, a blockchain-based transaction processing device is provided, including: a first determination module, configured to determine a smart contract for processing a transaction; a second determination module, configured to determine a target resident contract process based on a tag value corresponding to each resident contract process recorded in a maintenance array, the tag value being used to identify the execution status of the corresponding resident contract process, and the maximum number of resident contract processes recorded in the maintenance array being the maximum number of contract processes supported by a container deployed in a blockchain node; an array processing module, configured to replace the target resident contract process in the maintenance array with a target contract process corresponding to the smart contract, and modify the tag value corresponding to the target contract process to a first value, the first value indicating that the corresponding contract process is in an executed state; and a transaction processing module, configured to send the transaction to the target contract process for processing.
[0010] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising: one or more processors; and a storage device for storing one or more computer programs, wherein when the one or more computer programs are executed by the one or more processors, the electronic device implements the blockchain-based transaction processing method as described above.
[0011] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor of a computer, the computer executes the blockchain-based transaction processing method as described above.
[0012] According to one aspect of an embodiment of the present application, a computer program product is also provided, including a computer program, which, when executed by a processor, implements the blockchain-based transaction processing method as described above.
[0013] In the technical solution provided by the embodiment of the present application, a maintenance array is set to maintain the execution of smart contracts in the blockchain node. Specifically, the resident contract process set and the tag value of each resident contract process in the blockchain node are recorded through the maintenance array. When the contract process needs to be swapped in and out, the target resident contract process that needs to be swapped out is determined based on the tag value of each resident contract process in the maintenance array. Since the tag value can reflect the execution status of the corresponding resident contract process, the target contract process to be replaced by the target contract process can be determined more accurately based on this. The target resident contract process is then replaced with the target contract process that needs to be swapped in. Compared with using a linked list to perform execution maintenance on smart contracts, the operation method based on the maintenance array of the present application is simpler and requires less container resources, thereby improving transaction processing efficiency.
[0014] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] FIG1 is a schematic structural diagram of a blockchain system according to an exemplary embodiment;
[0016] FIG2 is a schematic diagram of the structure of a contract execution container configured in a blockchain node;
[0017] FIG3 shows an exemplary contract process execution sequence diagram;
[0018] FIG4 is a schematic diagram of the linked list operation process corresponding to the contract process execution sequence shown in FIG3;
[0019] FIG5 is a flowchart of a transaction processing method based on blockchain, shown in an exemplary embodiment of the present application;
[0020] FIG6 is a flowchart of another blockchain-based transaction processing method proposed based on the embodiment shown in FIG5 ;
[0021] FIG7 is a flowchart of another blockchain-based transaction processing method proposed based on the embodiment shown in FIG5 ;
[0022] FIG8 shows a schematic diagram of an exemplary maintenance array initialization process;
[0023] FIG9 is a flowchart of another blockchain-based transaction processing method proposed based on the embodiment shown in FIG5 ;
[0024] FIG10 is another exemplary contract process execution sequence diagram;
[0025] FIG11 is a schematic diagram of the array operation process corresponding to the contract process execution sequence 5-10 shown in FIG10 ;
[0026] FIG12 is a schematic diagram showing a regular presentation of an exemplary smart contract called by a user;
[0027] FIG13 is a schematic diagram showing an exemplary statistical result obtained by continuously counting the number of resident contract processes and the CPU usage of the blockchain node over a period of time;
[0028] FIG14 is a flowchart of a transaction processing method based on blockchain according to an exemplary application scenario;
[0029] FIG15 is a block diagram of a transaction processing device based on blockchain, shown in an exemplary embodiment of the present application;
[0030] FIG16 shows a schematic structural diagram of a computer system suitable for implementing an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0031] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. When the following description refers to the drawings, identical numerals in different figures represent identical or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0032] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0033] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, while others may be combined or partially combined. Therefore, the actual execution order may vary depending on the actual situation.
[0034] In this application, "plurality" refers to two or more. "And / or" describes the relationship between related objects, indicating that three possible relationships exist. For example, "A and / or B" can mean: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.
[0035] First of all, it should be noted that the embodiments of this application involve blockchain technology. Blockchain technology is a new distributed infrastructure and computing method that uses a block chain data structure to verify and store data, a distributed node consensus algorithm to generate and update data, cryptography to ensure the security of data transmission and access, and smart contracts composed of automated script code to program and operate data. Blockchain refers to a decentralized infrastructure with distributed storage characteristics. Specifically, it is a data structure that organizes data blocks in a chronological order in a manner similar to a linked list. It can securely store data that has a sequential relationship and can be verified within the system, and uses cryptography to ensure that the data cannot be tampered with or forged. Simply put, blockchain is a decentralized distributed ledger, and each chain is equivalent to an independent ledger.
[0036] FIG1 is a schematic diagram of the structure of a blockchain system shown in an exemplary embodiment. The blockchain system 100 shown in FIG1 may include a node device 10a, a node device 10b, a node device 10c, and a node device 10d. Node devices 10a, 10b, 10c, and 10d are all blockchain nodes (referred to as nodes) in the blockchain system 100 shown in FIG1 . These nodes may be any form of computing device connected to the blockchain system 100, such as a server, a user terminal, and the like. Node devices 10a, 10b, 10c, and 10d shown in FIG1 may also be connected to form the blockchain system 100 through network communication.
[0037] The types of blockchains involved in the architecture of blockchain system 100 shown in Figure 1 may include: public blockchain, private blockchain, and consortium blockchain. The types of blockchains used in different blockchain application scenarios may vary and are not limited here. A public blockchain is a blockchain that is publicly accessible and open to anyone to join and access. Blockchains on a public blockchain are viewable by anyone, and anyone can initiate transactions and participate in the public blockchain's consensus process at any time. A private blockchain is designed for use within a private organization. Read, write, and account-keeping permissions on the blockchain can be determined according to the organization's rules. It is typically used for internal enterprise data management and auditing. A consortium blockchain is a blockchain where members' read, write, and account-keeping permissions on the blockchain are determined according to the consortium's rules. It is typically used for inter-institutional transactions, settlement, or clearing.
[0038] Each node in the blockchain system 100 has a corresponding node identifier, and each node in the blockchain system 100 can store the node identifiers of other nodes in the blockchain system 100 so that the generated blocks can be broadcast to other nodes in the blockchain system 100 based on the node identifiers of other nodes. Each node in the blockchain system 100 stores the same blockchain (see blockchain 10e shown in Figure 1), so the blockchain system 100 can also be called a data sharing system.
[0039] As mentioned earlier, with the development of container technology, more and more blockchain technologies support containers as virtual machines for smart contracts. This can shield the limitations of smart contract languages and support smart contracts in a variety of development languages. For example, if a blockchain program is developed in Go, it can fully support smart contracts in languages such as Java and Python through container technology.
[0040] Because container technology is isolated from blockchain nodes, smart contract maintenance must be performed within the container. However, containers typically impose limits on resources like memory. Therefore, a maximum number of supported contract processes is typically configured within the container, representing the maximum number of concurrently executing contracts within the container. Within this maximum number of contract processes, contract processes need to be swapped in and out. Swapping in and out involves exiting certain contract processes and adding others.
[0041] The existing technology uses the LRU algorithm to implement the swapping in and out of contract processes. This algorithm requires the use of a linked list to maintain the contract process. However, since the linked list operation is often complicated, it requires a large amount of container resources.
[0042] Figure 2 is a structural diagram of the contract execution container configured in the blockchain node. As shown in Figure 2, the contract execution container is provided with a maintenance process and three contract processes. These three contract processes are also resident contract processes. The maintenance process is used to schedule the contract processes in the contract execution container. The LRU algorithm is also implemented through the maintenance process.
[0043] To further understand the LRU algorithm's implementation of contract process swapping, Figure 3 illustrates an exemplary contract process execution sequence diagram. As shown in Figure 3, assuming the maximum number of contract processes supported by a container is four, the resident contract process set also includes four contract processes. It should be understood that the resident contract process set refers to the set of contract processes that remain operational in the container for the majority of the time over a given period. Since a container supports a maximum of four concurrent contract processes, the number of resident contract processes included in the resident contract process set is four.
[0044] Figure 3 also assumes that the order of entry of the contract processes in the initial resident contract set is A, B, C, and D. That is, when the time sequence is 0, the resident contract process set contains contract processes A, B, C, and D. When the time sequence is 1, the contract process corresponding to contract C needs to be executed. Since the contract process corresponding to contract C is included in the resident contract process set, the contract process corresponding to contract C can be directly executed. It should be noted that a contract process mentioned in this application is also the contract process corresponding to a smart contract. For example, contract process A is also the contract process corresponding to smart contract A.
[0045] The contract process A that needs to be executed when the timing is 2, the contract process D that needs to be executed when the timing is 3, and the contract process B that needs to be executed when the timing is 4 are similar to the contract process execution process when the timing is 0, and will not be repeated here.
[0046] When the time sequence is 5, contract process E needs to be executed. Since contract process E is not currently in the resident contract process set, a contract process needs to be swapped out from the existing resident contract process set to replace contract process E. Based on the most recent usage sequence, we know that contract process C was executed first, that is, the contract process corresponding to contract C is the furthest from the current one. Therefore, after swapping contract process C out of the resident contract process set, contract process E is added to the resident contract process set.
[0047] The resident contract process sets corresponding to time sequences 6-8 all include contract processes A, B, E, and D. Since the contract processes that need to be executed at the current moment are all existing resident contract processes, the corresponding resident contract processes can be directly executed.
[0048] When the time sequence is 9, contract process C needs to be executed. Since contract process C is not currently in the resident contract process set, a contract process needs to be swapped out from the existing resident contract process set to replace contract process C. Based on the most recent usage time sequence, it can be known that contract process D was executed first. Therefore, after swapping contract process D out of the resident contract process set, contract process C is added to the resident contract process set.
[0049] When the time sequence is 10, contract process D needs to be executed. Since there is no contract process D in the current resident contract process set, according to the most recent usage time sequence, it can be known that contract process E was executed first. Therefore, after swapping contract process E out of the resident contract process set, contract process D is added to the resident contract process set.
[0050] Figure 4 is a schematic diagram of the linked list operation process corresponding to the contract process execution sequence shown in Figure 3. As shown in Figure 4, at sequence 0, contract processes A and D are linked in a chain, with contract process A at the head of the linked list and contract process D at the tail. At sequence 1, contract process C needs to be executed, so contract process C needs to be moved to the end of the linked list, and the link between contract processes B and D needs to be re-established. At sequence 2, contract process A needs to be moved to the end of the linked list because it is at the head of the linked list. The linked list operation process for sequences 3-4 and 6-8 is similar and will not be further described here.
[0051] It should be noted that during time sequences 1-4, the resident contract process set includes contract processes A, B, C, and D, and during time sequences 6-8, the resident contract process set includes contract processes A, B, E, and D. From this, it can be seen that although in these time sequences, the contract process to be executed is an existing resident contract process and does not require swapping in and out, the element link relationship in the linked list still needs to be modified.
[0052] At time 5, since the contract process E to be executed is not in the set of resident contract processes, a contract process needs to be swapped out from the set of resident contract processes. Therefore, the contract process C at the head of the linked list is swapped out, and the contract process E is added to the end of the linked list. The linked list implementation process for time 9-10 is similar and will not be repeated here.
[0053] It can be seen from the linked list implementation process shown in Figure 4 that in the LRU algorithm, each execution of a contract process will operate on the linked list in order to place the contract process in the correct position. When a contract process is missing, that is, when the resident contract process set does not contain the contract process to be executed and the contract process needs to be swapped in and out, the contract process at the head of the linked list will be swapped out and the new contract process will be added to the end of the linked list.
[0054] The resource overhead of the LRU algorithm is very high, for example, there are at least the following reasons:
[0055] 1. The elements in the linked list are actually allocated to different pages in memory, which will lead to two performance degradations. First, the principle of program locality cannot be well utilized, so each operation on the elements in the linked list involves multiple addressing. Second, because the elements in the linked list are allocated to different memory pages, when the CPU (Central Processing Unit) triggers a page fault interrupt, it will be affected.
[0056] It should be understood that the principle of program locality means that the program exhibits locality during execution. That is, within a period of time, the execution of the entire program is limited to a certain part of the program. Correspondingly, the storage space accessed by the execution is also limited to a certain memory area. Therefore, the linked list operations involved in the LRU algorithm require a large amount of memory resources.
[0057] 2. Linked list operations cannot be run in parallel because different contract threads need to lock when operating the linked list to ensure the correctness of the linked list. As we all know, locking is very performance-consuming.
[0058] 3. The resources required to maintain the linked list are relatively large. On the one hand, each element needs to contain its parent element and child elements. On the other hand, when an element is deleted, it needs to be recycled manually (or with the garbage collection strategy supported by some programs).
[0059] As can be seen from the above aspects, the LRU algorithm involves multiple competing operations. When a blockchain transaction needs to be executed, using the corresponding contract process to process the transaction is inefficient. To address this technical problem, the embodiments of this application respectively provide a blockchain-based transaction processing method, a blockchain-based transaction processing device, an electronic device, a computer-readable storage medium, and a computer program product.
[0060] These embodiments are described in detail below:
[0061] First, please refer to Figure 5, which is a flowchart illustrating a blockchain-based transaction processing method according to an exemplary embodiment of the present application. This method can be executed by a blockchain node. Specifically, it can be executed by a maintenance thread in a container deployed in the blockchain node, such as the maintenance thread in the contract process container shown in Figure 2. Of course, this method can also be executed by other blockchain node devices that support containers as virtual machines for smart contracts to achieve efficient processing of blockchain transactions. The execution of this method is not limited herein.
[0062] As shown in FIG5 , the method includes S510 to S540 , which are described in detail as follows:
[0063] S510: Determine a smart contract for processing the transaction.
[0064] In real-world applications, blockchain nodes typically have multiple smart contracts installed to process transactions to meet business needs. Different smart contracts have different business logic. Therefore, when a blockchain node receives a pending transaction, it queries the smart contract responsible for processing it, thereby determining the appropriate smart contract.
[0065] It's important to understand that in blockchain technology, a transaction is a digital record. This data is broadcast across the blockchain network and confirmed and verified across the network through a consensus mechanism, making it irreversible and tamper-proof. If you think of a blockchain as a distributed ledger that's constantly synchronized in real time, every action on it can be considered a transaction.
[0066] S520, determining the target resident contract process according to the tag value corresponding to each resident contract process recorded in the maintenance array, wherein the maximum number of resident contract processes recorded in the maintenance array is the maximum number of contract processes supported by the container deployed in the blockchain node.
[0067] First, it is important to understand that, as previously mentioned, containers are deployed in blockchain nodes as virtual machines for smart contracts, so that the execution and maintenance of smart contracts must be performed within the container. This embodiment sets up a maintenance array to assist in the execution and maintenance of contract processes in the container.
[0068] The maintenance array is used to record the set of resident contract processes. The maximum number of resident contract processes recorded in the maintenance array is also the maximum number of contract processes supported by the container. Therefore, the maximum number of array elements contained in the maintenance array is the same as the maximum number of contract processes supported by the container, and each element position records a corresponding resident contract process. It is understandable that because containers generally have restrictions on resources such as memory, the container is usually configured with a maximum number of supported contract processes to represent the maximum number of concurrently executing contracts in the container. For example, as shown in Figures 8, 10, and 11, in an exemplary maintenance array, the recorded set of resident contract processes includes 4 resident contract processes.
[0069] It should also be noted that since the contract process is essentially the smart contract program deployed on the blockchain node, the resident contract process is essentially the smart contract program that can be executed in the container, and the maintenance array mentioned in this embodiment is used for the execution and maintenance of the contract process in the container. Therefore, the recording of the resident contract process in the element position of the maintenance array mentioned in this embodiment is actually recording the name of the resident contract process at the element position, that is, the content of each array element contained in the maintenance array should be the name of the resident contract process.
[0070] As can be seen, when a contract process outside the resident contract process set needs to be executed, it is necessary to swap in and out the contract process. That is, the contract process is swapped out of the current resident contract process set and the contract process to be executed is swapped into the resident contract process set. The process of swapping in and out of contract processes is also called loss. Loss means that the current contract process cannot process transactions, so the existing contract process must be exited and a new contract process must be added.
[0071] In this embodiment, the maintenance array is further provided with a flag bit, and a flag bit is set for each array element. The flag bit is used to record the flag value of the corresponding array element. The flag value is used to represent the execution status of the corresponding array element. Different flag values represent different execution states of the contract process. For example, when the flag value of the flag bit is a first value, it represents that the corresponding contract process is in an executed state. The executed state can be understood as the corresponding contract process being executed recently. The length of time used to measure whether the contract process has been executed recently can be a preset value and is not limited here. When the flag value is a second value, it represents that the corresponding contract process is in an unexecuted state. Accordingly, the unexecuted state can be understood as the corresponding contract process not being executed recently. Therefore, when swapping in and out contract processes, the resident contract process with the second flag value is usually determined to be the target resident contract process that needs to be swapped out from the resident contract process set.
[0072] For example, if the number of resident contract processes with a mark value of the second value included in the current resident contract process set is 1, then this resident contract process can be directly determined as the target resident contract process that needs to be swapped out. If the number of resident contract processes with a mark value of the second value included in the resident contract process set is multiple, then one of the resident contract processes is determined as the target resident contract process, usually the first resident contract process with a mark bit of the second value is determined as the target resident contract process. For the determination method, please refer to the records in the subsequent embodiments, which will not be repeated here. If the number of resident contract processes with a mark value of the second value included in the resident contract process set is 0, then the mark value of the resident contract process needs to be modified to the first value before the target resident contract process is determined. For the detailed process, please refer to the records in the subsequent embodiments, which will not be repeated here.
[0073] It should also be noted that in some exemplary embodiments, the first value may be 1 and the second value may be 0, thereby requiring only one bit to implement the flag bit of each array element, thereby requiring very few resources. In other embodiments, the first value and the second value may also be values other than 0 or 1, which are not limited herein.
[0074] In some exemplary embodiments, after S510, a query is further performed to determine whether the smart contract used to process the transaction has been installed on the blockchain node. If so, step S520 is executed. If not, a prompt is performed to indicate that the contract does not exist, such as generating a corresponding prompt message and feeding the prompt message back to the user. Exemplarily, a blockchain node maintains a smart contract list that records the contract names of the smart contracts already installed on the blockchain node. Therefore, by obtaining the smart contract list and then searching the smart contract list for the contract name corresponding to the smart contract used to process the transaction, it is possible to query whether the smart contract used to process the transaction has been installed on the blockchain node.
[0075] S530, replacing the target resident contract process with the target contract process corresponding to the smart contract in the maintenance array, and modifying the tag value corresponding to the target contract process to the first value.
[0076] After determining the target resident contract process that needs to be swapped out based on the maintenance array, the target resident contract process in the maintenance array is replaced with the target contract process corresponding to the smart contract for processing the transaction determined in S510, and then the tag value corresponding to the target contract process in the maintenance array is modified to the first value.
[0077] As will be appreciated, this embodiment replaces the target resident contract process in the maintenance array with the target contract process, thereby adding the target contract process to the resident contract process set, thereby updating the resident contract process. This embodiment also modifies the tag value corresponding to the target contract process in the maintenance array to the first value. This is to indicate, through this first value, that the target contract process has recently been executed. This allows the target resident contract process to be determined based on this tag value the next time a contract process is swapped in or out.
[0078] S540: Send the transaction to the target contract process for processing.
[0079] Based on the modification of the tag value in S530, the target contract process is marked as a new resident contract process, so that the transaction to be processed can be sent to the target contract process to be processed by the target contract process.
[0080] As can be seen from the above, the transaction processing method provided by this embodiment is to set a maintenance array to maintain the execution of the smart contract in the blockchain node. Specifically, the maintenance array is used to record the set of resident contract processes in the blockchain node and the tag value of each resident contract process. When the contract process needs to be swapped in and out, the target resident contract process that needs to be swapped out is determined according to the tag value of each resident contract process in the maintenance array, and then the target resident contract process is replaced with the target contract process that needs to be swapped in.
[0081] Compared to the prior art method of using linked lists for smart contract execution maintenance, on the one hand, since the maintenance array used in this embodiment is a compact structure, this data structure occupies very little memory and basically does not appear in multiple memory pages, thereby reducing the performance loss caused by swapping out memory pages; on the other hand, since this embodiment involves array operations, there will be no operation competition, and different array elements can be operated in parallel, thereby further reducing performance loss; on the other hand, since the elements in the array can be operated concurrently, it can save performance consumption in the blockchain node. Therefore, it can be seen that the operation method based on the maintenance array of this application is simpler, the container resources required are also smaller, and the transaction processing efficiency can be improved.
[0082] FIG6 is a flow chart of another blockchain-based transaction processing method proposed based on the embodiment shown in FIG5. As shown in FIG6, based on S510-S540 shown in FIG5, the blockchain-based transaction processing method further includes S610 and S620 as shown below:
[0083] S610, determining whether the target contract process corresponding to the smart contract is a resident contract process;
[0084] S620: After modifying the tag value corresponding to the target contract process in the maintenance array to the first value, the transaction is sent to the target contract process for processing.
[0085] It should be noted that the determination performed in S610 should also be based on the maintenance array. Specifically, after determining the target contract process, the determination of whether the target contract process is a resident contract process can be made by querying whether the target contract process is an array element in the maintenance array. If the target contract process is an array element in the maintenance array, the target contract process is determined to be a resident contract process. Conversely, if the target contract process is not an array element in the maintenance array, the target contract process is determined not to be a resident contract process.
[0086] If the judgment in S610 is no, that is, it is determined that the target contract process does not belong to the resident contract process, it is considered that a missing is triggered, that is, the contract process needs to be swapped in and out, so the process jumps to S520.
[0087] If the answer in S610 is yes, that is, it is determined that the target contract process is a resident contract process, the target contract process can be used directly for transaction processing. Therefore, the process jumps to execute the content shown in S620. After the tag value corresponding to the target contract process in the bit array is modified to the first value, the transaction is sent to the target contract process for processing.
[0088] Still taking Figure 3 as an example, when the sequence is 1-4, 6-8, the contract processes that need to be executed are all existing resident contract processes, while when the sequence is 5, 9-10, the contract processes that need to be executed are not existing resident contract processes. This shows that various smart contract execution situations are prone to occur in actual application scenarios, and further proves that this embodiment, by introducing the judgment of whether the target contract process belongs to a resident contract process, can select appropriate step content for processing based on the judgment result, which is more suitable for actual application scenarios.
[0089] FIG7 is a flow chart of another blockchain-based transaction processing method proposed based on the embodiment shown in FIG5. As shown in FIG7, based on S510-S540 shown in FIG5, the blockchain-based transaction processing method further includes S710, S720 and S730 as shown below:
[0090] S710, determining whether the number of current resident contract processes in the container is less than the maximum number of contract processes supported by the container;
[0091] S720, set the target contract process as a resident contract process and record the target contract process in a maintenance array;
[0092] S730, modifying the tag value corresponding to the target contract process in the maintenance array to the first value, and setting the next element position of the element position where the target contract process is located as the cursor position, which represents the array position where the target resident contract process is started to be detected.
[0093] This embodiment needs to obtain the number of current resident contract processes in the container, wherein the number of current resident contract processes in the container can be obtained according to the number of resident contract processes recorded in the current maintenance array.
[0094] The purpose of determining whether the current number of resident contract processes in the container is less than the maximum number of contract processes supported by the container at step S710 is to determine whether the current number of resident contract processes has reached the container limit. If the determination at step S710 is yes, i.e., the current number of resident contract processes in the container is less than the maximum number of contract processes supported by the container, then the container can directly add the target contract process to the resident contract process set. Therefore, the process jumps to steps S720-S730, where the target contract process is designated as a resident contract process, recorded in the maintenance array, and the tag value corresponding to the target contract process in the maintenance array is modified to the first value.
[0095] It's worth noting that S730 also uses the position immediately following the element position where the target contract process resides as the cursor position. This cursor position indicates the element position at which detection of the target resident contract process begins. This means that by setting the cursor position in the maintenance array, the next time a contract process swap is triggered, detection of the target resident contract process to be swapped out of the resident contract process set will begin at that cursor position. The details of this detection process will be described in the next embodiment and are not detailed here.
[0096] If S710 is judged as no, that is, the number of current resident contract processes in the container is not less than the maximum number of contract processes supported by the container, it means that directly executing the target contract process will cause the container resources to exceed the limit. Therefore, it is necessary to jump to execute S520 to perform the swapping in and out of the contract process, and then perform transaction processing through the target contract process.
[0097] By judging the current number of resident contract processes and the maximum number of contract processes of the blockchain node, we can make targeted choices based on the judgment results to determine the target resident contract process from the resident contract processes in the maintenance array, or add the target contract process as a resident contract process to the maintenance array, thereby effectively improving resource utilization efficiency.
[0098] In the maintenance array initialization process illustrated in Figure 8 , the maintenance array is empty when the time sequence is 0. When the time sequence is 1, contract process A needs to be executed. Since the current number of resident contract processes in the container, 0, is less than the maximum number of contract processes supported by the container, 4, contract process A is recorded as a resident contract process in the maintenance array, and the tag value of contract process A is modified to the first value 1. The next array position of contract process A is used as the cursor position. The process of executing contract process B when the time sequence is 2 and contract process C when the time sequence is 3 is similar to the process for executing contract process B when the time sequence is 1 and will not be repeated here.
[0099] It's worth noting that when contract process D needs to be executed at time 4, the number of resident contract processes currently in the container (3) is less than the maximum number of contract processes supported by the container (4). Therefore, contract process D is recorded as a resident contract process in the maintenance array, and the tag value of contract process D is modified to the first value 1. However, since contract process D is located at the end of the maintenance array, using the next array position of contract process D as the cursor position will cause the cursor position to cross the boundary. In this case, the starting element position of the maintenance array can be used as the cursor position.
[0100] In the maintenance array shown in FIG8 , the element positions filled with darker gray represent the cursor positions, and the element positions filled with lighter gray represent the digital elements newly added to the resident contract process set. According to FIG8 , it can be seen that after the contract process D corresponding to sequence 4 is added to the maintenance array, the cursor position is out of bounds, so the starting element position of the maintenance array is used as the cursor position.
[0101] From the above, it can be seen that this embodiment further introduces a size comparison between the number of current resident contract processes in the container and the maximum number of contract processes supported by the container, and can select appropriate step content for processing based on the judgment result, which can meet the application requirements of maintaining the array in the initialization stage, and is further suitable for actual application scenarios.
[0102] It can be seen from the above that the maintenance array involved in this embodiment is a ring array structure, that is, in the array structure, the tail and head of the maintenance array are connected to form a ring array structure, and this ring array structure allows out-of-bounds.
[0103] FIG9 is a flow chart of another blockchain-based transaction processing method proposed based on the embodiment shown in FIG5. As shown in FIG9, based on S510-S540 shown in FIG5, S520 specifically includes S5201-S5203. The method also includes S5204 and S5205. The details are as follows:
[0104] S5201, obtain the tag value of the cursor position in the maintenance array;
[0105] S5202, determine whether the mark value of the cursor position is the second value; if so, execute S5203, if not, execute S5205.
[0106] S5203, determining the resident contract process corresponding to the cursor position as the target resident contract process;
[0107] S5204, determining the next element position of the target contract process in the maintenance array as the new cursor position;
[0108] S5205: Modify the mark value of the cursor position to a second value, and determine the next element position of the cursor position as a new cursor position.
[0109] As mentioned above, the cursor position in the maintenance array represents the element position where the target resident contract process is started to be detected. Therefore, when detecting the target resident contract process, the tag value of the cursor position in the maintenance array needs to be obtained.
[0110] After obtaining the tag value of the cursor position, it is necessary to determine whether the tag value of the cursor position is the second value. It should be understood that the second value indicates that the corresponding contract process is in an unexecuted state. If S5202 determines yes, it means that the resident contract process corresponding to the cursor position has not been used recently, and therefore it can be determined as the target resident contract process that needs to be swapped out. After swapping the target contract process into the resident contract process set, that is, replacing the target resident contract process in the maintenance array with the target contract process, and modifying the tag value of the target contract process in the maintenance array to the first value, the new cursor position is determined by the next element position in the maintenance array located at the target contract process.
[0111] If S5202 returns a negative result, the resident contract process corresponding to the cursor position has been recently used and is therefore unsuitable as the target resident contract process. Therefore, the flag value of the cursor position is modified to the second value, and the next element position after the cursor position is determined as the new cursor position. Execution then jumps to S5201, rechecking the maintenance array for the target resident contract process. Based on this process, the target resident contract process ultimately determined is generally the resident contract process that has not been processed for the longest time, which is more consistent with actual processing logic.
[0112] Likewise, in the process of updating the cursor position, if the cursor position determined based on the next element position is out of bounds, the starting element position of the maintenance array is determined as the cursor position.
[0113] To facilitate understanding of the above process, please refer to Figures 10 and 11. Figure 10 is a schematic diagram of another exemplary contract process execution sequence, and Figure 11 is a schematic diagram of the array operations corresponding to contract process execution sequences 5-10 shown in Figure 10. Furthermore, in the maintenance array shown in Figure 11, the dark gray element positions represent the cursor positions, while the light gray element positions represent the digital elements newly added to the resident contract process set.
[0114] As shown in Figures 10 and 11, when the sequence is 5, the target contract process E needs to be executed. The current cursor position in the maintenance array is the element position where the contract process A is located. Since the contract process E is deployed in the resident contract process, the tag value of the cursor position is the first value 1, not the second value 0. Therefore, the tag value of the cursor position is modified to the second value 0, and the next element position is determined as the new cursor position. The tag value of the new cursor position is still the first value 1, so the tag value of the cursor position needs to be modified to the second value 0, and the next element position is determined as the new cursor position. This cycle is executed until the tag value of the last element of the maintenance array is modified to the second value 0, and the starting element of the maintenance array is determined as the new cursor position. Since the tag value of the cursor position at this time is the second value 0, the resident contract process A corresponding to the cursor position is used as the target resident contract process to be swapped out and replaced by the target contract process E to be executed. The tag value of the target contract process E is modified to the first value 1, and the next element position of the target contract process E is used as the cursor position.
[0115] When the time sequence is 6, the target contract process B needs to be executed. Since the target contract process B is already a resident contract process, its mark value can be directly modified to the first value 1 in the maintenance array.
[0116] When the sequence is 7, the target contract process A needs to be executed. Since in the current maintenance array, the element position of the resident contract process B is the cursor position (this is the cursor position finally determined during the processing of sequence 5), and the mark value of the cursor position is the first value 1, the mark value needs to be modified to the second value 0, and the next element position is determined to be the new cursor position. Since the mark value of the new cursor position is the second value 0, the resident contract process C corresponding to this position is replaced with the target contract process A, and the mark value of the target contract process A is modified to the first value 1, and the next element position of the target contract process A is used as the new cursor position.
[0117] The processing of time sequences 8-10 is similar to that of the above time sequence and will not be elaborated on here. In summary, this embodiment further introduces the judgment of the mark value of the cursor position, and can select appropriate step content for processing based on the judgment result, which can meet various application requirements in actual applications and is further applicable to actual application scenarios.
[0118] In another exemplary embodiment, considering that the existing technology directly configures the maximum number of contract processes supported in the container, that is, the maximum number of contract processes supported by the container in the existing technology is a preset value, this cannot use changes in the application environment. After all, in actual application scenarios, different resource environments may be different.
[0119] Specifically, if the maximum number of contract processes supported in a container is not configured properly, the following two situations may occur:
[0120] 1) The maximum number of configured contract processes is too large, which can easily lead to excessive use of container resources, causing the contract process to be forcibly stopped by the container system, or frequent memory page swapping operations;
[0121] 2) The maximum number of configured contract processes is too small, resulting in insufficient utilization of container resources and frequent swapping of contract processes.
[0122] In order to solve the above problems, this embodiment also proposes a solution for determining the maximum number of contract processes supported by a container. Based on this solution, the maximum number of contract processes supported by the container can be dynamically adjusted to avoid the above two situations.
[0123] This solution includes S810-S820, detailed as follows:
[0124] S810, detecting the average missing time interval and the average missing processing time of the contract process in the blockchain node.
[0125] First, it should be noted that in a blockchain system, the smart contracts called by users often follow the pattern shown in Figure 12. Specifically, the number of smart contracts called will increase over time, but will eventually tend to a relatively stable range.
[0126] Based on this rule, this embodiment proposes two concepts: the average contract process missing time interval and the average contract process missing processing time.
[0127] The average contract process missing interval represents the average time interval between contract process missing events. A missing event indicates a contract process swap-in or swap-out operation. The average contract process missing interval is calculated by averaging the time intervals between consecutive missing events. For example, in Figure 3, since a missing event occurs at time sequences 5, 9, and 10, the time period T1 corresponding to time sequences 5 to 9 and the time period T2 corresponding to time sequences 9 to 10 are the time periods between the two contract process missing events. By averaging these two time intervals, the average contract process missing interval is calculated.
[0128] The average contract process missing processing time represents the time period for restarting a missing contract process. That is, when a contract process is missing, how long does it take to restart the contract process?
[0129] It is worth mentioning that there is a certain connection between the two parameters, the average contract process missing time interval and the average contract process missing processing time. It is understandable that if the average contract process missing time interval is greater than the average contract process missing processing time, it means that contract process missing does not occur frequently, and the CPU resource usage of the blockchain node has not reached the upper limit. If the average contract process missing time interval is less than the average contract process missing processing time, it means that contract process missing occurs frequently, and the CPU cannot process transactions normally because it needs to spend a lot of time to process the contract process missing situation.
[0130] It should also be noted that since the two parameters, the average contract process missing time interval and the average contract process missing processing time, change dynamically as the container runs, these two parameters need to be dynamically detected.
[0131] S820 : Determine the maximum number of contract processes supported by the container based on the average contract process missing time interval and the average contract process missing processing time.
[0132] As previously mentioned, the resident contract process set represents the set of contract processes that remain operational in the container for most of the time over a period of time. In this embodiment, the set of contract processes that remain operational in the container at a given point in time is also referred to as the current contract process set. If the resident contract process set includes the current contract process set, no contract process will be missing. Otherwise, a contract process will be missing.
[0133] Generally speaking, it's desirable to have a larger resident contract process set. This is because the larger the number of contract processes in the resident contract process set, the more likely the current contract process set is to be included in the resident contract process set, and thus, the less likely contract process loss will occur. However, a larger resident contract process set means more resource consumption. Therefore, this embodiment needs to find a balance based on the average contract process loss interval and the average contract process loss processing time.
[0134] If we continuously count the number of resident contract processes and the CPU usage of blockchain nodes over a period of time, we can obtain the statistical results shown in the upper figure of Figure 13. It can be seen that as the number of resident contract processes continues to increase, the CPU usage of blockchain nodes shows a trend of first increasing and then decreasing.
[0135] If we continuously count the number of resident contract processes, the CPU usage of the blockchain node at that time, the average time interval between contract process absences, and the average processing time for contract process absences over a period of time, we can obtain the statistical results shown in the lower figure of Figure 13. It can be seen that as the ratio of the average time interval between contract process absences to the average processing time for contract process absences gradually decreases, the CPU usage of the blockchain node also gradually decreases.
[0136] Ideally, it's desirable to set the number of resident contract processes where the "target optimal solution" resides as the maximum number of contract processes supported by the container, as CPU utilization is highest at this point. However, this is difficult to achieve in practice, as future processing scenarios cannot be predicted. Therefore, the solution of this embodiment uses the number of resident contract processes where the "calculation optimal solution" resides as the maximum number of contract processes supported by the container. This number is the number of contract processes resident in the container when the ratio between the average missing time interval of the contract process and the average missing processing time of the contract process is 1. As shown in Figure 13, while this number differs slightly from the number of resident contract processes where the "calculation optimal solution" resides, the difference is minimal.
[0137] Therefore, this embodiment determines the number of resident contract processes in the container when the ratio between the average contract process missing time interval and the average contract process missing processing time is 1, and then the number of resident contract processes can be used as the maximum number of contract processes supported by the container.
[0138] It should be noted that in other embodiments, the ratio between the average contract process missing time interval and the average contract process missing processing time used to determine the maximum number of contract processes supported by a container may be adjusted. For example, the ratio may be dynamically determined based on actual dynamic detection conditions. Therefore, this embodiment does not limit the ratio to 1. It is understood that, generally, the ratio dynamically detected based on actual scenarios should not differ much from 1.
[0139] Based on the method provided in this embodiment, according to the rules of smart contract execution, a more reasonable maximum number of contract processes supported by a container can be dynamically determined, that is, the maximum number of resident contract processes included in the resident contract process set. Under the limit of this maximum number of contract processes, the CPU resources in the blockchain node can be used with the highest efficiency.
[0140] Figure 14 is a flowchart of a proposed blockchain-based transaction processing method based on an exemplary application scenario. As shown in Figure 14, assume that the maximum number of resident contract processes is represented by Nmax, and the cursor position in the maintenance array is represented by last.
[0141] After obtaining the pending transaction, query the name of the smart contract corresponding to the transaction, assuming it is C;
[0142] Then determine whether the contract is on the chain, that is, whether the contract has been installed on the blockchain;
[0143] If the answer is no, it means that the contract does not exist;
[0144] If the answer is yes, then further determine whether contract process C is a resident contract process, that is, determine whether contract process C is included in the resident contract process set. The resident contract process set and the tag value of each resident contract process are recorded in the maintenance array;
[0145] If the judgment is yes, the tag value of the corresponding contract process C in the maintenance array is modified to 1, and then the transaction is sent to the contract process C for processing. At this time, the processing flow of the transaction ends;
[0146] If the answer is no, obtain the current number of resident contract processes Nc and further determine whether Nc is less than Nmax;
[0147] If the answer is yes, it means that the number of resident contract processes in the resident contract process set has not yet reached the maximum number of contract processes supported by the container. Therefore, contract process C is directly added to the resident contract process set, and its tag value is set to 1. The last position in the maintenance array is set to the next element position where contract process C is located, that is, last+1;
[0148] If the judgment is no, it means that a resident contract process needs to be exited from the resident contract process set before contract process C can be added to the resident contract process set. Therefore, the mark value X of the cursor position in the maintenance array at this time is obtained, and it is further determined whether the mark value X of the cursor position is 0;
[0149] If the result is negative, the mark value X of the cursor position is set to 0, and the next element position is used as the new cursor position, that is, last++. Then, the process of obtaining the mark value X of the cursor position in the current maintenance array and further determining whether the mark value X of the cursor position is 0 is continued.
[0150] If the judgment is yes, the resident contract process at the cursor position is replaced with contract process C, that is, the resident contract process at the cursor position is withdrawn from the resident contract process set, and contract process C is added to the resident contract process set. Then, the next element position is used as the new cursor position, that is, last++, and the transaction is sent to contract process C for processing. At this time, the processing flow of the transaction ends.
[0151] As can be seen from the above, the maintenance array used in this embodiment is used to implement the execution maintenance of the smart contract in the blockchain node. On the one hand, since the array data structure occupies very little memory, it basically does not appear in multiple memory pages, thereby reducing the performance loss caused by the swapping out of memory page faults; on the other hand, since this embodiment involves array operations, there will be no operation competition, and different array elements can be operated in parallel, thereby further reducing performance loss; on the other hand, since the elements in the array can be operated concurrently, it can save performance consumption in the blockchain node, thereby improving the transaction processing performance in the blockchain node.
[0152] It should be noted that the details of each step in the example process of FIG14 have been described in detail in the aforementioned embodiments, and these details will not be repeated in this embodiment. In addition, Nmax mentioned in the example process of FIG14 can be dynamically obtained using the solution described in the aforementioned embodiments, and the detailed acquisition process will not be repeated here.
[0153] Figure 15 is a block diagram of a blockchain-based transaction processing device, illustrating an exemplary embodiment of the present application. This device can be deployed on a blockchain node. Specifically, it can be implemented as a functional module on a maintenance thread within a container deployed within the blockchain node. Of course, this device can also be deployed on other blockchain node devices that support containers as virtual machines for smart contracts, and this is not a limitation herein.
[0154] As shown in FIG. 15 , the apparatus includes a first determination module 1510 , a second determination module 1520 , an array processing module 1530 and a transaction processing module 1540 .
[0155] First determination module 1510 is configured to determine the smart contract used to process the transaction. Second determination module 1520 is configured to determine the target resident contract process based on the tag values corresponding to each resident contract process recorded in the maintenance array. The tag value is used to identify the execution status of the corresponding resident contract process. The maximum number of resident contract processes recorded in the maintenance array is the maximum number of contract processes supported by the container deployed in the blockchain node. Array processing module 1530 is configured to replace the target resident contract process in the maintenance array with the target contract process corresponding to the smart contract and modify the tag value corresponding to the target contract process to a first value, which indicates that the corresponding contract process is in an executed state. Transaction processing module 1540 is configured to send the transaction to the target contract process for processing.
[0156] In another exemplary embodiment, the apparatus further includes a first judgment module, wherein the first judgment module is configured to perform the following steps:
[0157] Determine whether the target contract process is a resident contract process;
[0158] If the target contract process does not belong to the resident contract process, the step of determining the target resident contract process according to the tag value corresponding to each resident contract process recorded in the maintenance array is executed;
[0159] If the target contract process is a resident contract process, after the tag value corresponding to the target contract process in the maintenance array is modified to the first value, the transaction is sent to the target contract process for processing.
[0160] In another exemplary embodiment, the device further includes a first acquisition module and a second determination module. The first acquisition module is configured to acquire the number of current resident contract processes in the container. The second determination module is configured to perform the following steps:
[0161] If the number of current resident contract processes in the container is not less than the maximum number of contract processes supported by the container, then executing the step of determining the target resident contract process according to the tag value corresponding to each resident contract process recorded in the maintenance array;
[0162] If the number of current resident contract processes in the container is less than the maximum number of contract processes supported by the container, the target contract process will be used as a resident contract process and recorded in the maintenance array;
[0163] In the maintenance array, the tag value corresponding to the target contract process is modified to the first value, and the next element position of the element position where the target contract process is located is used as the cursor position. The cursor position represents the element position where the target resident contract process is started to be detected.
[0164] In another exemplary embodiment, the apparatus further includes a second acquisition module, a third determination module, and an update module. The second acquisition module is configured to acquire a tag value of a cursor position in a maintenance array. The update module is configured to, after modifying the tag value corresponding to the target contract process to a first value, determine the next element position in the maintenance array located at the target contract process as a new cursor position. The third determination module is configured to perform the following steps:
[0165] If the mark value of the cursor position is the second value, the resident contract process corresponding to the cursor position is determined as the target resident contract process, and the second value indicates that the corresponding contract process is in an unexecuted state;
[0166] If the mark value of the cursor position is not the second value, the mark value of the cursor position is modified to the second value, and the next element position of the cursor position is determined as the new cursor position, and jump to the step of obtaining the mark value of the cursor position in the maintenance array.
[0167] In another exemplary embodiment, the apparatus further comprises an out-of-bounds processing module configured to determine a starting element position of the maintenance array as the cursor position when the cursor position determined in the maintenance array is out of bounds.
[0168] In another exemplary embodiment, the apparatus further includes a quantity determination module configured to perform the following steps:
[0169] Detect the average contract process missing time interval and average contract process missing processing time in the blockchain node. The average contract process missing time interval represents the average time interval between smart contract process missing events, and the average contract process missing processing time represents the time period for restarting missing contract processes.
[0170] The maximum number of contract processes supported by the container is determined based on the average contract process missing time interval and the average contract process missing processing time.
[0171] In another exemplary embodiment, the quantity determination module is further configured to determine the number of resident contract processes in the container when the ratio between the average missing time interval of the contract process and the average missing processing time of the contract process is 1, and use the number of resident contract processes as the maximum number of contract processes supported by the container.
[0172] In another exemplary embodiment, the first determination module is further configured to:
[0173] Check whether the smart contract has been installed on the blockchain node;
[0174] If the smart contract has been installed on the blockchain node, determine whether the target contract process is a resident contract process;
[0175] If the smart contract is not installed on the blockchain node, a prompt indicating that the contract does not exist is performed.
[0176] In another exemplary embodiment, the first determination module is further configured to:
[0177] Obtain a smart contract list corresponding to the blockchain node, where the smart contract list records the contract names of the smart contracts installed in the blockchain node;
[0178] Search the smart contract list for the contract name corresponding to the smart contract.
[0179] It should be noted that the apparatus provided in the above embodiments and the methods provided in the above embodiments are based on the same concept. The specific manner in which the various modules and units perform their operations has been described in detail in the method embodiments and will not be repeated here. In actual applications, the apparatus provided in the above embodiments can, as needed, allocate the above functions to different functional modules, i.e., divide the internal structure of the apparatus into different functional modules to perform all or part of the functions described above. This is not a limitation herein.
[0180] An embodiment of the present application also provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device implements the blockchain-based transaction processing method provided in each of the above embodiments.
[0181] Figure 16 shows a schematic diagram of the structure of a computer system of an electronic device suitable for implementing an embodiment of the present application. It should be noted that the computer system 1600 of the electronic device shown in Figure 16 is only an example and should not bring any limitation to the functions and scope of use of the embodiment of the present application.
[0182] As shown in Figure 16, the computer system includes a central processing unit (CPU) 1601, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1602 or the program loaded from the storage part 1608 into the random access memory (RAM) 1603, such as executing the method in the above embodiment. Various programs and data required for system operation are also stored in the RAM 1603. The CPU 1601, ROM 1602 and RAM 1603 are connected to each other via a bus 1604. An input / output (I / O) interface 1605 is also connected to the bus 1604.
[0183] The following components are connected to the I / O interface 1605: an input section 1606 including a keyboard, a mouse, and the like; an output section 1607 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and speakers; a storage section 1608 including a hard disk; and a communication section 1609 including a network interface card such as a LAN (Local Area Network) card or a modem. The communication section 1609 performs communication processing via a network such as the Internet. A drive 1610 is also connected to the I / O interface 1605 as needed. Removable media 1611, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 1610 as needed, so that computer programs read from the removable media can be installed in the storage section 1608 as needed.
[0184] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1609, and / or installed from a removable medium 1611. When the computer program is executed by the central processing unit (CPU) 1601, the various functions defined in the system of the present application are executed.
[0185] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or component, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0186] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. Among them, each box in the flowchart or block diagram can represent a module, program segment, or part of the code, and the above-mentioned module, program segment, or part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0187] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. In some cases, the names of these units do not constitute limitations on the units themselves.
[0188] Another aspect of the present application provides a computer-readable storage medium having a computer program stored thereon. When executed by a processor, the computer program implements the aforementioned blockchain-based transaction processing method. The computer-readable storage medium may be included in the electronic device described in the above embodiments, or may exist independently and not be incorporated into the electronic device.
[0189] An embodiment of the present application further provides a computer program product including a computer program, which, when executed on a computer, enables the computer to execute the method provided in the above embodiment.
[0190] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. Ordinary technicians in this field can easily make corresponding changes or modifications based on the main ideas and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
[0191] It should also be noted that the collection and processing of relevant data in this application should be strictly in accordance with the requirements of relevant national laws and regulations when applied in practice, and the informed consent or separate consent of the personal information subject should be obtained. Subsequent data use and processing should be carried out within the scope of authorization of laws and regulations and the personal information subject.
Claims
1. A transaction processing method based on blockchain, the method being executed by a blockchain node, include: Identify the smart contract used to process the transaction; Determine the target resident contract process according to the tag value corresponding to each resident contract process recorded in the maintenance array, wherein the tag value is used to identify the execution status of the corresponding resident contract process, and the maximum number of resident contract processes recorded in the maintenance array is the maximum number of contract processes supported by the container deployed in the blockchain node; In the maintenance array, the target resident contract process is replaced with the target contract process corresponding to the smart contract, and the tag value corresponding to the target contract process is modified to a first value, wherein the first value indicates that the corresponding contract process is in an executed state; The transaction is sent to the target contract process for processing.
2. The method according to claim 1, after determining the smart contract for processing the transaction, the method further include: Determine whether the target contract process is a resident contract process; If the target contract process does not belong to the resident contract process, the step of determining the target resident contract process according to the tag value corresponding to each resident contract process recorded in the maintenance array is performed.
3. The method according to claim 2, further comprising: include: If the target contract process is a resident contract process, after the tag value corresponding to the target contract process in the maintenance array is modified to the first value, the transaction is sent to the target contract process for processing.
4. The method according to claim 1, further comprising: include: Get the number of current resident contract processes in the container; If the number of current resident contract processes in the container is not less than the maximum number of contract processes supported by the container, the step of determining the target resident contract process according to the tag value corresponding to each resident contract process recorded in the maintenance array is executed.
5. The method according to claim 4, further comprising: include: If the number of current resident contract processes in the container is less than the maximum number of contract processes supported by the container, the target contract process is used as a resident contract process, and the target contract process is recorded in the maintenance array; In the maintenance array, the tag value corresponding to the target contract process is modified to the first value, and the next element position of the element position where the target contract process is located is used as the cursor position, and the cursor position represents the element position for starting to detect the target resident contract process.
6. The method according to claim 1, wherein the target resident contract process is determined according to the tag value corresponding to each resident contract process recorded in the maintenance array, include: Obtaining a tag value of a cursor position in the maintenance array, wherein the cursor position represents an element position in the maintenance data at which detection of a target resident contract process begins; If the mark value of the cursor position is a second value, the resident contract process corresponding to the cursor position is determined as the target resident contract process, and the second value indicates that the corresponding contract process is in an unexecuted state; The method further comprises: After the tag value corresponding to the target contract process is modified to the first value, the next element position of the target contract process in the maintenance array is determined as a new cursor position.
7. The method according to claim 6, further comprising: include: If the mark value of the cursor position is not the second value, modifying the mark value of the cursor position to the second value, and determining the next element position of the cursor position as the new cursor position; Jump to the step of obtaining the tag value of the cursor position in the maintenance array.
8. The method according to any one of claims 5 to 7, further comprising: include: If the cursor position determined in the maintenance array is out of bounds, the starting element position of the maintenance array is determined as the cursor position.
9. The method according to claim 1, further comprising: include: Detecting the average missing time interval and the average missing processing time of the contract process in the blockchain node, wherein the average missing time interval of the contract process represents the average time interval of a missing smart contract process, and the average missing processing time of the contract process represents the time period for restarting the missing contract process; The maximum number of contract processes supported by the container is determined based on the average missing time interval of the contract processes and the average missing processing time of the contract processes.
10. The method according to claim 9, wherein the maximum number of contract processes supported by the container is determined based on the average missing time interval of the contract process and the average missing processing time of the contract process. include: determining the number of resident contract processes in the container when the ratio between the average missing time interval of the contract process and the average missing processing time of the contract process is 1; The number of resident contract processes is used as the maximum number of contract processes supported by the container.
11. The method according to claim 1, after determining the smart contract for processing the transaction, the method further include: Check whether the smart contract has been installed on the blockchain node; If the smart contract has been installed on the blockchain node, determine whether the target contract process is a resident contract process; If the smart contract is not installed on the blockchain node, a prompt is performed to indicate that the contract does not exist.
12. The method according to claim 11, wherein the querying whether the smart contract has been installed on the blockchain node, include: Obtain a smart contract list corresponding to the blockchain node, wherein the smart contract list records the contract names of the smart contracts installed in the blockchain node; Search the smart contract list for the contract name corresponding to the smart contract.
13. A transaction processing device based on blockchain, include: A first determination module configured to determine a smart contract for processing a transaction; A second determination module is configured to determine a target resident contract process according to a tag value corresponding to each resident contract process recorded in a maintenance array, wherein the tag value is used to identify an execution state of the corresponding resident contract process, and the maximum number of resident contract processes recorded in the maintenance array is the maximum number of contract processes supported by the container deployed in the blockchain node; an array processing module, configured to replace the target resident contract process with the target contract process corresponding to the smart contract in the maintenance array, and modify the tag value corresponding to the target contract process to a first value, wherein the first value indicates that the corresponding contract process is in an executed state; The transaction processing module is configured to send the transaction to the target contract process for processing.
14. An electronic device, include: one or more processors; A storage device for storing one or more computer programs, which, when executed by the one or more processors, enables the electronic device to implement the method as described in any one of claims 1 to 12.
15. A computer-readable storage medium having computer-readable instructions stored thereon, which, when executed by a processor of a computer, causes the computer to execute the method according to any one of claims 1 to 12.
16. A computer program product comprising a computer program, which, when run on a computer, causes the computer to perform the method according to any one of claims 1 to 12.
