Nothing Special   »   [go: up one dir, main page]

CN113468132B - Method and device for carrying out capacity reduction on fragments in block chain system - Google Patents

Method and device for carrying out capacity reduction on fragments in block chain system Download PDF

Info

Publication number
CN113468132B
CN113468132B CN202111019552.3A CN202111019552A CN113468132B CN 113468132 B CN113468132 B CN 113468132B CN 202111019552 A CN202111019552 A CN 202111019552A CN 113468132 B CN113468132 B CN 113468132B
Authority
CN
China
Prior art keywords
node
state
target contract
fragment
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111019552.3A
Other languages
Chinese (zh)
Other versions
CN113468132A (en
Inventor
郑子彬
徐泉清
郑沛霖
闫莺
张辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ant Blockchain Technology Shanghai Co Ltd
Original Assignee
Alipay Hangzhou Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alipay Hangzhou Information Technology Co Ltd filed Critical Alipay Hangzhou Information Technology Co Ltd
Priority to CN202111019552.3A priority Critical patent/CN113468132B/en
Publication of CN113468132A publication Critical patent/CN113468132A/en
Application granted granted Critical
Publication of CN113468132B publication Critical patent/CN113468132B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/174Redundancy elimination performed by the file system
    • G06F16/1744Redundancy elimination performed by the file system using compression, e.g. sparse files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/182Distributed file systems

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present specification provides a method and an apparatus for capacity reduction of 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 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. Therefore, the automatic capacity reduction of the blockchain system is realized, and the problem that the number of the fragments in the blockchain system cannot be reduced dynamically along with the reduction of the transaction number is solved.

Description

Method and device for carrying out capacity reduction on fragments in block chain system
Technical Field
One or more embodiments of the present disclosure relate to the field of blockchain technologies, and in particular, to a method and an apparatus for performing capacity reduction on slices in a blockchain system.
Background
The Blockchain (Blockchain) is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. The block chain is a chain data structure formed by combining data blocks in a sequential connection mode according to a time sequence, and is a distributed account book which is guaranteed in a cryptographic mode and cannot be tampered and forged. Because the blockchain has the characteristics of decentralization, information non-tampering, autonomy and the like, the blockchain is also paid more and more attention and is applied by people.
One of the most important factors that currently limit the large-scale application of blockchain technology is performance, which mainly includes throughput, which can be generally measured by Transaction Per Second (TPS). Developers have proposed various schemes to try to increase the throughput of blocks, a process known as "capacity expansion". The block chain fragmentation technology is a scheme for expanding a block chain. The basic idea of blockchain fragmentation is to divide nodes in a blockchain network into a plurality of relatively independent sub-networks, each sub-network forming a blockchain, i.e. a sub-network, i.e. a shard (shard). Through the parallel processing of a plurality of fragments, the throughput of the whole network can be improved.
At present, the number of fragments in the blockchain system is often not changed, and therefore, when the traffic flow on the blockchain is low, the whole system needs to be shut down and manually reduced, and the availability of the system is reduced. Therefore, there is a need for an automatic capacity reduction method for blockchain fragmentation.
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.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIGS. 1 a-1 c are block chain system architecture diagrams shown in accordance with an exemplary embodiment of the present description;
FIG. 2 is an interactive flow diagram illustrating a method for capacity reduction of tiles in a blockchain system in accordance with an exemplary embodiment of the present specification;
FIG. 3 is a schematic diagram of an intelligent contract shown in accordance with an exemplary embodiment of the present description;
FIG. 4 is a block diagram illustrating an apparatus for capacity reduction of tiles in a blockchain system in accordance with an exemplary embodiment;
fig. 5 is a block diagram illustrating another apparatus for capacity reduction of tiles in a blockchain system according to an example embodiment.
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.

Claims (18)

1. A method for carrying out capacity reduction on fragments in a blockchain system comprises a first fragment and a second fragment, wherein the first fragment comprises a first node, and the second fragment comprises 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.
2. The method of claim 1, wherein the obtaining the target contract state in the first slice comprises:
and acquiring the state of the target contract by using a state output function included in the target contract.
3. The method of claim 2, wherein the state output function is a function set for one data type.
4. The method of claim 2, wherein prior to said obtaining the target contract state using the state output function included in the target contract, further comprising:
the target contract is determined based on a contract address stored when the contract is deployed.
5. The method of claim 2, wherein the obtaining the target contract state using the state output function included in the target contract comprises:
inputting a plurality of groups of first parameters into the state output function respectively; any set of the first parameters corresponds to a variable involved in the target contract;
acquiring the target contract state output by the state output function; the target contract state includes respective state values corresponding to respective ones of a plurality of variables involved in the target contract.
6. The method of claim 1, wherein the blockchain system comprises a plurality of member parties, each member party comprising a respective central device and a plurality of sharded partial sharded nodes; the first node and the second node belong to a first member of the plurality of members; the first member side comprises a first central device;
wherein the receiving a capacity reduction request comprises: a capacity reduction request is received from the first central device.
7. A method for carrying out capacity reduction on fragments in a blockchain system comprises a first fragment and a second fragment, wherein the first fragment comprises a first node, and the second fragment comprises 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.
8. The method of claim 7, wherein the target contract state is obtained by the first node using a state output function included in the target contract;
wherein the merging the target contract state into the world state of the second shard comprises:
merging the target contract state into the world state of the second shard by using a state input function included by the target contract; the state input function corresponds to the state output function.
9. The method of claim 8, wherein the state output function and the state input function are functions set for one data type.
10. The method of claim 8, wherein the merging the target contract state into the world state of the second shard using a state input function included in the target contract comprises:
determining a plurality of sets of second parameters based on the target contract state; any set of the second parameters comprises a state value corresponding to a variable related to 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 shard.
11. A method for carrying out capacity reduction on fragments in a blockchain system comprises a first fragment and a second fragment, wherein the first fragment comprises a first node, and the second fragment comprises 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;
the block chain system comprises a plurality of member parties, wherein each member party comprises a respective central device and a plurality of fragmented partial fragmentation nodes; the first node and the second node belong to a first member of the plurality of members; the first member side comprises a first central device;
wherein the first node receives a capacity reduction request, comprising: the first node receives a capacity reduction request from the first central equipment;
wherein the method further comprises: the first central equipment sends a capacity reduction request to the first node when determining that a preset condition is met;
wherein the preset conditions include: the number of fragments included in the current block chain system is larger than the number of target fragments; the target number of slices is determined based on a total number of transactions performed by the blockchain system within a preset time period.
12. The method of claim 11, wherein the target number of slices is positively correlated with a target ratio, and the target ratio is a ratio of the total number of transactions to a preset number of transactions.
13. The method of claim 11, further comprising:
and the first central equipment stops sending the transaction of the modified state to the first node after sending the capacity reduction request to the first node.
14. The method of claim 11, further comprising:
after merging the target contract state into the world state of the second segment, the second node sends indication information for indicating that the capacity reduction operation is completed to the first central equipment;
and the first central equipment disconnects the connection with the first node in response to receiving the indication information so as to revoke the first fragment.
15. A device for carrying out capacity reduction on fragments in a blockchain system, wherein the blockchain system comprises a first fragment and a second fragment, the first fragment comprises a first node, and the second fragment comprises 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.
16. A device for carrying out capacity reduction on fragments in a blockchain system, wherein the blockchain system comprises a first fragment and a second fragment, the first fragment comprises a first node, and the second fragment comprises 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.
17. A computer-readable storage medium, having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method of any one of claims 1-10.
18. A computing device comprising a memory having executable code stored therein and a processor that, when executing the executable code, implements the method of any of claims 1-10.
CN202111019552.3A 2021-09-01 2021-09-01 Method and device for carrying out capacity reduction on fragments in block chain system Active CN113468132B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111019552.3A CN113468132B (en) 2021-09-01 2021-09-01 Method and device for carrying out capacity reduction on fragments in block chain system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111019552.3A CN113468132B (en) 2021-09-01 2021-09-01 Method and device for carrying out capacity reduction on fragments in block chain system

Publications (2)

Publication Number Publication Date
CN113468132A CN113468132A (en) 2021-10-01
CN113468132B true CN113468132B (en) 2021-12-21

Family

ID=77867107

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111019552.3A Active CN113468132B (en) 2021-09-01 2021-09-01 Method and device for carrying out capacity reduction on fragments in block chain system

Country Status (1)

Country Link
CN (1) CN113468132B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112260836A (en) * 2020-09-28 2021-01-22 电子科技大学 Method for improving block chain throughput based on fragmentation technology
CN112615905A (en) * 2020-12-03 2021-04-06 广州智链未来科技有限公司 Method, device and equipment for scheduling block chain fragments and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101544356B1 (en) * 2012-10-31 2015-08-13 삼성에스디에스 주식회사 Distributed database managing method and composition node thereof supporting dynamic sharding based on the metadata and data transaction quantity

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112260836A (en) * 2020-09-28 2021-01-22 电子科技大学 Method for improving block chain throughput based on fragmentation technology
CN112615905A (en) * 2020-12-03 2021-04-06 广州智链未来科技有限公司 Method, device and equipment for scheduling block chain fragments and storage medium

Also Published As

Publication number Publication date
CN113468132A (en) 2021-10-01

Similar Documents

Publication Publication Date Title
CN109639521B (en) Block chain performance testing method, device, equipment and storage medium
Etemad et al. Transparent, distributed, and replicated dynamic provable data possession
CN109189751A (en) Method of data synchronization and terminal device based on block chain
CN111008201B (en) Method and apparatus for parallel modification and reading of state trees
CN111061769A (en) Consensus method of block chain system and related equipment
CN111625593A (en) Data processing method and device based on block chain and computer equipment
JPH03139936A (en) Path selection method
CN112835977B (en) Database management method and system based on block chain
Tennakoon et al. Dynamic blockchain sharding
US20230367749A1 (en) Data migration method and apparatus, device, medium, and computer product
CN111399991B (en) Virtual resource locking method and device, storage medium and electronic device
CN113259478B (en) Method and device for executing transaction in blockchain system and blockchain system
CN113254538B (en) Method for executing transaction in block chain and block chain link point
CN112650812A (en) Data fragment storage method and device, computer equipment and storage medium
CN113157450B (en) Method and apparatus for executing blocks in a blockchain system
CN110597922A (en) Data processing method, device, terminal and storage medium
CN113064764A (en) Method and apparatus for performing blocks in a blockchain system
CN113468132B (en) Method and device for carrying out capacity reduction on fragments in block chain system
CN113468200B (en) Method and device for expanding fragments in block chain system
CN117348804A (en) Hierarchical storage method, hierarchical storage system and hierarchical storage medium for digital networking supervision system
Liu et al. OverlapShard: Overlap-based sharding mechanism
CN116303418A (en) Mass rule processing method, system and storage medium based on Internet of things platform
CN112001800B (en) Method and device for processing business in block chain system
CN108388658A (en) Data file reliable storage method
CN110677497B (en) Network medium distribution method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20220422

Address after: 310000 801-11 section B, 8th floor, 556 Xixi Road, Xihu District, Hangzhou City, Zhejiang Province

Patentee after: Alipay (Hangzhou) Information Technology Co.,Ltd.

Patentee after: Ant blockchain Technology (Shanghai) Co.,Ltd.

Address before: 310000 801-11 section B, 8th floor, 556 Xixi Road, Xihu District, Hangzhou City, Zhejiang Province

Patentee before: Alipay (Hangzhou) Information Technology Co.,Ltd.

TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20240923

Address after: Room 803, floor 8, No. 618 Wai Road, Huangpu District, Shanghai 200010

Patentee after: Ant blockchain Technology (Shanghai) Co.,Ltd.

Country or region after: China

Address before: 310000 801-11 section B, 8th floor, 556 Xixi Road, Xihu District, Hangzhou City, Zhejiang Province

Patentee before: Alipay (Hangzhou) Information Technology Co.,Ltd.

Country or region before: China

Patentee before: Ant blockchain Technology (Shanghai) Co.,Ltd.

TR01 Transfer of patent right