CN111444192A - Method, device and equipment for generating Hash of global state in block chain type account book - Google Patents

Method, device and equipment for generating Hash of global state in block chain type account book Download PDF

Info

Publication number
CN111444192A
CN111444192A CN202010537100.3A CN202010537100A CN111444192A CN 111444192 A CN111444192 A CN 111444192A CN 202010537100 A CN202010537100 A CN 202010537100A CN 111444192 A CN111444192 A CN 111444192A
Authority
CN
China
Prior art keywords
new
tree
global state
data block
block
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010537100.3A
Other languages
Chinese (zh)
Other versions
CN111444192B (en
Inventor
张渊
杨新颖
俞本权
李亿泽
闫文远
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ant Blockchain Technology Shanghai Co Ltd
Original Assignee
Alipay Hangzhou Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alipay Hangzhou Information Technology Co Ltd filed Critical Alipay Hangzhou Information Technology Co Ltd
Priority to CN202010537100.3A priority Critical patent/CN111444192B/en
Publication of CN111444192A publication Critical patent/CN111444192A/en
Application granted granted Critical
Publication of CN111444192B publication Critical patent/CN111444192B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/32Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
    • H04L9/3236Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/50Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols using hash chains, e.g. blockchains or hash trees

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Business, Economics & Management (AREA)
  • Accounting & Taxation (AREA)
  • Finance (AREA)
  • Computer Security & Cryptography (AREA)
  • Software Systems (AREA)
  • Economics (AREA)
  • Computing Systems (AREA)
  • General Business, Economics & Management (AREA)
  • Technology Law (AREA)
  • Strategic Management (AREA)
  • Marketing (AREA)
  • Development Economics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A method, a device and equipment for generating Hash of global state in a block chain type account book are disclosed. When the global state tree in the block chain type account book is updated and the temporary Merck tree is calculated in a batch updating mode for new transactions, the batch new transactions are divided into K parts, and K threads in one-to-one correspondence are created to calculate the hash value.

Description

Method, device and equipment for generating Hash of global state in block chain type account book
Technical Field
The embodiment of the specification relates to the technical field of information, in particular to a method, a device and equipment for generating a hash of a global state in a block chain type account book.
Background
In a block chain type account book, there is usually a global state tree for recording the global state. When updating the global state, batch calculations may be performed on incoming transactions. For example, each time a plurality of new transactions come, the transactions are subjected to hash calculation in sequence to obtain root hashes of subtrees corresponding to the new transactions, and then the root hashes of the global state tree are calculated according to the root hashes of the subtrees. When the new transaction root hash is calculated, a sequential calculation mode is adopted, and the efficiency is low.
Disclosure of Invention
The embodiment of the application aims to provide a scheme capable of improving efficiency when the hash of the global state is calculated in a block chain type account book.
In order to solve the above technical problem, the embodiment of the present application is implemented as follows:
the method for generating the hash of the global state in the block chain type account book is applied to a centralized database server side for storing data records by the block chain type account book, and comprises the following steps:
obtaining a plurality of new transactions for which an ledger has been determined to need to be written, wherein hashes of the plurality of new transactions have not been written to a global state tree;
sorting the plurality of new transactions, and dividing the sorted plurality of new transactions into K ordered sets;
aiming at the ith set, creating an ith thread corresponding to the set, generating an ith sub-tree taking the new transaction contained in the ith set as a leaf node according to the sequence of the new transaction contained in the ith set,
Figure DEST_PATH_IMAGE001
sequentially splicing and generating K sub-trees to generate a temporary Merck tree taking the new transactions as leaf nodes;
merging the temporary Mercker tree and the current global state tree to generate a new global state tree taking the hash of the plurality of new transactions as a leaf node;
and acquiring the root hash of the new global state tree, and writing the root hash of the new global state tree into the block header of the data block in the account book.
Correspondingly, an embodiment of the present specification further provides a device for generating a hash of a global state in a block chain type account book, which is applied to a centralized database server that stores data records in the block chain type account book, and includes:
the system comprises an acquisition module, a processing module and a processing module, wherein the acquisition module acquires a plurality of new transactions which are determined to need to be written into an account book, and the hashes of the plurality of new transactions are not written into a global state tree;
the sorting module is used for sorting the plurality of new transactions and dividing the sorted plurality of new transactions into K ordered sets;
the multithreading calculation module is used for creating an ith thread corresponding to the set aiming at the ith set, generating an ith sub-tree taking the new transaction contained in the ith set as a leaf node according to the sequence of the new transaction contained in the ith set,
Figure 785758DEST_PATH_IMAGE001
the splicing module sequentially splices the K sub-trees to generate a temporary Merck tree with the new transactions as leaf nodes;
the merging module merges the temporary Mercker tree and the current global state tree and generates a new global state tree taking the hash of the new transactions as a leaf node;
and the writing module is used for acquiring the root hash of the new global state tree and writing the root hash of the new global state tree into the block header of the data block in the account book.
Through the scheme provided in the embodiment of the description, when the global state tree in the block chain type account book is updated, the temporary merkel tree is calculated in batches for new transactions, the new transactions in batches are divided into K parts, and K threads in one-to-one correspondence are created to calculate the hash value, so that the updating efficiency of the global state tree is improved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of embodiments of the invention.
In addition, any one of the embodiments in the present specification is not required to achieve all of the effects described above.
Drawings
In order to more clearly illustrate the embodiments of the present specification or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments described in the embodiments of the present specification, and other drawings can be obtained by those skilled in the art according to the drawings.
FIG. 1 is a diagram illustrating updating a global state tree according to the prior art;
fig. 2 is a schematic flowchart of a method for generating a hash of a global state in a blockchain ledger according to an embodiment of the present specification;
FIG. 3 is a diagram illustrating a multi-threaded manner for generating a temporary Mercker tree according to an embodiment of the present disclosure;
FIG. 4 is a diagram illustrating a temporary Merck tree and a current global state tree that are spliced according to an embodiment of the present disclosure;
fig. 5 is a schematic flowchart of a process for generating a data block in a block chain ledger provided by an embodiment of the present specification;
fig. 6 is a schematic diagram of a block header of a data block provided in an embodiment of the present specification;
fig. 7 is a schematic structural diagram of an apparatus for generating a hash of a global state in a block chain ledger provided in an embodiment of the present specification;
fig. 8 is a schematic structural diagram of an apparatus for configuring a method according to an embodiment of the present disclosure.
Detailed Description
In order to make those skilled in the art better understand the technical solutions in the embodiments of the present specification, the technical solutions in the embodiments of the present specification will be described in detail below with reference to the drawings in the embodiments of the present specification, and it is obvious that the described embodiments are only a part of the embodiments of the present specification, and not all the embodiments. All other embodiments that can be derived by one of ordinary skill in the art from the embodiments given herein are intended to be within the scope of protection.
The set of ledger transaction records in block chain form is composed of connected blocks, and each block contains some ordered transactions. The global state may be regarded as a state that is continuously updated as the transaction is executed, and all transaction information in the ledger is embodied in the global state and is held by the global state tree.
Specifically, the current global state may be characterized by a root hash of the global state tree, and the global state includes all transaction information in the ledger. When the ledger is initially created, the global state is empty. Leaf nodes in the global state tree are in one-to-one correspondence with transactions in the ledger. Generally, the leaf nodes are ordered from left to right in a manner consistent with the order of the transactions corresponding to the service nodes in the account book.
In the current block chain type ledger, the updating mode for the global state tree is that every time a transaction is newly written in the ledger, that is, the global state tree needs to be updated (that is, a leaf node is newly added to the right side in the global state tree), the root hash of the global state tree needs to be recalculated once. As shown in fig. 1, fig. 1 is a schematic diagram of updating a global state tree in the prior art, and a dotted node in the diagram indicates that the node needs to recalculate a hash value.
If a batch calculation is used, for example, every 1024 new transactions, the temporary Merck tree for the batch of new transactions is calculated and the global state tree is updated. Since the order needs to be maintained to obtain the hash value of each transaction, if the new transaction root hash is calculated, the new transaction is calculated in a sequential manner.
In a centralized database server, because the transaction frequency is high, the number of new transactions contained in a batch may be large even when a batch calculation method is used for new transactions. This way of sequentially computing the root hash of the new transaction is inefficient. Based on this, the embodiments of the present specification provide a scheme that can improve efficiency when the hash of the global state is calculated in the blockchain ledger.
The technical solutions provided by the embodiments of the present description are described in detail below with reference to the accompanying drawings. As shown in fig. 2, fig. 2 is a schematic flowchart of a method for generating a hash of a global state in a block chain type account book provided in an embodiment of the present specification, where the flowchart specifically includes the following steps:
s201, acquiring a plurality of new transactions which are determined to need to be written into the account book.
Wherein the hashes of the plurality of new transactions have not been written to the global state tree.
The transaction referred to in the specification refers to a data record with a business intention, which is issued to a blockchain by a user; for example, an operator may build a federation chain based on actual business requirements, relying on the federation chain to deploy some other types of online business unrelated to value transfer (e.g., a rental house business, a vehicle dispatching business, an insurance claim settlement business, a credit service, a medical service, etc.), and in such federation chain, the transaction may be a business message or a business request with a business intent issued by a user in the federation chain.
The new transaction in the embodiment of the present specification refers to a transaction that has been determined to require the ledger to be written, but is waiting for the block condition to arrive without writing the ledger. The specific writing method will be described in detail later, in other words, the information of the new transaction is waiting to be written into the current global state tree.
The specific number of new transactions is typically a pre-specified number. For example, the server pre-designates every 1000 new transactions as a batch.
In practical application, the pre-designated amount can be set according to the writing frequency of the transaction in the account book. Further, in one embodiment, the number may be set according to a branching situation of the global state tree. If the global state tree is an M-ary tree, the number of new transactions may be specified in a form such as M ^ n when the number is specified in advance.
For example, if the global state tree is a 2-way tree, then the number of new transactions can be specified to be 2^9, i.e., 512. If the global state tree is a 3-way tree. The number of new transactions can be specified to be, for example, 3 < lambda > 6, i.e., 729. The temporary merkel tree generated later is a full tree by the adaptation of the specified number to the branching situation of the global state tree, so that the splicing of the temporary merkel tree and the current global state tree is facilitated.
S203, sorting the new transactions, and dividing the sorted new transactions into K ordered sets.
Since the sequence of transactions is also a part of information in the ledger, if any two transactions in the same global state tree generated by the transactions have different sequences, the root hashes of the generated global state tree will also be different, and therefore the sequential arrangement of the leaf nodes also needs to be reflected in the global state tree.
In one embodiment, the ordering information of the transaction in the ledger, including the writing time or position information, may be ordered as a plurality of new transactions. For example, for new transactions that have been written into the ledger, there will be a write timestamp for each transaction, and then the new transactions may be ordered according to the chronological order of the write timestamps.
In another embodiment, the ranking may also be based on the location information of the new transaction in the ledger. The location information for a transaction may be determined by the block height of the data block in which it is located and the offset in the data block.
In the specification, the block height is monotonically increased, and the smaller data blocks are ranked more forward; the ordering of transactions in the same block is also fixed, so the offset of a transaction in the block is also unambiguous. For example, where the length of a transaction is a fixed unit, the sequence number may also be used to specify the location information of the transaction in the data block in which it is located. That is, sequence numbers may also be used to indicate offsets, and the smaller the sequence number, the earlier the ordering is in the same data block. That is, the position of a transaction in the book is negatively related to the block height and the offset, and the smaller the block height and the offset are, the more the position is ranked.
For example, if the position information of five data records existing in the new transaction is (2, 08), (3, 01), (2, 09), (2, 10), (3, 01), the new transaction sequence after sorting is (2, 08), (2, 09), (2, 10), (3, 01).
When the temporary Merck tree is generated, the leaf nodes corresponding to the newly written transaction are on the left, and the leaf nodes corresponding to the later written transaction are on the right, and the temporary Merck tree is generated by arranging the leaf nodes in sequence. By the method, the consistency of the ordering of the newly generated temporary merkel tree and the ordering mode of the leaf nodes in the global state tree can be kept, so that the subsequent combination of the temporary merkel tree and the global state tree can be facilitated.
S205, aiming at the ith set, creating an ith thread corresponding to the set, generating an ith sub-tree taking the new transaction contained in the ith set as a leaf node according to the sequence of the new transaction contained in the ith set,
Figure 185646DEST_PATH_IMAGE001
specifically, after sorting, the plurality of new transactions may be divided into K ordered sets. Within each set, the new transactions are still ordered in order. And creating K threads corresponding to the sets one by one to calculate the subtree corresponding to each set, wherein the number of the K threads can be set by a user on the basis of the calculation performance of the server.
Namely, for the ith set, creating an ith thread corresponding to the set, generating an ith sub-tree taking the new transaction contained in the ith set as a leaf node according to the sequence of the new transactions contained in the ith set,
Figure 471134DEST_PATH_IMAGE001
. Each sub-tree generated in this manner still contains ordering information between new transactions.
S207, sequentially splicing and generating K sub-trees to generate a temporary Merck tree taking the new transactions as leaf nodes.
Fig. 3 is a schematic diagram of generating a temporary merkel tree in a multi-thread manner according to an embodiment of the present disclosure, as shown in fig. 3. In the diagram, 8 new transactions are divided into 4 parts, and a temporary Merck tree is constructed by 4 threads simultaneously computing. In practical applications, more threads may be created and the number of new transactions calculated in each thread may be larger, for example, dividing 1024 new transactions into 16 parts and creating 16 threads, each thread needs to calculate 64 new transactions. In such a parallel manner, the speed of generating the temporary merkel tree can be increased.
S209, combining the temporary Merck tree and the current global state tree, and generating a new global state tree taking the hash of the new transactions as a leaf node.
In the merging process, it is first guaranteed that each new transaction exists as a leaf node in the temporary mercker tree, and should also exist as a leaf node in the new global state tree. Only if the new transaction is used as a leaf node, the root hash of the global state tree can be guaranteed to accurately reflect the information of all transactions in the account book.
Based on this, one merging method may be to determine the height of the root node of the temporary mercker tree, keep the height of the root node of the temporary mercker tree unchanged, splice the temporary mercker tree to the right side of the latest leaf node in the current global state tree, and generate a new global state tree with the hash of the new transactions as the leaf node.
For example, assuming that the height of the root node of the temporary merkel tree is 3, it is necessary to ensure that the height of the root node in the global state tree is also 3 when splicing. Meanwhile, if the leaf nodes in the global state tree are also arranged in sequence based on the aforementioned sorting information, then the rightmost leaf node in the current global state tree is the latest leaf node, and then during the splicing, only the leftmost leaf node in the temporary merkel tree needs to be spliced to the right of the rightmost leaf node in the global state tree. Fig. 4 is a schematic diagram illustrating splicing of a temporary merkel tree and a current global state tree according to an embodiment of the present disclosure. In practical applications, a binary tree global state tree may reach 30 levels high and a temporary merkel tree may reach more than ten levels high to accommodate enough transactions.
By the splicing mode, the temporary Mercker tree is kept completely unchanged, and all leaf nodes in the newly generated global state tree are kept to be arranged in sequence. Namely, the newly generated global state tree completely reflects the information of each transaction in the account book.
Obviously, in the new global state tree obtained by merging, because the temporary mercker tree corresponding to the new transaction is added, the hash values of the relevant nodes on the path formed from the root node in the temporary mercker tree to the root node of the new global state tree all need to be recalculated. As shown in fig. 4, the nodes that need to recalculate the hash value are illustrated with dashed lines.
And S211, acquiring the root hash of the new global state tree, and writing the root hash of the new global state tree into the block header of the data block in the account book.
In the embodiment of the present specification, each new data block is generated, that is, the root hash of the current global state tree needs to be written in the block header of the data block.
As previously described, there may be multiple new transactions for which ledgers have been written, or multiple new transactions for which ledgers have been determined to need to be written, simply waiting for an out-of-block condition to arrive. There are a number of possible implementations as follows.
For example, assume that the threshold number of blocks out in the ledger is greater than the specified number of new transactions. For example, if the threshold number of blocks in the ledger is 1024 data records, one data block, and the specified number of new transactions per batch is 256, then obviously, the global state tree is updated four times during one block outputting, and in this process, since new transactions of multiple batches need to be written into one data block, the root hash of the last updated global state tree is actually stored in the block header of the data block.
For another example, assuming that the threshold of the number of extracted blocks in the ledger is smaller than the specified number of new transactions, for example, the threshold of the number of extracted blocks in the ledger is 1 data record and the specified number of new transactions in each batch is 256, obviously, 256 data blocks need to be generated during this period to update the global state tree once. In this way, the root hashes of the global state trees stored in the block headers of a plurality of consecutive data blocks are the same.
In one embodiment, the threshold number of blocks in the ledger may be set to be the same as the number of new transactions specified in each batch. For example, the threshold number of blocks in the ledger is 256 data records, one data block, and the specified number of new transactions per batch is 256. In this way, the newly generated data block contains all new transactions of the batch, the global state tree is updated every time a data block is sent, the root hash of the global state tree stored in the block header of the data block is different, and each update of the global state tree is written into the account book.
Through the scheme provided in the embodiment of the description, when the global state tree in the block chain type account book is updated and the temporary merkel tree is calculated in batch for the new transaction, the batch of new transaction is divided into K parts, and K threads in one-to-one correspondence are created to calculate the hash value, so that the updating efficiency of the global state tree is improved.
Further, in an embodiment, if it is determined that the root hash of the updated global state tree has been written into the ledger, the temporary mercker tree generated in the updating process can be deleted, the memory space is effectively released, and the system load is reduced.
In the centralized database service provider related to this specification, a block chain ledger is generated as follows, and as shown in fig. 5, fig. 5 is a schematic flow chart of generating data blocks in a block chain ledger provided in an embodiment of this specification, and includes:
s501, receiving data records to be stored, and determining hash values of the data records.
As mentioned above, the data records to be stored here may be various consumption records of individual users of the client, or may be business results, intermediate states, operation records, and the like generated by the application server when executing the business logic based on instructions of the users. Specific business scenarios may include consumption records, audit logs, supply chains, government regulatory records, medical records, and the like. The meaning of the data records here is the same as that of the aforementioned transactions.
In one embodiment, the data record may include a service attribute. In each mechanism interfacing with the database server, the business attribute is generally unique in the interfacing mechanism, and the business attribute is based on different business scenarios, and may include a user name, a user identification number, a driver license number, a mobile phone number, a unique item number, a type of data record (for example, a model number of various reports, a receipt, an invoice or a payment list, and the like), and the like.
For example, for a third-party payment mechanism, the data record is a consumption record of a user, and the service attribute at this time is a user identifier (including a mobile phone number, an identity card number, a user name, and the like), or a hash value obtained by performing a hash algorithm on the user identifier; alternatively, for a government agency, the data records are a running stream of costs for multiple common items, and the business attribute at this time may be a unique number for each item.
The business attributes may be stored in a designated field (e.g., a header or a trailer of the data record) in the data record, so that the business attributes of the data record may be conveniently retrieved by the database server and the user.
It should be noted that a plurality of data records may be included in the same account book. The service attributes of these data records are likely to be different. For example, when one account book is open to multiple users, the data records may originate from different users, and if the business attribute is the user identifier, it is easy to understand that different data records often include different user identifiers.
The data records uploaded by the same user may also include a variety of different service attributes. For example, in the case of a ledger for recording the flow of funds, the business attributes of the data record may be the model number of the various statements, receipts, invoices or income/expense tables, and so on.
S503, when the preset blocking condition is reached, determining each data record to be written into the data block, and generating the Nth data block containing the hash value of the data block and the data record.
The preset blocking condition comprises the following steps: when the number of data records to be stored reaches a number threshold, for example, a new data block is generated every time one thousand data records are received, and one thousand data records are written into the block; alternatively, a time interval from the last blocking time reaches a time threshold, e.g., every 5 minutes, a new data block is generated, and the data records received within the 5 minutes are written into the block.
N here refers to a sequence number of the data block, that is, in the embodiment of the present specification, the data block is arranged in a block chain manner, and is arranged in sequence based on the blocking time, so that the data block has a strong timing characteristic. The block height of the data block is monotonically increased based on the sequence of the blocking time. The block height may be a sequence number, and at this time, the block height of the nth data block is N; the block height may also be generated in other ways.
When N =1, the data block at this time is the initial data block. The hash value and the block height of the initial data block are given based on a preset mode. For example, the initial data block does not contain data records, the hash value is any given hash value, and the block height blknum = 0; for another example, the trigger condition for generation of the initial data block is consistent with the trigger conditions of other data blocks, but the hash value of the initial data block is determined by hashing all of the contents in the initial data block.
When N >1, since the content and hash value of the previous data block have already been determined, at this time, the hash value of the current data block (nth data block) may be generated based on the hash value of the previous data block (i.e., nth-1 data block), for example, one possible way is to determine the hash value of each data record to be written into the nth data block, generate a mercker tree in the order of arrangement in the blocks, concatenate the root hash value of the mercker tree with the hash value of the previous data block, and generate the hash value of the current block again using the hash algorithm. For example, the hash value of the data block may be generated by concatenating the data records in the order of the data records in the block and hashing the concatenated data records to obtain the hash value of the entire data record, concatenating the hash value of the previous data block and the hash value of the entire data record, and performing a hash operation on the concatenated string.
After the user successfully uploads the data, the hash value of the corresponding data record and the hash value of the located data block can be obtained and stored, and integrity verification can be initiated based on the hash values. The specific verification method comprises the steps of recalculating the hash value of the data record and the hash value of the data block, and comparing the recalculated hash value with the locally stored hash value.
The data block generated in the above manner may include two parts, a block header and a block body. The block body can be used for storing plaintext of splicing data, or hash values of the splicing data, and the like; the block header may be used to store metadata about the data block, such as a version number of the ledger, a hash value of a previous data block, a root hash value of a merkel tree composed of the concatenated data in the data block itself, a hash value of the data block itself, a state array for recording an operated state of the concatenated data, and the like. As shown in fig. 6, fig. 6 is a schematic diagram of a block header of a data block according to an embodiment of the present disclosure.
By the above-mentioned manner of generating data blocks, each data block is determined by a hash value, and the hash value of the data block is determined by the content and the sequence of data records in the data block and the hash value of the previous data block. The user can initiate integrity verification based on the hash value of the data block at any time, and modification of any content in the data block (including modification of data record content or sequence in the data block) can cause inconsistency between the hash value of the data block calculated during verification and the hash value generated during data block generation, so that verification failure is caused, and centralized non-tampering is realized.
The integrity verification comprises integrity verification of a data block, namely, reconstructing a Mercker tree according to the hash values of data records in the data block, calculating a root hash value of the Mercker tree, recalculating the hash value of the data block according to the root hash value of the Mercker tree and the hash value of the previous data block, and performing consistency comparison with the hash value of the data block saved in advance.
The integrity verification may also include integrity verification for several consecutive data blocks, i.e. the hash value of a data block is recalculated from the root hash value of the merkel tree stored in the block header of the data block and the hash value of the previous data block and compared with the hash values of the previously stored data blocks.
Integrity verification may also include integrity verification of a certain data record. In the block chain type account book, when verifying the integrity of the data record, one way may be: and determining a data block where the data record is located, constructing a Mercker tree according to the data record in the data block, and calculating the root hash value of the current Mercker tree, so that consistency comparison can be performed with the root hash value of the Mercker tree stored in the block header, and if the root hash value is not consistent, the data record is tampered.
Another way may be that, when the user or the docking mechanism uploads the data record to the server, the user or the docking mechanism locally stores a backup copy of the data record or a hash value of the backup copy, so that the current hash value of the data record may be calculated and compared with the hash value of the backup copy for consistency, thereby implementing integrity verification.
Correspondingly, an embodiment of the present specification further provides an apparatus for generating a hash of a global state in a block chain type account book, which is applied to a centralized database server that stores data records in the block chain type account book, as shown in fig. 7, fig. 7 is a schematic structural diagram of the apparatus for generating a hash of a global state in a block chain type account book provided in the embodiment of the present specification, and includes:
an obtaining module 701, configured to obtain a plurality of new transactions for which it is determined that an account book needs to be written, where a hash of the new transactions has not been written into a global state tree;
a sorting module 703, configured to sort the multiple new transactions, and divide the sorted multiple new transactions into K ordered sets;
the multithread calculation module 705, for the ith set, creates the ith thread corresponding to the set, generates the ith sub-tree using the new transaction contained in the ith set as the leaf node according to the order of the new transactions contained in the ith set,
Figure 891968DEST_PATH_IMAGE001
the splicing module 707 sequentially splices the K generated subtrees to generate a temporary merkel tree with the new transactions as leaf nodes;
a merging module 709, configured to merge the temporary merkel tree and the current global state tree to generate a new global state tree with hashes of the new transactions as leaf nodes;
the writing module 711 obtains the root hash of the new global state tree, and writes the root hash of the new global state tree into the block header of the data block in the account book.
Further, in the apparatus, the sorting module 703 determines sorting information of each new transaction in the ledger, where the sorting information includes writing time or location information; and sequencing the plurality of new transactions according to the sequence of the sequencing information.
Further, in the apparatus, the merging module 709 determines a height of a root node of the temporary merkel tree; and keeping the height of the root node of the temporary Merck tree unchanged, splicing the temporary Merck tree to the right side of the latest leaf node in the current global state tree, and generating a new global state tree taking the hash of the new transactions as the leaf node.
Further, in the apparatus, the writing module 711 generates a new data block including the plurality of new transactions, and writes the root hash of the new global state tree into a block header of the new data block.
Further, in the apparatus, a deleting module 713 is further included to delete the temporary merkel tree.
Further, in the apparatus, a data block generating module 715 is further included, and in the block chain ledger, a data block is generated as follows: receiving data records to be stored, and determining hash values of the data records; when a preset blocking condition is reached, determining each data record to be written into the data block, and generating an nth data block containing the hash value of the data block and the data record, specifically comprising:
when N =1, the hash value and the block height of the initial data block are given based on a preset mode;
and when N is greater than 1, determining the hash value of the Nth data block according to each data record to be written into the data block and the hash value of the (N-1) th data block, and generating the Nth data block comprising the hash value of the Nth data block and each data record.
The embodiment of the present specification further provides a computer device, which at least includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor executes the computer program to implement the hash generation method for the global state in the blockchain ledger shown in fig. 2.
Fig. 8 is a schematic diagram illustrating a more specific hardware structure of a computing device according to an embodiment of the present disclosure, where the computing device may include: a processor 1010, a memory 1020, an input/output interface 1030, a communication interface 1040, and a bus 1050. Wherein the processor 1010, memory 1020, input/output interface 1030, and communication interface 1040 are communicatively coupled to each other within the device via bus 1050.
The processor 1010 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an Application Specific Integrated Circuit (ASIC), or one or more Integrated circuits, and is configured to execute related programs to implement the technical solutions provided in the embodiments of the present disclosure.
The Memory 1020 may be implemented in the form of a ROM (Read Only Memory), a RAM (Random access Memory), a static storage device, a dynamic storage device, or the like. The memory 1020 may store an operating system and other application programs, and when the technical solution provided by the embodiments of the present specification is implemented by software or firmware, the relevant program codes are stored in the memory 1020 and called to be executed by the processor 1010.
The input/output interface 1030 is used for connecting an input/output module to input and output information. The i/o module may be configured as a component in a device (not shown) or may be external to the device to provide a corresponding function. The input devices may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output devices may include a display, a speaker, a vibrator, an indicator light, etc.
The communication interface 1040 is used for connecting a communication module (not shown in the drawings) to implement communication interaction between the present apparatus and other apparatuses. The communication module can realize communication in a wired mode (such as USB, network cable and the like) and also can realize communication in a wireless mode (such as mobile network, WIFI, Bluetooth and the like).
Bus 1050 includes a path that transfers information between various components of the device, such as processor 1010, memory 1020, input/output interface 1030, and communication interface 1040.
It should be noted that although the above-mentioned device only shows the processor 1010, the memory 1020, the input/output interface 1030, the communication interface 1040 and the bus 1050, in a specific implementation, the device may also include other components necessary for normal operation. In addition, those skilled in the art will appreciate that the above-described apparatus may also include only those components necessary to implement the embodiments of the present description, and not necessarily all of the components shown in the figures.
Embodiments of the present specification further provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for generating the hash of the global state in the blockchain ledger shown in fig. 2.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
From the above description of the embodiments, it is clear to those skilled in the art that the embodiments of the present disclosure can be implemented by software plus necessary general hardware platform. Based on such understanding, the technical solutions of the embodiments of the present specification may be essentially or partially implemented in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments of the present specification.
The systems, methods, modules or units described in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. A typical implementation device is a computer, which may take the form of a personal computer, laptop computer, cellular telephone, camera phone, smart phone, personal digital assistant, media player, navigation device, email messaging device, game console, tablet computer, wearable device, or a combination of any of these devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the method embodiment, since it is substantially similar to the method embodiment, it is relatively simple to describe, and reference may be made to the partial description of the method embodiment for relevant points. The above-described method embodiments are merely illustrative, wherein the modules described as separate components may or may not be physically separate, and the functions of the modules may be implemented in one or more software and/or hardware when implementing the embodiments of the present specification. And part or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
The foregoing is only a specific embodiment of the embodiments of the present disclosure, and it should be noted that, for those skilled in the art, a plurality of modifications and decorations can be made without departing from the principle of the embodiments of the present disclosure, and these modifications and decorations should also be regarded as the protection scope of the embodiments of the present disclosure.

Claims (13)

1. The method for generating the hash of the global state in the block chain type account book is applied to a centralized database server side for storing data records by the block chain type account book, and comprises the following steps:
obtaining a plurality of new transactions for which an ledger has been determined to need to be written, wherein hashes of the plurality of new transactions have not been written to a global state tree;
sorting the plurality of new transactions, and dividing the sorted plurality of new transactions into K ordered sets;
aiming at the ith set, creating an ith thread corresponding to the set, generating an ith sub-tree taking the new transaction contained in the ith set as a leaf node according to the sequence of the new transaction contained in the ith set,
Figure 916587DEST_PATH_IMAGE001
sequentially splicing and generating K sub-trees to generate a temporary Merck tree taking the new transactions as leaf nodes;
merging the temporary Mercker tree and the current global state tree to generate a new global state tree taking the hash of the plurality of new transactions as a leaf node;
and acquiring the root hash of the new global state tree, and writing the root hash of the new global state tree into the block header of the data block in the account book.
2. The method of claim 1, ordering the plurality of new transactions, comprising:
determining sequencing information of each new transaction in an account book, wherein the sequencing information comprises writing time or position information;
and sequencing the plurality of new transactions according to the sequence of the sequencing information.
3. The method of claim 1, merging the temporary merkel tree and the current global state tree to generate a new global state tree with hashes of the plurality of new transactions as leaf nodes, comprising:
determining a height of a root node of the temporary merkel tree;
and keeping the height of the root node of the temporary Merck tree unchanged, splicing the temporary Merck tree to the right side of the latest leaf node in the current global state tree, and generating a new global state tree taking the hash of the new transactions as the leaf node.
4. The method of claim 1, writing a root hash of the new global state tree into a block header of a data block in the ledger, comprising:
generating a new data block containing the plurality of new transactions, and writing the root hash of the new global state tree into a block header of the new data block.
5. The method of claim 1, further comprising: deleting the temporary merkel tree.
6. The method of claim 1, wherein in the block-chained ledger, a data block is generated by:
receiving data records to be stored, and determining hash values of the data records;
when a preset blocking condition is reached, determining each data record to be written into the data block, and generating an nth data block containing the hash value of the data block and the data record, specifically comprising:
when N =1, the hash value and the block height of the initial data block are given based on a preset mode;
and when N is greater than 1, determining the hash value of the Nth data block according to each data record to be written into the data block and the hash value of the (N-1) th data block, and generating the Nth data block comprising the hash value of the Nth data block and each data record.
7. The hash generation device of global state in the block chain type account book is applied to the centralized database server side for storing data records by the block chain type account book, and comprises the following components:
the system comprises an acquisition module, a processing module and a processing module, wherein the acquisition module acquires a plurality of new transactions which are determined to need to be written into an account book, and the hashes of the plurality of new transactions are not written into a global state tree;
the sorting module is used for sorting the plurality of new transactions and dividing the sorted plurality of new transactions into K ordered sets;
the multithreading calculation module is used for creating an ith thread corresponding to the set aiming at the ith set, generating an ith sub-tree taking the new transaction contained in the ith set as a leaf node according to the sequence of the new transaction contained in the ith set,
Figure 430745DEST_PATH_IMAGE001
the splicing module sequentially splices the K sub-trees to generate a temporary Merck tree with the new transactions as leaf nodes;
the merging module merges the temporary Mercker tree and the current global state tree and generates a new global state tree taking the hash of the new transactions as a leaf node;
and the writing module is used for acquiring the root hash of the new global state tree and writing the root hash of the new global state tree into the block header of the data block in the account book.
8. The apparatus of claim 7, the ranking module to determine ranking information for each new transaction in a ledger, the ranking information comprising write time or location information; and sequencing the plurality of new transactions according to the sequence of the sequencing information.
9. The apparatus of claim 7, the merge module to determine a height of a root node of the temporary merkel tree; and keeping the height of the root node of the temporary Merck tree unchanged, splicing the temporary Merck tree to the right side of the latest leaf node in the current global state tree, and generating a new global state tree taking the hash of the new transactions as the leaf node.
10. The apparatus of claim 7, the write module to generate a new block of data containing the plurality of new transactions, to write a root hash of the new global state tree into a block header of the new block of data.
11. The apparatus of claim 7, further comprising a deletion module that deletes the temporary merkel tree.
12. The apparatus of claim 7, further comprising a data block generation module, wherein in the block chaining ledger, a data block is generated by: receiving data records to be stored, and determining hash values of the data records; when a preset blocking condition is reached, determining each data record to be written into the data block, and generating an nth data block containing the hash value of the data block and the data record, specifically comprising:
when N =1, the hash value and the block height of the initial data block are given based on a preset mode;
and when N is greater than 1, determining the hash value of the Nth data block according to each data record to be written into the data block and the hash value of the (N-1) th data block, and generating the Nth data block comprising the hash value of the Nth data block and each data record.
13. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method of any of claims 1 to 6 when executing the program.
CN202010537100.3A 2020-06-12 2020-06-12 Method, device and equipment for generating Hash of global state in block chain type account book Active CN111444192B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010537100.3A CN111444192B (en) 2020-06-12 2020-06-12 Method, device and equipment for generating Hash of global state in block chain type account book

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010537100.3A CN111444192B (en) 2020-06-12 2020-06-12 Method, device and equipment for generating Hash of global state in block chain type account book

Publications (2)

Publication Number Publication Date
CN111444192A true CN111444192A (en) 2020-07-24
CN111444192B CN111444192B (en) 2020-10-16

Family

ID=71653721

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010537100.3A Active CN111444192B (en) 2020-06-12 2020-06-12 Method, device and equipment for generating Hash of global state in block chain type account book

Country Status (1)

Country Link
CN (1) CN111444192B (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111444196A (en) * 2020-06-12 2020-07-24 支付宝(杭州)信息技术有限公司 Method, device and equipment for generating Hash of global state in block chain type account book
CN112003940A (en) * 2020-08-25 2020-11-27 徐鹏飞 Payment network state processing method and server based on block chain and online service
CN112380209A (en) * 2020-10-29 2021-02-19 华东师范大学 Block chain multi-channel state data-oriented structure tree aggregation method
CN112767154A (en) * 2021-01-18 2021-05-07 中国工商银行股份有限公司 Merkel tree calculation method and system applied to block chain system
WO2022027175A1 (en) * 2020-08-03 2022-02-10 Alipay (Hangzhou) Information Technology Co., Ltd. Blockchain transaction processing systems and methods

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110688377A (en) * 2019-08-30 2020-01-14 阿里巴巴集团控股有限公司 Method and device for updating state Merck tree
CN111008201A (en) * 2020-03-09 2020-04-14 支付宝(杭州)信息技术有限公司 Method and apparatus for parallel modification and reading of state trees
CN111444196A (en) * 2020-06-12 2020-07-24 支付宝(杭州)信息技术有限公司 Method, device and equipment for generating Hash of global state in block chain type account book

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110688377A (en) * 2019-08-30 2020-01-14 阿里巴巴集团控股有限公司 Method and device for updating state Merck tree
CN111008201A (en) * 2020-03-09 2020-04-14 支付宝(杭州)信息技术有限公司 Method and apparatus for parallel modification and reading of state trees
CN111444196A (en) * 2020-06-12 2020-07-24 支付宝(杭州)信息技术有限公司 Method, device and equipment for generating Hash of global state in block chain type account book

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
CE ZHANG等: "GEM2-Tree: A Gas-Efficient Structure for", 《2019 IEEE 35TH INTERNATIONAL CONFERENCE ON DATA ENGINEERING》 *

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111444196A (en) * 2020-06-12 2020-07-24 支付宝(杭州)信息技术有限公司 Method, device and equipment for generating Hash of global state in block chain type account book
WO2022027175A1 (en) * 2020-08-03 2022-02-10 Alipay (Hangzhou) Information Technology Co., Ltd. Blockchain transaction processing systems and methods
US11604608B2 (en) 2020-08-03 2023-03-14 Alipay (Hangzhou) Information Technology Co., Ltd. Blockchain transaction processing systems and methods
CN112003940A (en) * 2020-08-25 2020-11-27 徐鹏飞 Payment network state processing method and server based on block chain and online service
CN112003940B (en) * 2020-08-25 2021-03-23 云账户技术(天津)有限公司 Payment network state processing method and server based on block chain and online service
CN112380209A (en) * 2020-10-29 2021-02-19 华东师范大学 Block chain multi-channel state data-oriented structure tree aggregation method
CN112767154A (en) * 2021-01-18 2021-05-07 中国工商银行股份有限公司 Merkel tree calculation method and system applied to block chain system

Also Published As

Publication number Publication date
CN111444192B (en) 2020-10-16

Similar Documents

Publication Publication Date Title
CN111444196B (en) Method, device and equipment for generating Hash of global state in block chain type account book
CN111444192B (en) Method, device and equipment for generating Hash of global state in block chain type account book
CN110188096B (en) Index creating method, device and equipment for data record
US10255108B2 (en) Parallel execution of blockchain transactions
CN110162662B (en) Verification method, device and equipment for data records in block chain type account book
CN110825737A (en) Index creation and data query method, device and equipment
US20230074102A1 (en) Method and apparatus for processing data based on block chain, device and readable storage medium
CN110837502B (en) Data storage method, device and equipment in block chain type account book
CN106980665B (en) Data dictionary implementation method and device and data dictionary management system
CN110162526A (en) Querying method, device and the equipment of data record in a kind of piece of chain type account book
CN110349019B (en) Verification method, device and equipment in block chain type account book
CN107085613B (en) Method and device for filtering files to be put in storage
CN110879687B (en) Data reading method, device and equipment based on disk storage
CN110716965B (en) Query method, device and equipment in block chain type account book
WO2021057482A1 (en) Method and device for generating bloom filter in blockchain
CN112087530B (en) Method, device, equipment and medium for uploading data to block chain system
CN111459948B (en) Transaction integrity verification method based on centralized block chain type account book
CN112965939A (en) File merging method, device and equipment
CN110059088B (en) Data attribute identification method, device and equipment in block chain type account book
CN114490509A (en) Tracking change data capture log history
CN110059087B (en) Data attribute identification method, device and equipment in block chain type account book
CN111444197B (en) Verification method, device and equipment for data records in block chain type account book
CN111444194B (en) Method, device and equipment for clearing indexes in block chain type account book
CN110636042B (en) Method, device and equipment for updating verified block height of server
CN114816509A (en) Block chain version compatibility verification method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40034044

Country of ref document: HK

TR01 Transfer of patent right

Effective date of registration: 20240919

Address after: Room 803, floor 8, No. 618 Wai Road, Huangpu District, Shanghai 200010

Patentee after: Ant blockchain Technology (Shanghai) Co.,Ltd.

Country or region after: China

Address before: 310000 801-11 section B, 8th floor, 556 Xixi Road, Xihu District, Hangzhou City, Zhejiang Province

Patentee before: Alipay (Hangzhou) Information Technology Co.,Ltd.

Country or region before: China