A node incentive method, device and electronic device for sharded blockchain
By dynamically adjusting the calculation method of gas overhead in the sharded blockchain and distinguishing the incentive mechanism based on transaction type and instruction type, the problem of imbalanced node incentives under the sharded blockchain is solved, and network processing efficiency and fairness of contract execution are improved.
Patent Information
- Application Number
- CN202411871571.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-18
- Publication Date
- 2025-04-08
AI Technical Summary
Under the sharded blockchain architecture, the existing gas incentive mechanism cannot effectively motivate nodes because the calculation work required for in-sanded transactions and cross-sanded transactions is different, resulting in uneven incentive intensity.
Through the storage address of the smart contract, transactions are divided into in-shatter transactions and cross-shatter transactions, and the calculation method of gas overhead is dynamically adjusted according to the transaction type and instruction type. For in-slice transactions, gas overhead is calculated based on the instruction type; for cross-slice transactions, corresponding shard execution is selected based on the quotation of broker nodes of other shards.
It realizes effective incentives for nodes under the sharded blockchain architecture, improves the processing efficiency of the overall network, and enhances the fairness and reliability of contract execution.
Smart Images

Figure CN119788685A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology; specifically, to a node incentive method, device and electronic device for a sharded blockchain. Background Art
[0002] With the development of blockchain technology, sharding architecture has been widely discussed and explored as a potential solution. Sharding technology can divide the blockchain network into multiple independent blockchain fragments (shards), each of which can process transactions in parallel, thereby improving the throughput and scalability of the overall network.
[0003] The current Ethereum network uses an incentive mechanism based on calculating gas instruction by instruction. The incentive strength is measured by calculating the gas consumption of each smart contract instruction, and rewards are given to the nodes that package the transaction in the form of handling fees, thereby incentivizing nodes to execute and verify smart contracts. The existing incentive mechanism works well under a single chain structure, but under a sharding architecture, the computational workload required for intra-shard transactions and cross-shard transactions is different, making it impossible to use the existing gas incentive mechanism.
[0004] Therefore, how to implement the node incentive method of sharded blockchain is an urgent problem to be solved. Summary of the invention
[0005] In order to solve the above technical problems, the embodiments of the present application provide a node incentive method, device and electronic device for a sharded blockchain, which solves the problem that node incentives for sharded blockchains cannot be implemented in related technologies.
[0006] According to one aspect of an embodiment of the present application, a node incentive method for a sharded blockchain is provided, wherein the sharded blockchain includes multiple shards, each shard includes a broker node, a pricing node and a plurality of packaging nodes, and the method includes: any node of the current shard receives a transaction message call from an external user, and determines whether the smart contract in the transaction message call is stored in the current shard; if it is stored in the current shard, broadcasts the transaction message call to the packaging node in the current shard, so that the packaging node in the current shard executes the smart contract in the transaction message call to obtain a corresponding instruction sequence; the pricing node in the current shard calculates the gas cost according to the instruction type in the instruction sequence; if it does not exist in the current shard, sends the transaction message call to the broker node in the current shard, so that the broker node of the current shard broadcasts the smart contract to the broker nodes of other shards; the broker nodes of other shards make quotes based on the smart contract, so that the broker node of the current shard selects the corresponding shard from at least one quote to execute the smart contract.
[0007] Optionally, the packaging node in the current shard executes the smart contract in the transaction message call to obtain a corresponding instruction sequence, including: obtaining a transaction message call to be processed from the transaction pool; obtaining a smart contract address, a function signature and transfer parameters according to the transaction message call; obtaining a corresponding bytecode from the current shard according to the smart contract address; executing instructions in the smart contract one by one according to the bytecode according to the function signature and the transfer parameters; obtaining the instruction sequence when the smart contract is executed; the instruction sequence includes multiple instructions.
[0008] Optionally, the pricing node in the current shard calculates the gas cost according to the instruction type in the instruction sequence, including: when the instruction type is to modify the blockchain state or read the blockchain state, the pricing node in the current shard obtains the resource coefficient according to the resource information of each packaging node in the current shard; obtains the time consumption coefficient according to the block time of the first n blocks; obtains the weight coefficient according to the resource coefficient and the time consumption coefficient; obtains the gas cost corresponding to the instruction according to the initial gas cost corresponding to the instruction type and the weight coefficient.
[0009] Optionally, according to the resource information of each packaging node in the current shard, the calculation formula for obtaining the resource coefficient is:
[0010]
[0011] Among them, C i Indicates the CPU score of the i-th packaging node in the current shard, M i Indicates the memory score of the i-th packaging node in the current shard; S i Indicates the hard disk score of the i-th packaging node in the current shard; R i It represents the reputation value of the i-th packaging node, ranging from 0 to 1; k represents the number of packaging nodes in the current shard.
[0012] Optionally, according to the block generation time of the first n blocks, the calculation formula for obtaining the time consumption coefficient is:
[0013]
[0014] Among them, T i It indicates the block time of the i-th block among the first n blocks; a indicates the exponential coefficient.
[0015] Optionally, the method also includes: if the smart contract in the transaction message call is not stored in the current shard, the broker node of the current shard sends a contract synchronization request to the broker nodes of other shards; the broker node of the target shard obtains the network coefficient between the shards; wherein the target shard is the shard in which the smart contract is stored; the broker node of the target shard calculates the transmission gas cost according to the network coefficient, the number of bytes of the contract code and the number of state variables, and sends the smart contract code, state data and the transmission gas cost to the broker node of the current shard; the broker node of the current shard broadcasts the smart contract code and state data to the packaging node in the current shard, so that the packaging node in the current shard executes the smart contract according to the smart contract code and state data.
[0016] Optionally, obtaining the network coefficient between shards includes: taking the broker node of each shard as the node, the association between different shards as the edge, and the communication delay between different shards as the edge weight, to construct a weighted network graph between the shards; according to the weighted network graph, obtaining the average edge weight between each node and all its neighboring nodes; normalizing the average edge weight to obtain the local clustering coefficient corresponding to each node; and obtaining the network coefficient according to the average value of the local clustering coefficient.
[0017] Optionally, the calculation formula for calculating the transmission gas cost according to the network coefficient, the number of bytes of the contract code and the number of state variables is:
[0018] G=(sG deploy +mG SSTORE )γ
[0019] Among them, s represents the number of bytes of the smart contract code, m represents the number of state variables, γ represents the network coefficient between shards, and G deploy Indicates the gas consumption of a single byte, G SSTORE Represents the gas consumption of a single state variable.
[0020] According to one aspect of an embodiment of the present application, a node incentive device for a sharded blockchain is provided, wherein the sharded blockchain includes multiple shards, each shard includes a broker node, a pricing node and a plurality of packaging nodes, and the device includes: a contract judgment module, which is used for any node of the current shard to receive a transaction message call from an external user, and to judge whether the smart contract in the transaction message call is stored in the current shard; a contract execution module, which is used for broadcasting the transaction message call to the packaging node in the current shard if it is stored in the current shard, so that the packaging node in the current shard executes the smart contract in the transaction message call to obtain a corresponding instruction sequence; a gas cost calculation module, which is used for the pricing node in the current shard to calculate the gas cost according to the instruction type in the instruction sequence; a contract broadcast module, which is used for sending the transaction message call to the broker node in the current shard if it does not exist in the current shard, so that the broker node of the current shard broadcasts the smart contract to the broker nodes of other shards; a contract quotation module, which is used for the broker nodes of other shards to quote according to the smart contract, so that the broker node of the current shard selects the corresponding shard from at least one quotation to execute the smart contract.
[0021] According to one aspect of an embodiment of the present application, a computer-readable medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the node incentive method of the sharded blockchain in the above technical solution is implemented.
[0022] According to one aspect of an embodiment of the present application, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to execute the executable instructions so that the electronic device implements a node incentive method for a sharded blockchain as in the above technical solution.
[0023] According to one aspect of an embodiment of the present application, a computer program product is provided, including a computer program, which, when executed by a processor, implements the node incentive method of the sharded blockchain in the above technical solution.
[0024] The technical solution provided by this application includes at least the following beneficial effects:
[0025] This application divides transactions into intra-shard transactions and cross-shard transactions through the storage address of the smart contract; for intra-shard transactions, the gas costs of different instructions are calculated separately based on the instruction type, thereby incentivizing the packaging nodes that package transactions within the shard; for cross-shard transactions, the corresponding shard is selected for execution based on the quotes of broker nodes in other shards, incentivizing the broker nodes of each shard to participate in and effectively process cross-shard transactions, thereby improving the processing efficiency of the overall network; therefore, this application dynamically adjusts the calculation method of gas costs according to transaction types and instruction types, while meeting the node incentive requirements of sharded blockchains, it also improves the fairness and reliability of contract execution. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0027] Figure 1 The figure shows a schematic diagram of the structure of a sharded blockchain provided in an embodiment of the present application;
[0028] Figure 2 The figure is a schematic diagram of a process of node incentive method of a sharded blockchain provided in an embodiment of the present application;
[0029] Figure 3 Shown Figure 2 An exemplary flow chart of step S40 in FIG.
[0030] Figure 4 The figure is a flow chart of another node incentive method for a sharded blockchain provided in an embodiment of the present application;
[0031] Figure 5 The figure is a flow chart of another node incentive method for a sharded blockchain provided in an embodiment of the present application;
[0032] Figure 6 The figure shows a schematic diagram of the structure of a node incentive device for a sharded blockchain provided in an embodiment of the present application;
[0033] Figure 7 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. DETAILED DESCRIPTION
[0034] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0035] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0036] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0037] It should also be noted that the "multiple" mentioned in this application refers to two or more than two. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship.
[0038] Key terms explained:
[0039] [Blockchain] is a decentralized distributed ledger technology used to securely record and verify transaction information, achieving traceable, transparent and tamper-proof data storage.
[0040] [Incentive mechanism] is usually used to encourage nodes to participate in network activities, maintain network security, verify transactions, etc., to ensure the stability and reliability of the network. Usually the incentive is obtained by the node responsible for packaging the transaction block.
[0041] [GAS] is a unit used to measure computing workload in the Ethereum blockchain, similar to fuel. Its quantity depends on the complexity of calculations and operations in executing smart contracts or transactions. Gas is closely related to the incentive mechanism. The execution cost of smart contracts and transactions is controlled through user-defined GasPrice. At the same time, after the transaction is completed, the handling fee is calculated through the Gas quantity and GasPrice, which incentivizes nodes to provide services for verifying and packaging transactions.
[0042] Sharding is a scalability technology that divides the entire blockchain network into multiple smaller parts. Each shard is responsible for processing a portion of transactions, reducing the number of transactions that each node needs to process, thereby improving the throughput and performance of the entire network. Figure 1 As shown, Figure 1 The left side of the figure is a non-sharded architecture, and the right side is a sharded architecture. Each shard includes several packaging nodes and broker nodes.
[0043] Broker nodes are nodes that are responsible for handling cross-shard task scheduling and coordinating communication or data transmission between different shards. They play a key role in the sharding architecture, helping different shards to exchange information and collaborate on tasks to improve the efficiency and performance of the entire blockchain network.
[0044] Under the sharding architecture, the existing incentive mechanism may have the following problems:
[0045] 1. It cannot adapt to the situation where smart contracts involve multiple shards, resulting in unbalanced resource allocation and performance issues. Specifically, under the sharding architecture, the computational workload required for intra-shard transactions and cross-shard transactions is different, which makes it impossible to use the existing gas incentive mechanism. Secondly, the resource distribution between shards is different, and continuing to use the original mechanism will lead to unfairness and fail to play an incentive role.
[0046] 2. The current incentive mechanism does not take into account the load conditions within different shards, which may lead to miscalculation of transaction fees. In this case, some transactions may pay too high or too low fees, which cannot effectively incentivize nodes to participate in transaction packaging, affecting the overall operating efficiency of the blockchain network.
[0047] 3. The current incentive mechanism lacks the ability to dynamically adjust to the overall situation of the current blockchain. As the state of the blockchain network changes, the existing incentive mechanism may not be able to be flexibly adjusted.
[0048] In order to solve the above problems, the present application provides a node incentive method for a sharded blockchain, which specifically includes the following embodiments:
[0049] Figure 2 FIG. 1 is a flow chart of a node incentive method for a sharded blockchain provided in an embodiment of the present application; Figure 2 As shown, the method specifically comprises the following steps:
[0050] Step S10: Any node of the current shard receives a transaction message call from an external user.
[0051] It should be noted that the sharded blockchain structure of this embodiment is as follows Figure 1 As shown in the right figure, it includes multiple shards, each of which includes the following roles:
[0052] 1. Several packaging nodes: responsible for packaging and verifying transactions within the shard.
[0053] 2. Broker node: responsible for processing cross-shard transactions and cross-shard smart contract execution.
[0054] 3. Pricing node: responsible for calculating gas costs and elected by members within the shard.
[0055] In addition, this embodiment uses a voting mechanism to select pricing nodes within the shard. In order to prevent a certain node from monopolizing the pricing for a long time, re-voting is performed according to the transaction round. The smart contract responsible for voting is triggered according to the time limit, and re-voting for pricing nodes is automatically triggered every n blocks.
[0056] The basic steps of the voting mechanism on this blockchain include:
[0057] S1. During the shard establishment phase, a smart contract responsible for voting will be embedded in the blockchain of the shard (implementing the relevant rules of the voting mechanism and automatically executing without intervention from other nodes), and the gas mechanism for executing the smart contract will not be intervened by the pricing module;
[0058] S2. When the voting round begins, the voting smart contract establishes the DAO and invites nodes in the shard to participate in the voting;
[0059] S3. The node joins the DAO by staking its own tokens to the voting contract. The number of staked tokens determines the node’s voting weight.
[0060] S4. Any node can submit a proposal to DAO, such as proposing a node as a pricing node;
[0061] S5. Once the proposal is broadcast on the blockchain network, other nodes can vote within a specified time. Voting is achieved by calling the interface of the smart contract.
[0062] S6. When the voting deadline is reached, the voting smart contract will independently determine the pricing node based on the number of votes and weights, and record the voting proposals and results on the blockchain to ensure fairness and transparency.
[0063] In this embodiment, an external user sends a transaction message call to a node on the blockchain to trigger the smart contract on the blockchain to execute a predetermined transaction logic; the transaction message call needs to contain the following data: smart contract address, function signature, function parameters, and transaction ETH amount.
[0064] Step S20: Determine whether the smart contract in the transaction message call is stored in the current shard. If it is stored in the current shard, execute step S30; if it does not exist in the current shard, execute step S50.
[0065] It should be noted that after any node in the current shard receives a transaction message call sent by an external user, it determines whether the contract is stored in the current shard based on the smart contract address in the transaction message call; any node in the current shard can be a packaging node, a broker node, or a pricing node. Smart contracts are stored in the shard blockchain, and all nodes in the current shard will maintain a copy of the blockchain of the current shard, so only the node in the current shard that receives the transaction message call needs to query its own stored copy of the blockchain to determine whether the contract is stored in the current shard.
[0066] Step S30: broadcast the transaction message call to the packaging node in the current shard, so that the packaging node in the current shard executes the smart contract in the transaction message call to obtain the corresponding instruction sequence.
[0067] It should be noted that if a smart contract exists in the current shard, it means that the smart contract can be executed based on the transaction message call in the current shard, which belongs to the intra-shard transaction; the node that receives the transaction message call broadcasts the transaction to the packaging node in the current shard, so that one of the packaging nodes among several packaging nodes executes the smart contract in the transaction message call.
[0068] In one embodiment, the packaging node in the current shard executes the smart contract in the transaction message call to obtain a corresponding instruction sequence, including: obtaining a pending transaction message call from the transaction pool; obtaining a smart contract address, a function signature, and transfer parameters according to the transaction message call; obtaining the corresponding bytecode from the current shard according to the smart contract address; executing the smart contract one by one according to the bytecode according to the function signature and the transfer parameters; when the smart contract is executed, obtaining the instruction sequence; wherein the instruction sequence includes multiple instructions.
[0069] It should be noted that after receiving the transaction message call, the packaging node of the current shard executes the smart contract according to the parameters on the transaction message call to obtain the instruction sequence corresponding to the transaction; the specific steps of the packaging node executing the smart contract include:
[0070] S1. Get pending transaction message calls from the transaction pool;
[0071] S2. Parse the smart contract address to be called, the function signature to be called, and the parameters passed to the function from the transaction message call;
[0072] S3. Obtain the corresponding bytecode from the blockchain according to the smart contract address; bytecode is the machine language after the smart contract is compiled, which can be converted one by one with instruction / assembly code;
[0073] S4. According to the parsed function signature and parameters, the instructions in the smart contract are executed one by one according to the bytecode. During the execution process, data structures such as stack, heap, and key-value state variables are maintained.
[0074] Among them, when the smart contract is executed, the instructions it passes through are the instruction sequence mentioned in this embodiment; the instruction sequence consists of multiple instructions in the order of execution, and each instruction includes an operation code (such as PUSH, JUMP, ADD, etc., used to describe the specific operation and calculation process of the smart contract) and an operand.
[0075] Step S40: The pricing node in the current shard calculates the gas cost according to the instruction type in the instruction sequence.
[0076] In one embodiment, when executing a smart contract, the packaging node calculates the gas cost according to the following rules:
[0077] 1. For instructions that do not involve modifying the blockchain status, such as JUMP / PUSH, gas is calculated according to the original price. For specific prices, please refer to the Ethereum Technical Yellow Paper;
[0078] 2. Instructions involving modification / reading of blockchain status, such as SSTORE / SLOAD, but the status variable is stored in the current shard and will be reported to the pricing module of the current shard, and the shard pricing module will quote the price;
[0079] 3. Instructions involving modification of other shard status will be reported to the global pricing module, which will quote the price;
[0080] 4. For instructions involving external calls, if the target contract is in the same shard, the gas is calculated according to the original price; otherwise, the price is reported to the global pricing module.
[0081] It should be noted that the packaging nodes running smart contracts will maintain a table that corresponds the opcodes of the operation instructions to the instruction types. You only need to query the table based on the opcode to determine which type the current instruction belongs to.
[0082] In this embodiment, the specific reasons for separate pricing according to different types are: different instruction types require different computing and storage resources. For example, the JUMP instruction only modifies the program counter PC to complete the jump; the PUSH instruction pushes a 256-bit data into the stack of the current context; this type of instruction only modifies the current execution context, does not modify data such as state variables, and has low gas consumption. If the instruction involves modifying\reading the blockchain state, but is limited to the state database within the shard, its scope of influence is limited (it can be regarded as a transaction within the shard), and the resources required are also limited. If it involves cross-shard operations, such as the need to modify the state database of other shards, the scope of influence is all global shards, and the required resources are higher; therefore, separate pricing by instruction type improves the rationality of the pricing method.
[0083] Step S50: Send the transaction message call to the broker node in the current shard, so that the broker node of the current shard broadcasts the smart contract to the broker nodes of other shards.
[0084] It should be noted that if it does not exist in the current shard, it means that the contract is stored in other shards and needs to be sent to other shards for execution, so it is sent to the broker node, which is responsible for cross-shard transactions; every time a cross-shard-related task needs to be executed in a shard, it needs to be reported to the broker node in this shard, and the broker node packages it into a task and broadcasts it among the broker nodes of other shards. Generally speaking, the broker node will carry the minimum credit value requirement when broadcasting, and only broker nodes in other shards that meet the requirement can undertake the task.
[0085] Step S60: Broker nodes of other shards make quotations based on the smart contract, so that the broker node of the current shard selects a corresponding shard from at least one quotation to execute the smart contract.
[0086] It should be noted that if the broker nodes of other shards store the code or state variables of the smart contract, they will quote to the requesting broker node, indicating that they can undertake the cross-shard task. The requesting broker node will ultimately decide which quote to use. Generally speaking, the one with the lowest price that meets the requirements will undertake the cross-shard task.
[0087] In general, broker nodes in other shards can calculate the value of cross-shard tasks according to the following process: (1) Evaluate the size of the smart contract to be called as the gas fee for loading the smart contract; (2) Evaluate the complexity of the smart contract to be called, such as the number of state variables that need to be modified, the number of branches that need to be experienced, the number of loops, etc.; (3) Evaluate whether it is necessary to chain calls to other shards; (4) Evaluate whether it meets the requirements for undertaking the task.
[0088] In summary, this application divides transactions into intra-shard transactions and cross-shard transactions through the storage address of the smart contract; for intra-shard transactions, the gas costs of different instructions are calculated separately based on the instruction type, thereby incentivizing the packaging nodes that package transactions within the shard; for cross-shard transactions, the corresponding shard execution is selected based on the quotes of broker nodes in other shards, incentivizing the broker nodes of each shard to participate in and effectively process cross-shard transactions, thereby improving the processing efficiency of the overall network; therefore, this application dynamically adjusts the calculation method of gas costs according to transaction types and instruction types, while meeting the node incentive requirements of sharded blockchains, it also improves the fairness and reliability of contract execution.
[0089] In one embodiment, if Figure 3 As shown, the pricing node in the current shard calculates the gas cost according to the instruction type in the instruction sequence, specifically including the following steps:
[0090] Step S410: When the instruction type is to modify the blockchain state or read the blockchain state, the pricing node in the current shard obtains the resource coefficient according to the resource information of each packaging node in the current shard;
[0091] In one embodiment, according to the resource information of each packaging node in the current slice, the calculation formula for obtaining the resource coefficient is:
[0092]
[0093] Among them, C i Indicates the CPU score of the i-th packaging node in the current shard, M i Indicates the memory score of the i-th packaging node in the current shard; S i Indicates the hard disk score of the i-th packaging node in the current shard; R i It represents the reputation value of the i-th packaging node, ranging from 0 to 1; k represents the number of packaging nodes in the current shard.
[0094] It should be noted that the higher the CPU frequency, the better i The higher the value, the larger the memory M i The higher the value, the larger the hard disk capacity. iThe higher the value, the higher the credibility. In addition, if the service time of the packaging node in the shard is longer and the number of blocks produced is higher, it means that its credibility is higher, so its reputation value R i The bigger.
[0095] In formula (1), the resource score reported by each packaging node is weighted by the reputation value of the node, and its range is limited to 0 to infinity through the log function, and the value becomes larger as the resource score increases. Furthermore, the higher the resource score, the smaller the value, and the value range is limited to between 0 and 1. It can be seen that the formula can express that the more abundant the resources in the shard, the smaller the resource coefficient α; when the resources in the shard are abundant, gas should be reduced.
[0096] Step S420, obtaining a time consumption coefficient according to the block generation time of the first n blocks;
[0097] In one embodiment, according to the block generation time of the first n blocks, the calculation formula for obtaining the time consumption coefficient is:
[0098]
[0099] Among them, T i It indicates the block time of the i-th block among the first n blocks; a indicates the exponential coefficient, which can be set according to the actual application scenario.
[0100] Formula (2) calculates the average of the block time of the first n blocks, maps it to [0,1] through the exponential function and the inverse, and the smaller the average of the block time, the smaller the coefficient (that is, the longer the block time of the first n blocks, the larger the β coefficient); generally speaking, the block time is linked to the network conditions. The smoother the network conditions, the faster the block is produced.
[0101] Step S430, obtaining a weight coefficient according to the resource coefficient and the time consumption coefficient;
[0102] It should be noted that the weight coefficient is obtained by averaging the resource coefficient α and the time consumption coefficient β.
[0103] Step S440: Obtain the gas cost corresponding to the instruction according to the initial gas cost and the weight coefficient corresponding to the instruction type.
[0104] In this embodiment, according to the initial gas cost and weight coefficient corresponding to the instruction type, the calculation formula for the gas cost corresponding to the instruction is obtained as follows:
[0105]
[0106] In formula (3), G represents the initial gas cost corresponding to a certain instruction type. Represents the weight coefficient. This embodiment returns the gas calculated based on the real-time load in the shard to the packaging node requesting the quotation based on the α and β coefficients and the gas required by the SSTORE and SLOAD instructions in the Ethereum Yellow Paper. Because the execution efficiency in the shard is higher than that in the original architecture, the gas consumption is lower.
[0107] In another embodiment, Figure 4 As shown, the node incentive method of the sharded blockchain provided by the present application also includes the following steps:
[0108] Step S710: If the smart contract in the transaction message call is not stored in the current shard, the broker node of the current shard sends a contract synchronization request to the broker nodes of other shards.
[0109] It should be noted that since there is no smart contract stored in the current shard, the broker node requests all broker nodes on the entire platform to synchronize the code and status data of the smart contract.
[0110] Step S720: The broker node of the target shard obtains the network coefficient between shards; wherein the target shard is the shard storing the smart contract.
[0111] In one embodiment, obtaining the network coefficient between shards includes: taking the broker node of each shard as a node, the association between different shards as an edge, and the communication delay between different shards as an edge weight, to construct a weighted network graph between the shards; according to the weighted network graph, obtaining the average edge weight between each node and all its neighboring nodes; normalizing the average edge weight to obtain the local clustering coefficient corresponding to each node; and obtaining the network coefficient according to the average value of the local clustering coefficient.
[0112] It should be noted that the calculation steps of the network coefficient between shards include:
[0113] (1) Construct a weighted network graph between shards: The broker nodes of each shard are regarded as nodes of the network graph, and the communication delays between different shards are regarded as edges and weights of the network graph;
[0114] (2) Calculate the local clustering coefficient: For node i in the network graph, calculate the average edge weight between node i and all neighboring node pairs and perform normalization;
[0115] (3) Calculate the global network coefficient: The network coefficient can be obtained by averaging the local clustering coefficients of all nodes i.
[0116] Step S730: The broker node of the target shard calculates the transmission gas cost according to the network coefficient, the number of bytes of the contract code and the number of state variables, and sends the smart contract code, state data and the transmission gas cost to the broker node of the current shard.
[0117] It should be noted that the calculation formula for calculating the transmission gas cost based on the network coefficient, the number of bytes of the contract code and the number of state variables is:
[0118] G= (sG deploy +mG SSTORE )γ (4)
[0119] Among them, formula (4) is used to calculate the gas required for transmitting synchronization data. In step S730, the code and state data of the smart contract are mainly transmitted. For this purpose, it can be calculated from two perspectives: Gcode and Gstate:
[0120] (1) G code Indicates the gas consumed in transmitting smart contract code, G deploy Indicates the gas consumption of a single byte, G code The calculation is set to the number of bytes of the smart contract bytecode s multiplied by G deploy , and then multiply it by the network coefficient γ. The larger the size of the smart contract and the higher the network latency, the greater the gas consumption. deploy Fixed and unchanged.
[0121] (2) G state Indicates the gas consumed in transmitting status data, G SSTORE Indicates the gas consumption of a single state variable, and m is the number of state variables. state Calculated as the number of state variables m multiplied by G SSTORE , and then multiply it by the network coefficient γ; if there are more state variables in the smart contract and the network delay is higher, the gas consumption will be greater; in general, G SSTORE Fixed and unchanged.
[0122] Step S740: The broker node of the current shard broadcasts the smart contract code and status data to the packaging node in the current shard, so that the packaging node in the current shard executes the smart contract according to the smart contract code and status data.
[0123] It should be noted that when the broker node of a shard receives the smart contract code and status data sent by the broker node of other shards, it broadcasts it to the packaging node in the current shard; the packaging node that receives the smart contract code and status data executes the smart contract within the shard and calculates the gas cost according to step S40, thereby converting cross-shard transactions into intra-shard transactions.
[0124] It can be seen that the node incentive method of the sharded blockchain provided in this application mainly involves different gas pricing processes such as Figure 5 As shown in the figure: (1) When the contract is within the shard, it is executed by the packaging node and quoted by the shard pricing module; (2) The contract is within the shard and executed by the packaging node. If cross-shard coordination is required, the global pricing module quotes; (3) When the contract is outside the shard, if other shards undertake the execution task, the global pricing module quotes; (4) If no other shard is willing to undertake the task, the status data is synchronized and the shard pricing module quotes. Among them, the quotation method of the shard pricing module is the same as that of the Figure 2 The same as step S40 in the above; the quotation method of the global pricing module is the same as Figure 2 The same as step S60.
[0125] The technical solution provided by this application includes at least the following beneficial effects:
[0126] 1. Promote cross-shard transaction processing: By rewarding Broker nodes to handle the gas consumption of cross-shard contract state synchronization, nodes are encouraged to participate in and effectively process cross-shard transactions, thereby improving the processing efficiency of the overall network.
[0127] 2. Enhanced network security: Incentivizing Broker nodes to process cross-shard transactions can enhance the security of the network, prevent malicious behavior, and ensure the reliability of contract state synchronization.
[0128] 3. Improve network scalability: By incentivizing the processing of cross-shard transactions, the scalability of the network can be promoted, enabling the blockchain system to better cope with the growing transaction volume and demand.
[0129] 4. By incentivizing packaging nodes to allocate the gas consumption of executing smart contracts according to the real-time packaging time, nodes can be encouraged to optimize transaction packaging and execution efficiency, thereby improving the overall transaction processing speed.
[0130] Figure 6 The figure is a schematic diagram of the structure of a node incentive device for a sharded blockchain provided in an embodiment of the present application; Figure 6 As shown, the sharded blockchain includes multiple shards, each shard includes a broker node, a pricing node and several packaging nodes, and the device includes:
[0131] The contract judgment module 610 is used for any node of the current shard to receive a transaction message call from an external user and to judge whether the smart contract in the transaction message call is stored in the current shard;
[0132] The contract execution module 620 is used to broadcast the transaction message call to the packaging node in the current shard if it is stored in the current shard, so that the packaging node in the current shard executes the smart contract in the transaction message call to obtain the corresponding instruction sequence;
[0133] The gas cost calculation module 630 is used for the pricing node in the current shard to calculate the gas cost according to the instruction type in the instruction sequence;
[0134] The contract broadcast module 640 is used to send the transaction message call to the broker node in the current shard if it does not exist in the current shard, so that the broker node of the current shard broadcasts the smart contract to the broker nodes of other shards;
[0135] The contract quotation module 650 is used for the broker nodes of other shards to make quotations based on the smart contract, so that the broker node of the current shard selects the corresponding shard from at least one quotation to execute the smart contract.
[0136] Figure 7 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown.
[0137] It should be noted that Figure 7 The computer system 1000 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0138] like Figure 7 As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1002 or the program loaded from the storage part 1008 to the random access memory (RAM) 1003, such as executing the method described in the above embodiment. In the RAM 1003, various programs and data required for system operation are also stored. The CPU 1001, the ROM 1002 and the RAM 1003 are connected to each other through the bus 1004. The input / output (I / O) interface 1005 is also connected to the bus 1004.
[0139] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, etc.; an output section 1007 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1010 as needed so that a computer program read therefrom is installed into the storage section 1008 as needed.
[0140] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 1009, and / or installed from a removable medium 1011. When the computer program is executed by a central processing unit (CPU) 1001, various functions defined in the system of the present application are executed.
[0141] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as a part of a carrier wave, wherein a computer-readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0142] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0143] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0144] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. A person skilled in the art can easily make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
Claims
1. A node incentive method for a sharded blockchain, characterized in that: The sharded blockchain includes multiple shards, each shard includes a broker node, a pricing node, and a plurality of packaging nodes, and the method includes: Any node of the current shard receives a transaction message call from an external user and determines whether the smart contract in the transaction message call is stored in the current shard; If it is stored in the current shard, broadcast the transaction message call to the packaging node in the current shard, so that the packaging node in the current shard executes the smart contract in the transaction message call to obtain the corresponding instruction sequence; The pricing node in the current shard calculates the gas cost according to the instruction type in the instruction sequence; If it does not exist in the current shard, the transaction message call is sent to the broker node in the current shard, so that the broker node of the current shard broadcasts the smart contract to the broker nodes of other shards; The broker nodes of other shards make quotations based on the smart contract, so that the broker node of the current shard selects the corresponding shard from at least one quotation to execute the smart contract.
2. The method according to claim 1, characterized in that The packaging node in the current shard executes the smart contract in the transaction message call to obtain a corresponding instruction sequence, including: Get pending transaction message calls from the transaction pool; According to the transaction message call, obtain the smart contract address, function signature and transfer parameters; According to the smart contract address, obtain the corresponding bytecode from the current shard; According to the function signature and the passed parameters, execute the instructions in the smart contract one by one according to the bytecode; When the smart contract is executed, the instruction sequence is obtained; the instruction sequence includes multiple instructions.
3. The method according to claim 1, characterized in that The pricing node in the current shard calculates the gas cost based on the instruction type in the instruction sequence, including: When the instruction type is to modify the blockchain status or read the blockchain status, the pricing node in the current shard obtains the resource coefficient based on the resource information of each packaging node in the current shard; According to the block generation time of the first n blocks, obtain the time consumption coefficient; Obtaining a weight coefficient according to the resource coefficient and the time consumption coefficient; According to the initial gas cost and weight coefficient corresponding to the instruction type, the gas cost corresponding to the instruction is obtained.
4. The method according to claim 3, characterized in that According to the resource information of each packaging node in the current shard, the calculation formula for obtaining the resource coefficient is: Among them, C i Indicates the CPU score of the i-th packaging node in the current shard, M i Indicates the memory score of the i-th packaging node in the current shard; S i Indicates the hard disk score of the i-th packaging node in the current shard; R i It represents the reputation value of the i-th packaging node, ranging from 0 to 1; k represents the number of packaging nodes in the current shard.
5. The method according to claim 3, characterized in that: According to the block time of the first n blocks, the calculation formula for obtaining the time consumption coefficient is: Among them, T i It indicates the block time of the i-th block among the first n blocks; a indicates the exponential coefficient.
6. The method according to claim 1, characterized in that The method further comprises: If the smart contract in the transaction message call is not stored in the current shard, the broker node of the current shard sends a contract synchronization request to the broker nodes of other shards; The broker node of the target shard obtains the network coefficient between shards; wherein the target shard is the shard storing the smart contract; The broker node of the target shard calculates the transmission gas cost according to the network coefficient, the number of bytes of the contract code and the number of state variables, and sends the smart contract code, state data and the transmission gas cost to the broker node of the current shard; The broker node of the current shard broadcasts the smart contract code and status data to the packaging node in the current shard, so that the packaging node in the current shard executes the smart contract according to the smart contract code and status data.
7. The method according to claim 6, characterized in that Obtaining the network coefficients between shards includes: The broker nodes of each shard are used as nodes, the connections between different shards are used as edges, and the communication delays between different shards are used as edge weights to construct a weighted network graph between shards. According to the weighted network graph, obtaining the average value of edge weights between each node and all its neighboring nodes; Normalizing the edge weight average to obtain a local clustering coefficient corresponding to each node; The network coefficient is obtained according to the average value of the local clustering coefficients.
8. The method according to claim 6, characterized in that The calculation formula for calculating the transmission gas cost based on the network coefficient, the number of bytes of the contract code and the number of state variables is: G=(sG deploy +mG SSTORE )c Among them, s represents the number of bytes of the smart contract code, m represents the number of state variables, γ represents the network coefficient between shards, and G deploy Indicates the gas consumption of a single byte, G SSTORE Represents the gas consumption of a single state variable.
9. A node incentive device for a sharded blockchain, characterized in that: The sharded blockchain includes multiple shards, each shard includes a broker node, a pricing node and several packaging nodes, and the device includes: The contract judgment module is used for any node of the current shard to receive a transaction message call from an external user and to judge whether the smart contract in the transaction message call is stored in the current shard; The contract execution module is used to broadcast the transaction message call to the packaging node in the current shard if it is stored in the current shard, so that the packaging node in the current shard executes the smart contract in the transaction message call to obtain the corresponding instruction sequence; A gas cost calculation module, used for the pricing node in the current shard to calculate the gas cost according to the instruction type in the instruction sequence; The contract broadcast module is used to send the transaction message call to the broker node in the current shard if it does not exist in the current shard, so that the broker node of the current shard broadcasts the smart contract to the broker nodes of other shards; The contract quotation module is used for broker nodes of other shards to make quotations based on the smart contract, so that the broker node of the current shard selects the corresponding shard from at least one quotation to execute the smart contract.
10. An electronic device, characterized in that: include: processor; And a memory for storing executable instructions of the processor; wherein the processor is configured to execute the executable instructions to enable the electronic device to implement the node incentive method of the sharded blockchain as described in any one of claims 1 to 8.
Citation Information
Cited By
Smart contract fragmentation method and device, storage medium and program product
CN122226782A