Disclosure of Invention
One or more embodiments of the present specification provide a method and an apparatus for capacity reduction of slices in a blockchain system.
According to a first aspect, a method for capacity reduction of a partition in a blockchain system is provided, where the blockchain system includes a first partition and a second partition, the first partition includes a first node, and the second partition includes a second node; the first node and the second node are deployed with a target contract, the method comprising:
the first node receives a capacity reduction request, acquires a target contract state of the target contract in the first fragment, and transmits the target contract state to the second node;
the second node merges the target contract state into a world state of the second shard.
According to a second aspect, a method for capacity reduction of a partition in a blockchain system is provided, where the blockchain system includes a first partition and a second partition, the first partition includes a first node, and the second partition includes a second node; the first node and the second node are deployed with a target contract, the method is performed by the first node, the method comprises:
receiving a capacity reduction request;
obtaining a target contract state of the target contract in the first segment;
transmitting the target contract state to the second node, so that the second node merges the target contract state into the world state of the second shard.
According to a third aspect, a method for capacity reduction of a partition in a blockchain system is provided, where the blockchain system includes a first partition and a second partition, the first partition includes a first node, and the second partition includes a second node; the first node and the second node are deployed with a target contract, the method is performed by the second node, the method comprises:
receiving a target contract status sent by the first node that the target contract is in the first slice;
merging the target contract state into a world state of the second shard.
According to a fourth aspect, there is provided an apparatus for performing capacity reduction on a segment in a blockchain system, where the blockchain system includes a first segment and a second segment, the first segment includes a first node, and the second segment includes a second node; the first node and the second node are deployed with target contracts, the apparatus is applied to the first node, and the apparatus comprises:
the receiving module is used for receiving the capacity reduction request;
an obtaining module, configured to obtain a target contract status of the target contract in the first segment;
and the transmission module is used for transmitting the target contract state to the second node, so that the second node merges the target contract state into the world state of the second fragment.
According to a fifth aspect, an apparatus for performing capacity reduction on a segment in a blockchain system is provided, where the blockchain system includes a first segment and a second segment, the first segment includes a first node, and the second segment includes a second node; the first node and the second node are deployed with target contracts, the apparatus is applied to the first node, and the apparatus comprises:
the receiving module is used for receiving the capacity reduction request;
an obtaining module, configured to obtain a target contract status of the target contract in the first segment;
and the transmission module is used for transmitting the target contract state to the second node, so that the second node merges the target contract state into the world state of the second fragment.
According to a sixth aspect, an apparatus for performing capacity reduction on a partition in a blockchain system is provided, where the blockchain system includes a first partition and a second partition, the first partition includes a first node, and the second partition includes a second node; the first node and the second node are deployed with target contracts, and the device is applied to the second node and comprises:
a receiving module, configured to receive a target contract status sent by the first node that the target contract is in the first slice;
and the merging module is used for merging the target contract state into the world state of the second fragment.
According to a seventh aspect, there is provided a computer readable storage medium, storing a computer program which, when executed by a processor, implements the method of any of the second or third aspects described above.
According to an eighth aspect, there is provided a computing device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method of any of the second or third aspects when executing the program.
The technical scheme provided by the embodiment of the specification can have the following beneficial effects:
in the method and the apparatus for performing capacity reduction on slices in a blockchain system provided in the embodiments of the present specification, when a preset condition is satisfied, a first node belonging to a first slice to be deleted obtains a target contract state in the first slice, and transmits the target contract state to a second node, and the second node belonging to a second slice to be merged merges the target contract state into a world state of the second slice, so that part of the world state in the first slice is selectively migrated to the world state of the second slice, and capacity reduction is performed on the slices in the blockchain system. The automatic capacity reduction of the block chain system is realized, and the problem that the number of the fragments in the block chain system cannot be reduced dynamically along with the reduction of the transaction number is solved. And the state hot migration is realized, so that the condition that the service of the block is interrupted in the capacity reduction process is avoided.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. The following description refers to the accompanying drawings in which like numerals refer to the same or similar elements throughout the different views unless otherwise specified. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present specification. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the specification, as detailed in the appended claims.
The terminology used in the description herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this specification and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It is to be understood that although the terms first, second, third, etc. may be used herein to describe various information, such information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the present application. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
At present, a very important factor limiting the large-scale floor application of the block chain technology is performance, which mainly includes throughput, and developers propose various schemes for capacity expansion in order to improve the throughput of the blocks. From the direction of the expansion technology, the expansion can be divided into two directions of on-chain expansion and under-chain expansion. On-strand expansion typically includes schemes of block expansion, isolation witness, fragmentation, and consensus layer refinement. The under-chain expansion generally comprises the schemes of state channel, side chain and under-chain calculation. The fragmentation technique belongs to a scheme of chain expansion. The sharding concept stems from the field of databases, which is intended to mean horizontal partitioning of data in a database (dividing different rows of a table into different partitions), each shard being maintained on a separate database server instance to spread the load.
The fragmentation technology can be divided into three types according to different fragmentation mechanisms: network sharding (network sharding), transaction sharding (transaction sharding), state sharding (state sharding). Network fragmentation is the most basic fragmentation method, i.e. dividing the whole blockchain network into multiple sub-networks, i.e. multiple fragments. In this way, multiple slices in a blockchain network can process different transactions in the network in parallel. The transaction slicing is to distribute the transaction to different slices according to a certain rule, and the idea is to distribute the transaction to the same slice according to a certain rule for processing, so that the purpose of parallel processing can be achieved, and the problem of double flowers can be avoided. The premise of transaction fragmentation is that network fragmentation is performed first. Among all fragmentation mechanisms, state fragmentation is the most challenging way to fragment. The key of the state fragmentation is to separate the whole storage area, so that different fragments store different parts, and each node is only responsible for storing own fragmentation data, but not storing the complete block chain state. State fragmentation can solve the storage capacity bottleneck problem.
However, when the traffic flow is low, the number of blockchain fragments cannot be reduced along with the reduction of the transaction number in unit time, so that the resource may be wasted, and the resource utilization efficiency is low. Therefore, from the perspective of improving the resource utilization efficiency, a technique for automatic capacity reduction during the low valley period of the block chain service is needed.
As shown in fig. 1 a-1 c, there is shown an architecture diagram of a blockchain system according to an exemplary embodiment.
In fig. 1a, the blockchain system may include a segment 1, a segment 2, a segment 3, and a segment 4, where a plurality of mutually trusted nodes of different segments may form a set, and the set may include 4 segment nodes belonging to 4 segments respectively and 1 central device. The sets communicate with each other through respective central equipment, and the shard nodes belonging to the same shard can also communicate with each other through the central equipment. In addition, the central device can also receive the transaction, carry out consensus on the received transaction, and respectively distribute the transaction to the fragmentation nodes of different fragments after consensus. The above-mentioned fragmentation node and the central device may be implemented as any device, server or device cluster with computing and processing capabilities.
The blockchain system can be a federation chain system, and the system can comprise a member party A, a member party B, a member party C and a member party D. It is to be understood that fig. 1a is merely illustrative of four shards and four membership parties, and that virtually any number of shards and membership parties may be included in a blockchain system. The following will be described by taking the blockchain system shown in fig. 1a to 1c as an example, and it is understood that the embodiments of the present disclosure are not limited to being applied to the blockchain system shown in fig. 1a to 1c, but can be applied to any blockchain system.
From the viewpoint of fragmentation, the fragmentation node 1A, the fragmentation node 1B, the fragmentation node 1C and the fragmentation node 1D all belong to the fragmentation 1. The fragmentation node 2A, the fragmentation node 2B, the fragmentation node 2C and the fragmentation node 2D all belong to the fragment 2. The fragmentation node 3A, the fragmentation node 3B, the fragmentation node 3C and the fragmentation node 3D all belong to a fragment 3. And, fragmentation node 4A, fragmentation node 4B, fragmentation node 4C and fragmentation node 4D all belong to fragment 4. From the perspective of the member party, the fragmentation node 1A, the fragmentation node 2A, the fragmentation node 3A and the fragmentation node 4A all belong to the member party a, and the four fragmentation nodes can communicate through the central device a. The fragmentation node 1B, the fragmentation node 2B, the fragmentation node 3B and the fragmentation node 4B all belong to a member party B, and the four fragmentation nodes can communicate through the central equipment B. The fragmentation node 1C, the fragmentation node 2C, the fragmentation node 3C and the fragmentation node 4C all belong to a member party C, and the four fragmentation nodes can communicate through the central device C. The fragmentation node 1D, the fragmentation node 2D, the fragmentation node 3D and the fragmentation node 4D all belong to a member party D, and the four fragmentation nodes can communicate through the central device D. And, the center device a, the center device B, the center device C, and the center device D can communicate with each other.
Each central device (including the central device a, the central device B, the central device C, and the central device D) may determine whether a preset capacity reduction condition is satisfied according to a total number of transactions executed by the block chain system in a preset time period, and if it is determined that the preset capacity reduction condition is satisfied, it is necessary to delete the original segment, and migrate the world state to be migrated in the deleted segment to the unremoved segment.
Specifically, after determining that the preset capacity reduction condition is met, each central device sends a capacity reduction request to the corresponding fragment node, and stops distributing the modified transaction to each fragment node. In the process of capacity reduction, the fragments can be divided into a first fragment to be deleted and a second fragment to be combined. In one implementation, the first and second shards may be determined by the hub device and the first and second shard nodes of the first and second shards notified. In another implementation, the first fragment and the second fragment may be pre-allocated, and the first fragment node and the second fragment node are notified.
First, in response to receiving a capacity reduction request, any first sharding node may search, through a scanner in the first sharding node, at least one state output function corresponding to each target contract in the first sharding after the current block is completed. And acquiring the world state to be migrated of the first segment by calling at least one state output function corresponding to each target contract.
Then, the first fragment node may establish a connection with a second fragment node of the corresponding second fragment, and transmit the to-be-migrated world state to the second fragment node. The second fragment node may migrate the to-be-migrated world state to the world state of the second fragment by calling the state input function corresponding to the state output function.
And finally, after the second fragment node completes the migration of the world state to be migrated, the central equipment is informed, the central equipment is disconnected with the first fragment node, and a fragment node list is updated, so that the first fragment is deleted and deleted, and the process of reducing the capacity of the fragments is completed.
For example, it may be predetermined that slice 3 and slice 4 are the first slices to be deleted, and slice 1 and slice 2 are the second slices to be merged, where slice 1 corresponds to slice 3, and slice 2 corresponds to slice 4. Taking the segment 1 and the segment 3 in the member party a as an example, after determining that the preset capacity reduction condition is met, the central device a sends capacity reduction requests to the segment node 1A and the segment node 3A respectively. In response to receiving the capacity reduction request, the sharding node 3A searches for at least one state output function corresponding to each target contract deployed in the shard 3. Then, the world state to be migrated of the slice 3 is obtained by calling each state output function. And as shown in fig. 1b, the fragment node 3A establishes a connection with the fragment node 1A, the fragment node 3A transmits the to-be-migrated world state of the fragment 3 to the fragment node 1A, and the fragment node 1A migrates the to-be-migrated world state to the world state of the fragment 1 by calling a corresponding state input function. Finally, as shown in fig. 1c, the central device a disconnects from the segment node 3A, and cancels and deletes the segment 3, thereby completing the process of capacity reduction. And the rest members can be analogized, and the description is omitted.
The embodiments provided in the present specification will be described in detail with reference to specific examples.
As shown in fig. 2, fig. 2 is an interactive flow diagram illustrating a method for capacity reduction of tiles in a blockchain system, according to an example embodiment. The block chain system comprises a central device, a first node belonging to a first fragment and a second node belonging to a second fragment, wherein the first fragment is a fragment to be deleted, the second fragment is a fragment to be merged, and a target contract is deployed at the first node and the second node, and the method comprises the following steps:
in step 201, the center apparatus determines that a preset condition is satisfied.
In this embodiment, the central device may be a central device in the blockchain system architecture shown in fig. 1a to 1c, or may be a device in other blockchain system architectures, for example, the central device may be a node device of a relay chain in the blockchain system, and it is understood that the aspect of the system architecture of the blockchain system is not limited in this embodiment.
In this embodiment, the condition that the preset condition is satisfied is the condition that the capacity reduction is satisfied, and the central device may determine whether the resource needs to be reduced by calculating the amount of the resource required by the current block chain system. If the resource needs to be reduced, it indicates that the capacity reduction needs to be performed on the fragments of the block chain system, that is, the capacity reduction condition is satisfied.
Specifically, the central device may first determine the target number of slices based on the total number of transactions performed by the blockchain system within a preset time period. When the central device determines that the number of fragments included in the current blockchain system is greater than the target number of fragments, it can be determined that the capacity reduction condition is met and the capacity reduction needs to be performed on the fragments of the blockchain system. Namely, at least part of the world state in the first fragment is migrated to the second fragment in the blockchain system, and the first fragment in the blockchain system is deleted.
The number of the target fragments is positively correlated with a target ratio, and the target ratio is the ratio of the total transaction number to a preset transaction number. For example, the target number of slices may be calculated by the following formula:
k=⌈log2(Ntx/△Ntx)⌉;
Nshard=2k;
wherein N istxRepresents the total number of transactions, DELTA N, actually performed by the blockchain system during a predetermined period of timetxRepresents the number of transactions executed during normal operation of a single segment in the block chain system in a preset time period, and k represents the log which is rounded up2(Ntx/△Ntx) Obtained integer, NshardRepresenting the number of target slices.
It can be understood that the manner of calculating the number of target segments is not limited to the above example, and the number of target segments may also be calculated in any other reasonable manner.
In step 203, the central device sends a capacity reduction request to the first node.
In this embodiment, the first node is a node belonging to a first slice to be pruned, and the second node is a node belonging to a second slice to be merged. Any number of first shards and any number of second shards can be included in the blockchain system, and the number of the first shards can be the same as or different from that of the second shards. For any first shard, its corresponding second shard (i.e., the second shard that merges at least part of the world states of the first shard) may be predefined or randomly assigned. Specifically, the first slice and the second slice may be divided according to a preset rule, for example, the first slice and the second slice may be determined according to the communication quality or the calculation speed of the slice. For another example, the segment increased by the previous expansion may be used as the first segment, and the node existing before the previous expansion may be used as the second segment. It can be understood that the first segment and the second segment may also be divided in any other reasonable manner, and the embodiment does not limit the specific dividing manner of the first segment and the second segment.
In one implementation, after determining that the preset condition is met, the central device determines a first node and a second node, and then sends a capacity reduction request to the first node, so that the first node performs a capacity reduction operation corresponding to the first node (i.e., obtains a target contract state in the first segment for the target contract, and transmits the target contract state to the second node). Optionally, the central device may also send a capacity reduction request to the second node, so that the second node performs a capacity reduction operation corresponding to the second node (i.e., merge the target contract state transmitted by the first node into the world state of the second segment).
In another implementation, after determining that the preset condition is met, the central device directly sends a capacity reduction request to each node connected to the central device. Each node judges whether the node is a first node or a second node and executes the capacity reduction operation corresponding to the first node or the second node.
In step 205, the first node obtains a target contract state for the target contract in the first segment.
In this embodiment, the target contract is an intelligent contract that requires state transition during the contraction process. For example, some intelligent contracts may change the world state after execution, and may need to be state-migrated during the reduction process. While some smart contracts (e.g., smart contracts for querying data, or for verifying permissions, etc.) do not change the world state after execution, they may not require state migration during the contraction process. Therefore, the number of target contracts to be deployed in the first slice may be one or more. When the target contract is deployed, the target contract can be deployed into each fragment of the blockchain system, and meanwhile, the contract address of the target contract can be saved.
Specifically, first, for any target contract, at least one state output function and a state input function corresponding to each state output function may be set in advance based on the data type related to the target contract. And recording each state output function and each corresponding state input function in the target contract. Wherein, aiming at any data type, a state output function and a state input function are correspondingly set. The state output function may be configured to extract state data of the data type from a world state corresponding to the target contract in the state database of the first shard. The state input function may be configured to insert the state data extracted by the state output function into the world state corresponding to the target contract in the state database of the second segment.
Optionally, on the one hand, when defining a function name of the state output/input function, an identifier capable of representing the corresponding data type may be added to the function name. For example, the function name of the state OUTPUT function whose data type corresponds to the boolean type may be defined as OUTPUT _ boost, and the function name of the state INPUT function whose data type corresponds to the boolean type may be defined as INPUT _ boost. On the other hand, the input parameter of the state output function corresponding to any data type may include an offset corresponding to any variable of the data type related to the target contract, where the offset corresponding to the variable may be a variable identifier of the variable, or a number (e.g., an integer number) corresponding to the variable in the data type. The returned result of the state output function may be the state value corresponding to the variable. The input parameters of the state input function corresponding to the state output function may include an offset corresponding to the variable and a state value corresponding to the variable. It should be noted that variables of different data types may correspond to the same offset.
In this embodiment, after receiving the capacity reduction request sent by the central device, the first node may obtain a saved contract address from the stored data, and use an intelligent contract corresponding to the saved contract address as a target contract. And based on the contract address of the target contract, acquiring the target contract state of the target contract in the first segment by using each state output function included in the target contract. Specifically, for any state output function, the first node may input multiple sets of first parameters into each state output function, so as to obtain each state value corresponding to each of multiple variables related to the target contract, as the target contract state. Any set of first parameters corresponds to a variable related to the target contract, that is, the first parameters may include an offset corresponding to the variable.
In step 207, the first node transmits the target contract state to the second node.
In one implementation, the first node may establish a communication connection with the second node, and transmit the obtained target contract state to the second node. In another implementation, the first node may further send the target contract status to the central device, and the central device sends the target contract status to the second node.
In step 209, the second node merges the target contract state into the world state of the second shard.
In this embodiment, after receiving the target contract state transmitted by the first node, the second node may merge the target contract state into the world state of the second segment by using a state input function corresponding to a state output function included in the target contract. Specifically, first, the second node may determine a plurality of sets of second parameters based on the target contract state and determine a state input function corresponding to the state output function. Wherein any set of second parameters comprises a state value corresponding to a variable related to the target contract. Then, the multiple groups of second parameters are respectively input into the state input function, so that the target contract state is merged into the world state of the second segment. For example, if the state output function outputs a state value corresponding to a variable, where the state value is an element in an array of a state tree of a world state corresponding to the first segment, the state input function corresponding to the state output function may insert the state value as an element in an array of a state tree of another world state, or may perform a preset calculation on the state value and a specified element in an array of a state tree of another world state, and insert the obtained result as an element in an array of a state tree of another world state. It is to be understood that the insertion logic may be set according to specific needs, and the present embodiment is not limited to the content of the specific insertion logic.
For ease of understanding, a specific application example for migrating target contract states is provided below:
the contracts A deployed in the first shard and the second shard are intelligent contracts needing state migration in the capacity reduction process, and addresses of the contracts A can be stored when the contracts A are deployed. Fig. 3 shows a schematic diagram of a contract a, and as shown in fig. 3, the contract a relates to data types of boolean type and address type, and a state output function and a state input function corresponding to the boolean type and a state output function and a state input function corresponding to the address type may be set in advance in the contract a. The function names of the state OUTPUT function and the state INPUT function corresponding to the boolean type may be OUTPUT _ boost and INPUT _ boost, respectively, and the function names of the state OUTPUT function and the state INPUT function corresponding to the ADDRESS type may be OUTPUT _ ADDRESS and INPUT _ ADDRESS, respectively. Variables of the boolean type related to the contract a include a variable a, a variable b and a variable c, and the numbers of the variable a, the variable b and the variable c in the boolean type are 0, 1 and 2 respectively. The offset of the variable a may be 0, the offset of the variable b may be 1, and the offset of the variable c may be 2. The variables of the address type related to the contract a include a variable e and a variable f, and the numbers of the variable e and the variable f corresponding to the address type are 0 and 1 respectively. The offset of the variable e may be 0 and the offset of the variable f may be 1.
After the first node of the first segment receives the capacity reduction request, the first node may obtain a contract address of a contract a saved in advance, and determine the contract a as a target contract for which state migration is required. First, the first node may determine the state OUTPUT functions OUTPUT _ BOOL and OUTPUT _ ADDRESS included in contract a using the contract ADDRESS of contract a. Then, the state OUTPUT function OUTPUT _ boul is called circularly by using the contract address of the contract a and an integer greater than or equal to 0 as an input parameter. When the input parameter is 0 (offset of variable a), the state OUTPUT function OUTPUT _ boost OUTPUTs the state value Va corresponding to the variable a. When the input parameter is 1 (offset of the variable b), the state OUTPUT function OUTPUT _ boost OUTPUTs the state value Vb corresponding to the variable b. When the input parameter is 2 (offset of the variable c), the state OUTPUT function OUTPUT _ boost OUTPUTs the state value Vc corresponding to the variable c. When the input parameter is 3, an error is reported, and the loop call of the state OUTPUT function OUTPUT _ BOOL is ended.
And then, using the contract ADDRESS of the contract A and using an integer which is greater than or equal to 0 as an input parameter, and circularly calling the state OUTPUT function OUTPUT _ ADDRESS. When the input parameter is 0 (offset of the variable e), the state OUTPUT function OUTPUT _ ADDRESS OUTPUTs the state value Ve corresponding to the variable e. When the input parameter is 1 (offset of the variable f), the state OUTPUT function OUTPUT _ ADDRESS OUTPUTs the state value Vf corresponding to the variable f. When the input parameter is 2, an error is reported, and the loop call to the state OUTPUT function OUTPUT _ ADDRESS is ended.
After the state output function included in the contract a is called, the first node may obtain a target contract state of the contract a in the first segment, where the target contract state includes a state value Va corresponding to the variable a, a state value Vb corresponding to the variable b, a state value Vc corresponding to the variable c, a state value Ve corresponding to the variable e, and a state value Vf corresponding to the variable f. And the first node can also acquire the associated information of the target contract state and transmit the target contract state and the associated information thereof to the second node. The association information of the target contract state may include a contract address of the contract a, a state output function included in the contract a, and a correspondence between an input parameter of the state output function and an output state value.
After receiving the target contract state and its associated information, the second node may determine the state INPUT functions INPUT _ boul and INPUT _ ADDRESS included in contract a based on the target contract state and its associated information. And determine the corresponding sets of INPUT parameters for each state INPUT function, for example, the corresponding sets of INPUT parameters for the state INPUT function INPUT _ boost may include (0, Va), (1, Vb) and (2, Vc), and the corresponding sets of INPUT parameters for the state INPUT function INPUT _ ADDRESS may include (0, Ve) and (1, Vf). Then, the contract address of the contract A and multiple groups of input parameters are utilized to respectively call corresponding state input functions, so that the target contract state is merged into the world state of the second fragment.
It should be noted that, the application example describes the migration of the target contract state only by taking one target contract (contract a) as an example, and actually, the target contract may also include a plurality of contracts, and the present embodiment does not limit the number of the target contracts.
In step 211, the second node transmits indication information indicating that the capacity reduction operation is completed to the center apparatus.
In this embodiment, after merging the target contract state into the world state of the second segment, the second node sends, to the central device, indication information for indicating that the capacity reduction operation corresponding to the second node is completed.
In step 213, the hub device disconnects from the first node.
In this embodiment, after receiving the message that the capacity reduction operation is completed and sent by the second node, the central device may disconnect from the first node to revoke the first fragment. And updating the fragment node list, deleting a first node belonging to the first fragment in the fragment node list, and destroying the virtual machine resource related to the first node, thereby completing the capacity reduction operation corresponding to the central equipment.
In the method for performing capacity reduction on slices in the blockchain system provided in the above embodiments of the present specification, when a preset condition is satisfied, a first node belonging to a first slice to be deleted obtains a target contract state in the first slice, and transmits the target contract state to a second node, and the second node belonging to a second slice to be merged merges the target contract state into a world state of the second slice, so that part of the world state in the first slice is selectively migrated into the world state of the second slice, and capacity reduction is performed on the slices in the blockchain system. The automatic capacity reduction of the block chain system is realized, and the problem that the number of the fragments in the block chain system cannot be reduced dynamically along with the reduction of the transaction number is solved. And the state hot migration is realized, so that the condition that the service of the block is interrupted in the capacity reduction process is avoided.
It should be noted that although in the above embodiments, the operations of the methods of the embodiments of the present specification have been described in a particular order, this does not require or imply that these operations must be performed in this particular order, or that all of the illustrated operations must be performed, to achieve desirable results. Rather, the steps depicted in the flowcharts may change the order of execution. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, and/or one step broken down into multiple step executions.
Corresponding to the foregoing embodiment of the method for capacity reduction of the fragments in the blockchain system, this specification further provides an embodiment of an apparatus for capacity reduction of the fragments in the blockchain system.
As shown in fig. 4, fig. 4 is a block diagram of an apparatus for reducing capacity of a partition in a blockchain system according to an exemplary embodiment, where the blockchain system includes a first partition and a second partition, the first partition includes a first node, the second partition includes a second node, the first node and the second node are deployed with a target contract, and the apparatus is applied to the first node, and the apparatus may include: a receiving module 401, an obtaining module 402 and a transmitting module 403.
The receiving module 401 is configured to receive a capacity reduction request.
An obtaining module 402 is configured to obtain a target contract status of a target contract in a first slice.
A transmitting module 403, configured to transmit the target contract state to the second node, so that the second node merges the target contract state into the world state of the second segment.
In some embodiments, the obtaining module 402 includes: an acquisition submodule (not shown in the figure).
The obtaining submodule is used for obtaining the state of the target contract by using a state output function included in the target contract.
In other embodiments, the state output function is a function set for one data type.
In other embodiments, the apparatus may further comprise: a determination module (not shown in the figures).
The determining module is used for determining a target contract based on a contract address stored when the contract is deployed.
In other embodiments, the acquisition submodule is configured to: and respectively inputting multiple groups of first parameters into the state output function, wherein any group of first parameters corresponds to one variable related to the target contract. And acquiring a target contract state output by the state output function, wherein the target contract state comprises each state value corresponding to each of a plurality of variables related to the target contract.
In other embodiments, the blockchain system may include a plurality of member parties, each member party including a respective central device and a plurality of fragmented partial sharded nodes. The first node and the second node belong to a first member party of a plurality of member parties, and the first member party comprises a first central device.
Wherein the receiving module 401 is configured to: a capacity reduction request is received from a first central device.
It should be understood that the above-mentioned apparatus may be preset in the first node, and may also be loaded into the first node by downloading or the like. The corresponding modules in the above device can cooperate with the modules in the first node to implement a solution of reducing the capacity of the fragments in the blockchain system.
As shown in fig. 5, fig. 5 is a block diagram of an apparatus for reducing capacity of a partition in a blockchain system according to an exemplary embodiment, where the blockchain system includes a first partition and a second partition, the first partition includes a first node therein, the second partition includes a second node therein, the first node and the second node are deployed with a target contract, and the apparatus is applied to the second node, and the apparatus may include: a receiving module 501 and a combining module 502.
The receiving module 501 is configured to receive a target contract status sent by the first node and about in the first segment.
A merging module 502, configured to merge the target contract state into the world state of the second segment.
In some embodiments, the target contract state is obtained by the first node using a state output function included in the target contract.
Wherein, the merging module 502 comprises: the submodules are merged (not shown in the figure).
And the merging submodule is used for merging the target contract state into the world state of the second segment by using the state input function included by the target contract, and the state input function corresponds to the state output function.
In other embodiments, the state output function and the state input function are functions set for one data type.
In other embodiments, the merge sub-module is configured to: based on the target contract state, a plurality of sets of second parameters are determined. Any set of second parameters includes a state value corresponding to a variable involved in the target contract. And respectively inputting the multiple groups of second parameters into the state input function so as to enable the target contract state to be merged into the world state of the second fragment.
It should be understood that the above-mentioned apparatus may be preset in the second node, and may also be loaded into the second node by means of downloading or the like. The corresponding modules in the above device can cooperate with the modules in the second node to implement a solution of reducing the capacity of the fragments in the blockchain system.
For the device embodiments, since they substantially correspond to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of one or more embodiments of the present specification. One of ordinary skill in the art can understand and implement it without inventive effort.
One or more embodiments of the present specification further provide a computer-readable storage medium storing a computer program, where the computer program is operable to execute the method for shrinking the tiles in the blockchain system provided in the embodiment of fig. 2.
One or more embodiments of the present specification further provide a computing device, which includes a memory and a processor, where the memory stores executable codes, and the processor executes the executable codes to implement the method for performing capacity reduction on slices in a blockchain system provided in the embodiment of fig. 2.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The foregoing description has been directed to specific embodiments of this disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
It will be further appreciated by those of ordinary skill in the art that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application. The software modules may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The above-mentioned embodiments, objects, technical solutions and advantages of the present application are described in further detail, it should be understood that the above-mentioned embodiments are merely exemplary embodiments of the present application, and are not intended to limit the scope of the present application, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present application should be included in the scope of the present application.