Transaction method and system of fragmented block chain based on master-slave mode
By introducing a shard structure of master-slave mode into the blockchain, dynamically managing the slave chain, the problems of node congestion and slow cross-chip transactions are solved, and efficient transaction processing and scalability are achieved.
Patent Information
- Application Number
- CN202411226689.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2024-11-08
AI Technical Summary
The existing blockchain sharding method can easily lead to node congestion and slow cross-chip transactions, and it is difficult to effectively improve the scalability of blockchain.
Using the sharded blockchain transaction method and system based on the master-slave mode, the nodes in the blockchain are divided into master chain, slave chain and shard chain, and the transaction processing unit is realized through vertical state channels and horizontal hash time lock connections. The distribution and cross-chip transaction processing, decoupling transaction processing functions, and dynamically generate or destroy slave chains to optimize resource utilization.
It realizes transaction processing with low latency and high success rate, significantly improves cross-chip transaction speed, reduces the processing pressure of the original shard chain, and improves the scalability of the blockchain.
Smart Images

Figure CN118917847A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to a transaction method and system for a sharded blockchain based on a master-slave mode. Background Art
[0002] Blockchain is a decentralized distributed ledger that is tamper-proof, secure and reliable. Starting from the early days of the Bitcoin network, blockchain has gradually evolved into a global technology. The characteristics of blockchain include decentralization, immutability, transparency, security and programmability. Each data block is linked to the previous block to form a continuous chain, ensuring the integrity of the transaction history. Subsequently, the emergence of a new generation of blockchain platforms such as Ethereum has further expanded the application field. The smart contract technology used by new platforms such as Ethereum makes blockchain programmable and supports a wider range of applications. Therefore, blockchain has been unprecedentedly widely used in finance, supply chain, medical care, real estate and other fields, making blockchain a powerful tool to change traditional business and social models.
[0003] The dilemma between the three key elements of decentralization, security and scalability faced in the design and implementation of blockchain technology and systems. In order to solve the above problems, blockchain sharding technology is a solution for expanding the capacity of blockchain. The basic idea of blockchain sharding is to divide the nodes in the blockchain network into several relatively independent sub-networks, each of which constitutes a blockchain, and a sub-network is a shard. Through the parallel processing of multiple shards, the throughput of the entire network can be improved. However, the existing sharding method still has major problems, which can easily cause node congestion and slow cross-shard transactions. Summary of the invention
[0004] The embodiments of this specification provide a transaction method and system for a sharded blockchain based on a master-slave mode, which divides each shard data in the blockchain into a master chain, a slave chain, and a shard chain. A master chain, at least one slave chain, and a shard chain are connected in the vertical direction through a state channel to form a sharded transaction processing unit. In the horizontal direction, the master chain and / or slave chain corresponding to the sharded transaction processing units of the sender and the receiver are connected through a hash time lock to perform transaction processing.
[0005] In some embodiments, a transaction method of a sharded blockchain based on a master-slave mode is provided, including:
[0006] Get a pending transaction based on the transaction list of the blockchain;
[0007] By randomly selecting a sharding function, the to-be-processed transaction is randomly assigned to a sharding module, wherein the sharding module is composed of at least one sharding transaction processing unit;
[0008] Determine whether the sender address and the receiver address corresponding to the transaction to be processed belong to the same shard transaction processing unit;
[0009] In response to the same shard transaction processing unit, executing the vertical transaction method;
[0010] In response to the transaction processing unit not being the same shard, a horizontal cross-shard transaction method is executed.
[0011] In some embodiments, a sharded blockchain matrix based on a master-slave mode is provided, including: dividing each node in the blockchain into a master chain, a slave chain, and a shard chain; connecting a master chain, at least one slave chain, and a shard chain through a state channel in the vertical direction to form a sharded transaction processing unit; and connecting the master chain and / or slave chain corresponding to the respective sharded transaction processing units of the sender and the receiver in the horizontal direction through a hash time lock.
[0012] In some embodiments, the sharded blockchain matrix based on the master-slave mode provided in this specification also includes: the master chain is used for data backup, coordinating the various transaction tasks in the transaction list, and calculating and compressing the pending transactions; the slave chain is used to assist the master chain in data processing, execute transactions within the task cycle of the pending transactions, and return the master chain processing results after execution. Furthermore, the slave chain can be dynamically generated or destroyed according to the transaction processing status of the master chain.
[0013] In some embodiments, a transaction system of a sharded blockchain matrix based on a master-slave mode is provided, characterized in that it includes:
[0014] The transaction acquisition module is used to obtain a pending transaction based on the transaction list of the blockchain;
[0015] A random sharding module, used to randomly assign the to-be-processed transaction to a sharding module by randomly selecting a sharding function, wherein the sharding module is composed of at least one sharding transaction processing unit;
[0016] Data judgment module: used to judge whether the sender address and the receiver address corresponding to the transaction to be processed belong to the same shard transaction processing unit;
[0017] A first transaction processing module, configured to execute a vertical transaction method in response to the same shard transaction processing unit;
[0018] The second transaction processing module is used to execute a horizontal cross-shard transaction method in response to a transaction processing unit that is not in the same shard.
[0019] One of the embodiments of this specification provides a computer-readable storage medium, which stores computer instructions. When a computer reads the computer instructions in the storage medium, the computer executes a transaction method based on a sharded blockchain matrix in a master-slave mode.
[0020] The transaction method and system of the sharded blockchain based on the master-slave mode provided by the present invention can achieve the following beneficial effects:
[0021] (1) While retaining the consensus authentication / validator management functions of the existing blockchain main chain and beacon chain, the task coordination and transaction processing functions are decoupled and handled separately by the master / slave chain. Each part performs its own duties and performs task coordination, thereby achieving the effect of low latency and low transaction failure rate;
[0022] (2) In the decoupled horizontal structure, the cross-shard transaction tasks are undertaken through the hash time lock technology, which reduces the bloated cross-shard task processing mechanism of the original shard chain and greatly improves the cross-shard transaction speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] This specification will be further described in the form of exemplary embodiments, which will be described in detail by the accompanying drawings. These embodiments are not restrictive, and in these embodiments, the same number represents the same structure, wherein:
[0024] Figure 1 It is an exemplary structural diagram of a sharded blockchain matrix based on a master-slave mode according to some embodiments of this specification;
[0025] Figure 2 is an exemplary flow chart of a transaction method of a sharded blockchain matrix based on a master-slave mode according to some embodiments of this specification;
[0026] Figure 3 It is an exemplary structural diagram in the vertical direction of a sharded blockchain matrix based on a master-slave mode as shown in some embodiments of this specification;
[0027] Figure 4 is an exemplary flow chart of a method for executing horizontal cross-shard transactions based on a sharded blockchain matrix in a master-slave mode according to some embodiments of this specification;
[0028] Figure 5 It is an exemplary structural diagram of horizontal cross-shard transactions in a sharded blockchain matrix based on a master-slave mode according to some embodiments of this specification;
[0029] Figure 6 This is an exemplary module diagram of a transaction system of a sharded blockchain matrix based on a master-slave mode as shown in some embodiments of this specification. DETAILED DESCRIPTION
[0030] In order to more clearly illustrate the technical solutions of the embodiments of this specification, the following is a brief introduction to the drawings required for the description of the embodiments. Obviously, the drawings described below are only some examples or embodiments of this specification. For ordinary technicians in this field, this specification can also be applied to other similar scenarios based on these drawings without creative work. Unless it is obvious from the language environment or otherwise explained, the same reference numerals in the figures represent the same structure or operation.
[0031] It should be understood that the "system", "device", "unit" and / or "module" used herein are a method for distinguishing different components, elements, parts, portions or assemblies at different levels. However, if other words can achieve the same purpose, the words can be replaced by other expressions.
[0032] As shown in this specification and claims, unless the context clearly indicates an exception, the words "a", "an", "an" and / or "the" do not refer to the singular and may also include the plural. Generally speaking, the terms "comprise" and "include" only indicate the inclusion of the steps and elements that have been clearly identified, and these steps and elements do not constitute an exclusive list. The method or device may also include other steps or elements.
[0033] Flowcharts are used in this specification to illustrate the operations performed by the system according to the embodiments of this specification. It should be understood that the preceding or following operations are not necessarily performed precisely in order. Instead, the steps may be processed in reverse order or simultaneously. At the same time, other operations may also be added to these processes, or one or more operations may be removed from these processes.
[0034] The dilemma between the three key elements of decentralization, security and scalability faced in the design and implementation of blockchain technology and systems. Blockchain sharding technology is a solution for expanding the capacity of blockchain. The core idea of blockchain sharding is divide and conquer, dividing all nodes in the blockchain network into different groups, each of which is called a shard. Originally, all nodes in the public chain performed the same tasks, but now tasks are assigned to different shards, each shard handles different tasks, and shards are processed in parallel to improve blockchain performance.
[0035] Taking Ethereum as an example, in order to solve problems such as Ethereum transaction node congestion / low scalability / slow cross-shard transactions, the Ethereum community has proposed a series of candidate upgrade plans to improve the performance and sustainability of the Ethereum network. According to the technical route, Ethereum's expansion plan is divided into on-chain expansion (Layer 1) and off-chain expansion (Layer 2), among which sharding is one of the on-chain expansion solutions.
[0036] Figure 1 It is an exemplary structural diagram of a sharded blockchain matrix based on a master-slave mode as shown in some embodiments of this specification. The present invention provides a sharded blockchain matrix based on a master-slave mode, including: dividing each node in the blockchain into a master chain, a slave chain and a shard chain; connecting a master chain, at least one slave chain and a shard chain through a state channel in the vertical direction to form a sharded transaction processing unit; connecting the master chain and / or slave chain corresponding to the sharded transaction processing unit of the sender and the receiver in the horizontal direction through a hash time lock.
[0037] In some embodiments, the sharded blockchain matrix based on the master-slave mode provided in this specification also includes: the master chain is used for data backup, coordinating the various transaction tasks in the transaction list, and calculating and compressing the pending transactions; the slave chain is used to assist the master chain in data processing, execute transactions within the task cycle of the pending transactions, and return the master chain processing results after execution. Furthermore, the slave chain can be dynamically generated or destroyed according to the transaction processing status of the master chain.
[0038] In some embodiments, slave chains can be dynamically generated or destroyed according to data conditions, and multiple layers of sub-slave chains can be regenerated.
[0039] Dynamic generation: When the master chain is processing transactions, the system will monitor the transactions queued in the shard queue and the status of the validator nodes in real time. When transaction congestion occurs and the master chain processing load exceeds the threshold, the system dynamically generates a slave chain anchored to the master chain to divert traffic and give priority to delivering complex transactions in the queue to the slave chain for processing.
[0040] Dynamic destruction: The system monitors the transactions queued in the shard queue and the status of the validator node in real time. When the slave chain load is in a low operation or even idling state for a long time, that is, the transaction queue is loose and the resource utilization rate is low, the system dynamically destroys the slave chain to save overall system resources and speed up the processing efficiency of the master chain.
[0041] Generate multi-layer slave chains: Ethereum EVM has three areas where data can be stored: storage, memory, and stack. Each account has a storage data area, which is persistent between function calls and transactions. Since it is impossible to list storage from a smart contract, the reading cost is high, and the cost of initializing and modifying storage is even higher. Due to this cost, the present invention reduces the content stored in persistent storage to the amount required for contract operation, and stores data such as derived calculations, caches, and aggregations outside the contract. Based on this cost consideration, the slave chain is designed to efficiently process complex calculations without having a complete master function. It only needs data and state anchored to the previous level. Therefore, if hardware resources and scheduling allow, it can be logically constructed: master<——(anchored) slave1<——(anchored) slave2<——(anchored) slave3 chain parallel structure, so that complex calculations are processed in batches, layers, and recursively, and delivered to chains at different levels for rapid processing, greatly improving the overall system's ability to process complex transactions.
[0042] Through the master-slave mode-based sharded blockchain matrix provided by the present invention, on the basis of retaining the consensus authentication / verifier management functions of the existing blockchain main chain and beacon chain, its task coordination and transaction processing functions are decoupled and processed separately by the master / slave chain. In the transaction processing process, each part performs its duties and performs task coordination, thereby reducing the delay of the transaction process and improving the success rate of the transaction.
[0043] It should be understood that the sharded transaction matrix structure proposed in the present invention can be applied to different types of blockchains such as consortium chains, public chains, private chains, etc. with similar underlying operating structures, and can be actually used in scenarios such as banking, securities, stock markets, judicial evidence, and Internet data collaboration.
[0044] Figure 2 is an exemplary flow chart of a transaction method of a sharded blockchain matrix based on a master-slave mode according to some embodiments of this specification, such as Figure 1 As shown, the process includes the following steps.
[0045] S201, obtaining a pending transaction based on the transaction list of the blockchain, wherein the pending transaction includes a sender address, a receiver address and transaction details.
[0046] In some embodiments, the transaction list of the blockchain includes at least one transaction, wherein the transaction data of each transaction includes the sender address, the receiver address and the transaction details, wherein the transaction details may include data information such as the transaction currency amount and the transaction time. A pending transaction is a transaction that is currently being processed by the system.
[0047] S202, randomly assigning the to-be-processed transactions to a sharding module by randomly selecting a sharding function, where the sharding module is composed of at least one sharding transaction processing unit.
[0048] In some embodiments, the random sharding function can generate a random sharding address and randomly assign a sharding address to each transaction to be processed. The random sharding function can be any random assignment function.
[0049] S203, determine whether the sender address and the receiver address corresponding to the transaction to be processed belong to the same shard transaction processing unit.
[0050] S204, in response to the same shard transaction processing unit, execute the vertical transaction method.
[0051] Figure 3 This is an exemplary structural diagram in the vertical direction of a sharded blockchain matrix based on the master-slave mode as shown in some embodiments of this specification.
[0052] In some embodiments, the vertical transaction method may include the following steps:
[0053] like Figure 3 As shown, the shard transaction processing unit corresponding to the pending transaction may include a master chain, create a state channel according to the address tag and task cycle in the pending transaction, perform data processing through the master chain and generate at least one slave chain, wherein the master chain and the slave chain are composed of at least one node in the blockchain. Through the slave chain, the task content of the pending transaction is calculated and processed, and the calculation result is returned to the master chain; the master chain sends the calculation result to the shard chain and the beacon chain main chain for verification, and completes the pending transaction.
[0054] In some embodiments, the master chain is responsible for the main computing / transaction compression / task coordination / data backup tasks, and creates a state channel based on factors such as address tags (such as exchange hot and cold wallets / payment institution periodic settlement addresses) and task cycles (such as setting up a one-week contract signing / transaction settlement validity period).
[0055] In some embodiments, the state channel allows two or more participants to interact multiple times off-chain without publishing each transaction on-chain. Only when the channel is closed will the final state be submitted to the Ethereum main chain. In terms of vertical design, data transmission is achieved through batch compression.
[0056] In some embodiments, after the master creates the state channel, a slave chain parallel to the master chain is generated for transaction execution within the task cycle. Among them, the slave chain can regenerate multiple layers of sub-slave chains to chain in parallel (child's child walking side by side). The actual principle is that the slave chain is only responsible for data calculation and contract execution, so complex transaction calculations can be delivered to slave chains at different levels in batches / layers / recursion, etc. After the execution is completed, the master chain calculation results are returned, and the slave chain is destroyed after the transaction cycle ends / status expires to save storage space, that is, the shard chain and the master chain exist persistently, and the slave chain is dynamically generated (multiple sub-chains are serialized) or destroyed (Blob data is deleted approximately every two weeks) according to the data situation.
[0057] In some embodiments, in the vertical processing method, the Master chain is only responsible for task coordination and result aggregation, the slave chain is responsible for calculating and processing transaction data, and the core data verification is still implemented by the shard segment and the basic beacon chain / Ethereum main chain. The shard segment is responsible for the verification of data types such as State Root state root, Tx Data transaction data, and ZK proof validity proof, so as to ensure data availability and state validity.
[0058] S105, in response to the case where the transaction processing units are not in the same shard, executing a horizontal cross-shard transaction method.
[0059] Figure 5 This is an exemplary structural diagram of horizontal cross-shard transactions in a sharded blockchain matrix based on a master-slave mode as shown in some embodiments of this specification. In some embodiments, not being the same sharded transaction processing unit means that the sender address and the receiver address do not belong to the same sharded transaction processing unit, which may include two specific situations:
[0060] (1) The transfer sending account A is in shard #1, and the receiving account B is in shard #2 or other shards.
[0061] (2) The transfer receiving account A is in shard #1, and the transfer sending account B is in shard #2 or other shards.
[0062] Figure 4 This is an exemplary flow chart of a method for executing horizontal cross-shard transactions based on a sharded blockchain matrix in a master-slave mode as shown in some embodiments of this specification.
[0063] In some embodiments, a horizontal cross-chip transaction method includes the following steps:
[0064] S401, determining whether the transaction to be processed is a simple transaction, and determining that it is a simple transaction when the transaction details of the transaction to be processed meet a preset threshold.
[0065] In some embodiments, the master chain makes decisions on the transaction details of pending transactions, and determines pending transactions with small data volume and high transaction fees as simple transactions, and pending transactions with large data volume and low transaction fees, and long-term suspension due to lack of transaction counterparties, as not simple transactions.
[0066] In some embodiments, the preset threshold for determining a pending transaction as a simple transaction is dynamically adjusted, and is dynamically calculated by the system provided by the present invention based on the real-time transaction status of the blockchain, including the transaction quantity and transaction fees.
[0067] Specifically, the preset threshold for determining a simple transaction may include the system's transaction fee threshold, and its dynamic calculation parameters may include: base fee (Base Fee), maximum priority fee (Max Priority Fee), and maximum fee per unit of Gas (Max Fee Per Gas).
[0068] Among them, the basic fee aims to keep the block complete at 50%, and automatically increases or decreases based on the content of the most recently confirmed block. For example, if the previous block is exactly 50% complete, then the basic fee will remain unchanged; if the previous block is a complete block (100%), then the basic fee of the next block will increase by up to 12.5%. The maximum priority fee is an "optional" additional fee that is added to make the transaction attractive to validators so that they choose to include it in the next block. The maximum fee per unit of Gas is the highest absolute value that the user is willing to pay per unit of Gas fee to have the transaction included in the block.
[0069] The setting and calculation of these fees ensures the smooth progress of transactions, while also providing incentives for validators and promoting the healthy operation and security of the network. For example, if the basic fee of a complete block is synchronized with the previous block, the transaction user sets the maximum priority fee to 0, and the maximum fee per unit of Gas is set to medium, then the dynamic threshold determines that the transaction fee is low. This mechanism is designed to help smooth transaction fees and prevent sudden spikes in transaction fees.
[0070] Specifically, the preset threshold for determining simple transactions may also include the system's data volume threshold. The system complexity needs to be considered in the calculation of the data volume threshold. For example, it can be fixedly set to a maximum of 8kb of data for a transaction. Less than 2kb is low data volume, greater than 2 and less than 4 is medium, and greater than 4 and less than 8 is high.
[0071] S402: In response to the transaction to be processed being a simple transaction, executing a first horizontal cross-chip transaction method.
[0072] In some embodiments, a first horizontal cross-chip transaction method includes:
[0073] The shard transaction processing unit corresponding to the sender of the transaction to be processed includes a master chain A, and the shard transaction processing unit corresponding to the receiver includes a master chain B. The master chain A and the master chain B are connected in the horizontal direction through a hash time lock.
[0074] The transaction data to be processed is calculated by the master chain B, and the result is fed back to the master chain A.
[0075] The master chain A sends the calculation results to the shard chain and the beacon chain main chain for verification to complete the pending transaction.
[0076] In some embodiments, Hash Time Lock Contracts (HTLC) lock assets based on smart contracts and enter the original value of the correct hash value within a limited time to complete the transaction. HTLC has the mechanism of "time limit" and "enforcement of transaction", which makes it impossible for the parties to the transaction to privately interrupt the contract transaction after the contract is signed, thereby building a secure network for fast payment, which can effectively solve the problem of cross-chain, cross-chip or transactions on different networks, and also makes multi-party payment and smart contracts possible, which can bring greater security and reliability to both parties at a lower cost.
[0077] S403: In response to the transaction to be processed not being a simple transaction, executing a second horizontal cross-chip transaction method.
[0078] In some embodiments, the second horizontal cross-chip transaction method includes:
[0079] The shard transaction processing unit corresponding to the sender of the pending transaction includes a master chain A and a corresponding slave chain A, and the shard transaction processing unit corresponding to the receiver includes a master chain C and a corresponding slave chain C, and the pending transaction is assigned to the slave chain A;
[0080] Based on the processing result of slave chain A, the transaction data to be processed is sent horizontally to the slave chain C of the corresponding shard of the receiver through a hash time lock;
[0081] Send the processing result of slave chain C to the master chain C of the corresponding shard of the receiver;
[0082] Based on the confirmation result of the master chain C, the transaction result is fed back to the slave chain A through the slave chain C and then fed back to the master chain A;
[0083] Master chain A sends the calculation results to the shard chain and beacon chain main chain for verification to complete the pending transaction.
[0084] In some embodiments, the master chain undertakes the main computing / transaction compression / task coordination / data backup tasks, and the slave chain is used to execute transactions within the task cycle, and returns the master chain calculation results after the execution is completed. Therefore, when the system recognizes transactions of entities other than the current shard, it coordinates tasks through the master chain and assigns tasks to the slave chain for transaction calculation. The slave chain breaks through the shard isolation through the hash time lock mechanism and completes cross-shard transactions.
[0085] The sharded blockchain matrix provided by the present invention adopts a horizontal and vertical matrix structure, which decouples the transaction processing function originally belonging to the shard chain and strips it to the master / slave chain. The shard chain is only responsible for packaging transaction groups and verifying the results returned by the master chain. The master / slave chain is actually responsible for transaction coordination and calculation. Each is responsible for processing and summarizing its own tasks. Therefore, the constructed MS2 matrix can greatly improve the overall transaction processing speed and solve the cross-shard transaction problem.
[0086] The consensus verification mechanism between Ethereum shards mainly relies on the coordination verification function of the beacon chain and the consensus mechanism of POS proof of equity. This combined mechanism is designed to ensure that the state of each shard chain can be consistent with the entire network and achieve global consensus among all shard chains. Since the decoupled architecture system of the present invention does not change the existing shard structure, the underlying POS consensus verification mechanism is still responsible for the original beacon chain, which mainly processes blocks and proofs, runs the fork selection algorithm, and manages rewards and penalties. The beacon chain is the core component of Ethereum 2.0 and plays the role of coordinating the entire network, including managing and coordinating the PoS verification process, the consensus of the shard chain, and the management / rotation of validators, block proposals and verification. Its operation is based on the concepts of epochs and slots: Slots: Every 12 seconds is a slot, and a slot represents a time slice in the beacon chain. Usually, a block is proposed and verified in each slot. Epoch: Every 32 slots constitute a cycle, and the cycle is the basic unit for validator status updates and shard chain status confirmation. In this way, the beacon chain can efficiently manage and coordinate the PoS validation of the entire Ethereum 2.0 network and ensure the security and stability of the network. At the same time, the combination of the PoS validation mechanism and the beacon chain, through the staking and verification process, also provides an efficient and low-energy consensus method, which ensures the security and decentralization of the Ethereum network through economic incentives and penalty mechanisms, while providing fair opportunities for validators in the shard chain to participate in block generation.
[0087] It should be noted that the above description of the relevant process is only for example and explanation, and does not limit the scope of application of this specification. For those skilled in the art, various modifications and changes can be made to the process under the guidance of this specification. However, these modifications and changes are still within the scope of this specification.
[0088] Figure 6 This is an exemplary module diagram of a transaction system of a sharded blockchain matrix based on a master-slave mode according to some embodiments of this specification.
[0089] In some embodiments, a transaction system based on a sharded blockchain matrix in a master-slave mode includes:
[0090] The transaction acquisition module 610 is used to acquire a pending transaction based on the transaction list of the blockchain;
[0091] A random sharding module 620, configured to randomly assign the to-be-processed transaction to a sharding module by randomly selecting a sharding function, wherein the sharding module is composed of at least one sharding transaction processing unit;
[0092] Data judgment module 630: used to judge whether the sender address and the receiver address corresponding to the transaction to be processed belong to the same shard transaction processing unit;
[0093] A first transaction processing module 640, configured to execute a vertical transaction method in response to the same shard transaction processing unit;
[0094] The second transaction processing module 650 is used to execute a horizontal cross-shard transaction method in response to a transaction processing unit that is not in the same shard.
[0095] In some embodiments, the present invention also provides a computer-readable storage medium, which stores computer instructions. When the computer reads the computer instructions in the storage medium, the computer executes the transaction method of the sharded blockchain matrix based on the master-slave mode as described above.
[0096] This embodiment provides a process for configuring vertical transactions and horizontal cross-shard transactions in a sharded blockchain structure based on a master-slave mode through a computer.
[0097] In some embodiments, the configuration process in the vertical direction includes:
[0098] 1. Define constants NUM_SHARDS=64: defines the number of shards. NUM_TRANSACTIONS=1000: defines the number of transactions to be processed.
[0099] 2. Initialize the slice array Create an array shards containing NUM_SHARDS empty lists to store transactions in each shard. 3. Randomly select shard ID function Function A: used to generate a random shard ID between 0 and NUM_SHARDS-1. 4. Allocate transactions to shards and synchronize to the master for coordination Function B: accepts Ethereum as input. For each transaction, call the function that randomly selects a shard ID to get a shard ID. Assign the transaction to the corresponding shard (that is, add the transaction to the corresponding shards[shardId] list). The master determines the content and status of the transaction group and coordinates tasks After all transactions are assigned, the updated shards array is returned.
[0100] 5. Main function Create an empty transaction list transactions. Generate NUM_TRANSACTIONS sample transactions through a loop and add these transaction objects to the transactions list. Call the function that allocates transactions to shards and synchronizes to the master, and allocate the generated transaction list to the shards. Finally, output the number of transactions in each shard through a loop. Calling the main function
[0101] 6. Execute the main function to complete the entire transaction allocation process.
[0102] In some embodiments, the configuration process in the horizontal direction includes:
[0103] 1. Define the HTLC structure Define the HTLC structure: used to store cross-shard transaction information, including sender, receiver, locked ETH amount, hash lock, time lock, whether it has been received, whether it has been refunded, etc.
[0104] 2.Store HTLC information Use mapping (byte32=>HTLC) to store each HTLC transaction, and the key value of the mapping is the unique identifier of the HTLC (htlcId).
[0105] 3. Cross-shard communication events Define the event CrossShardTransfer to notify the target shard of cross-shard transaction information.
[0106] 4. Create HTLC Input: receiver address _receiver, hash lock _hashLock, time lock _timeLock and transaction amount (via msg.value). Checks if the transaction amount is greater than zero. Generate a unique htlcId to ensure that the HTLC corresponding to the ID is not created repeatedly. Store HTLC information (including sender, receiver, amount, hash lock, time lock, etc.). Trigger a cross-shard communication event and send the HTLC information to the target shard.
[0107] 5. Process cross-shard communication message input: HTLC’s unique identifier _htlcId, recipient address _receiver, amount _amount, hash lock _hashLock, and time lock _timeLock. Store the corresponding HTLC information on the target shard (no need to store the sender information of the source shard).
[0108] 6. The recipient receives the funds input: the HTLC’s unique identifier _htlcId and preimage _preimage. Checks if the caller is the receiver. Checks if the HTLC has been claimed or refunded. Checks whether the time lock has expired. Verify that the preimage matches the hash lock. If the above checks pass, the funds are transferred to the recipient and the HTLC is marked as claimed.
[0109] 7. Refund by Sender Input: Unique identifier of the HTLC _htlcId. Checks if the caller is the sender. Check if the HTLC has been claimed or refunded. Checks whether the time lock has expired. If the above checks pass, the funds are returned to the sender and the HTLC is marked as refunded.
[0110] 8. Query HTLC status Input: Unique identifier of the HTLC _htlcId. Returns the status information of HTLC, including whether it has been claimed, whether it has been refunded, and the time of time lock.
[0111] It should be noted that the above description of the candidate item display and determination system and its modules is only for convenience of description and does not limit the present specification to the scope of the embodiments. It is understandable that, after understanding the principle of the system, those skilled in the art may arbitrarily combine the modules or form a subsystem to connect with other modules without deviating from the principle. In some embodiments, Figure 6 The transaction acquisition module, random sharding module, data judgment module, first transaction processing module and second transaction processing module disclosed in the specification can be different modules in a system, or a module can realize the functions of two or more modules. For example, each module can share a storage module, or each module can have its own storage module. Such variations are all within the scope of protection of this specification.
[0112] The basic concepts have been described above. Obviously, for those skilled in the art, the above detailed disclosure is only for example and does not constitute a limitation of this specification. Although not explicitly stated here, those skilled in the art may make various modifications, improvements and corrections to this specification. Such modifications, improvements and corrections are suggested in this specification, so such modifications, improvements and corrections still belong to the spirit and scope of the exemplary embodiments of this specification.
[0113] At the same time, this specification uses specific words to describe the embodiments of this specification. For example, "one embodiment", "an embodiment", and / or "some embodiments" refer to a certain feature, structure or characteristic related to at least one embodiment of this specification. Therefore, it should be emphasized and noted that "one embodiment" or "an embodiment" or "an alternative embodiment" mentioned twice or more in different positions in this specification does not necessarily refer to the same embodiment. In addition, certain features, structures or characteristics in one or more embodiments of this specification can be appropriately combined.
[0114] In addition, unless explicitly stated in the claims, the order of the processing elements and sequences described in this specification, the use of alphanumeric characters, or the use of other names are not intended to limit the order of the processes and methods of this specification. Although the above disclosure discusses some invention embodiments that are currently considered useful through various examples, it should be understood that such details are only for illustrative purposes, and the attached claims are not limited to the disclosed embodiments. On the contrary, the claims are intended to cover all modifications and equivalent combinations that are consistent with the essence and scope of the embodiments of this specification. For example, although the system components described above can be implemented by hardware devices, they can also be implemented only by software solutions, such as installing the described system on an existing server or mobile device.
[0115] Similarly, it should be noted that in order to simplify the description disclosed in this specification and thus help understand one or more embodiments of the invention, in the above description of the embodiments of this specification, multiple features are sometimes combined into one embodiment, figure or description thereof. However, this disclosure method does not mean that the features required by the subject matter of this specification are more than the features mentioned in the claims. In fact, the features of the embodiments are less than all the features of the single embodiment disclosed above.
[0116] In some embodiments, numbers describing the number of components and attributes are used. It should be understood that such numbers used in the description of the embodiments are modified by the modifiers "about", "approximately" or "substantially" in some examples. Unless otherwise specified, "about", "approximately" or "substantially" indicate that the numbers are allowed to vary by ±20%. Accordingly, in some embodiments, the numerical parameters used in the specification and claims are approximate values, which may change according to the required features of individual embodiments. In some embodiments, the numerical parameters should take into account the specified significant digits and adopt the general method of retaining digits. Although the numerical domains and parameters used to confirm the breadth of their range in some embodiments of this specification are approximate values, in specific embodiments, the setting of such numerical values is as accurate as possible within the feasible range.
[0117] Each patent, patent application, patent application publication, and other materials, such as articles, books, specifications, publications, documents, etc., cited in this specification are hereby incorporated by reference in their entirety. Except for application history documents that are inconsistent with or conflicting with the contents of this specification, documents that limit the broadest scope of the claims of this specification (currently or later attached to this specification) are also excluded. It should be noted that if the descriptions, definitions, and / or use of terms in the materials attached to this specification are inconsistent or conflicting with the contents described in this specification, the descriptions, definitions, and / or use of terms in this specification shall prevail.
[0118] Finally, it should be understood that the embodiments described in this specification are only used to illustrate the principles of the embodiments of this specification. Other variations may also fall within the scope of this specification. Therefore, as an example and not a limitation, alternative configurations of the embodiments of this specification may be considered consistent with the teachings of this specification. Accordingly, the embodiments of this specification are not limited to the embodiments explicitly introduced and described in this specification.
Claims
1. A transaction method for a sharded blockchain matrix based on a master-slave mode, characterized in that: include: Obtain a pending transaction based on the transaction list of the blockchain, wherein the pending transaction includes a sender address, a receiver address, and transaction details; By randomly selecting a sharding function, the to-be-processed transaction is randomly assigned to a sharding module, wherein the sharding module is composed of at least one sharding transaction processing unit; Determine whether the sender address and the receiver address corresponding to the transaction to be processed belong to the same shard transaction processing unit; In response to the same shard transaction processing unit, executing the vertical transaction method; In response to the transaction processing unit not being the same shard, a horizontal cross-shard transaction method is executed.
2. The transaction method of the sharded blockchain matrix based on the master-slave mode according to claim 1 is characterized in that: The method for executing vertical transactions comprises: The shard transaction processing unit corresponding to the pending transaction includes a master chain, creates a state channel according to the address tag and task cycle in the pending transaction, processes data through the master chain and generates at least one slave chain, wherein the master chain and the slave chain are composed of at least one node in the blockchain; The slave chain calculates and processes the task content of the pending transaction, and transmits the calculation result back to the master chain; The master chain sends the calculation results to the shard chain and the beacon chain main chain for verification, completing the pending transaction.
3. The transaction method of the sharded blockchain matrix based on the master-slave mode according to claim 1 is characterized in that: The horizontal cross-chip transaction method includes: Determine whether the pending transaction is a simple transaction, and determine it to be a simple transaction when the transaction details of the pending transaction meet a preset threshold; In response to the transaction to be processed being a simple transaction, executing a first horizontal cross-chip transaction method; In response to the transaction to be processed not being a simple transaction, a second horizontal cross-chip transaction method is executed.
4. The transaction method of the sharded blockchain matrix based on the master-slave mode according to claim 3 is characterized in that: The first horizontal cross-chip transaction method includes: The shard transaction processing unit corresponding to the sender of the to-be-processed transaction includes a master chain A, and the shard transaction processing unit corresponding to the receiver includes a master chain B, and the master chain A and the master chain B are connected in the horizontal direction through a hash time lock; Calculate the transaction data to be processed through the master chain B and feed the result back to the master chain A; The master chain A sends the calculation results to the shard chain and the beacon chain main chain for verification to complete the pending transaction.
5. The transaction method of the sharded blockchain matrix based on the master-slave mode according to claim 3 is characterized in that: The second horizontal cross-chip transaction method includes: The shard transaction processing unit corresponding to the sender of the pending transaction includes a master chain A and a corresponding slave chain A, and the shard transaction processing unit corresponding to the receiver includes a master chain C and a corresponding slave chain C, and the pending transaction is assigned to the slave chain A; Based on the processing result of the slave chain A, the transaction data to be processed is sent horizontally to the slave chain C of the corresponding shard transaction processing unit of the receiver through a hash time lock; Send the processing result of the slave chain C to the master chain C of the corresponding shard transaction processing unit of the recipient; Based on the confirmation result of the master chain C, the transaction result is fed back to the slave chain A through the slave chain C and then fed back to the master chain A; The master chain A sends the calculation results to the shard chain and the beacon chain main chain for verification to complete the pending transaction.
6. A sharded blockchain matrix based on a master-slave model, characterized in that: include: Divide each node in the blockchain into master chain, slave chain and shard chain; A shard transaction processing unit is formed by connecting a master chain, at least one slave chain, and a shard chain through a state channel in the vertical direction; In the horizontal direction, the master chain and / or slave chain corresponding to the sender and the receiver's respective shard transaction processing units are connected through hash time locks.
7. The master-slave mode-based sharded blockchain matrix according to claim 6 is characterized in that: include: The master chain is used for data backup, coordinating various transaction tasks in the transaction list, and calculating and compressing the pending transactions; The slave chain is used to assist the master chain in data processing, execute transactions within the task cycle of the pending transaction, and return the processing results of the master chain after the execution is completed.
8. The master-slave mode-based sharded blockchain matrix according to claim 7 is characterized in that: include: The slave chain is dynamically generated or destroyed according to the transaction processing status of the master chain.
9. A transaction system based on a sharded blockchain matrix in a master-slave mode, characterized in that: include: The transaction acquisition module is used to obtain a pending transaction based on the transaction list of the blockchain; A random sharding module, used to randomly assign the to-be-processed transaction to a sharding module by randomly selecting a sharding function, wherein the sharding module is composed of at least one sharding transaction processing unit; Data judgment module; Used to determine whether the sender address and the receiver address corresponding to the pending transaction belong to the same shard transaction processing unit; A first transaction processing module, configured to execute a vertical transaction method in response to the same shard transaction processing unit; The second transaction processing module is used to execute a horizontal cross-shard transaction method in response to a transaction processing unit that is not in the same shard.
10. A computer-readable storage medium, characterized in that: The storage medium stores computer instructions. When the computer reads the computer instructions in the storage medium, the computer executes the transaction method of the sharded blockchain matrix based on the master-slave mode as described in any one of claims 1 to 5.
