WO2021093461A1 - Method and apparatus for aggregation calculation in blockchain-type ledger, and device - Google Patents

Method and apparatus for aggregation calculation in blockchain-type ledger, and device Download PDF

Info

Publication number
WO2021093461A1
WO2021093461A1 PCT/CN2020/116810 CN2020116810W WO2021093461A1 WO 2021093461 A1 WO2021093461 A1 WO 2021093461A1 CN 2020116810 W CN2020116810 W CN 2020116810W WO 2021093461 A1 WO2021093461 A1 WO 2021093461A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
block
data record
record
data block
Prior art date
Application number
PCT/CN2020/116810
Other languages
French (fr)
Chinese (zh)
Inventor
杨新颖
殷山
张渊
孙勇
Original Assignee
蚂蚁区块链科技(上海)有限公司
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 蚂蚁区块链科技(上海)有限公司 filed Critical 蚂蚁区块链科技(上海)有限公司
Publication of WO2021093461A1 publication Critical patent/WO2021093461A1/en

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/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24553Query execution of query operations
    • G06F16/24554Unary operations; Data partitioning operations
    • G06F16/24556Aggregation; Duplicate elimination
    • 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/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • G06F16/244Grouping and aggregation
    • 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/06Asset management; Financial planning or analysis

Definitions

  • the embodiments of this specification relate to the field of information technology, and in particular, to an aggregate calculation method, device, and equipment in a block chain ledger.
  • aggregation calculation is a kind of more common calculation methods, including summation, averaging, counting and so on.
  • the data is usually directly aggregated based on the obtained data, and the authenticity of the data and the accuracy of the aggregated result cannot be guaranteed.
  • the embodiments of this specification provide a more accurate aggregation calculation method.
  • the purpose of the embodiments of the present application is to provide a more accurate aggregation calculation method in a blockchain ledger.
  • An aggregation calculation method in a block chain ledger includes: determining a collection including multiple data records used in the aggregation calculation, setting the initial value of the aggregation result to 0, and performing the following method on the collection and the aggregation result Iterative processing until the preset iterative requirement is reached: select a data record from the set, determine the data block where the data record is located; verify the integrity of the data record in the data block, and if the verification passes, the The data record is removed from the set, and the data record and the current aggregation result are aggregated to obtain the updated set and aggregation result; if the verification fails, the aggregation calculation is terminated, and the position of the current data record that fails the verification in the ledger is returned. Information; at the end of the iteration, the current aggregation result is output as the target result of the aggregation calculation.
  • the embodiment of the present specification also provides an aggregation calculation device in a block chain ledger, including: a set determination module, which determines a set including multiple data records used in the aggregation calculation, and sets the initial value of the aggregation result to 0 ; Iterative calculation module, select a data record from the set, determine the data block in which the data record is located; verify the integrity of the data record in the data block, and if the verification passes, remove the data record from the set Cancellation, aggregate the data record and the current aggregation result to obtain the updated collection and aggregation result; iteration termination module, terminate the aggregation calculation, and return the location information of the current data record that has failed verification in the ledger; output module, iteration At the end, output the current aggregation result as the target result of the aggregation calculation.
  • a set determination module which determines a set including multiple data records used in the aggregation calculation, and sets the initial value of the aggregation result to 0 ;
  • the calculation target is iteratively processed.
  • the integrity verification of the currently used data record is performed, and the verification is passed.
  • Perform aggregation calculation and terminate the aggregation calculation at any time if the verification fails, thereby ensuring that the data record is not tampered with or lost, and the result of the aggregation calculation is more accurate.
  • any one of the embodiments of the present specification does not need to achieve all the above-mentioned effects.
  • Figure 1 is a schematic diagram of the system architecture involved in an embodiment of the specification
  • Fig. 2 is a schematic diagram of a process for generating a block chain ledger provided by an embodiment of the specification
  • FIG. 3 is a schematic diagram of a block header of a data block provided by an embodiment of this specification.
  • FIG. 4 is a schematic flowchart of a method for creating an index of data records according to an embodiment of the specification
  • FIG. 5 is a schematic flowchart of the aggregation calculation method in the block chain ledger provided by the embodiment of the specification;
  • FIG. 6 is a schematic structural diagram of an aggregation computing device in a blockchain ledger provided by an embodiment of this specification
  • Fig. 7 is a schematic structural diagram of a device for configuring the method of the embodiment of this specification.
  • Blockchain ledger is a centralized data storage structure applied in the database. Its service objects are often various institutions, and each institution can communicate between them and third-party users (including other institutions or individuals). The generated data records are stored in the database server. As shown in FIG. 1, FIG. 1 is a schematic diagram of a system architecture involved in an embodiment of the specification. In this schematic diagram, an enterprise organization can face multiple users, and each user can query the database service provider through its corresponding enterprise organization.
  • the organization connected to the database server is a financial product company, and the data records can be individual users’ financial management records in the financial product company; or, the connected organization can be a government department, where the data records are what the government department has for the department. Expense details of the managed public project; or, the database server is connected to a hospital, and the data record is the patient’s medical record; or the database server is connected to a third-party payment agency, and the data record can be an individual user Payment records through the agency, and so on.
  • FIG. 2 is a schematic diagram of the process of generating a block chain ledger provided by the embodiment of this specification, including the following steps.
  • S201 Receive a data record to be stored, and determine a hash value of each data record, where the data record contains business attributes.
  • the data records to be stored here can be various consumption records of individual users of the client, or can be business results, intermediate states, and operation records generated when the application server executes business logic based on user instructions.
  • Specific business scenarios can include consumption records, audit logs, supply chains, government supervision records, medical records, and so on.
  • the business attribute is generally unique in the interface organization.
  • the business attributes are based on different business scenarios and can include user names, user ID numbers, and driver’s licenses. Number, mobile phone number, project unique number, type of data record (such as financial package number), etc.
  • the data record is the user's consumption record
  • the business attribute at this time is the user ID (including mobile phone number, ID number, user name, etc.), or the user ID is hashed
  • the hash value obtained by the algorithm; or, for government agencies, the data record is the overhead flow of multiple public projects, then the business attribute at this time can be a unique number for each project.
  • Business attributes can be stored in a specified location in the data record, such as the head or tail of the data record.
  • S203 When a preset block forming condition is reached, determine each data record to be written in the data block, and generate an Nth data block including the hash value of the data block and the data record.
  • the preset blocking conditions include: the number of data records to be stored reaches the number threshold, for example, every time one thousand data records are received, a new data block is generated and one thousand data records are written into the block; or , The time interval from the last block formation time reaches the time threshold, for example, every 5 minutes, a new data block is generated, and the data records received within these 5 minutes are written into the block.
  • N refers to the serial number of the data block.
  • the data block is in the form of a block chain, which is arranged sequentially based on the order of the block time, and has strong timing characteristics.
  • the block height of the data block increases monotonically based on the sequence of the block time.
  • the block height can be a sequence number.
  • the block height of the Nth data block is N; the block height can also be generated in other ways, for example, the block time symmetric encryption is converted into large integer data (for example, 12-bit or 15-bit Integer) as the block height.
  • the data block at this time is the initial data block.
  • the current data block (the first data block) can be generated based on the hash value of the previous data block (that is, the N-1th data block). For example, a feasible way is to determine the hash value of each data record to be written in the Nth block, and generate a Merck according to the order in the block.
  • the root hash value of the Merkel tree and the hash value of the previous data block are spliced together, and the hash algorithm is used again to generate the hash value of the current block.
  • 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 to store the plaintext of the spliced data, or the hash value of the spliced data, etc.;
  • the block header can be used to store metadata about the data block, for example, the version number of the ledger, the hash of the previous data block Value, the root hash value of the Merkel tree composed of the spliced data in the own data block, the hash value of the own data block, the state array used to record the operated state of the spliced data, and so on.
  • FIG. 3 is a schematic diagram of a block header of a data block provided by an embodiment of this specification.
  • the hash value of the corresponding data record and the hash value of the data block can be obtained and saved, and integrity verification can be initiated based on the hash value.
  • the specific verification method is to recalculate the hash value of the data record itself and the hash value of the data block in the database, and compare with the locally stored hash value.
  • each data block is determined by a hash value
  • the hash value of the data block is determined by the content and order of the data records in the data block and the hash value of the previous data block.
  • the user can initiate verification based on the hash value of the data block at any time. Any modification of the content of the data block (including the modification of the data record content or sequence in the data block) will result in the hash value of the data block calculated during verification.
  • the hash value of the data block is inconsistent when it is generated, which causes the verification to fail, thus realizing the immutability under centralization.
  • a segment of data block is designated for continuous integrity verification, or continuous integrity verification is performed from the initial data block.
  • the verification method is to obtain the hash value of the previous data block, and use the same algorithm as when generating the hash value of the data block, and recalculate its own data according to its own data record and the hash value of the previous data block.
  • the hash value of the block for verification is to obtain the hash value of the previous data block, and use the same algorithm as when generating the hash value of the data block, and recalculate its own data according to its own data record and the hash value of the previous data block.
  • the information in the block header can be pre-downloaded to the local for storage, so that when verification is needed, only the database server needs to be verified.
  • FIG. 4 is a schematic flowchart of a method for creating an index for data records provided by an embodiment of this specification, and the process specifically includes the following steps.
  • S401 In the block chain ledger, for any data record, obtain business attributes included in the data record.
  • the specific location and acquisition method of the business attributes can be negotiated in advance by the database server and the docking organization.
  • the business attributes can be obtained from the specified offset in the data record, or the start and end positions can be identified by specific characters; or, the docking organization provides
  • the header containing the business attribute can be directly spliced at the beginning of each data record when uploading by the docking agency, and the database server can directly obtain the business attribute of each data record from the header .
  • S403 Determine location information of the data record in the ledger, where the location information includes the block height of the data block where the data record is located, and the offset in the data block where the data record is located.
  • a block-chain ledger is composed of multiple data blocks, and at the same time, a data block usually contains multiple data records. Therefore, in the embodiment of this specification, the location information specifically refers to which data block in the ledger is located when a data record is saved, and where it is in the data block.
  • the hash value of the data block is a hash value obtained by hash calculation based on the previous block's hash value and its own data record, which can be used to uniquely and unambiguously identify a data block.
  • the block height of the first data block is 0, and the block height is increased by 1 for each additional data block; or, the block time of the data block can be converted into a large monotonic increase Integer data (usually 12 to 15 bits) sequence, as the block height of the data block. Therefore, a data block usually has a clear block height.
  • the order of the data records has also been fixed, so the serial number of a data record in the data block is also clear.
  • the sequence number can also be used to clarify the location information of the data record in the data block in which it is located. That is, the sequence number can also be used to indicate the offset of the data recorded in the data block.
  • the address offset of each data record in the data block can also be used to identify the data records in the data block respectively.
  • the address offset of each data record is not the same.
  • the specific format of the data block can be customized (for example, the metadata information and remark information contained in the block header of the data block, and the block height of the data block is adopted Format, etc.), in different formats, the content of the location information will also be different, which does not constitute a limitation to this solution.
  • S405 Establish a corresponding relationship between the business attribute and location information, and write an index with the business attribute as the main key.
  • the index is an inverted index.
  • the primary key is the business attribute contained in the data record.
  • the specific writing method is: when the primary key in the index does not include the designated identification field, an index record with the designated identification field as the primary key is created in the index table.
  • the location information is written into the index record where the designated identification field is located. It should be noted that the writing here is not an overwriting writing, but the location information is added to the value of the index record, and it is stored in the index record alongside other location information.
  • Table 1 is an exemplary index table provided in the embodiment of this specification.
  • the Key is the specific value of the business attribute, and each array in the Value part is a piece of position information.
  • the first part of each array is the block height, and the latter part is the serial number of the data recorded in the data block, passing the block height and serial number That is, a data record can be uniquely determined. It is easy to understand that in the index table, a key can correspond to multiple location information.
  • the business attributes of the data records and the storage location in the ledger are determined, the corresponding relationship between the two is established, and the business attribute is created as the main key. Sort index, without knowing the user's business details, from the index, you can perform corresponding statistics on data records based on business attributes, as well as subsequent query and verification.
  • the location information can also be arranged in sequence according to the order in which the data is recorded in the ledger, which is conducive to the user's query and verification.
  • the sequence of data records in the ledger can be reflected by the timestamp when the data record is written into the ledger (that is, the block timestamp of the data block), and the sequence of data records in the same data block can be reflected in the The order in the data block is reflected one after another.
  • aggregation calculations for a certain business attribute are often initiated, including summation, average, maximum/minimum, count, standard deviation, variance, and so on.
  • the docking agency needs to query the number of data records uploaded by several users it serves in the past 12 months. This process needs to ensure that the data records of each user in the ledger are not tampered with or omitted, otherwise the accuracy of the aggregation results cannot be guaranteed.
  • an embodiment of this specification provides an aggregation calculation method in a block chain ledger, as shown in FIG. 5, which is a schematic flow chart of the aggregation calculation method in a block chain ledger provided by the embodiment of this specification, including The following steps.
  • S501 Determine a set including multiple data records used in the aggregation calculation, and set the initial value of the aggregation result to 0.
  • Count ID, Blknum
  • Blknum the block height
  • the database server receives the instruction, that is, it can use the traversal method to query the entire ledger to determine the data records that contain the business attribute in the ledger, so as to obtain the inclusion A collection of N data records.
  • the location information corresponding to the business attributes can be queried from the index, and the location information obtained from the query can be obtained based on the location information obtained.
  • the preset iteration requirement is generally that all data records in the set have been traversed.
  • the set may be iterated to an empty set.
  • the following method is used to iterate the set and aggregation result.
  • S503 Select a data record from the set, determine the data block in which the data record is located, and verify the integrity of the data record in the data block.
  • the iterative sequence of data records can be random or ordered.
  • the random selection of data records does not affect the aggregation results.
  • it can also be selected in a certain order, for example, based on the generation time or upload time of the data record.
  • the sequence can be determined according to the block height of the data recorded in the ledger, and the data records can be selected for iteration in the order of block height.
  • the aforementioned set is obtained by querying the location information corresponding to the business attribute in the index, at this time, correspondingly, if the values in the index record (ie, multiple pieces of location information) are sorted according to the timestamp, then at this time, the same
  • the data in the collection is sorted in the same order according to the position information, so that the data records can be iterated in sequence.
  • Data recording based on time sequence (the order of block height can also be considered as a time sequence) can be connected with the user's reality, and the iteration based on the time sequence can meet the needs of the user's actual application.
  • one way when verifying the integrity of data records, one way can be: determine the data block where the data record is located, and build a Merkel tree based on the data records in the data block, and calculate the current The hash value of the Merkel tree can be compared with the hash value of the Merkel tree stored in the block header. If it is inconsistent, it means that the data record has been tampered with.
  • Another way is to store a backup copy of the data record or the hash value of the backup copy when the user or the docking organization uploads the data record to the server, so that the current hash value of the data record can be calculated. And compare it with the hash value of the backup copy to achieve integrity verification.
  • the hash value of the backup copy may be returned by the database server, and the centralized database server may digitally sign the hash value to ensure that the hash value is recognized by the database server.
  • the server when the user uploads data, the server has already determined the hash value of each data record, and at this time, the hash value can be digitally signed and returned to the user.
  • the user only needs to save the hash value with the digital signature. Therefore, integrity verification can be performed at any time based on the hash value and the corresponding data record.
  • the aggregation calculation is performed again according to the i-th data record and the current aggregation result S(i-1), and the aggregation result is updated to obtain S (i).
  • the data record is removed from the current set (including the first one) to avoid repeated calculations, and an updated set containing data records is obtained. It is easy to understand that the data record in the collection is reduced by one after each update.
  • the database server obtains the location information of the data record that fails the verification, and returns the location information of the ith data record that failed the verification in the ledger to the aggregate calculation instruction
  • the initiator of the aggregation instruction shall be notified of the "incorrect data record" for further follow-up.
  • the end of the iteration here means that the verification has been successful until the set is empty, and does not include the aforementioned termination of the aggregation calculation caused by the verification failure.
  • the calculation target is iteratively processed, and the integrity of the currently used data record is verified for each iteration calculation. Perform aggregation calculation, and terminate the aggregation calculation at any time if the verification fails, thereby ensuring that the data record is not tampered with or lost, and the result of the aggregation calculation is more accurate.
  • an embodiment of this specification also provides an aggregation computing device in a blockchain ledger, as shown in FIG. 6, which is a schematic structural diagram of an aggregation computing device in a blockchain ledger provided by an embodiment of this specification , Including the following modules.
  • the set determining module 601 determines the set including multiple data records used in the aggregation calculation, and sets the initial value of the aggregation result to 0.
  • the iterative calculation module 603 selects a data record from the set to determine the data block where the data record is located; verifies the integrity of the data record in the data block, and if the verification passes, removes the data record from the set If the data record and the current aggregation result are aggregated, the updated collection and aggregation result are obtained.
  • the iteration termination module 605 terminates the aggregation calculation, and returns the location information of the current data record in the ledger that has failed the verification.
  • the output module 607 at the end of the iteration, outputs the current aggregation result as the target result of the aggregation calculation.
  • the embodiments of this specification also provide a computer device, which at least includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein the processor implements the aggregation shown in FIG. 5 when the program is executed. Calculation method.
  • FIG. 7 shows a more specific hardware structure diagram of a computing device provided by an embodiment of this specification.
  • the device may include a processor 1010, a memory 1020, an input/output interface 1030, a communication interface 1040, and a bus 1050.
  • the processor 1010, the memory 1020, the input/output interface 1030, and the communication interface 1040 realize the communication connection between each other in the device through the bus 1050.
  • the processor 1010 may be implemented by a general CPU (Central Processing Unit, central processing unit), microprocessor, application specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, etc., for execution related Program to realize the technical solutions provided in the embodiments of this specification.
  • CPU Central Processing Unit
  • ASIC Application Specific Integrated Circuit
  • the memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc.
  • the memory 1020 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, related program codes are stored in the memory 1020 and called and executed by the processor 1010.
  • the input/output interface 1030 is used to connect an input/output module to realize information input and output.
  • the input/output/module can be configured in the device as a component (not shown in the figure), or it can be connected to the device to provide corresponding functions.
  • the input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc.
  • an output device may include a display, a speaker, a vibrator, an indicator light, and the like.
  • the communication interface 1040 is used to connect a communication module (not shown in the figure) to realize the communication interaction between the device and other devices.
  • the communication module can realize communication through wired means (such as USB, network cable, etc.), or through wireless means (such as mobile network, WIFI, Bluetooth, etc.).
  • the bus 1050 includes a path to transmit information between various components of the device (for example, the processor 1010, the memory 1020, the input/output interface 1030, and the communication interface 1040).
  • the above device only shows the processor 1010, the memory 1020, the input/output interface 1030, the communication interface 1040, and the bus 1050, in the specific implementation process, the device may also include the equipment necessary for normal operation. Other components.
  • the above-mentioned devices may also include only the components necessary to implement the solutions of the embodiments of the present specification, and not necessarily include all the components shown in the figures.
  • the embodiment of the present specification also provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the aggregate calculation method shown in FIG. 5 is implemented.
  • Computer-readable media include permanent and non-permanent, removable and non-removable media, and information storage can be realized by any method or technology.
  • the information can be computer-readable instructions, data structures, program modules, 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, CD-ROM, digital versatile disc (DVD) or other optical storage, Magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media can be used to store information that can be accessed by computing devices. According to the definition in this article, computer-readable media does not include transitory media, such as modulated data signals and carrier waves.
  • a typical implementation device is a computer.
  • the specific form of the computer can be a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email receiving and sending device, and a game control A console, a tablet computer, a wearable device, or a combination of any of these devices.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • General Physics & Mathematics (AREA)
  • Business, Economics & Management (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • Development Economics (AREA)
  • Finance (AREA)
  • Computational Linguistics (AREA)
  • Accounting & Taxation (AREA)
  • Game Theory and Decision Science (AREA)
  • Entrepreneurship & Innovation (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Human Resources & Organizations (AREA)
  • Operations Research (AREA)
  • Economics (AREA)
  • Marketing (AREA)
  • Strategic Management (AREA)
  • Technology Law (AREA)
  • General Business, Economics & Management (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A method and apparatus for aggregation calculation in a blockchain-type ledger, and a device. The method comprises: when aggregation calculation is performed in a blockchain-type ledger, performing iteration processing on a calculation target; each time iteration calculation is performed, performing integrity verification on a currently used data record; and after verification is passed, performing aggregation calculation, and if verification fails, terminating aggregation calculation at any time.

Description

一种块链式账本中的聚合计算方法、装置及设备Method, device and equipment for aggregation calculation in block chain ledger 技术领域Technical field
本说明书实施例涉及信息技术领域,尤其涉及一种块链式账本中的聚合计算方法、装置及设备。The embodiments of this specification relate to the field of information technology, and in particular, to an aggregate calculation method, device, and equipment in a block chain ledger.
背景技术Background technique
在数据库领域中,聚合计算是一类较为常见的计算方法,包括求和、求平均、计数等等。在这个过程中,通常都是根据取得的数据进行直接聚合,无法保证数据的真实与聚合结果的准确。In the field of database, aggregation calculation is a kind of more common calculation methods, including summation, averaging, counting and so on. In this process, the data is usually directly aggregated based on the obtained data, and the authenticity of the data and the accuracy of the aggregated result cannot be guaranteed.
基于此,本说明书实施例提供一种更为准确的聚合计算方法。Based on this, the embodiments of this specification provide a more accurate aggregation calculation method.
发明内容Summary of the invention
本申请实施例的目的是提供一种在块链式账本中更为准确的聚合计算方法。The purpose of the embodiments of the present application is to provide a more accurate aggregation calculation method in a blockchain ledger.
为解决上述技术问题,本申请实施例是通过以下方法实现的。In order to solve the above technical problems, the embodiments of the present application are implemented by the following methods.
一种块链式账本中的聚合计算方法,包括:确定聚合计算所采用的包括多条数据记录的集合,将聚合结果的初始值置为0,采用如下方式进行对所述集合和聚合结果进行迭代处理,直至达到预设的迭代要求:从集合中选取一条数据记录,确定该数据记录所处的数据块;验证该数据记录在所述数据块中的完整性,若验证通过,将所述数据记录从所述集合中剔除,聚合所述数据记录和当前聚合结果,得到更新后的集合和聚合结果;若验证失败,终止所述聚合计算,返回验证失败的当前数据记录在账本中的位置信息;迭代结束时,输出当前的聚合结果为聚合计算的目标结果。An aggregation calculation method in a block chain ledger includes: determining a collection including multiple data records used in the aggregation calculation, setting the initial value of the aggregation result to 0, and performing the following method on the collection and the aggregation result Iterative processing until the preset iterative requirement is reached: select a data record from the set, determine the data block where the data record is located; verify the integrity of the data record in the data block, and if the verification passes, the The data record is removed from the set, and the data record and the current aggregation result are aggregated to obtain the updated set and aggregation result; if the verification fails, the aggregation calculation is terminated, and the position of the current data record that fails the verification in the ledger is returned. Information; at the end of the iteration, the current aggregation result is output as the target result of the aggregation calculation.
对应的,本说明书实施例还提供一种块链式账本中的聚合计算装置,包括:集合确定模块,确定聚合计算所采用的包括多条数据记录的集合,将聚合结果的初始值置为0;迭代计算模块,从集合中选取一条数据记录,确定该数据记录所处的数据块;验证该数据记录在所述数据块中的完整性,若验证通过,将所述数据记录从所述集合中剔除,聚合所述数据记录和当前聚合结果,得到更新后的集合和聚合结果;迭代终止模块,终止所述聚合计算,返回验证失败的当前数据记录在账本中的位置信息;输出模块,迭代结束时,输出当前的聚合结果为聚合计算的目标结果。Correspondingly, the embodiment of the present specification also provides an aggregation calculation device in a block chain ledger, including: a set determination module, which determines a set including multiple data records used in the aggregation calculation, and sets the initial value of the aggregation result to 0 ; Iterative calculation module, select a data record from the set, determine the data block in which the data record is located; verify the integrity of the data record in the data block, and if the verification passes, remove the data record from the set Cancellation, aggregate the data record and the current aggregation result to obtain the updated collection and aggregation result; iteration termination module, terminate the aggregation calculation, and return the location information of the current data record that has failed verification in the ledger; output module, iteration At the end, output the current aggregation result as the target result of the aggregation calculation.
通过本说明书实施例所提供的方案,在块链式账本中进行聚合计算时,对计算目标进行迭代处理,每次迭代计算时,对当前所采用的数据记录进行完整性验证,验证通过之后再进行聚合计算,若验证失败则随时终止聚合计算,从而保证了数据记录未经篡改或者丢失,聚合计算的结果更为准确。Through the solution provided in the embodiment of this specification, when performing aggregation calculation in the blockchain ledger, the calculation target is iteratively processed. In each iteration calculation, the integrity verification of the currently used data record is performed, and the verification is passed. Perform aggregation calculation, and terminate the aggregation calculation at any time if the verification fails, thereby ensuring that the data record is not tampered with or lost, and the result of the aggregation calculation is more accurate.
应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本说明书实施例。It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the embodiments of this specification.
此外,本说明书实施例中的任一实施例并不需要达到上述的全部效果。In addition, any one of the embodiments of the present specification does not need to achieve all the above-mentioned effects.
附图说明Description of the drawings
为了更清楚地说明本说明书实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本说明书实施例中记载的一些实施例,对于本领域普通技术人员来讲,还可以根据这些附图获得其他的附图。In order to more clearly describe the technical solutions in the embodiments of this specification or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only These are some of the embodiments described in the embodiments of this specification. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings.
图1为本说明书实施例所涉及的系统架构示意图;Figure 1 is a schematic diagram of the system architecture involved in an embodiment of the specification;
图2为本说明书实施例所提供的一种生成块链式账本的流程示意图;Fig. 2 is a schematic diagram of a process for generating a block chain ledger provided by an embodiment of the specification;
图3为本说明书实施例所提供的一种数据块的块头的示意图;FIG. 3 is a schematic diagram of a block header of a data block provided by an embodiment of this specification;
图4为本说明书实施例提供的一种数据记录的索引创建方法的流程示意图;FIG. 4 is a schematic flowchart of a method for creating an index of data records according to an embodiment of the specification;
图5为本说明书实施例所提供的块链式账本中的聚合计算方法的流程示意图;FIG. 5 is a schematic flowchart of the aggregation calculation method in the block chain ledger provided by the embodiment of the specification; FIG.
图6是本说明书实施例提供的一种块链式账本中的聚合计算装置的结构示意图;6 is a schematic structural diagram of an aggregation computing device in a blockchain ledger provided by an embodiment of this specification;
图7是用于配置本说明书实施例方法的一种设备的结构示意图。Fig. 7 is a schematic structural diagram of a device for configuring the method of the embodiment of this specification.
具体实施方式Detailed ways
为了使本领域技术人员更好地理解本说明书实施例中的技术方案,下面将结合本说明书实施例中的附图,对本说明书实施例中的技术方案进行详细地描述,显然,所描述的实施例仅仅是本说明书的一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员所获得的所有其他实施例,都应当属于保护的范围。In order to enable those skilled in the art to better understand the technical solutions in the embodiments of this specification, the technical solutions in the embodiments of this specification will be described in detail below in conjunction with the drawings in the embodiments of this specification. Obviously, the described implementation The examples are only a part of the embodiments in this specification, not all the embodiments. Based on the embodiments in this specification, all other embodiments obtained by those of ordinary skill in the art should fall within the scope of protection.
首先对本说明书实施例中所涉及的块链式账本进行说明。First, the block chain ledger involved in the embodiment of this specification will be described.
块链式账本是一种应用在数据库中的中心化的数据存储结构,其面向的服务对象常 常为各种机构,各机构则可以将它们与第三方用户(包括其它机构或者个人)之间所产生的数据记录在数据库服务方进行存储。如图1所示,图1为本说明书实施例所涉及的系统架构示意图。在该示意图中,一个企业机构可以面向多名用户,而每个用户均可以通过其对应的企业机构向数据库服务提供方进行查询。Blockchain ledger is a centralized data storage structure applied in the database. Its service objects are often various institutions, and each institution can communicate between them and third-party users (including other institutions or individuals). The generated data records are stored in the database server. As shown in FIG. 1, FIG. 1 is a schematic diagram of a system architecture involved in an embodiment of the specification. In this schematic diagram, an enterprise organization can face multiple users, and each user can query the database service provider through its corresponding enterprise organization.
例如,数据库服务端对接的机构是某金融产品公司,数据记录可以是个人用户在该金融产品公司的理财记录;或者,对接的机构可以是政府部门,其中的数据记录是政府部门对于该部门所管理的公共项目的开销明细;或者,数据库服务方对接的机构是某个医院,其中的数据记录是病人的病历;或者,数据库服务方对接的机构是第三方支付机构,数据记录可以是个人用户通过该机构的支付记录,等等。For example, the organization connected to the database server is a financial product company, and the data records can be individual users’ financial management records in the financial product company; or, the connected organization can be a government department, where the data records are what the government department has for the department. Expense details of the managed public project; or, the database server is connected to a hospital, and the data record is the patient’s medical record; or the database server is connected to a third-party payment agency, and the data record can be an individual user Payment records through the agency, and so on.
在中心化的数据库服务端,块链式的账本通过如下方式生成,如图2所示,图2为本说明书实施例所提供的一种生成块链式账本的流程示意图,包括以下步骤。On the centralized database server, the block chain ledger is generated in the following manner, as shown in FIG. 2, which is a schematic diagram of the process of generating a block chain ledger provided by the embodiment of this specification, including the following steps.
S201,接收待存储的数据记录,确定各数据记录的哈希值,其中,数据记录中包含业务属性。S201: Receive a data record to be stored, and determine a hash value of each data record, where the data record contains business attributes.
此处的待存储的数据记录,可以是客户端个人用户的各种消费记录,也可以是应用服务器基于用户的指令,在执行业务逻辑时产生的业务结果、中间状态以及操作记录等等。具体的业务场景可以包括消费记录、审计日志、供应链条、政府监管记录、医疗记录等等。The data records to be stored here can be various consumption records of individual users of the client, or can be business results, intermediate states, and operation records generated when the application server executes business logic based on user instructions. Specific business scenarios can include consumption records, audit logs, supply chains, government supervision records, medical records, and so on.
在每个与数据库服务方对接的机构中,所述业务属性在所述对接机构中,一般而言是唯一存在的,业务属性基于不同的业务场景,可以包括用户名、用户身份证号、驾照编号、手机号、项目唯一编号、数据记录的类型(例如金融包编号)等等。In each organization that interfaces with the database server, the business attribute is generally unique in the interface organization. The business attributes are based on different business scenarios and can include user names, user ID numbers, and driver’s licenses. Number, mobile phone number, project unique number, type of data record (such as financial package number), etc.
例如,对于第三方支付机构而言,数据记录是用户的消费记录,此时的业务属性即为用户标识(包括手机号、身份证号、用户名等等),或者对该用户标识进行哈希算法所得到的哈希值;或者,对于政府机构而言,数据记录为多个公共项目的开销流水,则此时的业务属性可以为每个项目的唯一编号。For example, for a third-party payment institution, the data record is the user's consumption record, and the business attribute at this time is the user ID (including mobile phone number, ID number, user name, etc.), or the user ID is hashed The hash value obtained by the algorithm; or, for government agencies, the data record is the overhead flow of multiple public projects, then the business attribute at this time can be a unique number for each project.
业务属性可以存储在数据记录中的指定位置,例如数据记录的头部或者尾部。Business attributes can be stored in a specified location in the data record, such as the head or tail of the data record.
S203,当达到预设的成块条件时,确定待写入数据块中的各数据记录,生成包含数据块的哈希值和数据记录的第N个数据块。S203: When a preset block forming condition is reached, determine each data record to be written in the data block, and generate an Nth data block including the hash value of the data block and the data record.
所述预设的成块条件包括:待存储的数据记录数量达到数量阈值,例如,每接收到一千条数据记录时,生成一个新数据块,将一千条数据记录写入块中;或者,距离上一 次成块时刻的时间间隔达到时间阈值,例如,每隔5分钟,生成一个新数据块,将在这5分钟内接收到的数据记录写入块中。The preset blocking conditions include: the number of data records to be stored reaches the number threshold, for example, every time one thousand data records are received, a new data block is generated and one thousand data records are written into the block; or , The time interval from the last block formation time reaches the time threshold, for example, every 5 minutes, a new data block is generated, and the data records received within these 5 minutes are written into the block.
此处的N指的是数据块的序号,换言之,在本说明书实施例中,数据块是以块链的形式,基于成块时间的顺序先后排列,具有很强的时序特征。其中,数据块的块高基于成块时间的先后顺序单调递增。块高可以是序号,此时第N个数据块的块高即为N;块高也可以其它方式生成,例如,将成块时间对称加密转换为大整型数据(例如,12位或者15位的整数)作为块高。Here, N refers to the serial number of the data block. In other words, in the embodiment of this specification, the data block is in the form of a block chain, which is arranged sequentially based on the order of the block time, and has strong timing characteristics. Among them, the block height of the data block increases monotonically based on the sequence of the block time. The block height can be a sequence number. At this time, the block height of the Nth data block is N; the block height can also be generated in other ways, for example, the block time symmetric encryption is converted into large integer data (for example, 12-bit or 15-bit Integer) as the block height.
当N=1时,即此时的数据块为为初始数据块。初始数据块的哈希值和块高基于预设方式给定。例如,初始数据块中不包含数据记录,哈希值则为任一给定的哈希值,块高blknum=0;又例如,初始数据块的生成触发条件与其它数据块的触发条件一致,但是初始数据块的哈希值由对初始数据块中的所有内容取哈希确定。When N=1, that is, the data block at this time is the initial data block. The hash value and block height of the initial data block are given based on a preset method. For example, if 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 generation trigger condition of the initial data block is consistent with the trigger conditions of other data blocks. However, the hash value of the initial data block is determined by hashing all the contents in the initial data block.
当N>1时,由于前一数据块的内容和哈希值已经确定,则此时,可以基于前一数据块(即第N-1个数据块)的哈希值生成当前数据块(第N个数据块)的哈希值,例如,一种可行的方式为,确定每一条将要写入第N个块中的数据记录的哈希值,按照在块中的排列顺序,生成一个默克尔树,将默克尔树的根哈希值和前一数据块的哈希值拼接在一起,再次采用哈希算法,生成当前块的哈希值。又例如,还可以按照块中数据记录的顺序进行拼接并取哈希得到整体数据记录的哈希值,拼接前一数据块的哈希值和整体数据记录的哈希值,并对拼接得到的字串进行哈希运算,生成数据块的哈希值。When N>1, since the content and hash value of the previous data block have been determined, at this time, the current data block (the first data block) can be generated based on the hash value of the previous data block (that is, the N-1th data block). For example, a feasible way is to determine the hash value of each data record to be written in the Nth block, and generate a Merck according to the order in the block. In the Er tree, the root hash value of the Merkel tree and the hash value of the previous data block are spliced together, and the hash algorithm is used again to generate the hash value of the current block. For another example, it is also possible to splice according to the order of the data records in the block and obtain the hash value of the entire data record by hashing, splicing the hash value of the previous data block and the hash value of the entire data record, and combining the result The string is hashed to generate the hash value of the data block.
上述方式生成的数据块,可以包括块头和块体两个部分。块体中可以用于存储拼接数据的明文,或者拼接数据的哈希值等等;块头中可以用于存储有关本数据块的元数据,例如,账本的版本号,前一数据块的哈希值,自身数据块中的拼接数据所组成的默克尔树的根哈希值,自身数据块的哈希值,用于记录拼接数据的被操作状态的状态数组等等。如图3所示,图3为本说明书实施例所提供的一种数据块的块头的示意图。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 to store the plaintext of the spliced data, or the hash value of the spliced data, etc.; the block header can be used to store metadata about the data block, for example, the version number of the ledger, the hash of the previous data block Value, the root hash value of the Merkel tree composed of the spliced data in the own data block, the hash value of the own data block, the state array used to record the operated state of the spliced data, and so on. As shown in FIG. 3, FIG. 3 is a schematic diagram of a block header of a data block provided by an embodiment of this specification.
用户在上传数据成功后,即可以得到对应的数据记录的哈希值以及所处的数据块的哈希值,并保存,并且可以基于该哈希值发起完整性验证。具体的验证方式即为在数据库中重新计算数据记录自身的哈希值以及所处的数据块的哈希值,与本地所保存的进行对比。After the user uploads the data successfully, the hash value of the corresponding data record and the hash value of the data block can be obtained and saved, and integrity verification can be initiated based on the hash value. The specific verification method is to recalculate the hash value of the data record itself and the hash value of the data block in the database, and compare with the locally stored hash value.
通过前述的数据块的生成方式,每一个数据块通过哈希值确定,数据块的哈希值由数据块中的数据记录的内容、顺序以及前一数据块的哈希值决定。用户可以随时基于数 据块的哈希值发起验证,对于数据块中任何内容(包括对于数据块中数据记录内容或者顺序的修改)的修改都会造成在验证时计算得到的数据块的哈希值和数据块生成时的哈希值不一致,而导致验证失败,从而实现了中心化下的不可篡改。Through the foregoing method 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 order of the data records in the data block and the hash value of the previous data block. The user can initiate verification based on the hash value of the data block at any time. Any modification of the content of the data block (including the modification of the data record content or sequence in the data block) will result in the hash value of the data block calculated during verification. The hash value of the data block is inconsistent when it is generated, which causes the verification to fail, thus realizing the immutability under centralization.
在对于块链式账本中的数据块进行完整性验证时,一般而言,即指定一段数据块进行连续的完整性验证,或者从初始数据块开始进行连续的完整性验证。验证的方式即为获取前一数据块的哈希值,并采用与生成数据块的哈希值时的同样算法,根据自身的数据记录和前一数据块的哈希值,重新计算一遍自身数据块的哈希值,以进行验证。When performing integrity verification on data blocks in a blockchain ledger, generally speaking, a segment of data block is designated for continuous integrity verification, or continuous integrity verification is performed from the initial data block. The verification method is to obtain the hash value of the previous data block, and use the same algorithm as when generating the hash value of the data block, and recalculate its own data according to its own data record and the hash value of the previous data block. The hash value of the block for verification.
在一种实施方式下,如果是用户需要在本地对一条数据记录进行完整性验证,则可以预先将块头中的信息预先下载至本地进行存储,从而可以在需要验证时,只需向数据库服务端查询“默克尔路径”即可,并在本地计算该数据记录的哈希值,以及根据“默克尔路径”计算默克尔树的根哈希,并与本地所保存的块头信息中的根哈希进行一致性对比。In one implementation, if the user needs to verify the integrity of a data record locally, the information in the block header can be pre-downloaded to the local for storage, so that when verification is needed, only the database server needs to be verified. Just query the "Merkel path", and calculate the hash value of the data record locally, and calculate the root hash of the Merkel tree according to the "Merkel path", and compare it with the locally saved block header information. The root hash is compared for consistency.
基于前述方式,在数据库服务端中可以得到一份难以篡改的块链式账本用于存储数据记录。为了查询数据方便,本说明书实施例还提供一种针对于块链式账本的索引创建方法。如图4所示,图4为本说明书实施例提供的一种数据记录的索引创建方法的流程示意图,该流程具体包括如下步骤。Based on the foregoing method, a block chain ledger that is difficult to tamper with can be obtained in the database server for storing data records. For the convenience of querying data, the embodiment of this specification also provides an index creation method for the block chain ledger. As shown in FIG. 4, FIG. 4 is a schematic flowchart of a method for creating an index for data records provided by an embodiment of this specification, and the process specifically includes the following steps.
S401,在块链式账本中,针对任一数据记录,获取所述数据记录中所包含的业务属性。S401: In the block chain ledger, for any data record, obtain business attributes included in the data record.
业务属性的具体位置以及获取方式可以是数据库服务方和对接机构事先协商。例如,对接机构所提供的数据记录为标准结构化的数据记录时,业务属性可以从数据记录中指定偏移量获取,或者由特定字符标识起始位置和结束位置;又或者,对接机构所提供的数据记录为非结构化的数据时,在对接机构上传时可以直接在每条数据记录的开头拼接上包含业务属性的头部,数据库服务方可以直接从头部获取每条数据记录的业务属性。The specific location and acquisition method of the business attributes can be negotiated in advance by the database server and the docking organization. For example, when the data record provided by the docking organization is a standard structured data record, the business attributes can be obtained from the specified offset in the data record, or the start and end positions can be identified by specific characters; or, the docking organization provides When the data record of is unstructured data, the header containing the business attribute can be directly spliced at the beginning of each data record when uploading by the docking agency, and the database server can directly obtain the business attribute of each data record from the header .
S403,确定所述数据记录在账本中的位置信息,所述位置信息包括数据记录所处的数据块的块高,以及,在所处的数据块中的偏移量。S403: Determine location information of the data record in the ledger, where the location information includes the block height of the data block where the data record is located, and the offset in the data block where the data record is located.
如前所述,一个块链式的账本由多个数据块组成,同时,一个数据块中通常包含多个数据记录。因此,在本说明书实施例中,所述的位置信息具体指的是一条数据记录被保存时,处于账本中的哪个数据块上,以及,在该数据块中的什么位置。As mentioned earlier, a block-chain ledger is composed of multiple data blocks, and at the same time, a data block usually contains multiple data records. Therefore, in the embodiment of this specification, the location information specifically refers to which data block in the ledger is located when a data record is saved, and where it is in the data block.
在本说明书实施例所提供的数据块中,可以有多种方式用来标识不同的数据块,包 括数据块的哈希值或者块高。In the data blocks provided in the embodiments of this specification, there can be multiple ways to identify different data blocks, including the hash value or block height of the data block.
数据块的哈希值为根据前一区块哈希值和自身数据记录进行哈希计算而得到的哈希值,可以用于唯一、明确地标识一个数据块。在块链式的账本中,通常第一个数据块其块高为0,以后每增加一个数据块,块高加1;或者,还可以将数据块的成块时间转换为一个大的单调递增整型数据(一般为12至15位)序列,作为数据块的块高。因此,一个数据块通常有一个明确的块高。The hash value of the data block is a hash value obtained by hash calculation based on the previous block's hash value and its own data record, which can be used to uniquely and unambiguously identify a data block. In a block chain ledger, usually the block height of the first data block is 0, and the block height is increased by 1 for each additional data block; or, the block time of the data block can be converted into a large monotonic increase Integer data (usually 12 to 15 bits) sequence, as the block height of the data block. Therefore, a data block usually has a clear block height.
又例如,在一个已经确定的要写入数据库的数据块,其中数据记录的排序也已经固定,因此一个数据记录在该数据块中的序号也是明确的,在数据记录的长度为固定单位时,序号同样可以用于明确该数据记录在其所处的数据块中的位置信息。即,序号同样也可以用于指示数据记录在数据块中的偏移量。For another example, in a data block that has been determined to be written to the database, the order of the data records has also been fixed, so the serial number of a data record in the data block is also clear. When the length of the data record is a fixed unit, The sequence number can also be used to clarify the location information of the data record in the data block in which it is located. That is, the sequence number can also be used to indicate the offset of the data recorded in the data block.
同时,在一个数据块中,由于通常包含了多个数据记录,因此,还可以用各数据记录在该数据块中的地址偏移量来分别标识数据块中的数据记录。显而易见,在同一个数据块中,各数据记录的地址偏移量并不相同。At the same time, in a data block, since multiple data records are usually included, the address offset of each data record in the data block can also be used to identify the data records in the data block respectively. Obviously, in the same data block, the address offset of each data record is not the same.
当然,由于在本说明书实施例所提供的方式中,数据块的具体格式是可以自定义的(例如,数据块的块头中所包含的元数据信息和备注信息,数据块的块高所采取的形式等等),在不同的格式下,位置信息的内容也会有所不同,这并不构成对本方案的限定。Of course, because in the method provided by the embodiment of this specification, the specific format of the data block can be customized (for example, the metadata information and remark information contained in the block header of the data block, and the block height of the data block is adopted Format, etc.), in different formats, the content of the location information will also be different, which does not constitute a limitation to this solution.
S405,建立所述业务属性和位置信息的对应关系,写入以所述业务属性为主键的索引。S405: Establish a corresponding relationship between the business attribute and location information, and write an index with the business attribute as the main key.
即,该索引是一个倒排索引。在该索引中,主键是数据记录中所包含的业务属性。具体的写入方式为,当索引中的主键不包含所述指定标识字段时,在索引表中创建以所述指定标识字段为主键的索引记录。That is, the index is an inverted index. In this index, the primary key is the business attribute contained in the data record. The specific writing method is: when the primary key in the index does not include the designated identification field, an index record with the designated identification field as the primary key is created in the index table.
当所述索引中的主键包含所述指定标识字段时,将所述位置信息写入所述指定标识字段所处的索引记录。需要说明的是,此处的写入不是覆盖性的写入,而是将位置信息添加到该索引记录的值中,与其它位置信息并列存在与该索引记录中。When the primary key in the index includes the designated identification field, the location information is written into the index record where the designated identification field is located. It should be noted that the writing here is not an overwriting writing, but the location information is added to the value of the index record, and it is stored in the index record alongside other location information.
如表1所示,表1为本说明书实施例所提供的一种示例性索引表。其中Key即为业务属性的具体值,Value部分的每个数组即为一条位置信息,每个数组中的前部分块高,后部分为数据记录在该数据块中的序号,通过块高和序号即可以唯一的确定一条数据记录。容易理解,在索引表中,一个key可以对应于多个位置信息。As shown in Table 1, Table 1 is an exemplary index table provided in the embodiment of this specification. The Key is the specific value of the business attribute, and each array in the Value part is a piece of position information. The first part of each array is the block height, and the latter part is the serial number of the data recorded in the data block, passing the block height and serial number That is, a data record can be uniquely determined. It is easy to understand that in the index table, a key can correspond to multiple location information.
表1Table 1
KeyKey ValueValue
0X1234560X123456 (2,08),(2,10),(300,89),(300,999)(2,08), (2,10), (300,89), (300,999)
344X0001344X0001 (5,01),(8,22)(5,01), (8,22)
……... ……...
通过本说明书实施例所提供的方案,对于写入账本的数据记录,确定出数据记录的业务属性,以及在账本中的存储位置,建立起二者的对应关系,创建以业务属性为主键的倒排索引,不必了解用户的业务详情,从索引中即可以基于业务属性对于数据记录进行相应统计,以及后续的查询和验证。Through the solution provided by the embodiment of this specification, for the data records written into the ledger, the business attributes of the data records and the storage location in the ledger are determined, the corresponding relationship between the two is established, and the business attribute is created as the main key. Sort index, without knowing the user's business details, from the index, you can perform corresponding statistics on data records based on business attributes, as well as subsequent query and verification.
在该索引表中,由于一个业务属性可以对应于多个位置信息(即一条索引记录中可以包含多个位置信息,或者说一个业务属性可以对应于多个数据记录),在将位置信息写入索引中时,还可以将位置信息按照数据记录在账本中的先后顺序依次进行排列,有利于用户的查询以及验证。数据记录在账本中的先后顺序即可以数据记录被写入账本的时间戳(即数据块的成块时间戳)来体现,以及,对于同一数据块中的数据记录的先后顺序,则可以通过在数据块中的排序先后来体现。通过对位置信息进行排序,可以便于在查询获取读取数据记录时依序获取得到相应的数据记录,提高用户体验。In the index table, since one business attribute can correspond to multiple location information (that is, one index record can contain multiple location information, or one business attribute can correspond to multiple data records), when writing the location information In the index, the location information can also be arranged in sequence according to the order in which the data is recorded in the ledger, which is conducive to the user's query and verification. The sequence of data records in the ledger can be reflected by the timestamp when the data record is written into the ledger (that is, the block timestamp of the data block), and the sequence of data records in the same data block can be reflected in the The order in the data block is reflected one after another. By sorting the location information, it is convenient to obtain corresponding data records in sequence when querying, acquiring, and reading data records, thereby improving user experience.
在实际应用中,经常会发起针对某个业务属性的聚合计算,包括求和、求均值、求最大值/最小值、计数、求标准差、求方差等等。例如,以用户ID为业务属性时,对接机构需要查询自己所服务的若干用户在过去12个月中所分别上传的数据记录的数量。这个过程就需要保证账本中各用户的数据记录都是没有篡改或者遗漏的,否则不能保证聚合结果的准确性。In practical applications, aggregation calculations for a certain business attribute are often initiated, including summation, average, maximum/minimum, count, standard deviation, variance, and so on. For example, when the user ID is used as the business attribute, the docking agency needs to query the number of data records uploaded by several users it serves in the past 12 months. This process needs to ensure that the data records of each user in the ledger are not tampered with or omitted, otherwise the accuracy of the aggregation results cannot be guaranteed.
基于此,本说明书实施例提供一种块链式账本中的聚合计算方法,如图5所示,图5为本说明书实施例所提供的块链式账本中的聚合计算方法的流程示意图,包括以下步骤。Based on this, an embodiment of this specification provides an aggregation calculation method in a block chain ledger, as shown in FIG. 5, which is a schematic flow chart of the aggregation calculation method in a block chain ledger provided by the embodiment of this specification, including The following steps.
S501,确定聚合计算所采用的包括多条数据记录的集合,将聚合结果的初始值置为0。S501: Determine a set including multiple data records used in the aggregation calculation, and set the initial value of the aggregation result to 0.
具体而言,用户或者对接结构在发起聚合计算时,可以通过相应的聚合指令发送至数据库服务端。例如,Count(ID,Blknum),在其中,“Count”为计数,“ID”为业务属性,Blknum为块高,通过该指令,计算用户“ID”在块高“Blknum”之前的数据记录的条数。Specifically, when the user or the docking structure initiates the aggregation calculation, it can be sent to the database server through the corresponding aggregation instruction. For example, Count (ID, Blknum), where "Count" is the count, "ID" is the business attribute, and Blknum is the block height. Through this instruction, calculate the data record of the user "ID" before the block height "Blknum" Number of articles.
在一种实施方式下,基于业务属性在账本中的唯一性,数据库服务端接收到该指令,即可以采用遍历的方式,查询整个账本,确定账本中包含有业务属性的数据记录,从而得到包含N条数据记录的集合。In one embodiment, based on the uniqueness of the business attribute in the ledger, the database server receives the instruction, that is, it can use the traversal method to query the entire ledger to determine the data records that contain the business attribute in the ledger, so as to obtain the inclusion A collection of N data records.
在另一种实施方式下,若数据库服务端已经建立了关于业务属性和位置信息的索引,则可以从索引中查询所述业务属性所对应的位置信息,根据查询得到的位置信息获取包含有所述业务属性的多条数据记录,生成所述集合。初始的聚合结果作为0,不会影响聚合计算。In another implementation manner, if the database server has established an index on business attributes and location information, the location information corresponding to the business attributes can be queried from the index, and the location information obtained from the query can be obtained based on the location information obtained. Multiple data records of the business attribute to generate the set. The initial aggregation result is regarded as 0, which will not affect the aggregation calculation.
预设的迭代要求一般为集合中的所有数据记录都被遍历过,在本说明书实施例中可以是集合被迭代至空集。The preset iteration requirement is generally that all data records in the set have been traversed. In the embodiment of this specification, the set may be iterated to an empty set.
在确定了初始的集合、初始的聚合结果以及迭代结束条件之后,采用如下方式对集合和聚合结果进行迭代。After determining the initial set, the initial aggregation result, and the end condition of the iteration, the following method is used to iterate the set and aggregation result.
S503,从集合中选取一条数据记录,确定该数据记录所处的数据块,验证该数据记录在所述数据块中的完整性。S503: Select a data record from the set, determine the data block in which the data record is located, and verify the integrity of the data record in the data block.
在聚合运算中,数据记录迭代顺序可以是随机的,也可以是有序的。数据记录的随机选取,不影响聚合结果。当然,也可以按照一定的顺序进行选取,例如,按照数据记录的产生时间或者上传时间进行选取。In the aggregation operation, the iterative sequence of data records can be random or ordered. The random selection of data records does not affect the aggregation results. Of course, it can also be selected in a certain order, for example, based on the generation time or upload time of the data record.
具体而言,若采用的是从初始数据块开始,遍历账本的方式获得前述集合,则可以根据数据记录在账本中的块高确定先后顺序,并按照块高的顺序依次选取数据记录进行迭代。Specifically, if the aforementioned set is obtained by traversing the ledger from the initial data block, the sequence can be determined according to the block height of the data recorded in the ledger, and the data records can be selected for iteration in the order of block height.
若通过索引中查询业务属性所对应的位置信息而得到前述集合,此时,相应的,如果索引记录中的值(即多条位置信息)是依据时间戳排序的,那么此时,同样可以对集合中的数据寄了根据位置信息的排序进行同样的排序,从而得到可以依序对数据记录进行迭代。数据记录基于时间顺序(块高的顺序也可以认为是一种时间顺序)的可以与用户的现实相联系,基于时间顺序的迭代可以满足用户的实际应用的需要。If the aforementioned set is obtained by querying the location information corresponding to the business attribute in the index, at this time, correspondingly, if the values in the index record (ie, multiple pieces of location information) are sorted according to the timestamp, then at this time, the same The data in the collection is sorted in the same order according to the position information, so that the data records can be iterated in sequence. Data recording based on time sequence (the order of block height can also be considered as a time sequence) can be connected with the user's reality, and the iteration based on the time sequence can meet the needs of the user's actual application.
在块链式账本中,对于数据记录的完整性进行验证时,一种方式可以是:确定数据记录所处的数据块,并且根据该数据块中的数据记录构建默克尔树,并计算当前的默克尔树的哈希值,从而可以与块头中所存储的默克尔树的哈希值进行一致性对比,若不一致,则说明该数据记录已经被篡改。In the block chain ledger, when verifying the integrity of data records, one way can be: determine the data block where the data record is located, and build a Merkel tree based on the data records in the data block, and calculate the current The hash value of the Merkel tree can be compared with the hash value of the Merkel tree stored in the block header. If it is inconsistent, it means that the data record has been tampered with.
另一种方式则可以是,在用户或者对接机构将数据记录上传服务端时,自己本地保 存有数据记录的备用副本或者备用副本的哈希值,从而可以计算该数据记录的当前哈希值,并且与备用副本的哈希值进行一致性对比,以实现完整性验证。Another way is to store a backup copy of the data record or the hash value of the backup copy when the user or the docking organization uploads the data record to the server, so that the current hash value of the data record can be calculated. And compare it with the hash value of the backup copy to achieve integrity verification.
需要说明的是,备用副本的哈希值可以是数据库服务端所返回的,中心化的数据库服务端可以对该哈希值进行数字签名,以确保该哈希值是得到了数据库服务端的认可。It should be noted that the hash value of the backup copy may be returned by the database server, and the centralized database server may digitally sign the hash value to ensure that the hash value is recognized by the database server.
例如,在用户上传数据时,服务端就已经确定了各数据记录的哈希值,此时就可以对哈希值进行数字签名并且返回至用户。用户保存该具有数字签名的哈希值即可。从而可以随时基于该哈希值与对应的数据记录进行完整性验证。For example, when the user uploads data, the server has already determined the hash value of each data record, and at this time, the hash value can be digitally signed and returned to the user. The user only needs to save the hash value with the digital signature. Therefore, integrity verification can be performed at any time based on the hash value and the corresponding data record.
具体的聚合结果S(i)与聚合计算的方式相关,1≤i≤N。例如,在选取了第一条数据记录进行计算时,若聚合计算为求和SUM或者求最值,则S(1)等于第一条数据记录中的相关值;若聚合计算为计数COUNT,则S(1)=1,等等。The specific aggregation result S(i) is related to the way of aggregation calculation, 1≤i≤N. For example, when the first data record is selected for calculation, if the aggregate calculation is the sum SUM or the maximum value, S(1) is equal to the relevant value in the first data record; if the aggregate calculation is the count COUNT, then S(1)=1, and so on.
S505,若验证通过,将所述数据记录从所述集合中剔除,聚合所述数据记录和当前聚合结果,得到更新后的集合和聚合结果。S505: If the verification is passed, remove the data record from the set, aggregate the data record and the current aggregation result, and obtain an updated set and aggregation result.
在初次验证通过之后,对于第i次迭代中的所使用的第i条数据记录,即根据第i条数据记录和当前的聚合结果S(i-1)再次进行聚合计算,更新聚合结果得到S(i)。After the initial verification is passed, for the i-th data record used in the i-th iteration, the aggregation calculation is performed again according to the i-th data record and the current aggregation result S(i-1), and the aggregation result is updated to obtain S (i).
同时,在每次验证成功并进行计算之后,即将该数据记录从当前的集合中剔除(包括第一条),避免重复计算,从而得到更新后的包含数据记录的集合。容易理解,每次更新之后集合中的数据记录减少一条。At the same time, after each successful verification and calculation, the data record is removed from the current set (including the first one) to avoid repeated calculations, and an updated set containing data records is obtained. It is easy to understand that the data record in the collection is reduced by one after each update.
例如,在i=2时,若聚合计算为求和SUM,则S(2)等于S(1)与第二条数据记录中的相关值的和;若聚合计算为计数COUNT,则根据S(1)=1和当第二条数据记录计数,得到S(2)=2,等等。For example, when i=2, if the aggregation calculation is the sum SUM, then S(2) is equal to the sum of S(1) and the related value in the second data record; if the aggregation calculation is the count COUNT, then S( 1)=1 and when the second data record is counted, S(2)=2 is obtained, and so on.
容易理解,若每次验证都成功,则i值从2开始,每次迭代之后,i值自动加1,直至i等于N。在这个过程中,每次迭代时只会获取一条数据记录,并进行完整性验证,如果每条数据记录都通过了完整性验证,则迭代不会终止,直至i=N,将会输出最终聚合结果S(N)。It is easy to understand that if each verification succeeds, the value of i starts from 2. After each iteration, the value of i is automatically increased by 1 until i is equal to N. In this process, only one data record will be obtained during each iteration and integrity verification is performed. If each data record passes the integrity verification, the iteration will not be terminated until i=N, and the final aggregation will be output. The result is S(N).
S507,若验证失败,终止所述聚合计算,返回验证失败的当前数据记录在账本中的位置信息。S507: If the verification fails, the aggregation calculation is terminated, and the location information of the current data record in the ledger that fails the verification is returned.
若任一数据记录的完整性验证失败,则迭代即时终止,数据库服务端获取该验证失败的数据记录的位置信息,并返回验证失败的第i条数据记录在账本中的位置信息至聚 合计算指令的发起方,通知聚合指令的发起方“数据记录有误”,以便进一步进行后续的跟进。If the integrity verification of any data record fails, the iteration is immediately terminated, and the database server obtains the location information of the data record that fails the verification, and returns the location information of the ith data record that failed the verification in the ledger to the aggregate calculation instruction The initiator of the aggregation instruction shall be notified of the "incorrect data record" for further follow-up.
S509,迭代结束时,输出当前的聚合结果为聚合计算的目标结果。S509: When the iteration ends, output the current aggregation result as the target result of the aggregation calculation.
此处的迭代结束指的是验证一直成功直至集合为空,而不包括前述的因为验证失败导致的聚合计算终止。The end of the iteration here means that the verification has been successful until the set is empty, and does not include the aforementioned termination of the aggregation calculation caused by the verification failure.
通过本说明书实施例所提供的方案,在块链式账本中进行聚合计算时,对计算目标进行迭代处理,每次迭代计算时,对当前所采用的数据记录进行完整性验证,验证通过之后再进行聚合计算,若验证失败则随时终止聚合计算,从而保证了数据记录未经篡改或者丢失,聚合计算的结果更为准确。Through the solution provided by the embodiment of this specification, when performing aggregation calculation in the blockchain ledger, the calculation target is iteratively processed, and the integrity of the currently used data record is verified for each iteration calculation. Perform aggregation calculation, and terminate the aggregation calculation at any time if the verification fails, thereby ensuring that the data record is not tampered with or lost, and the result of the aggregation calculation is more accurate.
对应的,本说明书实施例还提供一种块链式账本中的聚合计算装置,如图6所示,图6是本说明书实施例提供的一种块链式账本中的聚合计算装置的结构示意图,包括以下模块。Correspondingly, an embodiment of this specification also provides an aggregation computing device in a blockchain ledger, as shown in FIG. 6, which is a schematic structural diagram of an aggregation computing device in a blockchain ledger provided by an embodiment of this specification , Including the following modules.
集合确定模块601,确定聚合计算所采用的包括多条数据记录的集合,将聚合结果的初始值置为0。The set determining module 601 determines the set including multiple data records used in the aggregation calculation, and sets the initial value of the aggregation result to 0.
迭代计算模块603,从集合中选取一条数据记录,确定该数据记录所处的数据块;验证该数据记录在所述数据块中的完整性,若验证通过,将所述数据记录从所述集合中剔除,聚合所述数据记录和当前聚合结果,得到更新后的集合和聚合结果。The iterative calculation module 603 selects a data record from the set to determine the data block where the data record is located; verifies the integrity of the data record in the data block, and if the verification passes, removes the data record from the set If the data record and the current aggregation result are aggregated, the updated collection and aggregation result are obtained.
迭代终止模块605,终止所述聚合计算,返回验证失败的当前数据记录在账本中的位置信息。The iteration termination module 605 terminates the aggregation calculation, and returns the location information of the current data record in the ledger that has failed the verification.
输出模块607,迭代结束时,输出当前的聚合结果为聚合计算的目标结果。The output module 607, at the end of the iteration, outputs the current aggregation result as the target result of the aggregation calculation.
本说明书实施例还提供一种计算机设备,其至少包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其中,处理器执行所述程序时实现图5所示的聚合计算方法。The embodiments of this specification also provide a computer device, which at least includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein the processor implements the aggregation shown in FIG. 5 when the program is executed. Calculation method.
图7示出了本说明书实施例所提供的一种更为具体的计算设备硬件结构示意图,该设备可以包括:处理器1010、存储器1020、输入/输出接口1030、通信接口1040和总线1050。其中处理器1010、存储器1020、输入/输出接口1030和通信接口1040通过总线1050实现彼此之间在设备内部的通信连接。FIG. 7 shows a more specific hardware structure diagram of a computing device provided by an embodiment of this specification. The device may include a processor 1010, a memory 1020, an input/output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input/output interface 1030, and the communication interface 1040 realize the communication connection between each other in the device through the bus 1050.
处理器1010可以采用通用的CPU(Central Processing Unit,中央处理器)、微处理 器、应用专用集成电路(Application Specific Integrated Circuit,ASIC)、或者一个或多个集成电路等方式实现,用于执行相关程序,以实现本说明书实施例所提供的技术方案。The processor 1010 may be implemented by a general CPU (Central Processing Unit, central processing unit), microprocessor, application specific integrated circuit (Application Specific Integrated Circuit, ASIC), or one or more integrated circuits, etc., for execution related Program to realize the technical solutions provided in the embodiments of this specification.
存储器1020可以采用ROM(Read Only Memory,只读存储器)、RAM(Random Access Memory,随机存取存储器)、静态存储设备,动态存储设备等形式实现。存储器1020可以存储操作系统和其他应用程序,在通过软件或者固件来实现本说明书实施例所提供的技术方案时,相关的程序代码保存在存储器1020中,并由处理器1010来调用执行。The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, related program codes are stored in the memory 1020 and called and executed by the processor 1010.
输入/输出接口1030用于连接输入/输出模块,以实现信息输入及输出。输入输出/模块可以作为组件配置在设备中(图中未示出),也可以外接于设备以提供相应功能。其中输入设备可以包括键盘、鼠标、触摸屏、麦克风、各类传感器等,输出设备可以包括显示器、扬声器、振动器、指示灯等。The input/output interface 1030 is used to connect an input/output module to realize information input and output. The input/output/module can be configured in the device as a component (not shown in the figure), or it can be connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and an output device may include a display, a speaker, a vibrator, an indicator light, and the like.
通信接口1040用于连接通信模块(图中未示出),以实现本设备与其他设备的通信交互。其中通信模块可以通过有线方式(例如USB、网线等)实现通信,也可以通过无线方式(例如移动网络、WIFI、蓝牙等)实现通信。The communication interface 1040 is used to connect a communication module (not shown in the figure) to realize the communication interaction between the device and other devices. The communication module can realize communication through wired means (such as USB, network cable, etc.), or through wireless means (such as mobile network, WIFI, Bluetooth, etc.).
总线1050包括一通路,在设备的各个组件(例如处理器1010、存储器1020、输入/输出接口1030和通信接口1040)之间传输信息。The bus 1050 includes a path to transmit information between various components of the device (for example, the processor 1010, the memory 1020, the input/output interface 1030, and the communication interface 1040).
需要说明的是,尽管上述设备仅示出了处理器1010、存储器1020、输入/输出接口1030、通信接口1040以及总线1050,但是在具体实施过程中,该设备还可以包括实现正常运行所必需的其他组件。此外,本领域的技术人员可以理解的是,上述设备中也可以仅包含实现本说明书实施例方案所必需的组件,而不必包含图中所示的全部组件。It should be noted that although the above device only shows the processor 1010, the memory 1020, the input/output interface 1030, the communication interface 1040, and the bus 1050, in the specific implementation process, the device may also include the equipment necessary for normal operation. Other components. In addition, those skilled in the art can understand that the above-mentioned devices may also include only the components necessary to implement the solutions of the embodiments of the present specification, and not necessarily include all the components shown in the figures.
本说明书实施例还提供一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现图5所示的聚合计算方法。The embodiment of the present specification also provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the aggregate calculation method shown in FIG. 5 is implemented.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑 可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media include permanent and non-permanent, removable and non-removable media, and information storage can be realized by any method or technology. The information can be computer-readable instructions, data structures, program modules, 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, CD-ROM, digital versatile disc (DVD) or other optical storage, Magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media can be used to store information that can be accessed by computing devices. According to the definition in this article, computer-readable media does not include transitory media, such as modulated data signals and carrier waves.
通过以上的实施方式的描述可知,本领域的技术人员可以清楚地了解到本说明书实施例可借助软件加必需的通用硬件平台的方式来实现。基于这样的理解,本说明书实施例的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本说明书实施例各个实施例或者实施例的某些部分所述的方法。From the description of the foregoing implementation manners, it can be understood that those skilled in the art can clearly understand that the embodiments of this specification can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solutions of the embodiments of this specification can be embodied in the form of software products, which can be stored in storage media, such as ROM/RAM, A magnetic disk, an optical disk, etc., include several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute the methods described in the various embodiments or some parts of the embodiments of this specification.
上述实施例阐明的系统、方法、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。The systems, methods, modules, or units explained in the above embodiments may be implemented by computer chips or entities, or implemented by products with certain functions. A typical implementation device is a computer. The specific form of the computer can be a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email receiving and sending device, and a game control A console, a tablet computer, a wearable device, or a combination of any of these devices.
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于方法实施例而言,由于其基本相似于方法实施例,所以描述得比较简单,相关之处参见方法实施例的部分说明即可。以上所描述的方法实施例仅仅是示意性的,其中所述作为分离部件说明的模块可以是或者也可以不是物理上分开的,在实施本说明书实施例方案时可以把各模块的功能在同一个或多个软件和/或硬件中实现。也可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性劳动的情况下,即可以理解并实施。The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, as for the method embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for related parts, please refer to the part of the description of the method embodiment. The method embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separated. When implementing the solutions of the embodiments of this specification, the functions of the modules may be in the same Or multiple software and/or hardware implementations. It is also possible to select some or all of the modules according to actual needs to achieve the objectives of the solutions of the embodiments. Those of ordinary skill in the art can understand and implement it without creative work.
以上所述仅是本说明书实施例的具体实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本说明书实施例原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本说明书实施例的保护范围。The above are only specific implementations of the embodiments of this specification. It should be pointed out that for those of ordinary skill in the art, without departing from the principle of the embodiments of this specification, several improvements and modifications can be made. These Improvement and retouching should also be regarded as the protection scope of the embodiments of this specification.

Claims (13)

  1. 一种块链式账本中的聚合计算方法,包括:An aggregation calculation method in a blockchain ledger, including:
    确定聚合计算所采用的包括多条数据记录的集合,将聚合结果的初始值置为0,采用如下方式进行对所述集合和聚合结果进行迭代处理,直至达到预设的迭代要求;Determine the set including multiple data records used in the aggregation calculation, set the initial value of the aggregation result to 0, and perform iterative processing on the set and the aggregation result in the following manner until the preset iteration requirement is reached;
    从集合中选取一条数据记录,确定该数据记录所处的数据块,验证该数据记录在所述数据块中的完整性;Select a data record from the set, determine the data block where the data record is located, and verify the integrity of the data record in the data block;
    若验证通过,将所述数据记录从所述集合中剔除,聚合所述数据记录和当前聚合结果,得到更新后的集合和聚合结果;If the verification is passed, remove the data record from the collection, aggregate the data record and the current aggregation result, and obtain an updated collection and aggregation result;
    若验证失败,终止所述聚合计算,返回验证失败的当前数据记录在账本中的位置信息;If the verification fails, terminate the aggregation calculation, and return the location information of the current data recorded in the ledger for the failed verification;
    迭代结束时,输出当前的聚合结果为聚合计算的目标结果。At the end of the iteration, the current aggregation result is output as the target result of the aggregation calculation.
  2. 如权利要求1所述的方法,确定聚合计算所采用的包括多条数据记录的集合,包括:The method according to claim 1, determining a set including a plurality of data records used in the aggregation calculation includes:
    接收聚合计算指令,其中,所述聚合计算指令中包含有业务属性;Receiving an aggregate calculation instruction, where the aggregate calculation instruction includes a business attribute;
    遍历账本,确定包含有所述业务属性的多条数据记录,生成所述集合;或者,从预先建立的索引中查询所述业务属性所对应的位置信息,根据查询得到的位置信息获取包含有所述业务属性的多条数据记录,生成所述集合。Traverse the ledger, determine multiple data records containing the business attributes, and generate the set; or query the location information corresponding to the business attributes from a pre-built index, and obtain information that contains information based on the query location information. Multiple data records of the business attribute to generate the set.
  3. 如权利要求1所述的方法,所述块链式账本通过如下方式预先生成:The method according to claim 1, wherein the block chain ledger is pre-generated in the following manner:
    接收待存储的数据记录,确定各数据记录的哈希值,其中,数据记录中包含业务属性;Receive the data records to be stored and determine the hash value of each data record, where the data record contains business attributes;
    当达到预设的成块条件时,确定待写入数据块中的各数据记录,生成包含数据块的哈希值和数据记录的第N个数据块,具体包括:When the preset blocking condition is reached, each data record to be written in the data block is determined, and the Nth data block containing the hash value of the data block and the data record is generated, which specifically includes:
    当N=1时,初始数据块的哈希值和块高基于预设方式给定;When N=1, the hash value and block height of the initial data block are given based on a preset method;
    当N>1时,根据待写入数据块中的各数据记录和第N-1个数据块的哈希值确定第N个数据块的哈希值,生成包含第N个数据块的哈希值和各数据记录的第N个数据块。When N>1, determine the hash value of the Nth data block according to the data records in the data block to be written and the hash value of the N-1th data block, and generate a hash containing the Nth data block Value and the Nth data block of each data record.
  4. 如权利要求3所述的方法,所述预设的成块条件包括:The method according to claim 3, wherein the preset blocking condition comprises:
    待存储的数据记录数量达到数量阈值;或者,距离上一次成块时刻的时间间隔达到时间阈值。The number of data records to be stored reaches the number threshold; or, the time interval from the last block time reaches the time threshold.
  5. 如权利要求2所述的方法,所述索引通过如下方式预先建立:The method according to claim 2, wherein the index is pre-established in the following manner:
    在块链式账本中,针对任一数据记录,获取所述数据记录中所包含的业务属性;In the blockchain ledger, for any data record, obtain the business attributes contained in the data record;
    确定所述数据记录在账本中的位置信息,所述位置信息包括数据记录所处的数据块 的块高,以及,在所处的数据块中的偏移量;Determine the location information of the data record in the ledger, where the location information includes the block height of the data block where the data record is located, and the offset in the data block where the data record is located;
    建立所述业务属性和位置信息的对应关系,写入以所述业务属性为主键的索引。The corresponding relationship between the business attribute and the location information is established, and an index with the business attribute as the main key is written.
  6. 如权利要求5所述的方法,写入以所述业务属性为主键的索引,包括:The method according to claim 5, writing an index with the business attribute as the primary key, comprising:
    确定数据记录的时间戳;在同一索引记录中按照时间戳的先后顺序,将数据记录的位置信息依序写入索引记录的值;Determine the time stamp of the data record; in the same index record, according to the order of the time stamp, write the position information of the data record into the value of the index record in order;
    相应的,遍历其它数据记录进行迭代处理,包括:按照索引记录中的位置信息的顺序依序对所述数据记录进行迭代处理。Correspondingly, traversing other data records to perform iterative processing includes: sequentially performing iterative processing on the data records according to the order of the position information in the index record.
  7. 一种块链式账本中的聚合计算装置,包括:An aggregation computing device in a block chain ledger, including:
    集合确定模块,确定聚合计算所采用的包括多条数据记录的集合,将聚合结果的初始值置为0;The set determination module determines the set including multiple data records used in the aggregation calculation, and sets the initial value of the aggregation result to 0;
    迭代计算模块,从集合中选取一条数据记录,确定该数据记录所处的数据块;验证该数据记录在所述数据块中的完整性,若验证通过,将所述数据记录从所述集合中剔除,聚合所述数据记录和当前聚合结果,得到更新后的集合和聚合结果;The iterative calculation module selects a data record from the set and determines the data block where the data record is located; verifies the integrity of the data record in the data block, and if the verification passes, removes the data record from the set Eliminate, aggregate the data record and the current aggregation result, and obtain the updated collection and aggregation result;
    迭代终止模块,终止所述聚合计算,返回验证失败的当前数据记录在账本中的位置信息;The iterative termination module terminates the aggregation calculation, and returns the location information of the current data record in the ledger that fails the verification;
    输出模块,迭代结束时,输出当前的聚合结果为聚合计算的目标结果。The output module, at the end of the iteration, outputs the current aggregation result as the target result of the aggregation calculation.
  8. 如权利要求7所述的装置,所述集合确定模块,接收聚合计算指令,其中,所述聚合计算指令中包含有业务属性;遍历账本,确定包含有所述业务属性的多条数据记录,生成所述集合;或者,从预先建立的索引中查询所述业务属性所对应的位置信息,根据查询得到的位置信息获取包含有所述业务属性的多条数据记录,生成所述集合。7. The device of claim 7, wherein the set determination module receives an aggregate calculation instruction, wherein the aggregate calculation instruction contains a business attribute; traverse the ledger to determine a plurality of data records containing the business attribute, and generate The set; or, query the location information corresponding to the business attribute from a pre-established index, obtain multiple data records containing the business attribute according to the query location information, and generate the set.
  9. 如权利要求7所述的装置,还包括数据块生成模块,接收待存储的数据记录,确定各数据记录的哈希值,其中,数据记录中包含业务属性;当达到预设的成块条件时,确定待写入数据块中的各数据记录,生成包含数据块的哈希值和数据记录的第N个数据块,具体包括:The device according to claim 7, further comprising a data block generation module, which receives the data records to be stored and determines the hash value of each data record, wherein the data record contains the business attribute; when the preset block condition is reached , Determine each data record in the data block to be written, and generate the Nth data block containing the hash value of the data block and the data record, which specifically includes:
    当N=1时,初始数据块的哈希值和块高基于预设方式给定;When N=1, the hash value and block height of the initial data block are given based on a preset method;
    当N>1时,根据待写入数据块中的各数据记录和第N-1个数据块的哈希值确定第N个数据块的哈希值,生成包含第N个数据块的哈希值和各数据记录的第N个数据块。When N>1, determine the hash value of the Nth data block according to the data records in the data block to be written and the hash value of the N-1th data block, and generate a hash containing the Nth data block Value and the Nth data block of each data record.
  10. 如权利要求9所述的装置,所述预设的成块条件包括:9. The device of claim 9, wherein the preset blocking condition comprises:
    待存储的数据记录数量达到数量阈值;或者,距离上一次成块时刻的时间间隔达到时间阈值。The number of data records to be stored reaches the number threshold; or, the time interval from the last block time reaches the time threshold.
  11. 如权利要求9所述的装置,还包括索引创建模块,在块链式账本中,针对任一 数据记录,获取所述数据记录中所包含的业务属性;确定所述数据记录在账本中的位置信息,所述位置信息包括数据记录所处的数据块的块高,以及,在所处的数据块中的偏移量;建立所述业务属性和位置信息的对应关系,写入以所述业务属性为主键的索引。The device according to claim 9, further comprising an index creation module, in the block chain ledger, for any data record, obtain the business attributes contained in the data record; determine the position of the data record in the ledger Information, the location information includes the block height of the data block where the data record is located, and the offset in the data block where the data record is located; the corresponding relationship between the service attribute and the location information is established, and the service attribute is written in the service The index of the attribute as the primary key.
  12. 如权利要求11所述的装置,所述索引创建模块,确定数据记录的时间戳;在同一索引记录中按照时间戳的先后顺序,将数据记录的位置信息依序写入索引记录的值;相应的,遍历其它数据记录进行迭代处理,包括:按照索引记录中的位置信息的顺序依序对所述数据记录进行迭代处理。The device according to claim 11, wherein the index creation module determines the time stamp of the data record; in the same index record, according to the order of the time stamp, the position information of the data record is sequentially written into the value of the index record; correspondingly Yes, traversing other data records to perform iterative processing includes: sequentially performing iterative processing on the data records according to the order of the position information in the index record.
  13. 一种计算机设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其中,所述处理器执行所述程序时实现如权利要求1至6任一项所述的方法。A computer device, comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein the processor executes the program as described in any one of claims 1 to 6 method.
PCT/CN2020/116810 2019-11-11 2020-09-22 Method and apparatus for aggregation calculation in blockchain-type ledger, and device WO2021093461A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911094079.8A CN111046069B (en) 2019-11-11 2019-11-11 Aggregation calculation method, device and equipment in block chain type account book
CN201911094079.8 2019-11-11

Publications (1)

Publication Number Publication Date
WO2021093461A1 true WO2021093461A1 (en) 2021-05-20

Family

ID=70232330

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/116810 WO2021093461A1 (en) 2019-11-11 2020-09-22 Method and apparatus for aggregation calculation in blockchain-type ledger, and device

Country Status (2)

Country Link
CN (2) CN113434550A (en)
WO (1) WO2021093461A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116664129A (en) * 2023-07-28 2023-08-29 杭州趣链科技有限公司 Block chain account book data iteration method, electronic equipment and readable storage medium

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113434550A (en) * 2019-11-11 2021-09-24 蚂蚁区块链科技(上海)有限公司 Aggregation calculation method, device and equipment in block chain type account book
CN111556115B (en) * 2020-04-22 2023-04-21 财付通支付科技有限公司 Block chain-based data processing method, device, equipment and storage medium
CN112286939A (en) * 2020-06-12 2021-01-29 支付宝(杭州)信息技术有限公司 Method, device and equipment for generating Hash of global state in block chain type account book

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107817946A (en) * 2016-09-13 2018-03-20 阿里巴巴集团控股有限公司 For mixing the method and device of storage device read-write data
US20180198626A1 (en) * 2015-02-27 2018-07-12 Guardtime Ip Holdings Limited Blockchain-supported, fail-safe synchronization in a data authentication infrastructure
CN108664322A (en) * 2017-03-29 2018-10-16 广东神马搜索科技有限公司 Data processing method and system
CN110084699A (en) * 2019-04-30 2019-08-02 深圳前海微众银行股份有限公司 Polymerization, device, transaction List Table system and the storage medium of transaction record
CN110349019A (en) * 2019-06-03 2019-10-18 阿里巴巴集团控股有限公司 Verification method, device and equipment in a kind of piece of chain type account book
CN111046069A (en) * 2019-11-11 2020-04-21 支付宝(杭州)信息技术有限公司 Aggregation calculation method, device and equipment in block chain type account book

Family Cites Families (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105187218B (en) * 2015-09-30 2018-11-23 谈建 A kind of digitized record signature, the verification method of multi-core infrastructure
KR101795696B1 (en) * 2016-07-14 2017-11-09 주식회사 코인플러그 Method for providing archiving and verification services of data transceived via messenger service and server using the same
US10346398B2 (en) * 2017-03-07 2019-07-09 International Business Machines Corporation Grouping in analytical databases
CN106850193A (en) * 2017-03-23 2017-06-13 中国人民公安大学 A kind of cloud storage persistent data detection method based on MD5 and key
CN107240002B (en) * 2017-06-06 2020-09-29 北京汇通金财信息科技有限公司 Electric power transaction method and device and micro-grid system
CN107315786B (en) * 2017-06-12 2020-12-11 腾讯科技(深圳)有限公司 Service data storage method and device
CN108073699B (en) * 2017-12-12 2020-06-16 中国联合网络通信集团有限公司 Big data aggregation analysis method and device
CN109656873B (en) * 2018-11-02 2023-04-14 平安科技(深圳)有限公司 Block chain-based data archiving method and device and terminal equipment
CN109472598A (en) * 2018-11-07 2019-03-15 平安医疗健康管理股份有限公司 A kind of health data method of calibration, equipment and server based on block chain
CN109658259A (en) * 2018-11-19 2019-04-19 平安科技(深圳)有限公司 Peasant household's listings data processing method, device, computer equipment and storage medium
CN110033363B (en) * 2018-12-14 2024-01-23 创新先进技术有限公司 Event processing method and device based on block chain and electronic equipment
CN110162662B (en) * 2019-04-18 2023-02-28 创新先进技术有限公司 Verification method, device and equipment for data records in block chain type account book
CN110222109A (en) * 2019-05-29 2019-09-10 邓子航 Node splicing system, method and block chain node based on distributed account book technology
CN110225012B (en) * 2019-05-30 2021-09-24 电子科技大学 Method for checking and updating ownership of outsourced data based on alliance chain
CN110378697B (en) * 2019-07-22 2023-03-31 南京信息工程大学 Block chain light node UTXO transaction verification method and device based on RSA accumulator

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180198626A1 (en) * 2015-02-27 2018-07-12 Guardtime Ip Holdings Limited Blockchain-supported, fail-safe synchronization in a data authentication infrastructure
CN107817946A (en) * 2016-09-13 2018-03-20 阿里巴巴集团控股有限公司 For mixing the method and device of storage device read-write data
CN108664322A (en) * 2017-03-29 2018-10-16 广东神马搜索科技有限公司 Data processing method and system
CN110084699A (en) * 2019-04-30 2019-08-02 深圳前海微众银行股份有限公司 Polymerization, device, transaction List Table system and the storage medium of transaction record
CN110349019A (en) * 2019-06-03 2019-10-18 阿里巴巴集团控股有限公司 Verification method, device and equipment in a kind of piece of chain type account book
CN111046069A (en) * 2019-11-11 2020-04-21 支付宝(杭州)信息技术有限公司 Aggregation calculation method, device and equipment in block chain type account book

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116664129A (en) * 2023-07-28 2023-08-29 杭州趣链科技有限公司 Block chain account book data iteration method, electronic equipment and readable storage medium
CN116664129B (en) * 2023-07-28 2023-11-10 武汉趣链数字科技有限公司 Block chain account book data iteration method, electronic equipment and readable storage medium

Also Published As

Publication number Publication date
CN113434550A (en) 2021-09-24
CN111046069B (en) 2021-05-07
CN111046069A (en) 2020-04-21

Similar Documents

Publication Publication Date Title
WO2021073242A1 (en) Index creation and data querying methods, apparatus and device
WO2021093461A1 (en) Method and apparatus for aggregation calculation in blockchain-type ledger, and device
CN110188096B (en) Index creating method, device and equipment for data record
WO2020211569A1 (en) Method for constructing index of data record
CN110162662B (en) Verification method, device and equipment for data records in block chain type account book
WO2020244239A1 (en) Index creation method, apparatus and device based on service identifier
WO2021017422A1 (en) Index creation method in block chain type account book, device and apparatus
CN110162526B (en) Method, device and equipment for inquiring data records in block chain type account book
WO2020244237A1 (en) Verification method, device and apparatus for blockchain ledger
WO2021073240A1 (en) Method, device, and apparatus for storing data in blockchain ledger
WO2020233146A1 (en) Data operation record storage method, system and apparatus, and device
WO2020253231A1 (en) Receipt-based data storage method and apparatus, and device
WO2021073241A1 (en) Disk storage-based data reading method and device, and apparatus
WO2021057164A1 (en) Query method and device for blockchain ledger, and apparatus
WO2020244238A1 (en) Data storage method, device and apparatus employing multilevel blockchain ledgers
US10990705B2 (en) Index creation for data records
WO2021057127A1 (en) Method, device, and equipment for data storage based on multiple service attributes
CN110019278B (en) Data verification method, device and equipment
US10999062B2 (en) Blockchain-type data storage
WO2021093462A1 (en) Method and apparatus for storing operation record in database, and device
CN110347678B (en) Financial data storage method, system, device and equipment
CN110362570B (en) Data storage method, device and equipment
US11115189B2 (en) Verifying a blockchain-type ledger
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

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20888590

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20888590

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205 DATED 05/07/2022)

122 Ep: pct application non-entry in european phase

Ref document number: 20888590

Country of ref document: EP

Kind code of ref document: A1