Agricultural product transaction data tracking and recording system and method based on block chain
By introducing sharding technology, proof of stake consensus mechanism and cross-shash verification mechanism into the blockchain network, the shortcomings of data sharding, consensus efficiency and cross-shash verification in agricultural product transaction data management have been solved, efficient, safe and trustworthy data management have been achieved, and the healthy development of the agricultural product trading market has been promoted.
Patent Information
- Application Number
- CN202411820698.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-03-25
AI Technical Summary
The existing blockchain-based agricultural product transaction data management solutions have shortcomings in data sharding, data consensus efficiency and cross-slice verification, which makes it difficult to guarantee the authenticity, integrity and transparency of the data.
By introducing sharding technology and proof of stake consensus mechanism into the blockchain network, combined with cross-shash verification mechanism, efficient allocation, rapid consensus and cross-shash verification of agricultural product transaction data can be achieved, ensuring the authenticity and integrity of the data.
It improves the processing efficiency and scalability of agricultural product trading data, enhances the security and credibility of data, ensures the transparency and fairness of transaction data, and provides technical support for the healthy development of the agricultural product trading market.
Smart Images

Figure CN119696755A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of agricultural product transaction management, and in particular to a blockchain-based agricultural product transaction data tracking and recording system and method thereof. Background Art
[0002] In the current agricultural product trading market, the recording, verification, tracking and management of transaction data is a complex and critical process. Traditional agricultural product trading data management methods often rely on centralized database systems. Although such systems can meet the basic management needs of transaction data to a certain extent, they have deficiencies in data security, transparency and credibility. For example, centralized database systems are vulnerable to hacker attacks or internal personnel tampering, resulting in inaccurate and unreliable transaction data. In addition, since data is stored in a centralized manner, once a database fails, it may lead to data loss or inaccessibility, causing great inconvenience to both parties to the transaction and market supervision.
[0003] In order to overcome the defects of traditional agricultural product transaction data management methods, the industry has begun to explore the use of blockchain technology to record and manage transaction data. Blockchain technology, with its distributed ledger, data immutability, transparency and smart contracts, provides a new solution for the recording and management of agricultural product transaction data. Through blockchain technology, the data of each agricultural product transaction can be securely recorded on the chain and can be queried and verified at any time, thereby greatly improving the credibility and transparency of transaction data.
[0004] However, the existing blockchain-based agricultural product transaction data management solutions still have some shortcomings. For example, due to the complexity and diversity of agricultural product transaction data, how to efficiently distribute this data to different shards in the blockchain network and ensure the authenticity and integrity of the data is an urgent problem to be solved. In addition, the existing solutions often only rely on verification nodes within a single shard during the data consensus stage, which may lead to limited efficiency and credibility of data consensus. At the same time, how to ensure the effectiveness and efficiency of cross-shard verification, and how to securely package transaction data into blocks and add them to the blockchain are also areas where existing solutions need to be improved.
[0005] Therefore, it is necessary to provide a blockchain-based agricultural product transaction data tracking and recording system and method to solve the above technical problems. Summary of the invention
[0006] To solve the above technical problems, the present invention provides a blockchain-based agricultural product transaction data tracking and recording system and method, which can efficiently manage and store agricultural product transaction data, realize rapid data verification and consensus, support cross-shard data verification and consensus, and ensure the authenticity and integrity of agricultural product transaction data, improve the transparency and fairness of transactions, and provide strong guarantees for the healthy development of the agricultural product transaction market.
[0007] On the one hand, the present invention provides a method for tracking and recording agricultural product transaction data based on blockchain, including a blockchain network pre-constructed based on agricultural product transactions and multiple shards deployed in the blockchain network, wherein a cross-shard communication network is established between the multiple shards, and the method includes:
[0008] In response to a request for uploading agricultural product transaction data to a blockchain, the agricultural product transaction data is allocated to a target shard according to a preset sharding rule, wherein the target shard is one of the specific shards in the blockchain network allocated according to the preset sharding rule and carrying the agricultural product transaction data;
[0009] In the target shard, at least one verification node is selected through a proof-of-stake consensus mechanism, and the at least one verification node is used to perform data consensus on the agricultural product transaction data, wherein the verification node is a node pre-registered in the blockchain network and deployed in the multiple shards for performing consensus verification on the agricultural product transaction data;
[0010] After consensus is reached in the data consensus phase, cross-shard verification is triggered, wherein the cross-shard verification is to send a verification request to other shards except the target shard through the cross-shard communication network, and select a response shard for data consensus based on preset screening conditions;
[0011] After consensus is reached in the data consensus phase of the response shard, the agricultural product transaction data is packaged into blocks and added to the blockchain in the target shard.
[0012] Preferably, the preset sharding rule includes allocating shards according to at least one of the transaction type, agricultural product category, transaction time or transaction location of the agricultural product transaction data.
[0013] Preferably, the response to the on-chain request for agricultural product transaction data further includes:
[0014] The agricultural product transaction data in the chain request is preliminarily verified, and whether the agricultural product transaction data meets the chain conditions is determined based on the result of the preliminary verification. If so, shard allocation is performed according to the preset sharding rules; if not, the chain request is rejected.
[0015] Preferably, in response to the request for uploading agricultural product transaction data to a chain, allocating the agricultural product transaction data to a target shard according to a preset sharding rule comprises:
[0016] Acquiring characteristics of the agricultural product transaction data, wherein the characteristics include transaction type, agricultural product type, transaction location, and transaction time;
[0017] Matching the features with a preset sharding strategy, wherein the sharding strategy is a distributed sharding algorithm based on a hash function;
[0018] The target shard is determined according to the matching result, and the agricultural product transaction data is allocated to the corresponding target shard.
[0019] Preferably, in the target shard, at least one verification node is selected through a proof-of-stake consensus mechanism, and data consensus is performed on the agricultural product transaction data using the at least one verification node, including:
[0020] Calculating the weight of each node according to the equity values of the multiple nodes in the blockchain network;
[0021] A random selection algorithm is used, combined with node weights, to select a set of verification nodes participating in data consensus from multiple nodes pre-registered and deployed in the target shard;
[0022] Each verification node in the verification node set independently performs a verification operation on the agricultural product transaction data;
[0023] After each verification node completes the verification, it broadcasts the verification result to other verification nodes in the target shard;
[0024] If the proportion of verification nodes that have reached a consensus exceeds a predetermined proportion, it is considered that a consensus has been reached in the data consensus stage of the agricultural product trading data.
[0025] Preferably, after reaching consensus in the data consensus phase, triggering cross-shard verification includes:
[0026] Sending a verification request including the agricultural product transaction data and the identifier of the target shard to all shards except the target shard through the cross-shard communication network;
[0027] Receive responses from other shards, where the responses include voting results on whether to approve the transaction data being uploaded to the chain and response timestamps;
[0028] Based on the response speed and voting results, select the shard with fast response speed and voting results that meet the preset conditions as the response shard;
[0029] The response shards are used to perform data consensus on the agricultural product transaction data again.
[0030] Preferably, when selecting the response shard, the selection mechanism based on the response speed and the voting result includes:
[0031] A response time threshold is pre-set, and only shards that respond within the response time threshold are considered;
[0032] Among the shards whose response speed meets the requirements, the shards are sorted according to the voting results, and the shard with the highest proportion of approval votes and exceeding the preset approval proportion threshold is selected as the final response shard;
[0033] If there are multiple shards that meet the conditions, one or more shards with the fastest response speed are selected as the response shards.
[0034] Preferably, after reaching a consensus in the data consensus phase of the response shard, packaging the agricultural product transaction data into blocks and adding them to the blockchain in the target shard includes:
[0035] The verification node in the response shard generates a block containing the agricultural product transaction data and consensus information generated by the data consensus process;
[0036] Broadcasting the block to all nodes in the target shard except all verification nodes through the broadcast mechanism of the blockchain network;
[0037] All nodes except all verification nodes verify and confirm the block according to the consensus rules of the blockchain, and after the block is confirmed, add the block to the blockchain of the target shard.
[0038] Preferably, when adding the block to the blockchain of the target shard, it also includes:
[0039] Verify whether the transaction data included in the block is consistent with the data consensus reached in the response shard;
[0040] Checking whether the properties of the block meet the specifications of the blockchain;
[0041] After confirmation, the block is linked to the end of the blockchain of the target shard and the status of the blockchain is updated.
[0042] On the other hand, the present invention also provides a blockchain-based agricultural product transaction data tracking and recording system, which is used to execute the blockchain-based agricultural product transaction data tracking and recording method, including a blockchain network pre-constructed based on agricultural product transactions and multiple shards deployed in the blockchain network, wherein a cross-shard communication network is established between the multiple shards, and the system includes:
[0043] A shard allocation module, configured to respond to a request for uploading agricultural product transaction data to a blockchain and allocate the agricultural product transaction data to a target shard according to a preset sharding rule, wherein the target shard is one of the specific shards in the blockchain network allocated according to the preset sharding rule and carrying the agricultural product transaction data;
[0044] A first data consensus module is used to select at least one verification node in the target shard through a proof-of-stake consensus mechanism, and use the at least one verification node to perform data consensus on the agricultural product transaction data, wherein the verification node is a node pre-registered in the blockchain network and deployed in the multiple shards for performing consensus verification on the agricultural product transaction data;
[0045] A second data consensus module is used to trigger cross-shard verification after consensus is reached in the data consensus phase, wherein the cross-shard verification is to send a verification request to other shards except the target shard through the cross-shard communication network, and select a response shard for data consensus based on a preset screening condition;
[0046] The on-chain module is used to package the agricultural product transaction data into blocks and add them to the blockchain in the target shard after consensus is reached in the data consensus stage of the response shard.
[0047] Compared with related technologies, the blockchain-based agricultural product transaction data tracking and recording system and method provided by the present invention have the following beneficial effects:
[0048] First, the preset sharding rules are intelligently allocated according to the characteristics of transaction data, which not only effectively disperses the load of the blockchain network, but also improves the speed and efficiency of data processing. On this basis, the introduction of the proof-of-stake consensus mechanism makes the selection of verification nodes more fair and reasonable, and further ensures the authenticity and integrity of transaction data in the consensus process. Next, the cross-shard verification mechanism realizes the re-verification of transaction data by sending verification requests to other shards and screening the response shards, effectively enhancing the security and credibility of the data. Finally, the transaction data that has been strictly verified by consensus is packaged into blocks and added to the blockchain of the target shard through the broadcast mechanism of the blockchain network. This process not only ensures the permanent storage and traceability of the data, but also provides a reliable data foundation for subsequent market supervision and data analysis.
[0049] In summary, the present invention realizes efficient, secure and reliable management of agricultural product trading data through preset sharding rules, proof-of-stake consensus mechanism, cross-shard verification and other technical means, providing strong technical support for the healthy development and standardized management of the agricultural product trading market. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 A flowchart of the method for tracking and recording agricultural product transaction data based on blockchain provided by the present invention;
[0051] Figure 2 This is a module structure diagram of the blockchain-based agricultural product transaction data tracking and recording system provided by the present invention. DETAILED DESCRIPTION
[0052] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only the parts related to the present invention, rather than all structures, are shown in the accompanying drawings. In addition, the embodiments of the present invention and the features in the embodiments may be combined with each other without conflict.
[0053] It should also be noted that, for ease of description, only the part relevant to the present invention but not all content is shown in the accompanying drawings. It should be mentioned before discussing exemplary embodiments in more detail that some exemplary embodiments are described as processing or methods depicted as flow charts. Although the flow chart describes each operation (or step) as sequential processing, many operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of each operation can be rearranged. When its operation is completed, the processing can be terminated, but it can also have additional steps not included in the accompanying drawings. The processing can correspond to methods, functions, procedures, subroutines, subprograms, etc.
[0054] Embodiment 1
[0055] In the present invention, the blockchain network is an infrastructure that is built using distributed ledger technology and is specifically used to store and manage agricultural product transaction data. This network consists of many nodes, each of which stores part of the network's data and follows a unified consensus protocol to ensure data consistency and security. The blockchain network's decentralization, data immutability, and transparency make it an ideal choice for recording and tracking agricultural product transaction data.
[0056] In order to improve data processing efficiency and scalability, the present invention introduces sharding technology in the blockchain network. Sharding is the process of dividing the entire blockchain network into multiple sub-networks (i.e., shards), each of which is responsible for processing specific transaction data. These shards communicate and collaborate through a cross-shard communication network to ensure data consistency and security of the entire network. The application of sharding technology enables multiple transactions to be processed in parallel, thereby greatly improving transaction throughput.
[0057] Among them, nodes, as the basic components of the blockchain network, bear the important responsibilities of storing data, verifying transactions and participating in the consensus process. In the present invention, nodes are deployed in multiple shards and pre-registered in the blockchain network. Nodes calculate weights based on the equity value they hold and have the right to participate in the data consensus process of their shards. The introduction of the equity proof consensus mechanism ensures that only nodes with sufficient equity and reputation can participate in the consensus, thereby improving the credibility and efficiency of data consensus.
[0058] In addition, a cross-shard communication network is set up between different shards, which allows data and messages to be transmitted between shards. In particular, after consensus is reached in the data consensus stage, the target shard will use the cross-shard communication network to send verification requests to other shards and receive responses from other shards. These responses are generated by nodes in other shards and are used to further verify the authenticity and integrity of transaction data. Through the collaboration of the cross-shard communication network, the present invention realizes cross-shard data verification and consensus, thereby ensuring the data consistency and security of the entire blockchain network.
[0059] Therefore, the blockchain network, shards, nodes, and cross-shard communication networks together constitute the core architecture of the present invention. The close collaboration between them not only improves the processing efficiency and scalability of agricultural product trading data, but also ensures the authenticity and integrity of the data. This innovative technical solution provides strong technical support for the healthy development and standardized management of the agricultural product trading market.
[0060] In specific implementation, the method for tracking and recording agricultural product transaction data based on blockchain includes the following steps:
[0061] S1: In response to a request to upload agricultural product transaction data to the blockchain, the agricultural product transaction data is allocated to a target shard according to a preset sharding rule, wherein the target shard is one of the specific shards in the blockchain network that is allocated according to the preset sharding rule and carries the agricultural product transaction data.
[0062] In the present invention, step S1 is the basis of the entire blockchain-based agricultural product transaction data tracking and recording method, which involves preliminary verification of the agricultural product transaction data in the received on-chain request and allocation of these data to appropriate target shards according to the preset sharding rules, specifically including:
[0063] When an agricultural product transaction occurs, the relevant transaction data will be submitted to the blockchain network as a chain request. This chain request contains all the necessary information about the transaction, including the transaction type, the types of agricultural products involved, the transaction location and time, etc. After receiving the chain request, the agricultural product transaction data in the request is firstly verified to ensure the legitimacy and integrity of the transaction data, including but not limited to verifying whether the transaction data conforms to the predefined data format and structure; checking whether the identity information of the transaction participants is valid, and illustratively verifying the identity of the sender through a digital signature; confirming whether the timestamp contained in the transaction data is reasonable to prevent the illegal chaining of old or future data; verifying whether the transaction amount and other key fields are within a reasonable range to avoid the entry of abnormal values.
[0064] If the preliminary verification results show that the transaction data meets all the conditions for on-chain transmission, proceed to the next step; otherwise, the on-chain transmission request is rejected and an error message is returned to the request initiator, indicating the problem.
[0065] For agricultural product transaction data that has passed preliminary verification, it is necessary to determine which specific shard it should be assigned to. This process relies on pre-set sharding rules in order to optimize data processing efficiency and resource utilization. Key features for sharding allocation are extracted from transaction data that has passed preliminary verification, including transaction type, agricultural product type, transaction location, and transaction time.
[0066] Use a distributed sharding algorithm based on a hash function to match the above extracted features with the preset sharding strategy. Specifically, each feature can be input into the hash function to obtain a hash value, and then the shard to which the data should belong is determined based on the hash value. This method can ensure that transaction data with the same features are always assigned to the same shard, thereby simplifying subsequent data query and verification work.
[0067] More specifically, when agricultural product transaction data needs to be distributed in shards, key features such as transaction type, agricultural product type, transaction location, and transaction time are extracted from the agricultural product transaction data. Then, each feature is treated as an independent input and passed to the selected hash function to generate its own hash value. For example, a secure hash algorithm such as SHA-256 can be used to generate a 256-bit binary number as a hash value for each feature.
[0068] Suppose there is a blockchain network that consists of N shards. We need a way to determine which shard a particular feature hash value should correspond to. This can usually be achieved by taking a modulo operation on the hash value. Specifically, the hash value of each feature is divided by the total number of shards N, and the remainder determines the shard number corresponding to the feature. The formula is as follows:
[0069] Fragment code = hash value ÷ N
[0070] This means that for each feature, a possible shard number will be obtained. However, since a transaction data contains multiple features, a strategy is needed to finally determine which shard the transaction should be assigned to. Common strategies include but are not limited to:
[0071] Select the main feature: Select one of the features (such as transaction location or agricultural product type) as the main feature and use its hash value to determine the target shard.
[0072] Weighted average or weighted sum: Different weights are assigned to each feature according to its importance, and then their hash values are weighted averaged or weighted summed, followed by a modulo operation.
[0073] Majority voting: Calculate the shard numbers corresponding to all feature hash values and select the shard with the most occurrences as the target shard.
[0074] Random selection: If multiple feature hash values point to different shards, one of the shards can be selected, or some random mechanism can be used to decide.
[0075] Assume that the blockchain network has 4 shards (N=4) and is processing a purchase transaction (transaction type) involving apples (agricultural product type) in Beijing (transaction location) on January 1, 2024 (transaction time). Combine this information into a string, such as "apples, Beijing, purchase, 2024-01-01", and then hash it using the SHA-256 hash function to obtain a 256-bit hash value. To simplify the example, assume that the resulting hexadecimal hash value is "9e8c7d6f5b4a39281706..." (the actual hash value will be longer).
[0076] Next, we need to convert this hash value into an integer so that we can do the modulo operation. Since the hash value is in hexadecimal, we can convert it to a decimal number. To simplify further, assume that the converted decimal hash value is H.
[0077] Now, we apply the modulo operation to decide which shard this transaction should be assigned to. If the remainder of H divided by 4 is 2, then this transaction will be assigned to shard numbered 2.
[0078] Therefore, based on the output of the hash function, it is possible to determine which shard will be the target shard for carrying the agricultural product transaction data. Once the target shard is determined, the transaction data will be sent to the shard and ready to enter the next step of the data consensus process.
[0079] S2: In the target shard, at least one verification node is selected through a proof-of-stake consensus mechanism, and the at least one verification node is used to perform data consensus on the agricultural product transaction data, wherein the verification node is a node pre-registered in the blockchain network and deployed in the multiple shards for consensus verification of the agricultural product transaction data.
[0080] In step S2, once the transaction data is successfully allocated to the target shard, it is necessary to select at least one verification node within the shard through the Proof of Stake (PoS) consensus mechanism, and use these verification nodes to reach data consensus on the agricultural product transaction data.
[0081] The stake of each node in the network is determined by the number of tokens it holds. A higher stake means that the node has a higher reputation and influence in the network. The weights of each node are calculated based on their stake. The weight reflects the relative importance of the node in the network and the likelihood of participating in the consensus process. Usually, the weight can be calculated by a simple ratio, that is, the stake of a node divided by the sum of the stakes of all nodes.
[0082] To ensure fairness and security, a random selection algorithm is used to select the set of verification nodes participating in the data consensus. This algorithm combines the weight of the node so that nodes with higher equity values have a greater probability of being selected, but also ensures a certain degree of randomness to prevent certain nodes from over-controlling the consensus process. Only those nodes that have been pre-registered in the blockchain network and deployed in the target shard are eligible to participate in the consensus process. This ensures that the nodes participating in the consensus are audited and trusted.
[0083] More specifically, a pseudo-random number generator is used to generate one or more random numbers to determine which nodes will be selected as verification nodes. Once the random numbers are generated, the set of verification nodes will be selected based on these random numbers and the weights of the nodes, specifically:
[0084] First, the weights of all nodes are accumulated to form a cumulative weight distribution. Then a random number between 0 and 1 is generated and mapped to the cumulative weight distribution. Finally, the above steps are repeated according to the number of verification nodes that need to be selected until a sufficient number of verification nodes are selected.
[0085] In addition, to avoid repeatedly selecting the same node, the selected node can be removed from the candidate node list after each selection.
[0086] Once the set of verification nodes is determined, each verification node will independently perform verification operations on the agricultural product transaction data. This includes but is not limited to checking the format of the transaction data, verifying the identities of the two parties to the transaction, confirming the validity of the transaction amount, etc. After each verification node completes the verification, it will broadcast the verification results to other verification nodes in the target shard. This step is to ensure that all verification nodes can receive the latest verification information and prepare for the subsequent consensus. When all verification nodes have completed their respective verifications and broadcast the results, these results will be counted. If the proportion of verification nodes that reach a consensus exceeds a predetermined proportion (for example, 67% or higher), it is considered that a consensus has been reached in the data consensus stage of the agricultural product transaction data. This predetermined proportion can be adjusted according to the needs of the specific application to balance security and efficiency.
[0087] Assume that there are 5 pre-registered nodes in a specific target shard, and their stake values are 100, 150, 200, 250, and 300 respectively. First, the weight of each node is calculated based on these stake values: 10% for node A, 15% for node B, 20% for node C, 25% for node D, and 30% for node E. Then, a random selection algorithm is used to select one or more sets of verification nodes from these 5 nodes. Assume that nodes C, D, and E are selected as the set of verification nodes. These three nodes will independently verify the data involving an Apple purchase transaction. After the verification is completed, each node broadcasts the verification results to other nodes in the target shard.
[0088] Assume that the verification results of nodes C, D, and E are consistent, indicating that the transaction data is legal and valid. Since the sum of the weights of these three nodes is 20% + 25% + 30% = 75%, which exceeds the predetermined ratio (e.g. 67%), it is considered that the data consensus stage of this transaction data has reached a consensus.
[0089] Through the above steps, step S2 not only ensures that only nodes with sufficient rights and reputation can participate in the consensus, but also improves the credibility and efficiency of data consensus. The application of the PoS consensus mechanism makes the whole process more fair, transparent and secure. At the same time, the mechanism of independent verification and broadcasting of verification results ensures that all verification nodes can obtain the latest verification information in a timely manner, thereby effectively preventing single point failures and malicious attacks. Finally, when consensus is reached, we can proceed to the next step, namely cross-shard verification and block generation.
[0090] S3: After consensus is reached in the data consensus stage, cross-shard verification is triggered, wherein the cross-shard verification is to send a verification request to other shards except the target shard through the cross-shard communication network, and select a response shard for data consensus based on preset screening conditions.
[0091] In step S3, once consensus is reached in the data consensus phase within the target shard, cross-shard verification needs to be triggered through the cross-shard communication network. This process ensures the authenticity and integrity of transaction data in the entire blockchain network and further enhances the security and consistency of the system.
[0092] After reaching a consensus in the target shard, a verification request is sent to all shards except the target shard through the cross-shard communication network. This verification request contains the agricultural product transaction data and the target shard's identifier so that other shards can identify and process it. The content of the verification request includes transaction data (such as transaction type, agricultural product type involved, transaction location, transaction time and other key information) and the target shard identifier, which is used to identify the target shard that initiated the verification request and ensure that other shards can respond correctly.
[0093] After receiving the verification request, other shards will perform preliminary verification of the transaction data according to their own verification mechanism and generate a response. Each response contains the voting result (indicating whether the transaction data is approved to be put on the chain, such as "agree" or "disagree") and the response timestamp (recording the time of the response). The target shard will collect responses from all other shards and summarize them to prepare for the next selection.
[0094] In order to ensure the effectiveness and security of cross-shard verification, eligible response shards are selected from all responses. The selection mechanism is based on response speed and voting results. The specific steps are as follows:
[0095] First, a response time threshold is set in advance, and only shards that respond within this threshold are considered. This helps to exclude shards that respond too slowly and improves verification efficiency.
[0096] Then, among the shards whose response speed meets the requirements, further screening is performed based on the voting results. The voting results of each shard are counted, and the shard with the highest proportion of approval votes and exceeding the preset approval ratio threshold is selected as the final response shard. If there are multiple shards that meet the above conditions, one or more shards with the fastest response speed are selected as the response shards. This ensures that the selected shards not only meet the voting results requirements, but also have the fastest response speed, which improves the efficiency and reliability of verification.
[0097] The selected response shard will once again reach a data consensus on the agricultural product transaction data. This step is to further confirm the authenticity and integrity of the transaction data and ensure that it complies with the standards and rules of the entire blockchain network. The verification nodes in the response shard will independently verify the transaction data and broadcast the verification results to other verification nodes in the target shard. When all verification nodes reach a consensus, it is considered that a consensus has been reached in the cross-shard verification phase.
[0098] For example, there are 5 pre-registered nodes in a specific target shard, and their equity values are 100, 150, 200, 250 and 300 respectively. The target shard has completed the local data consensus and now needs to send a verification request to the other 3 shards (shards A, B, C) through the cross-shard communication network. The target shard sends a verification request containing transaction data and the target shard identifier to shards A, B, and C. Shard A responds within 1 second and the voting result is "agree". Shard B responds within 2 seconds and the voting result is "agree". Shard C responds within 3 seconds and the voting result is "disagree".
[0099] Assuming the response time threshold is 2 seconds, only the responses of Shard A and Shard B will be considered. Among the shards whose response speed meets the requirements, the voting results of Shard A and Shard B are both "Agree", and the proportion of agreeing votes is 100% (2 / 2), which exceeds the preset agreeing proportion threshold (for example, 67%). Therefore, Shard A and Shard B are both selected as responding shards. Shard A and Shard B verify the transaction data again and reach a consensus. Assuming that the verification results of the two shards are consistent, it indicates that the transaction data is legal and valid. The target shard confirms the authenticity and integrity of the transaction data based on the verification results of Shard A and Shard B, and prepares to enter the next step, that is, block generation.
[0100] Through the above steps, step S3 not only ensures the authenticity and integrity of transaction data in the entire blockchain network, but also further enhances security and consistency. The application of the cross-shard verification mechanism enables different shards to collaborate with each other and jointly verify transaction data, preventing errors or malicious behavior of a single shard from affecting the entire network.
[0101] In addition, the selection mechanism based on response speed and voting results ensures the efficiency and fairness of the verification process, improving the reliability and performance of the system. Finally, when the cross-shard verification reaches a consensus, it proceeds to the next step, which is to package the transaction data into blocks and add them to the blockchain of the target shard.
[0102] S4: After consensus is reached in the data consensus phase of the response shard, the agricultural product transaction data is packaged into blocks and added to the blockchain in the target shard.
[0103] In step S4, once the data consensus phase of the response shard reaches a consensus, the agricultural product transaction data needs to be packaged into blocks and added to the blockchain in the target shard. This process ensures that the transaction data is recorded safely and reliably in the blockchain and further enhances the integrity and consistency of the system.
[0104] The verification node in the response shard generates a block containing agricultural product transaction data and consensus information generated by the data consensus process. This block contains not only the transaction data itself, but also related information generated during the consensus process, such as verification results, timestamps, etc. This information is used to prove the validity and legitimacy of the transaction data. The block content includes transaction data (such as transaction type, type of agricultural products involved, transaction location, transaction time and other key information), consensus information (such as the list of verification nodes participating in the consensus, voting results, timestamps, etc.) and other metadata (such as block height, hash value of the previous block, etc.), to ensure the link relationship between blocks and form a complete blockchain.
[0105] The generated block is broadcasted to all nodes except all verification nodes in the target shard through the broadcast mechanism of the blockchain network. This step ensures that all nodes except all verification nodes can receive the latest block information and prepare for subsequent verification and confirmation. The verification node sends the block to all nodes except all verification nodes in the target shard. After receiving the block, each node will perform a preliminary check to ensure that the content and format of the block conform to the blockchain specifications.
[0106] All nodes except all verification nodes in the target shard verify and confirm the block according to the consensus rules of the blockchain. The verification process includes the following aspects: first, verify whether the transaction data contained in the block is consistent with the data consensus reached in the response shard to ensure that there is no tampering or error; second, check whether the attributes of the block meet the specifications of the blockchain, such as block size, timestamp, hash value of the previous block, etc., to ensure the legitimacy and integrity of the block; finally, according to the consensus rules of the blockchain, verify whether the block meets the consensus requirements to ensure that it is recognized by the majority of nodes. When all nodes complete the verification and reach a consensus, the block is considered to be confirmed. At this point, the block can be officially added to the blockchain of the target shard.
[0107] Among them, the number of most nodes is customizable, and a ratio can be set in advance. If the proportion of recognized nodes exceeds this ratio, it can be determined that it is recognized by the majority of nodes.
[0108] After confirmation, the block is linked to the end of the blockchain of the target shard. This step forms an immutable chain structure by linking the hash value of the new block with the hash value of the previous block, ensuring the security and integrity of the blockchain. As new blocks are added, the blockchain status of the target shard is also updated accordingly. This includes updating information such as block height, transaction records, node balances, etc. to ensure that the latest status of the blockchain is reflected on all nodes.
[0109] Through the above operations, step S4 not only ensures that the agricultural product transaction data is safely and reliably recorded in the blockchain, but also further enhances the integrity and consistency of the system. The process of block generation, broadcasting, verification and confirmation ensures the authenticity and legitimacy of the transaction data, while the chain structure of the blockchain ensures the immutability and transparency of the data. Finally, when the block is successfully added to the blockchain of the target shard, the system can continue to process new transaction data, ensuring the efficient operation and security of the entire blockchain network.
[0110] Embodiment 2
[0111] The present invention also provides a blockchain-based agricultural product transaction data tracking and recording system for executing the blockchain-based agricultural product transaction data tracking and recording method, including a blockchain network pre-constructed based on agricultural product transactions and multiple shards deployed in the blockchain network, wherein a cross-shard communication network is established between the multiple shards, and a cross-shard communication network is established between the multiple shards. Figure 2 As shown, the system comprises:
[0112] The shard allocation module 100 is used to respond to the request for uplinking agricultural product transaction data and allocate the agricultural product transaction data to the target shard according to the preset sharding rules, wherein the target shard is one of the specific shards in the blockchain network allocated according to the preset sharding rules and carrying the agricultural product transaction data.
[0113] Specifically, the shard allocation module 100 is further used for:
[0114] When an agricultural product transaction occurs, the relevant transaction data will be submitted to the blockchain network as a chain request. This chain request contains all the necessary information about the transaction, including the transaction type, the types of agricultural products involved, the transaction location and time, etc. After receiving the chain request, the agricultural product transaction data in the request is firstly verified to ensure the legitimacy and integrity of the transaction data, including but not limited to verifying whether the transaction data conforms to the predefined data format and structure; checking whether the identity information of the transaction participants is valid, and illustratively verifying the identity of the sender through a digital signature; confirming whether the timestamp contained in the transaction data is reasonable to prevent the illegal chaining of old or future data; verifying whether the transaction amount and other key fields are within a reasonable range to avoid the entry of abnormal values.
[0115] If the preliminary verification results show that the transaction data meets all the conditions for on-chain transmission, proceed to the next step; otherwise, the on-chain transmission request is rejected and an error message is returned to the request initiator, indicating the problem.
[0116] For agricultural product transaction data that has passed preliminary verification, it is necessary to determine which specific shard it should be assigned to. This process relies on pre-set sharding rules in order to optimize data processing efficiency and resource utilization. Key features for sharding allocation are extracted from transaction data that has passed preliminary verification, including transaction type, agricultural product type, transaction location, and transaction time.
[0117] Use a distributed sharding algorithm based on a hash function to match the above extracted features with the preset sharding strategy. Specifically, each feature can be input into the hash function to obtain a hash value, and then the shard to which the data should belong is determined based on the hash value. This method can ensure that transaction data with the same features are always assigned to the same shard, thereby simplifying subsequent data query and verification work.
[0118] The first data consensus module 200 is used to select at least one verification node in the target shard through a proof-of-stake consensus mechanism, and use the at least one verification node to perform data consensus on the agricultural product transaction data, wherein the verification node is a node pre-registered in the blockchain network and deployed in the multiple shards for consensus verification of the agricultural product transaction data.
[0119] Specifically, the first data consensus module 200 is also used for:
[0120] The stake of each node in the network is determined by the number of tokens it holds. A higher stake means that the node has a higher reputation and influence in the network. The weights of each node are calculated based on their stake. The weight reflects the relative importance of the node in the network and the likelihood of participating in the consensus process. Usually, the weight can be calculated by a simple ratio, that is, the stake of a node divided by the sum of the stakes of all nodes.
[0121] To ensure fairness and security, a random selection algorithm is used to select the set of verification nodes participating in the data consensus. This algorithm combines the weight of the node so that nodes with higher equity values have a greater probability of being selected, but also ensures a certain degree of randomness to prevent certain nodes from over-controlling the consensus process. Only those nodes that have been pre-registered in the blockchain network and deployed in the target shard are eligible to participate in the consensus process. This ensures that the nodes participating in the consensus are audited and trusted.
[0122] Once the set of verification nodes is determined, each verification node will independently perform verification operations on the agricultural product transaction data. This includes but is not limited to checking the format of the transaction data, verifying the identities of the two parties to the transaction, confirming the validity of the transaction amount, etc. After each verification node completes the verification, it will broadcast the verification results to other verification nodes in the target shard. This step is to ensure that all verification nodes can receive the latest verification information and prepare for the subsequent consensus. When all verification nodes have completed their respective verifications and broadcast the results, these results will be counted. If the proportion of verification nodes that reach a consensus exceeds a predetermined proportion (for example, 67% or higher), it is considered that a consensus has been reached in the data consensus stage of the agricultural product transaction data. This predetermined proportion can be adjusted according to the needs of the specific application to balance security and efficiency.
[0123] The second data consensus module 300 is used to trigger cross-shard verification after consensus is reached in the data consensus stage, wherein the cross-shard verification is to send a verification request to other shards except the target shard through the cross-shard communication network, and select a response shard for data consensus based on preset screening conditions.
[0124] Specifically, the second data consensus module 300 is also used for:
[0125] After reaching a consensus in the target shard, a verification request is sent to all shards except the target shard through the cross-shard communication network. This verification request contains the agricultural product transaction data and the target shard's identifier so that other shards can identify and process it. The content of the verification request includes transaction data (such as transaction type, agricultural product type involved, transaction location, transaction time and other key information) and the target shard identifier, which is used to identify the target shard that initiated the verification request and ensure that other shards can respond correctly.
[0126] After receiving the verification request, other shards will perform preliminary verification of the transaction data according to their own verification mechanism and generate a response. Each response contains the voting result (indicating whether the transaction data is approved to be put on the chain, such as "agree" or "disagree") and the response timestamp (recording the time of the response). The target shard will collect responses from all other shards and summarize them to prepare for the next selection.
[0127] In order to ensure the effectiveness and security of cross-shard verification, eligible response shards are selected from all responses. The selection mechanism is based on response speed and voting results. The specific steps are as follows:
[0128] First, a response time threshold is set in advance, and only shards that respond within this threshold are considered. This helps to exclude shards that respond too slowly and improves verification efficiency.
[0129] Then, among the shards whose response speed meets the requirements, further screening is performed based on the voting results. The voting results of each shard are counted, and the shard with the highest proportion of approval votes and exceeding the preset approval ratio threshold is selected as the final response shard. If there are multiple shards that meet the above conditions, one or more shards with the fastest response speed are selected as the response shards. This ensures that the selected shards not only meet the voting results requirements, but also have the fastest response speed, which improves the efficiency and reliability of verification.
[0130] The selected response shard will once again reach a data consensus on the agricultural product transaction data. This step is to further confirm the authenticity and integrity of the transaction data and ensure that it complies with the standards and rules of the entire blockchain network. The verification nodes in the response shard will independently verify the transaction data and broadcast the verification results to other verification nodes in the target shard. When all verification nodes reach a consensus, it is considered that a consensus has been reached in the cross-shard verification phase.
[0131] The on-chain module 400 is used to package the agricultural product transaction data into blocks and add them to the blockchain in the target shard after consensus is reached in the data consensus stage of the response shard.
[0132] Specifically, the uplink module 400 is also used for:
[0133] The verification node in the response shard generates a block containing agricultural product transaction data and consensus information generated by the data consensus process. This block contains not only the transaction data itself, but also related information generated during the consensus process, such as verification results, timestamps, etc. This information is used to prove the validity and legitimacy of the transaction data. The block content includes transaction data (such as transaction type, type of agricultural products involved, transaction location, transaction time and other key information), consensus information (such as the list of verification nodes participating in the consensus, voting results, timestamps, etc.) and other metadata (such as block height, hash value of the previous block, etc.), to ensure the link relationship between blocks and form a complete blockchain.
[0134] The generated block is broadcasted to all nodes except all verification nodes in the target shard through the broadcast mechanism of the blockchain network. This step ensures that all nodes except all verification nodes can receive the latest block information and prepare for subsequent verification and confirmation. The verification node sends the block to all nodes except all verification nodes in the target shard. After receiving the block, each node will perform a preliminary check to ensure that the content and format of the block conform to the blockchain specifications.
[0135] All nodes except all verification nodes in the target shard verify and confirm the block according to the consensus rules of the blockchain. The verification process includes the following aspects: first, verify whether the transaction data contained in the block is consistent with the data consensus reached in the response shard to ensure that there is no tampering or error; second, check whether the attributes of the block meet the specifications of the blockchain, such as block size, timestamp, hash value of the previous block, etc., to ensure the legitimacy and integrity of the block; finally, according to the consensus rules of the blockchain, verify whether the block meets the consensus requirements to ensure that it is recognized by the majority of nodes. When all nodes complete the verification and reach a consensus, the block is considered to be confirmed. At this point, the block can be officially added to the blockchain of the target shard.
[0136] Among them, the number of most nodes is customizable, and a ratio can be set in advance. If the proportion of recognized nodes exceeds this ratio, it can be determined that it is recognized by the majority of nodes.
[0137] After confirmation, the block is linked to the end of the blockchain of the target shard. This step forms an immutable chain structure by linking the hash value of the new block with the hash value of the previous block, ensuring the security and integrity of the blockchain. As new blocks are added, the blockchain status of the target shard is also updated accordingly. This includes updating information such as block height, transaction records, node balances, etc. to ensure that the latest status of the blockchain is reflected on all nodes.
[0138] The present application is described with reference to flowcharts and / or block diagrams of methods, devices (systems) and computer program products according to embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0139] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, the storage medium including a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable programmable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0140] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
Claims
1. A method for tracking and recording agricultural product transaction data based on blockchain, comprising a blockchain network pre-built based on agricultural product transactions and multiple shards deployed in the blockchain network, wherein a cross-shard communication network is established between the multiple shards, characterized in that: The method comprises: In response to a request for uploading agricultural product transaction data to a blockchain, the agricultural product transaction data is allocated to a target shard according to a preset sharding rule, wherein the target shard is one of the specific shards in the blockchain network allocated according to the preset sharding rule and carrying the agricultural product transaction data; In the target shard, at least one verification node is selected through a proof-of-stake consensus mechanism, and the at least one verification node is used to perform data consensus on the agricultural product transaction data, wherein the verification node is a node pre-registered in the blockchain network and deployed in the multiple shards for performing consensus verification on the agricultural product transaction data; After consensus is reached in the data consensus phase, cross-shard verification is triggered, wherein the cross-shard verification is to send a verification request to other shards except the target shard through the cross-shard communication network, and select a response shard for data consensus based on preset screening conditions; After consensus is reached in the data consensus phase of the response shard, the agricultural product transaction data is packaged into blocks and added to the blockchain in the target shard.
2. The method for tracking and recording agricultural product transaction data based on blockchain according to claim 1 is characterized in that: The preset sharding rule includes allocating shards according to at least one of the transaction type, agricultural product category, transaction time or transaction location of the agricultural product transaction data.
3. The method for tracking and recording agricultural product transaction data based on blockchain according to claim 2 is characterized in that: The response to the on-chain request for agricultural product transaction data also includes: The agricultural product transaction data in the chain request is preliminarily verified, and whether the agricultural product transaction data meets the chain conditions is determined based on the result of the preliminary verification. If so, shard allocation is performed according to the preset sharding rules; if not, the chain request is rejected.
4. The method for tracking and recording agricultural product transaction data based on blockchain according to claim 3 is characterized in that: In response to the request for uplinking the agricultural product transaction data, the agricultural product transaction data is allocated to the target shard according to the preset sharding rule, including: Acquiring characteristics of the agricultural product transaction data, wherein the characteristics include transaction type, agricultural product type, transaction location, and transaction time; Matching the features with a preset sharding strategy, wherein the sharding strategy is a distributed sharding algorithm based on a hash function; The target shard is determined according to the matching result, and the agricultural product transaction data is allocated to the corresponding target shard.
5. The method for tracking and recording agricultural product transaction data based on blockchain according to claim 1, characterized in that: In the target shard, selecting at least one verification node through a proof-of-stake consensus mechanism, and using the at least one verification node to perform data consensus on the agricultural product transaction data, including: Calculating the weight of each node according to the equity values of the multiple nodes in the blockchain network; A random selection algorithm is used, combined with node weights, to select a set of verification nodes participating in data consensus from multiple nodes pre-registered and deployed in the target shard; Each verification node in the verification node set independently performs a verification operation on the agricultural product transaction data; After each verification node completes the verification, it broadcasts the verification result to other verification nodes in the target shard; If the proportion of verification nodes that have reached a consensus exceeds a predetermined proportion, it is considered that a consensus has been reached in the data consensus stage of the agricultural product trading data.
6. The method for tracking and recording agricultural product transaction data based on blockchain according to claim 5 is characterized in that: After consensus is reached in the data consensus phase, cross-shard verification is triggered, including: Sending a verification request including the agricultural product transaction data and the identifier of the target shard to all shards except the target shard through the cross-shard communication network; Receive responses from other shards, where the responses include voting results on whether to approve the transaction data being uploaded to the chain and response timestamps; Based on the response speed and voting results, select the shard with fast response speed and voting results that meet the preset conditions as the response shard; The response shards are used to perform data consensus on the agricultural product transaction data again.
7. The method for tracking and recording agricultural product transaction data based on blockchain according to claim 6 is characterized in that: When selecting a response shard, the selection mechanism based on response speed and voting results includes: A response time threshold is pre-set, and only shards that respond within the response time threshold are considered; Among the shards whose response speed meets the requirements, the shards are sorted according to the voting results, and the shard with the highest proportion of approval votes and exceeding the preset approval proportion threshold is selected as the final response shard; If there are multiple shards that meet the conditions, one or more shards with the fastest response speed are selected as the response shards.
8. The method for tracking and recording agricultural product transaction data based on blockchain according to claim 1, characterized in that: After reaching a consensus in the data consensus phase of the response shard, the agricultural product transaction data is packaged into blocks and added to the blockchain in the target shard, including: The verification node in the response shard generates a block containing the agricultural product transaction data and consensus information generated by the data consensus process; Broadcasting the block to all nodes in the target shard except all verification nodes through the broadcast mechanism of the blockchain network; All nodes except all verification nodes verify and confirm the block according to the consensus rules of the blockchain, and after the block is confirmed, add the block to the blockchain of the target shard.
9. The method for tracking and recording agricultural product transaction data based on blockchain according to claim 8 is characterized in that: When adding the block to the blockchain of the target shard, it also includes: Verify whether the transaction data included in the block is consistent with the data consensus reached in the response shard; Checking whether the properties of the block meet the specifications of the blockchain; After confirmation, the block is linked to the end of the blockchain of the target shard and the status of the blockchain is updated.
10. A blockchain-based agricultural product transaction data tracking and recording system, used to execute the blockchain-based agricultural product transaction data tracking and recording method according to any one of claims 1 to 9, comprising a blockchain network pre-built based on agricultural product transactions and multiple shards deployed in the blockchain network, wherein a cross-shard communication network is established between the multiple shards, characterized in that: The system comprises: A shard allocation module, configured to respond to a request for uploading agricultural product transaction data to a blockchain and allocate the agricultural product transaction data to a target shard according to a preset sharding rule, wherein the target shard is one of the specific shards in the blockchain network allocated according to the preset sharding rule and carrying the agricultural product transaction data; A first data consensus module is used to select at least one verification node in the target shard through a proof-of-stake consensus mechanism, and use the at least one verification node to perform data consensus on the agricultural product transaction data, wherein the verification node is a node pre-registered in the blockchain network and deployed in the multiple shards for performing consensus verification on the agricultural product transaction data; A second data consensus module is used to trigger cross-shard verification after consensus is reached in the data consensus phase, wherein the cross-shard verification is to send a verification request to other shards except the target shard through the cross-shard communication network, and select a response shard for data consensus based on a preset screening condition; The on-chain module is used to package the agricultural product transaction data into blocks and add them to the blockchain in the target shard after consensus is reached in the data consensus stage of the response shard.