A fast indexing method for commodity traceability system based on alliance chain

By storing product ID and Merkel tree index location in the alliance chain, using cache and block distance models to quickly locate traceability information, the problem of slow traceability in traditional blockchain traceability systems is solved, and efficient product traceability is achieved Query.

CN114547029BActive Publication Date: 2024-12-03NANJING UNIV OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210137278.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-15
Publication Date
2024-12-03
Estimated Expiration
2042-02-15

AI Technical Summary

Technical Problem

Traditional blockchain traceability systems have repetitive indexing operations when traced multiple times in a short period of time, and the query efficiency is low and the previous transaction block cannot be quickly located, resulting in too slow traceability and affecting system efficiency.

Method used

Using a fast indexing method based on alliance chain, by storing product ID and Merkel leaf node index locations in block headers, recording the latest block ID and timestamp, generating transaction information nodes, and using cache and block distance models to achieve fast Positioning and jumping to reduce duplicate queries.

Benefits of technology

It improves the query efficiency of traceability information, reduces the time complexity, and ensures the authenticity of product information and efficient indexing of transaction information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114547029B_ABST
    Figure CN114547029B_ABST
Patent Text Reader

Abstract

The present invention provides a fast indexing method for a commodity traceability system based on an alliance chain, comprising the following steps: S1: chaining information on commodities after leaving the factory, storing commodity ID and Merkle tree subnode index position in a fast positioning leaf node model in each block header, and recording the latest block ID of the commodity and its generation timestamp; S2: traceability query; S3: calculating the remaining cache quantity according to a repeated indexing mechanism; S4: taking out part of the transaction information in the cache and putting it into a result set; S5: calculating the Merkle tree subnode index position of the commodity; S6: calculating the number of blocks between the last transaction block and the current transaction block through a block distance model; S7: entering a jump block; S8: returning the result set to the user layer and displaying the traceability information, and caching the transaction data. Compared with the prior art, the present invention can ensure the authenticity and reliability of the traceability commodity information while also ensuring the efficiency of the transaction information index.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of commodity trading, and in particular to a fast indexing method for a commodity traceability system based on an alliance chain. Background Art

[0002] In recent years, with the continuous development of my country's e-commerce business, the number of electronic transactions of goods has continued to expand. Since imported goods have the characteristics of high value and high tax rates, it is easy for many imitators to produce and sell counterfeit goods for sale. Consumers lack the ability to distinguish genuine goods and are prone to buy counterfeit goods. Therefore, it is necessary to improve the transparency of commodity source information and prevent counterfeit goods. High tax rates are prone to smuggling and affect the normal market operation order. Therefore, it is necessary to trace the source of goods and improve the coverage and accuracy of traceability information. However, the traditional blockchain traceability system has the following problems: Problem 1. Because the traceability traverses the entire blockchain at one time, when the same commodity is traced multiple times in a short period of time, some unnecessary repetitive index operations will be performed, thereby affecting the efficiency of the system. Problem 2. The traditional blockchain traceability system only has commodity information from the factory to the dealer on the chain, and does not involve the situation where the information of multiple discontinuous transactions is repeatedly on the chain. Since the blockchain adopts a chain structure, it is necessary to search and match from the back block one by one when tracing the source, and it is impossible to directly realize the rapid positioning of the previous transaction block, which will waste a lot of time consumed by entering irrelevant blocks. Question three: A block is composed of four or more transaction information nodes. To enter a specified block and find matching commodity transaction information, it is necessary to compare the transaction information of the Merkle tree leaf nodes one by one. The query efficiency is low, the methods are limited, and the time complexity is high, which makes the traceability speed too slow, thereby weakening the application value of blockchain technology.

[0003] In view of this, it is indeed necessary to provide a fast indexing method for a product traceability system based on an alliance chain to solve the above problems. Summary of the invention

[0004] The purpose of the present invention is to provide a fast indexing method for a commodity traceability system based on an alliance chain, which can ensure the authenticity and reliability of traceable commodity information while also ensuring the efficiency of transaction information indexing.

[0005] To achieve the above object, the present invention provides a fast indexing method for a product traceability system based on an alliance chain, comprising the following steps:

[0006] S1: The information of the goods after leaving the factory is uploaded to the chain, and the product ID and the index position of the Merkle tree leaf node are stored in a specific form in the fast positioning leaf node model in each block header. At the same time, the latest block ID of the product and the latest block generation timestamp of the product are recorded in the off-chain table. When a transaction occurs, a transaction information node is generated and the latest block generation timestamp of the transaction product is also stored in it as the last transaction block generation timestamp, and the data in the off-chain table is updated synchronously;

[0007] S2: The user enters the unique traceability ID of the product to enter the system traceability query;

[0008] S3: Calculate the remaining cache quantity of the product according to the repeated index mechanism. If there is decay, it means that the latest transaction block of the product is inconsistent with the latest block in the cache, and continue to step S4; otherwise, take out all transaction information and put it into the result set, and then jump to step S8;

[0009] S4: First, retrieve some transaction information from the cache and put it into the result set. Then, retrieve the latest block ID of the product from the table and locate the latest transaction block of the product.

[0010] S5: The Merkle tree leaf node index position of the transaction storage corresponding to the product is obtained through the fast positioning leaf node model in the block header and the input product ID, and then the leaf node where the transaction information is located is quickly located and the transaction information is taken out and put into the result set;

[0011] S6: If the timestamp of the last transaction block generation exists in the block information, the number of blocks between the last transaction block and the current transaction block is calculated by the difference between the timestamp of the last transaction block generation and the timestamp of the current transaction block generation and the block distance model, so as to quickly jump to the last transaction block of the commodity and obtain information through the block during the tracing process; otherwise, it means that the root information has been traced back, and it directly jumps to step S8;

[0012] S7: After entering the jump block, if the timestamp of the current transaction block generated by the jump is inconsistent with the timestamp of the last transaction block generated, the block interval is calculated again to achieve the jump until the timestamp of the current transaction block generated is equal to the timestamp of the last transaction block generated, and then the detailed transaction data is taken out and step S6 is repeated;

[0013] S8: Return the result set to the user layer and display the traceability information, while caching the transaction data.

[0014] As a further improvement of the present invention, in step S1, the product ID and the Merkle tree child node index position are stored in the address of the calculated F(ID) subscript position. If the F(ID) position in the array already exists, a new data block is inserted in the form of a linked list.

[0015] F(key)=(H(key)%100)&(L-1) (1)

[0016] Among them, ID in F(ID) is the ID of the traceable product; key is the unique traceability identification ID of the input product; H(key) is a function that converts a string into a unique numeric string; and L is the array length.

[0017] As a further improvement of the present invention, the F(ID) position in the array already exists means that a subscript conflict occurs in F(ID).

[0018] As a further improvement of the present invention, in step S3, in the repeated indexing mechanism, as the index interval increases and time passes, the number of caches will decrease accordingly, and the remaining number of caches is shown in formula (2):

[0019]

[0020] Among them, CacheSum is the remaining cache amount of the product; Num(GID) is the total block information amount of the product; frequency is the number of queries by the user in the last hour; t is the time since the user's last traceback.

[0021] As a further improvement of the present invention, in step S3, if it is the first time to trace the source, CacheSum is 0, and all the information of the traceable product is required.

[0022] As a further improvement of the present invention, in step S3, if the traceability is performed multiple times in a short period of time, it is calculated according to formula (2) whether there is attenuation. If there is attenuation, continue to step S4; if there is no attenuation, directly retrieve all transaction information and put it into the result set, and then jump to step S8.

[0023] As a further improvement of the present invention, in step S5, the ID is input, and F(ID) is calculated using the above formula (1). The product ID stored in the head node of the F(ID) subscript position in the array is checked to see if it is consistent with the input product ID. If not, the next node position of the node linked list is checked until they are consistent. The Merkle tree leaf node index position in the data is taken out, and then the Merkle tree leaf node index position is output.

[0024] As a further improvement of the present invention, in step S6, the number of interval blocks is obtained according to formula (3):

[0025]

[0026] Among them, DiffBlockNum is the number of blocks between the last transaction block and the current transaction block; currT is the current transaction block timestamp converted to date; preT is the last transaction block timestamp converted to date; d is the difference in days between the two blocks; N is the average total number of new blocks added to the blockchain per day; P i Represents the probability of generating a block at time point i.

[0027] As a further improvement of the present invention, P in formula (3) i According to formula (4), we can get:

[0028]

[0029] Among them, P represents the probability of generating a block; i represents the time point; λ represents the frequency of the event.

[0030] As a further improvement of the present invention, in step S6, the root information refers to the factory information of the product.

[0031] The beneficial effects of the present invention are: while ensuring that the traceability product information is authentic and reliable, the present invention does not have the problems of low transparency and user trust crisis of the centralized management traceability system, and can also ensure the high efficiency of the transaction information index. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 It is a diagram of the architecture of a commodity traceability system in accordance with a preferred embodiment of the present invention.

[0033] Figure 2 It is a flow chart of the design of a fast indexing scheme in accordance with a preferred embodiment of the present invention.

[0034] Figure 3 It is a graph of the number of caches in the duplicate indexing mechanism.

[0035] Figure 4 It is a model diagram for quickly locating leaf nodes.

[0036] Figure 5 It is a block generation time probability curve.

[0037] Figure 6 It is a flowchart of the fast indexing method. DETAILED DESCRIPTION

[0038] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure more clear, the technical solution of the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings of the embodiments of the present disclosure.

[0039] See also Figures 1 to 6As shown, the present invention discloses a rapid indexing method for a commodity traceability system based on an alliance chain. By adopting this method, the authenticity and reliability of the traceable commodity information can be ensured while eliminating the problems of low transparency and user trust crisis in the centralized management traceability system, and the efficiency of the transaction information indexing can be ensured.

[0040] In the embodiment of the present invention, an experiment is conducted based on a luxury goods transaction traceability system based on an alliance chain, where G represents a certain luxury goods and T represents a transaction. Then, the fast indexing method of the luxury goods G is as follows:

[0041] Step S1: After the luxury product G leaves the factory, the manufacturer information is uploaded to the chain, and the luxury product ID (GID) and the leaf node index position Tindex corresponding to the Merkle tree are stored in a specific form in the fast positioning leaf node model in each block header. The storage format is as follows: Figure 4 As shown, the latest block ID (lastBlockID) of the luxury item G and the latest block generation timestamp (lastBlockTimestamp) of the luxury item G are recorded in the off-chain table. When a luxury item is traded twice or multiple times thereafter, a transaction information node is generated and the lastBlockTimestamp of the item is also stored as the last transaction block generation timestamp (preBlockTimestamp) field, and the data in the off-chain table is updated synchronously.

[0042] like Figure 4 As shown, assuming that F(GID)=1 is calculated, and the leaf node in the merkle tree of the block is T3, GID and T3 are stored in the address of the array subscript position 1. If the F(GID) position in the F(GID) array already exists (that is, a subscript conflict occurs), a new data block is inserted at the array position in the form of a linked list.

[0043] F(key)=(H(key)%100)&(L-1) (1)

[0044] Among them, key is the unique traceability ID of the input product; H(key) is the function that converts a string into a unique numeric string; and L is the length of the array.

[0045] Step S2: The user enters the unique traceability ID of luxury product G to enter the system traceability query.

[0046] Step S3: Calculate the remaining cache quantity of the product according to the repeated index mechanism. If there is decay, it means that the latest transaction block (lastBlockID) of luxury product G is inconsistent with the latest block in the cache (cacheBlockID). Continue to step S4. Otherwise, take out all transaction information and put it into the result set (result), and then jump to step S8.

[0047] Furthermore, in step S3, in the repeated indexing mechanism, as the indexing interval increases and time passes, the number of caches will decrease accordingly, and the remaining number of caches is shown in formula (2):

[0048]

[0049] Among them, GID is the luxury ID of the traceable product; CacheSum is the remaining cache amount of luxury product G; Num(GID) is the total block information amount of luxury product G; frequency is the number of queries by the user in the last hour; t is the time since the user's last traceability, in minutes.

[0050] Understandably, if it is the first time to trace the source, that is, t is positive infinity, formula (2) will give CacheSum as 0, indicating that all the information of luxury product G needs to be traced. However, if it is multiple traces within a short period of time, the formula (2) is used to calculate whether there is attenuation. If there is attenuation, continue to step S4; if there is no attenuation, directly retrieve all transaction information and put it into result, and then jump to step S8.

[0051] The present invention adds a repeated indexing mechanism to the system architecture. As the index interval increases and time passes, the number of caches will decrease accordingly. If a user searches for traceability information of the same product multiple times in a short period of time, some of the existing information can be directly obtained from the cache. To query on the blockchain, it is only necessary to query the last block in the cache, and there is no need to traverse all blocks, which greatly reduces repeated query work and improves efficiency.

[0052] Step S4: first take out part of the transaction information in the cache and put it into result, then take lastBlockID in the table and locate the latest transaction block position of the luxury product G.

[0053] Step S5: After entering the block, the merkle tree leaf node index position Tindex of the transaction storage corresponding to the luxury item G can be obtained through the quick positioning leaf node model in the block header and the input GID, and then the leaf node where the transaction information is located can be quickly located and the transaction information can be taken out and put into the result.

[0054] Furthermore, in step S5, the input is GID, and the above formula (1) is used to calculate F(GID), that is, the subscript position in the array is 1, and the GID stored in the head node in the subscript position 1 in the array is compared with the input to see if they are consistent. If not, continue to check the next node position of the node linked list until they are consistent, then take out Tindex in the data, and then output (output) is Tindex. The final output taken out is T3.

[0055] According to T3, the node position of the merkle tree corresponding to the transaction information of the luxury product G can be quickly located, and the traceability information corresponding to the luxury product G in the block can be quickly retrieved and put into the result.

[0056] In this embodiment, the structure of array plus linked list is adopted in the model for quickly locating leaf nodes, and the array subscript position is calculated by formula, and the ID of luxury product G and the corresponding position index of the Merkle tree leaf node in the block body are stored in the subscript position. When the ID is input, the subscript position is calculated by formula, and the index position of the leaf node in the Merkle tree can be quickly reached at the subscript position to return a leaf node in the Merkle tree, so as to quickly locate the leaf node index position where the transaction information is located and retrieve the transaction information, so that the time complexity is reduced and the query efficiency is greatly improved.

[0057] Step S6: If preBlockTimestamp exists in the block information, the number of blocks between the last transaction block and the current transaction block is calculated through the difference between preBlockTimestamp and the timestamp (currBlockTimestamp) generated by the current transaction block and the block distance model, so that during the traceability process, it is possible to quickly jump to the last transaction block of the luxury product G through the block and obtain information; otherwise, it means that the root information, i.e., the factory information of the product, has been traced back, and it jumps directly to step S8.

[0058] Furthermore, the number of blocks in the interval is obtained according to formula (3):

[0059]

[0060] Among them, DiffBlockNum is the number of blocks between the last transaction block and the current transaction block; currT is the current transaction block timestamp converted to date, assuming it is 2021-08-06 14:50:49; preT is the last transaction block timestamp converted to date, assuming it is 2021-08-04 13:50:49; d is the difference in days between the two blocks, assuming it is 2 days; N is the average total number of new blocks added to the blockchain per day, assuming it is 100; P i Represents the probability of generating a block at time point i, such as Figure 5 shown.

[0061] Furthermore, P in formula (3) i According to formula (4), we can get:

[0062]

[0063] Among them, P represents the probability of generating a block; i represents the time point; λ represents the frequency of the event.

[0064] Through calculation, it can be concluded that DiffBlockNum is 189 blocks. According to the above output of 189, the block with a height interval of 189 blocks can be directly jumped without entering the block header for comparison and search.

[0065] In this embodiment, by first modifying the storage structure of the metadata in the block body, it will first be determined whether the luxury product G is the first transaction. If it is not the first transaction, the timestamp of the last transaction block generation of the luxury product G is added to the metadata of the current transaction for storage. Then, when it is necessary to obtain the last transaction block of the luxury product G, the number of blocks between the last transaction block and the current transaction block can be calculated according to the block distance model, so that the last transaction block of the luxury product G can be quickly jumped to during the tracing process and the detailed transaction data can be retrieved.

[0066] Step S7: After entering the jump block, if the currBlockTimestamp and preBlockTimestamp are inconsistent, the block interval is calculated again according to the above block distance model based on these two timestamps to achieve the jump until currBlockTimestamp is equal to preBlockTimestamp, and then the detailed transaction data is taken out and step S6 is repeated.

[0067] Step S8: Return the result to the user layer and display the traceability information, while caching the data.

[0068] In summary, the present invention ensures that the traceability product information is authentic and reliable, does not have the problems of low transparency and user trust crisis of the centralized management traceability system, and can also ensure the efficiency of transaction information indexing.

[0069] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A fast indexing method for a product traceability system based on an alliance chain, characterized by: The following steps are involved: S1: The information of the goods after leaving the factory is uploaded to the chain, and the product ID and the index position of the Merkle tree leaf node are stored in a specific form in the fast positioning leaf node model in each block header. At the same time, the latest block ID of the product and the latest block generation timestamp of the product are recorded in the off-chain table. When a transaction occurs, a transaction information node is generated and the latest block generation timestamp of the transaction product is also stored in it as the last transaction block generation timestamp, and the data in the off-chain table is updated synchronously; S2: The user enters the unique traceability ID of the product to enter the system traceability query; S3: Calculate the remaining cache quantity of the product according to the repeated index mechanism. If there is decay, it means that the latest transaction block of the product is inconsistent with the latest block in the cache, and continue to step S4; otherwise, take out all transaction information and put it into the result set, and then jump to step S8; S4: First, retrieve some transaction information from the cache and put it into the result set. Then, retrieve the latest block ID of the product from the table and locate the latest transaction block of the product. S5: The Merkle tree leaf node index position of the transaction storage corresponding to the product is obtained through the fast positioning leaf node model in the block header and the input product ID, and then the leaf node where the transaction information is located is quickly located and the transaction information is taken out and put into the result set; S6: If the timestamp of the last transaction block generation exists in the block information, the number of blocks between the last transaction block and the current transaction block is calculated by the difference between the timestamp of the last transaction block generation and the timestamp of the current transaction block generation and the block distance model, so as to quickly jump to the last transaction block of the commodity and obtain information through the block during the tracing process; otherwise, it means that the root information has been traced back, and it directly jumps to step S8; S7: After entering the jump block, if the timestamp of the current transaction block generated by the jump is inconsistent with the timestamp of the last transaction block generated, the block interval is calculated again according to the two timestamps to achieve the jump until the timestamp of the current transaction block generated is equal to the timestamp of the last transaction block generated, and then the detailed transaction data is taken out and step S6 is repeated; S8: Return the result set to the user layer and display the traceability information, while caching the transaction data.

2. The fast indexing method of the commodity traceability system based on the alliance chain according to claim 1 is characterized by: In step S1, the product ID and the Merkle tree node index position are stored in the address of the calculated F(ID) subscript position. If the F(ID) position in the array already exists, a new data block is inserted in the form of a linked list. F(key)=(H(key)%100)&(L-1) (1) Among them, ID in F(ID) is the ID of the traceable product; key is the unique traceability identification ID of the input product; H(key) is a function that converts a string into a unique numeric string; and L is the array length.

3. The fast indexing method of the commodity traceability system based on the alliance chain according to claim 2 is characterized by: The F(ID) position in the array already exists, which means that there is a subscript conflict for F(ID).

4. The fast indexing method of the commodity traceability system based on the alliance chain according to claim 1 is characterized in that: In step S3, in the repeated indexing mechanism, as the indexing interval increases and time passes, the number of caches will decrease accordingly. The remaining number of caches is shown in formula (2): Among them, CacheSum is the remaining cache quantity of the product; Num(ID) is the total block information quantity of the product; frequency is the number of queries by the user in the last hour; t is the time since the user's last traceback.

5. The fast indexing method of the commodity traceability system based on the alliance chain according to claim 4 is characterized in that: In step S3, if it is the first time to trace the source, CacheSum is 0, and all the information of the traceable product is required.

6. The fast indexing method of the commodity traceability system based on the alliance chain according to claim 4 is characterized in that: In step S3, if the traceback is performed multiple times in a short period of time, calculate whether there is attenuation according to formula (2). If there is attenuation, proceed to step S4; if there is no attenuation, directly retrieve all transaction information and put it into the result set, and then jump to step S8.

7. The fast indexing method of the commodity traceability system based on the alliance chain according to claim 2 is characterized by: In step S5, the ID is input, and F(ID) is calculated using formula (1). The product ID stored in the head node of the F(ID) subscript position in the array is checked to see if it is consistent with the input product ID. If not, the next node position of the node list is checked until they are consistent. The Merkle tree subnode index position in the data is taken out, and then the Merkle tree subnode index position is output.

8. The fast indexing method of the commodity traceability system based on the alliance chain according to claim 1 is characterized by: In step S6, the number of blocks in the interval is obtained according to formula (3): Among them, DiffBlockNum is the number of blocks between the last transaction block and the current transaction block; currT is the current transaction block timestamp converted to date; preT is the last transaction block timestamp converted to date; d is the difference in days between the two blocks; N is the average total number of new blocks added to the blockchain per day; P i Represents the probability of generating a block at time point i.

9. The fast indexing method of the commodity traceability system based on the alliance chain according to claim 8 is characterized in that: P in formula (3) i According to formula (4), we can get: Among them, P represents the probability of generating a block; i represents the time point; λ represents the frequency of the event.

10. The fast indexing method of the commodity traceability system based on the alliance chain according to claim 1 is characterized by: In step S6, the root information refers to the factory information of the product.