Disclosure of Invention
The invention provides a distributed commodity data storage system based on a block chain, a circulation and tracing method, aiming at the technical defects, the ideas of the block chain and the distributed data storage are introduced, a block chain alliance tracing system is established by organically integrating data resources of supervision departments, industry associations, production enterprises and circulation enterprises, all parties of the whole supply chain from raw materials to retailers participate in information entry and maintenance of the block chain together, and the data are ensured to be real, ordered and not to be forged. The forward traceable, reverse traceable and risk controllable functions are realized, products can be recalled, reasons can be found, responsibility can be found when quality safety problems occur, the responsibility of a quality safety main body is practically implemented, and a credible, transparent and efficient collaborative distributed industry alliance ecology is constructed.
In order to achieve the above object, the present invention provides a distributed commodity data storage system based on a block chain, which includes a plurality of super nodes and a plurality of common nodes;
the super node comprises: the system is used for examining and approving the joining qualification of a new member of the alliance in the block chain and verifying the validity of the transaction submitted by the member, storing the basic data of the common node in the block chain and the hash code generated according to the key control link information and reported by the common node, and maintaining an unencrypted account book for generating a traceability chain;
when a tracing request exists, the method is also used for verifying the consistency of the stored hash code and the hash code corresponding to the key control link information reported by the common node, and forming the key control link information and the tracing chain into complete commodity tracing information;
the common node comprises: the method comprises the steps that data information of the whole block chain is obtained and verified in an authorized mode, transaction records of the block chain are checked through a secret key, new transaction data are added into the block chain after the super node is verified, key control link information in a production and circulation link is recorded according to the requirements of laws and regulations, and a hash code is generated and reported to the super node;
and when a tracing request exists, reporting the recorded key control link information to the super node.
Preferably, the corresponding members of the super node at least comprise government regulatory departments and industry associations; the common nodes at least comprise a production enterprise, a raw material supplier, a distributor and a retailer.
Preferably, the super node includes:
an approval module: the system is used for examining and approving the joining qualification of a new member of the alliance in the blockchain and verifying the legality of the member submitting transaction;
account book module: the system comprises a node, a block chain and a source chain, wherein the node is used for generating an encrypted account book according to a transaction record of a common node, broadcasting the encrypted account book to the block chain and maintaining an unencrypted account book for generating the source chain;
a storage module: the hash code is used for storing basic data of a common node in a block chain and is generated according to key control link information and reported by the common node;
a tracing module: the system is used for receiving a traceability request of a traceability person, splicing traceability chains in transaction records of an account book according to time, verifying the consistency of the stored hash codes and the hash codes corresponding to the key control link information reported by the common node, and forming complete commodity traceability information by the key control link information and the traceability chains to send the commodity traceability information to the traceability person.
Preferably, the common node includes:
a data acquisition module: the method comprises the steps of acquiring and checking data information in the whole block chain;
a data reporting module: the system is used for adding new block data into the block chain after the super node verification;
a storage module: the system is used for storing key control link information;
a hash code generation module: and the hash code is generated according to the key control link information and is reported to the super node.
Preferably, the common node further includes:
the encryption signature module: for encrypting and signing the transaction record;
trace back code and case code generation module: the tracing code is used for generating a tracing code of the commodity and a box code of the packing box;
a binding module: the box code scanning and binding device is used for scanning and binding the box code corresponding to the packing box and the tracing code corresponding to the commodity in the box body according to the commodity packing condition.
Preferably, the key control link information at least includes a raw material detection report, a finished product detection report and a used raw material batch number of each batch.
The invention also provides a distributed commodity circulation method based on the block chain, which comprises the following steps:
s10, generating a hash code by the common node of the production enterprise in the block chain according to the key control link information, and generating a commodity tracing code and a packing box code;
s20, the super node in the block chain saves the hash code and verifies the tracing code and the box code;
s30, according to the commodity packing condition, scanning and binding box codes corresponding to packing boxes and tracing codes corresponding to commodities in a box body, and storing the association relationship between the box codes and the tracing codes into super nodes in a block chain;
s40, encrypting and signing the transaction record by the common node of the production enterprise in the block chain, and verifying the validity of the verification by the super node;
s50, scanning box codes by common nodes of circulation enterprises in the block chain to determine the goods feeding, and adding an encrypted transaction record to the super node and broadcasting the encrypted transaction record;
s60, scanning the sold commodity tracing code by the common nodes of the retailers in the block chain to generate an order, and associating the payment account number with the commodity tracing code and storing the payment account number and the commodity tracing code to the super node in the block chain when the consumer pays.
The invention also provides a distributed commodity tracing method based on the block chain, which comprises the following steps:
s100, scanning a tracing code of a commodity by a tracer, and initiating a tracing request to a super node;
s200, inquiring a box code to which the tracing code belongs in the circulation link in the record;
s300, searching circulation link transaction records corresponding to the box codes in the transaction records;
s400, sequentially splicing the super nodes into a tracing chain according to time in the circulation link transaction record;
s500, inquiring the production enterprise of the commodity through the tracing code, and initiating a key control link information inquiry request to a common node of the production enterprise;
s600, reporting the recorded key control link information to a super node, and verifying whether the hash value of the reported information is consistent with that recorded before by the super node;
and S700, combining the production key control link information with the traceability chain to form complete commodity traceability information, and returning the complete commodity traceability information to a traceability person.
The invention provides a distributed commodity data storage system based on a block chain and a circulation and tracing method, wherein the distributed commodity data storage system comprises three key contents, namely: block chaining, distributed storage, and tracing methods; the block chain solves the problem that transaction data in the current commodity production and circulation chain are not transparent, the credibility and authority of the data are ensured by means of the characteristic that the block chain can not be tampered, and trust friction between enterprises and between the enterprises and supervision departments is reduced; the distributed storage solves the problem of high storage pressure of a centralized tracing platform, the detailed information of the production and circulation links is dispersedly stored in the database of each enterprise node, and meanwhile, the data are ensured not to be tampered by enterprises through hash codes; finally, the tracing method provided by the invention solves the problems of incomplete supply chain tracing data and difficult positioning of responsibility, takes the tracing code as a core, and records all relevant information of the commodity from raw materials to consumers in the whole life cycle by combining means such as box code association, mobile payment and the like, so that when the quality problem occurs, a responsible party can be quickly positioned, and a recall notice is sent to relevant enterprises and consumers.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that, if directional indications (such as up, down, left, right, front, and back … …) are involved in the embodiment of the present invention, the directional indications are only used to explain the relative positional relationship between the components, the movement situation, and the like in a specific posture (as shown in the drawing), and if the specific posture is changed, the directional indications are changed accordingly.
In addition, if there is a description of "first", "second", etc. in an embodiment of the present invention, the description of "first", "second", etc. is for descriptive purposes only and is not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In addition, technical solutions between various embodiments may be combined with each other, but must be realized by a person skilled in the art, and when the technical solutions are contradictory or cannot be realized, such a combination should not be considered to exist, and is not within the protection scope of the present invention.
The invention provides a distributed commodity data storage system based on a block chain; the invention adopts a mode of alliance chain for deployment, government supervision departments (quality supervision bureau, food and drug administration, industry and commerce bureau, and the like) and industry associations are super nodes of a block chain, and have approval authority, and each time a new node is brought into the alliance chain, the new node is required to be agreed by the super nodes. The authorized access node is called as a common node, new tracing information block data can be added, the newly added data can be formally added into the chain after the validity of the newly added data is verified by the super node, and the data can not be changed once the chain is linked. The data on the block chain is disclosed to the full alliance members, but because the data is encrypted by the enterprise secret key, each enterprise can only check the own transaction data through the secret key, and therefore the safety of business privacy is guaranteed.
In a first preferred embodiment of the present invention, the system comprises a plurality of super nodes (government regulators and industry associations) and a plurality of regular nodes (manufacturing enterprises, raw material suppliers, distributors and retailers);
the super node comprises: the system is used for examining and approving the joining qualification of a new member of the alliance in the block chain and verifying the validity of the transaction submitted by the member, storing the basic data of the common node in the block chain and the hash code generated according to the key control link information and reported by the common node, and maintaining an unencrypted account book for generating a traceability chain; when a tracing request exists, the method is also used for verifying the consistency of the stored hash code and the hash code corresponding to the key control link information reported by the common node, and forming the key control link information and the tracing chain into complete commodity tracing information;
in the embodiment of the invention, the super node is responsible for approving the joining qualification of the new member of the alliance and verifying whether the transaction submitted by the member is legal. Each super node stores basic data such as basic information of the alliance enterprise, commodity type information, correlation information of the commodity tracing code and the box code and the like. Besides the encrypted account book on the public chain, an unencrypted account book is maintained on the super node, and a traceability chain can be generated through the account book when the public and the supervision personnel perform traceability. In order to save the storage space of the super node, the key control link information in the production and circulation link, such as raw material batches, inspection reports, environmental monitoring data in the transportation process and the like, is stored in a server of an enterprise, the super node only stores hash codes generated by the information, and the hash codes are changed if the enterprise modifies the information without permission.
The common node comprises: the system comprises a super node, a block chain, a data link and a data link, wherein the data link is used for acquiring and verifying data information in the whole block chain, adding new block data into the block chain after the super node is verified, recording key control link information in a production and circulation link according to a regulation requirement, generating a hash code and reporting the hash code to the super node; and when a tracing request exists, reporting the recorded key control link information and the generated hash code to the super node.
In the embodiment of the invention, the production enterprises, raw material suppliers, distributors, retailers and the like which join in the alliance belong to common nodes. The common node has the authority to acquire and check the data information of the whole block chain, but only can check the transaction record of the common node through an enterprise key, the common node can add new block data into the chain block, and the new data is formally added into the block chain after being confirmed by the confirmation super node. The common node needs to record key control link information in a production and circulation link according to the regulation requirement, generate a hash code and report the hash code to the super node.
In a second preferred embodiment of the present invention, as shown in fig. 1, the super node includes:
an approval module: the system is used for examining and approving the joining qualification of a new member of the alliance in the blockchain and verifying the legality of the member submitting transaction;
account book module: the system comprises a node, a block chain and a source chain, wherein the node is used for generating an encrypted account book according to a transaction record of a common node, broadcasting the encrypted account book to the block chain and maintaining an unencrypted account book for generating the source chain;
a storage module: the hash code is used for storing basic data of a common node in the block chain and is generated according to key control link information reported by the common node;
a tracing module: the system is used for receiving a traceability request of a traceability person, splicing traceability chains in transaction records of an account book according to time, verifying the consistency of the stored hash codes and the hash codes corresponding to the key control link information reported by the common node, and forming complete commodity traceability information by the key control link information and the traceability chains to send the commodity traceability information to the traceability person.
The common node comprises:
a data acquisition module: the method comprises the steps of acquiring and checking data information in the whole block chain;
a data reporting module: the system is used for adding new block data into the block chain after the super node verification;
a storage module: the system is used for storing key control link information;
a hash code generation module: and the hash code is generated according to the key control link information and is reported to the super node.
In a third preferred embodiment of the present invention, as shown in fig. 2, the common node further includes:
and an encryption signature module: for encrypting and signing the transaction record;
trace back code and box code generation module: the tracing code is used for generating a tracing code of the commodity and a box code of the packing box;
a binding module: the box code scanning and binding device is used for scanning and binding the box code corresponding to the packing box and the tracing code corresponding to the commodity in the box body according to the commodity packing condition.
The invention also provides a distributed commodity circulation method based on the block chain;
in a fourth preferred embodiment of the present invention, as shown in fig. 3 and 4, the method comprises the following steps:
s10, generating a hash code by the common node of the production enterprise in the block chain according to the key control link information, and generating a commodity tracing code and a packing box code;
in the embodiment of the invention, a production enterprise formulates a production plan, produces commodities according to batches, records key control link information such as raw material detection reports, finished product detection reports, raw material batch numbers and the like of each batch, connects the information in series to generate a hash code, and stores the association relationship between the hash code and the production batch by a super node; a production enterprise generates a certain number of tracing codes and box codes according to batch yield, and a template of the generated codes can be configured by the enterprise in a self-defined way;
s20, the super node in the block chain saves the hash code and verifies the tracing code and the box code;
in the embodiment of the invention, the association relationship between the hash code and the production batch is stored, and the uniqueness and the legality of the tracing code and the box code are verified;
s30, according to the commodity packing condition, scanning and binding box codes corresponding to packing boxes and tracing codes corresponding to commodities filled in the boxes, and storing the association relationship between the box codes and the tracing codes into super nodes in a block chain;
in the embodiment of the invention, the verified traceability codes and box codes are respectively attached to the commodities and the packing boxes by production enterprises, and it is worth mentioning that the box codes can also be not associated with batches, but directly generated in batches before production scheduling and printed on the packing boxes.
The method comprises the following steps that a production enterprise carries out boxing on commodities, and the operation steps during boxing are as follows:
setting the number of commodities put in each box, such as 6;
firstly, scanning the tracing codes of 6 commodities, and then automatically switching the system to a box code scanning mode;
thirdly, scanning the box codes to finish the binding operation;
and fourthly, automatically switching the system back to the tracing code scanning mode, and continuously scanning the next 6 tracing codes.
The whole process does not need any click operation, and binding can be completed only by continuously scanning the codes. And the association relation between the box code and the tracing code is stored in the super node.
S40, encrypting and signing the transaction record by the common node of the production enterprise in the block chain, and verifying the validity of the verification by the super node.
In the embodiment of the invention, a production enterprise fills in a sales order, inputs information such as a client name, a commodity name, a quantity, an amount and the like, scans and inputs a commodity box code corresponding to the sales order, and finally encrypts and signs a transaction record through an enterprise private key, so that a super node verifies the legality of the transaction.
S50, scanning box codes by common nodes of circulation enterprises in the block chain to determine the goods feeding, and adding an encrypted transaction record to the super node and broadcasting the encrypted transaction record;
in the embodiment of the invention, a circulation enterprise fills in a purchase order, scans box codes to complete purchase confirmation, and after two transaction parties complete confirmation, a super node adds an encrypted transaction record on an open block chain and broadcasts the encrypted transaction record to the whole network. Note: the figure omits the multi-stage distribution relation of the circulation link, and in practical application, when the intermediate circulation trader delivers goods to the downstream, the sales order and the scanning box code also need to be filled, and the specific flow is consistent with the sales of the production enterprises.
S60, scanning the sold commodity tracing code by the common nodes of the retailers in the block chain to generate an order, and associating the payment account number with the commodity tracing code and storing the payment account number and the commodity tracing code to the super node in the block chain when the consumer pays.
In the embodiment of the invention, after the commodity arrives at the terminal retailer and is sold on shelves, the retailer scans the tracing code of the commodity selected by the consumer to form an order, if the consumer pays through the mobile terminal, the system pays the association relationship between the account and the commodity tracing code and stores the association relationship in the super node, and if the commodity has quality problems and needs to be recalled, a supervision department can find the consumer who purchases the problem batch according to the records and remind the consumer.
The invention also provides a distributed commodity tracing method based on the block chain,
in a fifth preferred embodiment of the present invention, as shown in fig. 5 and 6, the method comprises the following steps:
s100, scanning a tracing code of a commodity by a tracer (consumer), and initiating a tracing request to a super node;
s200, inquiring a box code to which the tracing code belongs in a circulation link in a record;
in the embodiment of the invention, a tracing request is sent to a super node firstly, and the super node finds a box code to which a tracing code belongs in a circulation link in a tracing code-box code incidence relation table recorded before;
s300, searching circulation link transaction records corresponding to the box codes in the transaction records;
s400, sequentially splicing the super nodes into a tracing chain according to time in the circulation link transaction record;
s500, inquiring the production enterprise of the commodity through the tracing code, and initiating a key control link information inquiry request to a common node of the production enterprise;
s600, reporting the recorded key control link information and the generated hash code to a super node for verification, and verifying whether the hash value of the information returned by the production enterprise is consistent with the hash value recorded before;
and S700, combining the production key control link information with the traceability chain to form complete commodity traceability information, and returning the complete commodity traceability information to the consumer.
In the present invention, as shown in fig. 7, a block chain organizes data in units of blocks, and a block is a data structure for recording transactions. Each block consists of a block header and a block body, and the block header of each block except the created block contains the hash code of the previous block, the timestamp generated by the block, and the mercker root generated from the transaction data in the block body.
The Merck root is the root node of the Merck tree, and assuming that there are 8 transaction records in the block, the Merck root is constructed in the following way:
1. performing hash operation on the transaction records 1-8;
2. connecting two adjacent transaction records in series, and then performing hash operation to obtain 2-1-2-4;
3. repeating the second step to obtain 3-1 and 3-2;
4. repeating the second step to obtain 4-1, namely the mercker root.
The block body comprises a field of transaction amount and a transaction record list. The data fields of the transaction record are designed as follows:
according to the invention, a block chain transformation experiment is carried out on the basis of a food traceability platform in Guangdong province, transaction data of the traceability platform is obtained in real time through an API (application program interface) and then is encrypted and stored on a block chain, a food traceability block chain with 8 nodes is established at present, the functions of a purchase order, a sales order, a return order query and commodity traceability are realized, under the condition of the height of 1000 thousands of block areas, the concurrency number supported by the block chain APIs is more than 100, the response time is less than 1 second, and the commercial-grade transaction frequency can be met.
In summary, the transaction record of the present invention is written into the blockchain and then is published to all the federation members, each node in the federation keeps a complete ledger, and entries in the ledger can only be added, and cannot be tampered and deleted. The data in the public account book is encrypted, and enterprises can only check the transaction records of the enterprises through the secret keys; the key control link information in the production and circulation process is dispersedly stored in enterprise nodes, and the super nodes only store hash codes to check whether the hash codes are tampered; the generation of the tracing code and the box code needs to be verified through the super node for the uniqueness and the legality; and during boxing, the incidence relation between the box codes and the tracing codes is established, and the goods entering and exiting conditions can be recorded only by scanning the box codes in the circulation process. When the commodity tracing code is scanned, firstly, the box code to which the tracing code belongs in the circulation link is found through the association relation table, then, the circulation link transaction records corresponding to the box code are searched in the transaction records of the block chain, and the tracing chain is spliced according to time; the operation flow of associating the box codes with the tracing codes is improved, no click operation is needed in the whole box packing process, and the box packing efficiency is greatly improved; when a consumer purchases goods through mobile payment, the incidence relation between the goods tracing code and the consumer payment account is recorded, and a recall notice can be sent to the corresponding consumer when a certain batch of goods have quality problems.
The above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention, and all modifications and equivalents of the present invention, which are made by the contents of the present specification and the accompanying drawings, or directly/indirectly applied to other related technical fields, are included in the scope of the present invention.