WO2021057482A1 - Method and device for generating bloom filter in blockchain - Google Patents

Method and device for generating bloom filter in blockchain Download PDF

Info

Publication number
WO2021057482A1
WO2021057482A1 PCT/CN2020/114235 CN2020114235W WO2021057482A1 WO 2021057482 A1 WO2021057482 A1 WO 2021057482A1 CN 2020114235 W CN2020114235 W CN 2020114235W WO 2021057482 A1 WO2021057482 A1 WO 2021057482A1
Authority
WO
WIPO (PCT)
Prior art keywords
block
bloom filter
topic
bits
topics
Prior art date
Application number
PCT/CN2020/114235
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 WO2021057482A1 publication Critical patent/WO2021057482A1/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/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Definitions

  • the present invention relates to the field of financial technology (Fintech) and the field of blockchain (Blockchain), in particular to a method and device for generating a Bloom filter in a blockchain.
  • each transaction includes at least one event
  • each event includes at least one topic.
  • it may involve searching for an event.
  • the event can be searched by the subject of the event.
  • a Bloom filter with a fixed length of 2048 bits is used to store the subject of the block.
  • Bloom filters can completely store themes of blocks with small transaction volume.
  • a Bloom filter with a fixed length of 2048 bits will inevitably have bit duplication. Phenomenon, the Bloom filter will completely fail and cannot accurately store the subject of the block.
  • the subject of a block with a small transaction volume will waste a lot of storage space, which is an urgent problem to be solved.
  • the embodiments of the present application provide a method and device for generating a bloom filter in a block chain, which solves the problem of the inability to accurately store the subject of the block in the prior art and the waste of a lot of storage space.
  • an embodiment of the present application provides a method for generating a Bloom filter in a blockchain: obtaining the number of topics of a block; according to the number of topics, determining the topics that need to be occupied for storing each topic of the block The number of stored bits; the number of stored bits of the topic is positively correlated with the number of topics; the bloom filter of the block is generated according to the number of stored bits of the topic; the storage space of the bloom filter is greater than The number of bits in the topic storage; the initial value of each bit in the storage space of the Bloom filter is a first preset value; for each topic of the block, the The value of the bits mapped by the theme in the bloom filter is updated from the first preset value to a second preset value, and a bloom filter storing each theme of the block is obtained; the bloom In the storage space of the filter, the number of bits whose value is the second preset value is the number of bits for storing the topic; the Bloom filter is used to determine whether the block contains the subject of the query.
  • the number of topics in the block is first obtained, and the number of topics stored in the topic is determined according to the number of topics, so as to generate the Bloom filter of the block according to the number of bits in the topic storage.
  • the number of topics stored in the topic is positively correlated with the number of topics, and the storage space of the bloom filter is greater than the number of topics stored in the topic. Therefore, when the number of topics in a block is large, the bloom filter The storage space of the filter should also be correspondingly larger. When the number of topics in the block is small, the storage space of the bloom filter will be correspondingly small, so a bloom with a suitable storage space can be generated according to the number of topics in the block. filter.
  • the initial values of the bits in the storage space of the bloom filter are all the first preset values.
  • the theme can be placed in the bloom according to a preset mapping relationship.
  • the value of the bits mapped in the filter is updated from the first preset value to the second preset value, and the Bloom filter storing each theme of the block is obtained.
  • the Bloom filter The storage space of the device is sufficient to meet the storage of each topic of the block, and in the storage space of the Bloom filter, the number of bits whose value is the second preset value is the number of bits stored in the topic , Indicating that the bits of the mapping between the topics do not conflict, and the topic of the block can be accurately stored, so that the query result can be accurately provided when determining whether the block contains the subject of the query later.
  • the number of topic storage bits is proportional to the number of topics, and the number of bits occupied by each topic in the Bloom filter is the same, so that the number of topic storage bits can be conveniently calculated according to the number of topics.
  • a method of determining the number of bits stored in a topic is proposed.
  • the ratio of the number of bits of the topic storage bit to the storage space of the bloom filter is m; m is the storage space usage rate configured by the bloom filter.
  • the discreteness of the theme bits in the Bloom filter can be adjusted according to the setting of m, thereby improving the flexibility of storing the theme through the Bloom filter.
  • the obtaining the number of topics of the block includes: determining the transactions in the block and the events of each transaction; determining the number of index parameters for each event in the block; wherein , The number of index parameters of each event corresponds to a topic; the sum of the number of index parameters of each event in the block is used as the number of topics.
  • the sum of the index parameters of each event in the block is used as the number of topics. Since the index parameters can be used to search for events, it can be ensured that each topic has a corresponding index. All topics can be searched.
  • the present application provides a device for generating bloom filters in a blockchain, including: an acquisition module, configured to acquire the number of topics in a block; a processing module, configured to determine and store the number of topics based on the number of topics.
  • the storage space of the Bloom filter is greater than the number of bits stored in the theme;
  • the initial value of each bit in the storage space of the Bloom filter is a first preset value; and is used to target the block
  • the Bloom filter of each theme; in the storage space of the Bloom filter, the number of bits whose value is the second preset value is the number of bits stored in the theme; the Bloom filter uses To determine whether the subject of the query
  • the ratio of the number of bits of the topic storage bit to the storage space of the bloom filter is m; m is the storage space usage rate configured by the bloom filter.
  • the acquisition module is specifically configured to: determine the transaction in the block and the event of each transaction; determine the number of index parameters for each event in the block; wherein each The number of index parameters of an event corresponds to a topic; the sum of the number of index parameters of each event in the block is taken as the number of topics.
  • an embodiment of the present application provides a computer device including a program or instruction, and when the program or instruction is executed, it is used to execute the method of the foregoing first aspect and each embodiment of the first aspect.
  • an embodiment of the present application provides a storage medium including a program or instruction, and when the program or instruction is executed, it is used to execute the methods of the first aspect and the embodiments of the first aspect.
  • Figure 1 is a schematic diagram of the structure of the blockchain
  • FIG. 2 is a schematic flowchart of steps of a method for generating a Bloom filter in a blockchain according to an embodiment of the application;
  • FIG. 3 is a schematic structural diagram of a device for generating a Bloom filter in a blockchain according to an embodiment of the application.
  • Block chain As shown in Figure 1, the block chain is a chain composed of a series of blocks. In addition to recording the data of this block, each block also records the hash value of the previous block. Through this Way to form a chain.
  • Node Each participant in the network is a node, and the node participates in network formation and data exchange.
  • a node refers to a participant with a unique identity.
  • the node has a complete copy of the ledger and has the ability to participate in the consensus of the blockchain network and the maintenance of the ledger.
  • Smart contract is a computer protocol designed to spread, verify, or execute a contract in an information-based way. Smart contracts allow for trusted transactions without a third party, which are traceable and irreversible.
  • the specific form of the smart contract is the code that is deployed on the blockchain to complete specific functions.
  • Solidity is a mainstream smart contract programming language. Smart contracts written in Solidity language can be called Solidity contracts.
  • a contract address will be generated, and users can call this smart contract through the contract address.
  • the function defined in the smart contract is called the contract interface.
  • the call to the smart contract is to call a contract interface in the contract through the contract address.
  • a transaction is a user's request for an operation on the smart contract interface deployed on the blockchain.
  • the transaction is initiated by the user and sent from the user's client to the blockchain node.
  • the blockchain node After the blockchain node receives the transaction, it calls the corresponding smart contract according to the contract address and interface specified by the transaction.
  • any operation (deploy contract, call contract interface, etc.) is carried out by sending transactions.
  • the transaction is initiated by the user and sent to the blockchain node through the client. After receiving the transaction, the blockchain node will package the transaction into a block and execute it.
  • the transaction receipt stores the execution result of the transaction.
  • a typical transaction receipt contains important information such as the transaction hash, status bits that identify whether the transaction was successfully executed, and logs generated during execution.
  • Bloom filter is a data structure, a more ingenious probabilistic data structure.
  • the core implementation is a large bit array and several hash functions. It is characterized by efficient insertion and query, which can be used to determine whether an element may exist or be certain. does not exist. Ethereum's Bloom filter greatly improves the efficiency of querying events.
  • Event is a convenient interface provided by the virtual machine log infrastructure, which can be predefined and used to generate logs in a predetermined format.
  • an event call
  • it will trigger parameters to be stored in the transaction log (a special data structure on the blockchain).
  • These logs are associated with the address of the contract and recorded in the blockchain.
  • Each transaction receipt of the blockchain will contain 0 or more log records.
  • the logs represent the events triggered by the smart contract.
  • a block can include multiple transactions, each transaction includes at least one event, and each event includes at least one topic.
  • the current method is to store the subject of the block through a fixed-length Bloom filter.
  • a Bloom filter will be completely invalid and cannot accurately store the subject of the block; for the subject of a block with a small transaction volume, It will also cause a lot of waste of storage space. This situation does not meet the needs of banks and other financial institutions, and cannot guarantee the efficient operation of various businesses of financial institutions.
  • Step 201 Obtain the subject count of the block.
  • Step 202 According to the number of topics, determine the number of topic storage bits needed to store each topic of the block.
  • the number of theme storage bits is positively correlated with the number of themes.
  • Step 203 Generate a Bloom filter of the block according to the number of bits stored in the theme.
  • the storage space of the Bloom filter is greater than the number of bits of the theme storage; the initial value of each bit in the storage space of the Bloom filter is a first preset value;
  • Step 204 For each topic of the block, update the bit value of the topic mapped in the Bloom filter from the first preset value to the second preset according to a preset mapping relationship Value to obtain the Bloom filter storing each topic of the block.
  • the number of bits whose value is the second preset value is the number of bits stored in the topic; the bloom filter is used to determine whether a block contains query data theme.
  • Step 201 occurs after the block is executed, and the number of topics of the block is obtained, which can be obtained by counting the number of topics included in all transaction receipts of the block. Specifically, the following implementation methods can be adopted:
  • step 202 the relationship between the number of theme storage bits and the number of themes may be as follows:
  • K T*n; where K is the number of stored bits for the topic; T is the number of topics; n is the number of bits occupied by each topic of the block in the Bloom filter.
  • the number of bits occupied by each theme in the bloom filter can be freely set according to requirements. For example, each theme occupies 3 bits in the bloom filter.
  • configuration items may be added in advance: the storage space utilization rate of the bloom filter; m is the storage space utilization rate configured by the bloom filter. Under the configuration of m, the ratio of the number of bits of the theme storage bit to the storage space of the Bloom filter is m.
  • This configuration item affects the query efficiency of the Bloom filter and the storage space of the Bloom filter.
  • m can be set to 10%, which is not limited here.
  • the storage space size of the bloom filter of the current block can be calculated according to the number of topics of the block and the usage rate of the bloom filter bits:
  • Bloom filter size the number of topics in the block*3/bloom filter space usage rate; unit: bit.
  • the initial value of each bit in the storage space of the Bloom filter generated in step 203 is the first preset value.
  • the The value of the bits mapped by the theme in the bloom filter is updated from the first preset value to a second preset value, and a bloom filter storing each theme of the block is obtained.
  • the first preset value is 0 and the second preset value is 1. It is also possible that the first preset value is 1 and the second preset value is 0.
  • step 204 it is necessary to ensure that: in the storage space of the bloom filter, the number of bits whose value is the second preset value is the number of bits for storing the theme. In other words, each bit can only uniquely identify one topic, and there will be no conflicts in storage between the topics.
  • each topic of the block is correspondingly stored in the Bloom filter.
  • you can do so by querying a target topic in the target event. If the target subject can be queried, the target event is determined to exist; otherwise, the target event does not exist.
  • the size of the Bloom filter in block one is:
  • the size of the Bloom filter in block two is:
  • the number of topics in the block is first obtained, and the number of topic storage bits is determined according to the number of topics, so as to generate the layout of the block according to the number of topics stored in the topic.
  • Long filter because the number of topics stored in the topic is positively correlated with the number of topics, and the storage space of the Bloom filter is greater than the number of topics stored in the topic, so when the number of topics in a block is large, The storage space of the bloom filter should also be correspondingly larger. When the number of topics of the block is small, the storage space of the bloom filter will be correspondingly small, so a suitable one can be generated according to the number of topics of the block. Bloom filter for storage space.
  • the initial values of the bits in the storage space of the bloom filter are all the first preset values.
  • the theme can be placed in the bloom according to a preset mapping relationship.
  • the value of the bits mapped in the filter is updated from the first preset value to the second preset value, and the Bloom filter storing each theme of the block is obtained.
  • the Bloom filter The storage space of the device is sufficient to meet the storage of each topic of the block, and in the storage space of the Bloom filter, the number of bits whose value is the second preset value is the number of bits stored in the topic , Indicating that the bits of the mapping between the topics do not conflict, and the topic of the block can be accurately stored, so that the query result can be accurately provided when determining whether the block contains the subject of the query later.
  • the present application provides a device for generating Bloom filters in a blockchain, including: an acquisition module 301, configured to acquire the number of topics in a block; and a processing module 302, configured to obtain the number of topics based on the number of topics.
  • the number of theme storage bits required to store each theme of the block is positively correlated with the number of topics; according to the number of theme storage bits, the layout of the block is generated Long filter; the storage space of the bloom filter is greater than the number of bits stored in the theme; the initial value of each bit in the storage space of the bloom filter is a first preset value; and For each topic of the block, the value of the bit mapped by the topic in the Bloom filter is updated from the first preset value to the second preset value according to the preset mapping relationship, and the storage is obtained.
  • the bloom filter of each theme of the block in the storage space of the bloom filter, the number of bits whose value is the second preset value is the number of bits stored in the theme; Bloom filter is used to determine whether the subject of the query is included in the block.
  • the ratio of the number of bits of the topic storage bit to the storage space of the bloom filter is m; m is the storage space usage rate configured by the bloom filter.
  • the obtaining module 301 is specifically configured to: determine the transaction in the block and the event of each transaction; determine the number of index parameters for each event in the block; wherein, each The number of index parameters of each event corresponds to one topic; the sum of the number of index parameters of each event in the block is used as the number of topics.
  • An embodiment of the application provides a computer device, including a program or instruction, when the program or instruction is executed, it is used to execute a method for generating a Bloom filter in a blockchain provided in an embodiment of the application and any one Optional method.
  • the embodiment of the application provides a storage medium, including a program or instruction, when the program or instruction is executed, it is used to execute a method for generating a bloom filter in a blockchain provided in the embodiment of the application and any one Optional method.
  • this application can be provided as methods, systems, or computer program products. Therefore, this application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, optical storage, etc.) containing computer-usable program codes.
  • a computer-usable storage media including but not limited to disk storage, optical storage, etc.
  • These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device.
  • the device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.

Abstract

A method and device for generating a Bloom filter in a blockchain. The method comprises: acquiring the number of topics of a block (201); according to the number of topics, determining the number of topic storage bits needing to be occupied for storing the topics of the block (202), the number of topic storage bits being positively correlated with the number of topics; generating a Bloom filter of the block according to the number of topic storage bits (203); and for each topic of the block, according to a preset mapping relationship, updating the value of the bit mapped by the topic in the Bloom filter from a first preset value to a second preset value, so as to obtain the Bloom filter for storing the topics of the block (204). When the method above is applied to Fintech, the storage space of the Bloom filter is sufficient, so that the storage of various topics of the block can be satisfied, the bits of the mapping between the topics do not conflict, and an accurate query can be achieved when it is determined subsequently whether the block contains a queried topic.

Description

一种区块链中布隆过滤器的生成方法及装置Method and device for generating bloom filter in block chain
相关申请的交叉引用Cross-references to related applications
本申请要求在2019年09月26日提交中国专利局、申请号为201910918040.7、申请名称为“一种区块链中布隆过滤器的生成方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on September 26, 2019, the application number is 201910918040.7, and the application name is "a method and device for generating a Bloom filter in a blockchain", all of which The content is incorporated in this application by reference.
技术领域Technical field
本发明涉及金融科技(Fintech)领域和区块链(Blockchain)领域,尤其涉及一种区块链中布隆过滤器的生成方法及装置。The present invention relates to the field of financial technology (Fintech) and the field of blockchain (Blockchain), in particular to a method and device for generating a Bloom filter in a blockchain.
背景技术Background technique
随着计算机技术的发展,越来越多的技术(大数据、分布式、区块链(Blockchain)、人工智能等)应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变。目前,金融科技领域中,常通过区块链实现金融活动。一个区块中可能有多笔交易,每笔交易包括至少一个事件,每个事件又包括至少一个主题。在一些场景下,可能会涉及到对某个事件的查找。事件可通过事件的主题来进行查找。With the development of computer technology, more and more technologies (big data, distributed, Blockchain, artificial intelligence, etc.) are applied in the financial field, and the traditional financial industry is gradually changing to Fintech. At present, in the field of financial technology, financial activities are often realized through blockchain. There may be multiple transactions in a block, each transaction includes at least one event, and each event includes at least one topic. In some scenarios, it may involve searching for an event. The event can be searched by the subject of the event.
现有技术中的方式为,采取定长为2048比特的布隆过滤器来存储区块的主题。布隆过滤器完全可以存储交易量较小的区块的主题,然而,对于单个区块能够打包上万笔交易的区块,定长为2048比特的布隆过滤器必然会出现比特位重复的现象,布隆过滤器会完全失效,不能准确地存储区块的主题,另外,对于交易量较小的区块的主题,又会造成大量存储空间浪费,这是一个亟待解决的问题。In the prior art, a Bloom filter with a fixed length of 2048 bits is used to store the subject of the block. Bloom filters can completely store themes of blocks with small transaction volume. However, for a block that can pack tens of thousands of transactions in a single block, a Bloom filter with a fixed length of 2048 bits will inevitably have bit duplication. Phenomenon, the Bloom filter will completely fail and cannot accurately store the subject of the block. In addition, the subject of a block with a small transaction volume will waste a lot of storage space, which is an urgent problem to be solved.
发明内容Summary of the invention
本申请实施例提供一种区块链中布隆过滤器的生成方法及装置,解决了 现有技术中不能准确存储区块的主题及造成大量存储空间浪费的问题。The embodiments of the present application provide a method and device for generating a bloom filter in a block chain, which solves the problem of the inability to accurately store the subject of the block in the prior art and the waste of a lot of storage space.
第一方面,本申请实施例提供一种区块链中布隆过滤器的生成方法:获取区块的主题数量;根据所述主题数量,确定存储所述区块的各主题所需要占用的主题存储比特位数;所述主题存储比特位数与所述主题数量呈正相关;根据所述主题存储比特位数,生成所述区块的布隆过滤器;所述布隆过滤器的存储空间大于所述主题存储比特位数;所述布隆过滤器的存储空间中各比特位的初始值均为第一预设值;针对所述区块的每个主题,按照预设映射关系将所述主题在所述布隆过滤器中映射的比特位的值由所述第一预设值更新为第二预设值,获得存储所述区块的各主题的布隆过滤器;所述布隆过滤器的存储空间中,值为所述第二预设值的比特位的个数为所述主题存储比特位数;所述布隆过滤器用于确定区块中是否包含查询的主题。In the first aspect, an embodiment of the present application provides a method for generating a Bloom filter in a blockchain: obtaining the number of topics of a block; according to the number of topics, determining the topics that need to be occupied for storing each topic of the block The number of stored bits; the number of stored bits of the topic is positively correlated with the number of topics; the bloom filter of the block is generated according to the number of stored bits of the topic; the storage space of the bloom filter is greater than The number of bits in the topic storage; the initial value of each bit in the storage space of the Bloom filter is a first preset value; for each topic of the block, the The value of the bits mapped by the theme in the bloom filter is updated from the first preset value to a second preset value, and a bloom filter storing each theme of the block is obtained; the bloom In the storage space of the filter, the number of bits whose value is the second preset value is the number of bits for storing the topic; the Bloom filter is used to determine whether the block contains the subject of the query.
上述方法中,首先获取了区块的主题数量,并根据所述主题数量,确定主题存储比特位数,从而再根据所述主题存储比特位数,生成所述区块的布隆过滤器,由于所述主题存储比特位数与所述主题数量呈正相关,且所述布隆过滤器的存储空间大于所述主题存储比特位数,因此当区块的主题数量较大时,所述布隆过滤器的存储空间也要相应较大,当区块的主题数量较小时,所述布隆过滤器的存储空间也会相应较小,所以可根据区块的主题数量生成一个适宜存储空间的布隆过滤器。另外,所述布隆过滤器的存储空间中比特位的初始值均为第一预设值,针对所述区块的每个主题,可按照预设映射关系将所述主题在所述布隆过滤器中映射的比特位的值由所述第一预设值更新为第二预设值,获得存储所述区块的各主题的布隆过滤器,综上,上述方法中,布隆过滤器的存储空间充足,能满足区块各主题的存储,且所述布隆过滤器的存储空间中,值为所述第二预设值的比特位的个数为所述主题存储比特位数,说明各主题之间的映射的比特位不冲突,能准确地存储区块的主题,以便在后续确定区块中是否包含查询的主题时,准确地提供查询结果。In the above method, the number of topics in the block is first obtained, and the number of topics stored in the topic is determined according to the number of topics, so as to generate the Bloom filter of the block according to the number of bits in the topic storage. The number of topics stored in the topic is positively correlated with the number of topics, and the storage space of the bloom filter is greater than the number of topics stored in the topic. Therefore, when the number of topics in a block is large, the bloom filter The storage space of the filter should also be correspondingly larger. When the number of topics in the block is small, the storage space of the bloom filter will be correspondingly small, so a bloom with a suitable storage space can be generated according to the number of topics in the block. filter. In addition, the initial values of the bits in the storage space of the bloom filter are all the first preset values. For each theme of the block, the theme can be placed in the bloom according to a preset mapping relationship. The value of the bits mapped in the filter is updated from the first preset value to the second preset value, and the Bloom filter storing each theme of the block is obtained. In summary, in the above method, the Bloom filter The storage space of the device is sufficient to meet the storage of each topic of the block, and in the storage space of the Bloom filter, the number of bits whose value is the second preset value is the number of bits stored in the topic , Indicating that the bits of the mapping between the topics do not conflict, and the topic of the block can be accurately stored, so that the query result can be accurately provided when determining whether the block contains the subject of the query later.
一种可选实施方式中,所述主题存储比特位数与所述主题数量的关系如下:K=T*n;其中,K为所述主题存储比特位数;T为所述主题数量;n为所 述区块的每个主题在所述布隆过滤器占用的比特位数。In an optional implementation manner, the relationship between the number of topic storage bits and the number of topics is as follows: K=T*n; where K is the number of topic storage bits; T is the number of topics; n Is the number of bits occupied by each topic of the block in the bloom filter.
上述方法中,主题存储比特位数与所述主题数量呈正比,每个主题在所述布隆过滤器占用的比特位数都相同,从而可以方便根据主题数量统计出主题存储比特位数,提供了一种确定主题存储比特位数的方法。In the above method, the number of topic storage bits is proportional to the number of topics, and the number of bits occupied by each topic in the Bloom filter is the same, so that the number of topic storage bits can be conveniently calculated according to the number of topics. A method of determining the number of bits stored in a topic is proposed.
一种可选实施方式中,所述主题存储比特位数与所述布隆过滤器的存储空间的比值为m;m为所述布隆过滤器配置的存储空间使用率。In an optional implementation manner, the ratio of the number of bits of the topic storage bit to the storage space of the bloom filter is m; m is the storage space usage rate configured by the bloom filter.
上述方法中,可根据m的设置,调节布隆过滤器中各主题比特位的离散性,从而提升了通过布隆过滤器存储主题的灵活性。In the above method, the discreteness of the theme bits in the Bloom filter can be adjusted according to the setting of m, thereby improving the flexibility of storing the theme through the Bloom filter.
一种可选实施方式中,所述获取区块的主题数量,包括:确定所述区块中的交易及每个交易的事件;确定所述区块中每个事件的索引参数个数;其中,每个事件的索引参数个数对应于一个主题;将所述区块中各事件的索引参数个数之和,作为所述主题数量。In an optional implementation manner, the obtaining the number of topics of the block includes: determining the transactions in the block and the events of each transaction; determining the number of index parameters for each event in the block; wherein , The number of index parameters of each event corresponds to a topic; the sum of the number of index parameters of each event in the block is used as the number of topics.
上述方式下,将所述区块中各事件的索引参数个数之和,作为主题数量,由于索引参数可以用来搜索事件,因此可以保证每个主题都有对应索引,主题数量的主题中每个主题都能被搜索到。In the above method, the sum of the index parameters of each event in the block is used as the number of topics. Since the index parameters can be used to search for events, it can be ensured that each topic has a corresponding index. All topics can be searched.
第二方面,本申请提供一种区块链中布隆过滤器的生成装置,包括:获取模块,用于获取区块的主题数量;处理模块,用于根据所述主题数量,确定存储所述区块的各主题所需要占用的主题存储比特位数;所述主题存储比特位数与所述主题数量呈正相关;根据所述主题存储比特位数,生成所述区块的布隆过滤器;所述布隆过滤器的存储空间大于所述主题存储比特位数;所述布隆过滤器的存储空间中各比特位的初始值均为第一预设值;以及用于针对所述区块的每个主题,按照预设映射关系将所述主题在所述布隆过滤器中映射的比特位的值由所述第一预设值更新为第二预设值,获得存储所述区块的各主题的布隆过滤器;所述布隆过滤器的存储空间中,值为所述第二预设值的比特位的个数为所述主题存储比特位数;所述布隆过滤器用于确定区块中是否包含查询的主题。In a second aspect, the present application provides a device for generating bloom filters in a blockchain, including: an acquisition module, configured to acquire the number of topics in a block; a processing module, configured to determine and store the number of topics based on the number of topics. The number of topic storage bits required for each topic of the block; the number of topic storage bits is positively correlated with the number of topics; the Bloom filter of the block is generated according to the number of topic storage bits; The storage space of the Bloom filter is greater than the number of bits stored in the theme; the initial value of each bit in the storage space of the Bloom filter is a first preset value; and is used to target the block For each topic of, update the bit value of the topic mapped in the Bloom filter from the first preset value to a second preset value according to a preset mapping relationship, and obtain and store the block The Bloom filter of each theme; in the storage space of the Bloom filter, the number of bits whose value is the second preset value is the number of bits stored in the theme; the Bloom filter uses To determine whether the subject of the query is included in the block.
一种可选实施方式中,所述主题存储比特位数与所述主题数量的关系如 下:K=T*n;其中,K为所述主题存储比特位数;T为所述主题数量;n为所述区块的每个主题在所述布隆过滤器占用的比特位数。In an optional implementation manner, the relationship between the number of topic storage bits and the number of topics is as follows: K=T*n; where K is the number of topic storage bits; T is the number of topics; n Is the number of bits occupied by each topic of the block in the bloom filter.
一种可选实施方式中,所述主题存储比特位数与所述布隆过滤器的存储空间的比值为m;m为所述布隆过滤器配置的存储空间使用率。In an optional implementation manner, the ratio of the number of bits of the topic storage bit to the storage space of the bloom filter is m; m is the storage space usage rate configured by the bloom filter.
一种可选实施方式中,所述获取模块具体用于:确定所述区块中的交易及每个交易的事件;确定所述区块中每个事件的索引参数个数;其中,每个事件的索引参数个数对应于一个主题;将所述区块中各事件的索引参数个数之和,作为所述主题数量。In an optional implementation manner, the acquisition module is specifically configured to: determine the transaction in the block and the event of each transaction; determine the number of index parameters for each event in the block; wherein each The number of index parameters of an event corresponds to a topic; the sum of the number of index parameters of each event in the block is taken as the number of topics.
上述第二方面及第二方面各个实施例的有益效果,可以参考上述第一方面及第一方面各个实施例的有益效果,这里不再赘述。For the beneficial effects of the above-mentioned second aspect and the embodiments of the second aspect, reference may be made to the beneficial effects of the above-mentioned first aspect and the embodiments of the first aspect, which will not be repeated here.
第三方面,本申请实施例提供一种计算机设备,包括程序或指令,当所述程序或指令被执行时,用以执行上述第一方面及第一方面各个实施例的方法。In a third aspect, an embodiment of the present application provides a computer device including a program or instruction, and when the program or instruction is executed, it is used to execute the method of the foregoing first aspect and each embodiment of the first aspect.
第四方面,本申请实施例提供一种存储介质,包括程序或指令,当所述程序或指令被执行时,用以执行上述第一方面及第一方面各个实施例的方法。In a fourth aspect, an embodiment of the present application provides a storage medium including a program or instruction, and when the program or instruction is executed, it is used to execute the methods of the first aspect and the embodiments of the first aspect.
附图说明Description of the drawings
图1为区块链的结构示意图;Figure 1 is a schematic diagram of the structure of the blockchain;
图2为本申请实施例提供的一种区块链中布隆过滤器的生成方法的步骤流程示意图;FIG. 2 is a schematic flowchart of steps of a method for generating a Bloom filter in a blockchain according to an embodiment of the application;
图3为本申请实施例提供的一种区块链中布隆过滤器的生成装置的结构示意图。FIG. 3 is a schematic structural diagram of a device for generating a Bloom filter in a blockchain according to an embodiment of the application.
具体实施方式detailed description
为了更好的理解上述技术方案,下面将结合说明书附图及具体的实施方式对上述技术方案进行详细的说明,应当理解本申请实施例以及实施例中的具体特征是对本申请技术方案的详细的说明,而不是对本申请技术方案的限 定,在不冲突的情况下,本申请实施例以及实施例中的技术特征可以相互结合。In order to better understand the above technical solutions, the above technical solutions will be described in detail below with reference to the drawings and specific implementations of the specification. It should be understood that the embodiments of the application and the specific features in the embodiments are detailed to the technical solutions of the application. Note, rather than limiting the technical solution of the present application, the embodiments of the present application and the technical features in the embodiments can be combined with each other if there is no conflict.
下面首先解释本申请实施例中出现的名词。The following first explains the terms appearing in the embodiments of the present application.
区块链:如图1所示,区块链是由一系列区块组成的一条链,每个块上除了记录本块的数据还会记录上一块的哈希(Hash)值,通过这种方式组成一条链。区块链的核心理念有两个,一个是密码学技术,另一个是去中心化思想,基于这两个理念做到区块链上的历史信息无法被篡改。Block chain: As shown in Figure 1, the block chain is a chain composed of a series of blocks. In addition to recording the data of this block, each block also records the hash value of the previous block. Through this Way to form a chain. There are two core concepts of the blockchain, one is cryptography and the other is decentralization. Based on these two concepts, the historical information on the blockchain cannot be tampered with.
节点:网络中的每一个参与者就是一个节点,节点参与网络组建和数据交换。在区块链网络中,一个节点是指一个具有唯一身份的参与者,该节点具有一份完整的账本拷贝,具有参与区块链网络共识和账本维护的能力。Node: Each participant in the network is a node, and the node participates in network formation and data exchange. In the blockchain network, a node refers to a participant with a unique identity. The node has a complete copy of the ledger and has the ability to participate in the consensus of the blockchain network and the maintenance of the ledger.
智能合约:智能合约是一种旨在以信息化方式传播、验证或执行合同的计算机协议。智能合约允许在没有第三方的情况下进行可信交易,这些交易可追踪且不可逆转。智能合约具体形式为部署在区块链上,完成特定功能的代码。举例来说,Solidity是一种主流的智能合约编程语言,用Solidity语言编写的智能合约,可以称为Solidity合约。当智能合约被部署到区块链上时,会产生合约地址,用户可通过合约地址调用此智能合约。智能合约中定义的函数,称为合约接口,对智能合约的调用,就是通过合约地址调用合约中的某个合约接口。Smart contract: A smart contract is a computer protocol designed to spread, verify, or execute a contract in an information-based way. Smart contracts allow for trusted transactions without a third party, which are traceable and irreversible. The specific form of the smart contract is the code that is deployed on the blockchain to complete specific functions. For example, Solidity is a mainstream smart contract programming language. Smart contracts written in Solidity language can be called Solidity contracts. When a smart contract is deployed on the blockchain, a contract address will be generated, and users can call this smart contract through the contract address. The function defined in the smart contract is called the contract interface. The call to the smart contract is to call a contract interface in the contract through the contract address.
交易:交易是用户对部署在区块链上智能合约接口的一次操作请求。交易由用户发起,从用户的客户端发往区块链节点,区块链节点收到交易后,根据交易指定的合约地址和接口去调用相应的智能合约。在区块链中,任何操作(部署合约、调用合约接口等)都是通过发送交易的方式进行。交易由用户发起,并通过客户端发送至区块链节点。区块链节点在收到交易后,会将交易打包为区块并执行。Transaction: A transaction is a user's request for an operation on the smart contract interface deployed on the blockchain. The transaction is initiated by the user and sent from the user's client to the blockchain node. After the blockchain node receives the transaction, it calls the corresponding smart contract according to the contract address and interface specified by the transaction. In the blockchain, any operation (deploy contract, call contract interface, etc.) is carried out by sending transactions. The transaction is initiated by the user and sent to the blockchain node through the client. After receiving the transaction, the blockchain node will package the transaction into a block and execute it.
区块中每笔交易执行后都会产生一份相应的交易收据。交易收据存储了交易的执行结果,典型的交易收据包含交易哈希、标识交易是否执行成功的状态位及执行期间产生的日志等重要信息。After each transaction in the block is executed, a corresponding transaction receipt will be generated. The transaction receipt stores the execution result of the transaction. A typical transaction receipt contains important information such as the transaction hash, status bits that identify whether the transaction was successfully executed, and logs generated during execution.
布隆过滤器:Bloom filter:
布隆过滤器是一种数据结构,比较巧妙的概率型数据结构,核心实现是一个超大的位数组和几个哈希函数,特点是高效地插入和查询,可以用来判断元素可能存在或者一定不存在。以太坊的布隆过滤器极大地提高了查询事件的效率。Bloom filter is a data structure, a more ingenious probabilistic data structure. The core implementation is a large bit array and several hash functions. It is characterized by efficient insertion and query, which can be used to determine whether an element may exist or be certain. does not exist. Ethereum's Bloom filter greatly improves the efficiency of querying events.
事件(Event)、日志(Log):Event, Log:
事件是虚拟机日志基础设施提供的一个便利接口,可被预先定义,用于生成预定格式的日志。当被发送事件(调用)时,会触发参数存储到交易的日志中(一种区块链上的特殊数据结构)。这些日志与合约的地址关联,并记录到区块链中,区块链每一个交易回执会包含0到多个日志记录,日志代表着智能合约所触发的事件。Event is a convenient interface provided by the virtual machine log infrastructure, which can be predefined and used to generate logs in a predetermined format. When an event (call) is sent, it will trigger parameters to be stored in the transaction log (a special data structure on the blockchain). These logs are associated with the address of the contract and recorded in the blockchain. Each transaction receipt of the blockchain will contain 0 or more log records. The logs represent the events triggered by the smart contract.
主题(topic):Topic:
在区块链中,在定义一个事件时,需要指定该事件的参数。参数分为两种,一种是被索引参数关键字(indexed)修饰的,另外一种没有被indexed修饰。这两种参数的区别在于前者将被存储在日志的topic字段,而后者将会被存储在日志的data字段中。日志的topic字段可以用作搜索,而data字段不可以用作搜索。In the blockchain, when defining an event, you need to specify the parameters of the event. Parameters are divided into two types, one is modified by indexed parameter keywords (indexed), and the other is not modified by indexed. The difference between these two parameters is that the former will be stored in the topic field of the log, while the latter will be stored in the data field of the log. The topic field of the log can be used for search, but the data field cannot be used for search.
在金融机构(银行机构、保险机构或证券机构)在进行业务(如银行的贷款业务、存款业务等)运转过程中,数据中心节点之间进行任务调度时,由于各任务之间可能存在先后依赖关系,常通过区块链实现金融活动。在一些场景下,可能会涉及到对某个事件的查找,一个区块中可以包括多笔交易,每笔交易包括至少一个事件,每个事件又包括至少一个主题。When a financial institution (banking institution, insurance institution, or securities institution) is in the process of conducting business (such as bank loan business, deposit business, etc.), when task scheduling is performed between data center nodes, there may be sequential dependencies between tasks Relations, often through the blockchain to achieve financial activities. In some scenarios, it may involve searching for an event. A block can include multiple transactions, each transaction includes at least one event, and each event includes at least one topic.
目前的方式是通过定长的布隆过滤器来存储区块的主题。这种方式对于交易量较大的区块的主题,会出现比特位重复的现象,布隆过滤器会完全失效,不能准确地存储区块的主题;对于交易量较小的区块的主题,又会造成大量存储空间浪费。这种情况不符合银行等金融机构的需求,无法保证金融机构各项业务的高效运转。The current method is to store the subject of the block through a fixed-length Bloom filter. In this way, for the subject of a block with a large transaction volume, there will be a phenomenon of bit duplication, and the Bloom filter will be completely invalid and cannot accurately store the subject of the block; for the subject of a block with a small transaction volume, It will also cause a lot of waste of storage space. This situation does not meet the needs of banks and other financial institutions, and cannot guarantee the efficient operation of various businesses of financial institutions.
由此可见,当前的布隆过滤器并不能满足区块链多场景下的需求,需要对生成布隆过滤器的策略进行调整,如图2所示的步骤流程示意图,本申请提出一种区块链中布隆过滤器的生成方法。It can be seen that the current Bloom filter cannot meet the needs of the blockchain in multiple scenarios, and the strategy for generating the Bloom filter needs to be adjusted, as shown in the schematic diagram of the process flow shown in Figure 2. This application proposes a zone The method of generating Bloom filters in the block chain.
步骤201:获取区块的主题数量。Step 201: Obtain the subject count of the block.
步骤202:根据所述主题数量,确定存储所述区块的各主题所需要占用的主题存储比特位数。Step 202: According to the number of topics, determine the number of topic storage bits needed to store each topic of the block.
所述主题存储比特位数与所述主题数量呈正相关。The number of theme storage bits is positively correlated with the number of themes.
步骤203:根据所述主题存储比特位数,生成所述区块的布隆过滤器。Step 203: Generate a Bloom filter of the block according to the number of bits stored in the theme.
所述布隆过滤器的存储空间大于所述主题存储比特位数;所述布隆过滤器的存储空间中各比特位的初始值均为第一预设值;The storage space of the Bloom filter is greater than the number of bits of the theme storage; the initial value of each bit in the storage space of the Bloom filter is a first preset value;
步骤204:针对所述区块的每个主题,按照预设映射关系将所述主题在所述布隆过滤器中映射的比特位的值由所述第一预设值更新为第二预设值,获得存储所述区块的各主题的布隆过滤器。Step 204: For each topic of the block, update the bit value of the topic mapped in the Bloom filter from the first preset value to the second preset according to a preset mapping relationship Value to obtain the Bloom filter storing each topic of the block.
所述布隆过滤器的存储空间中,值为所述第二预设值的比特位的个数为所述主题存储比特位数;所述布隆过滤器用于确定区块中是否包含查询的主题。In the storage space of the bloom filter, the number of bits whose value is the second preset value is the number of bits stored in the topic; the bloom filter is used to determine whether a block contains query data theme.
步骤201发生在区块执行之后,获取区块的主题数量,可以通过统计区块所有交易回执包含的主题数量获取。具体来说,可采取以下实施方式:Step 201 occurs after the block is executed, and the number of topics of the block is obtained, which can be obtained by counting the number of topics included in all transaction receipts of the block. Specifically, the following implementation methods can be adopted:
确定所述区块中的交易及每个交易的事件;确定所述区块中每个事件的索引参数个数;其中,每个事件的索引参数个数对应于一个主题;将所述区块中各事件的索引参数个数之和,作为所述主题数量。Determine the transaction in the block and the event of each transaction; determine the number of index parameters for each event in the block; wherein, the number of index parameters for each event corresponds to a topic; divide the block The sum of the number of index parameters of each event in, is used as the number of topics.
举例来说,区块中有100个交易,每个交易的事件数均为2。而每个事件被indexed修饰的索引参数有2个。那么区块中各事件的索引参数之和即为100*2*2=400,区块的主题数量为400。需要说明的是,不同交易的事件数可能不同,不同事件的索引参数个数也不相同,此处仅举例说明主题数量如何获取到。For example, there are 100 transactions in a block, and the number of events for each transaction is 2. There are 2 index parameters modified by indexed for each event. Then the sum of the index parameters of each event in the block is 100*2*2=400, and the number of topics in the block is 400. It should be noted that the number of events for different transactions may be different, and the number of index parameters for different events is also different. Here we only illustrate how to obtain the number of topics.
步骤202中,所述主题存储比特位数与所述主题数量的关系可以如下:In step 202, the relationship between the number of theme storage bits and the number of themes may be as follows:
K=T*n;其中,K为所述主题存储比特位数;T为所述主题数量;n为所述区块的每个主题在所述布隆过滤器占用的比特位数。K=T*n; where K is the number of stored bits for the topic; T is the number of topics; n is the number of bits occupied by each topic of the block in the Bloom filter.
其中,每个主题在所述布隆过滤器占用的比特位数可以根据需求自由设定,举例来说,每个主题占用布隆过滤器3位。Wherein, the number of bits occupied by each theme in the bloom filter can be freely set according to requirements. For example, each theme occupies 3 bits in the bloom filter.
在步骤203的布隆过滤器的生成过程中,还可以事先添加配置项:布隆过滤器的存储空间使用率;m为所述布隆过滤器配置的存储空间使用率。在m的配置下,所述主题存储比特位数与所述布隆过滤器的存储空间的比值为m。In the process of generating the bloom filter in step 203, configuration items may be added in advance: the storage space utilization rate of the bloom filter; m is the storage space utilization rate configured by the bloom filter. Under the configuration of m, the ratio of the number of bits of the theme storage bit to the storage space of the Bloom filter is m.
该配置项影响布隆过滤器的查询效率以及布隆过滤器的存储空间,使用率越小说明布隆过滤器冲突率越低,查询速度更快,但是需要存储空间越大,根据实际需要在查找效率与存储之间寻求平衡。举例来说,m可以设置为10%,在此不做限定。This configuration item affects the query efficiency of the Bloom filter and the storage space of the Bloom filter. The smaller the usage rate, the lower the conflict rate of the Bloom filter and the faster the query speed. However, the larger the storage space is required. Seek a balance between search efficiency and storage. For example, m can be set to 10%, which is not limited here.
步骤203中,可以根据区块的主题数量与布隆过滤器比特位的使用率计算当前区块的布隆过滤器的存储空间大小:In step 203, the storage space size of the bloom filter of the current block can be calculated according to the number of topics of the block and the usage rate of the bloom filter bits:
布隆过滤器大小=区块的主题数量*3/布隆过滤器空间使用率;单位:比特(bit)。Bloom filter size=the number of topics in the block*3/bloom filter space usage rate; unit: bit.
步骤203中生成的布隆过滤器的存储空间中各比特位的初始值均为第一预设值,在步骤204中,针对所述区块的每个主题,按照预设映射关系将所述主题在所述布隆过滤器中映射的比特位的值由所述第一预设值更新为第二预设值,获得存储所述区块的各主题的布隆过滤器。举例来说,第一预设值为0,第二预设值为1;也可以第一预设值为1,第二预设值为0。The initial value of each bit in the storage space of the Bloom filter generated in step 203 is the first preset value. In step 204, for each topic of the block, the The value of the bits mapped by the theme in the bloom filter is updated from the first preset value to a second preset value, and a bloom filter storing each theme of the block is obtained. For example, the first preset value is 0 and the second preset value is 1. It is also possible that the first preset value is 1 and the second preset value is 0.
步骤204中需要保证:所述布隆过滤器的存储空间中,值为所述第二预设值的比特位的个数为所述主题存储比特位数。也就是说,每个比特位只能唯一标识一个主题,各主题之间存储不会出现冲突。In step 204, it is necessary to ensure that: in the storage space of the bloom filter, the number of bits whose value is the second preset value is the number of bits for storing the theme. In other words, each bit can only uniquely identify one topic, and there will be no conflicts in storage between the topics.
步骤204之后,区块的各个主题都相应地存储在布隆过滤器中。当需要查询某个目标事件时,可以通过查询目标事件中的一个目标主题来进行。若能查询到目标主题,则确定目标事件存在;否则,目标事件不存在。After step 204, each topic of the block is correspondingly stored in the Bloom filter. When you need to query a target event, you can do so by querying a target topic in the target event. If the target subject can be queried, the target event is determined to exist; otherwise, the target event does not exist.
下面结合两种不同的具体场景说明上述区块链中布隆过滤器的生成方法。The following describes the method of generating the Bloom filter in the above-mentioned blockchain in combination with two different specific scenarios.
场景一:scene one:
此时区块链工作在高负载,高吞吐量(Transaction Per Second,TPS)模式下,其中区块一的参数如下:At this time, the blockchain works in a high-load, high-throughput (Transaction Per Second, TPS) mode. The parameters of block one are as follows:
Figure PCTCN2020114235-appb-000001
Figure PCTCN2020114235-appb-000001
区块一的布隆过器大小为:The size of the Bloom filter in block one is:
区块一的主题数量*3/比特位的使用率=40000*3/10%=1200000bit≈1.2Mb。The number of topics in block one*3/bit usage rate=40,000*3/10%=1200000bit≈1.2Mb.
场景二:Scene two:
该场景下区块链的负载比较低,其中区块二的参数如下:In this scenario, the load of the blockchain is relatively low, and the parameters of block two are as follows:
Figure PCTCN2020114235-appb-000002
Figure PCTCN2020114235-appb-000002
区块二的布隆过器大小为:The size of the Bloom filter in block two is:
区块一的主题数量*3/比特位的使用率=60*3/10%=1800bit≈1.8Kb。The number of topics in block one*3/bit usage rate=60*3/10%=1800bit≈1.8Kb.
步骤201~步骤204的方法中,首先获取了区块的主题数量,并根据所述主题数量,确定主题存储比特位数,从而再根据所述主题存储比特位数,生成所述区块的布隆过滤器,由于所述主题存储比特位数与所述主题数量呈正相关,且所述布隆过滤器的存储空间大于所述主题存储比特位数,因此当区块的主题数量较大时,所述布隆过滤器的存储空间也要相应较大,当区块的主题数量较小时,所述布隆过滤器的存储空间也会相应较小,所以可根据区块的主题数量生成一个适宜存储空间的布隆过滤器。另外,所述布隆过滤器 的存储空间中比特位的初始值均为第一预设值,针对所述区块的每个主题,可按照预设映射关系将所述主题在所述布隆过滤器中映射的比特位的值由所述第一预设值更新为第二预设值,获得存储所述区块的各主题的布隆过滤器,综上,上述方法中,布隆过滤器的存储空间充足,能满足区块各主题的存储,且所述布隆过滤器的存储空间中,值为所述第二预设值的比特位的个数为所述主题存储比特位数,说明各主题之间的映射的比特位不冲突,能准确地存储区块的主题,以便在后续确定区块中是否包含查询的主题时,准确地提供查询结果。In the method from step 201 to step 204, the number of topics in the block is first obtained, and the number of topic storage bits is determined according to the number of topics, so as to generate the layout of the block according to the number of topics stored in the topic. Long filter, because the number of topics stored in the topic is positively correlated with the number of topics, and the storage space of the Bloom filter is greater than the number of topics stored in the topic, so when the number of topics in a block is large, The storage space of the bloom filter should also be correspondingly larger. When the number of topics of the block is small, the storage space of the bloom filter will be correspondingly small, so a suitable one can be generated according to the number of topics of the block. Bloom filter for storage space. In addition, the initial values of the bits in the storage space of the bloom filter are all the first preset values. For each theme of the block, the theme can be placed in the bloom according to a preset mapping relationship. The value of the bits mapped in the filter is updated from the first preset value to the second preset value, and the Bloom filter storing each theme of the block is obtained. In summary, in the above method, the Bloom filter The storage space of the device is sufficient to meet the storage of each topic of the block, and in the storage space of the Bloom filter, the number of bits whose value is the second preset value is the number of bits stored in the topic , Indicating that the bits of the mapping between the topics do not conflict, and the topic of the block can be accurately stored, so that the query result can be accurately provided when determining whether the block contains the subject of the query later.
如图3所示,本申请提供一种区块链中布隆过滤器的生成装置,包括:获取模块301,用于获取区块的主题数量;处理模块302,用于根据所述主题数量,确定存储所述区块的各主题所需要占用的主题存储比特位数;所述主题存储比特位数与所述主题数量呈正相关;根据所述主题存储比特位数,生成所述区块的布隆过滤器;所述布隆过滤器的存储空间大于所述主题存储比特位数;所述布隆过滤器的存储空间中各比特位的初始值均为第一预设值;以及用于针对所述区块的每个主题,按照预设映射关系将所述主题在所述布隆过滤器中映射的比特位的值由所述第一预设值更新为第二预设值,获得存储所述区块的各主题的布隆过滤器;所述布隆过滤器的存储空间中,值为所述第二预设值的比特位的个数为所述主题存储比特位数;所述布隆过滤器用于确定区块中是否包含查询的主题。As shown in FIG. 3, the present application provides a device for generating Bloom filters in a blockchain, including: an acquisition module 301, configured to acquire the number of topics in a block; and a processing module 302, configured to obtain the number of topics based on the number of topics. Determine the number of theme storage bits required to store each theme of the block; the number of theme storage bits is positively correlated with the number of topics; according to the number of theme storage bits, the layout of the block is generated Long filter; the storage space of the bloom filter is greater than the number of bits stored in the theme; the initial value of each bit in the storage space of the bloom filter is a first preset value; and For each topic of the block, the value of the bit mapped by the topic in the Bloom filter is updated from the first preset value to the second preset value according to the preset mapping relationship, and the storage is obtained. The bloom filter of each theme of the block; in the storage space of the bloom filter, the number of bits whose value is the second preset value is the number of bits stored in the theme; Bloom filter is used to determine whether the subject of the query is included in the block.
一种可选实施方式中,所述主题存储比特位数与所述主题数量的关系如下:K=T*n;其中,K为所述主题存储比特位数;T为所述主题数量;n为所述区块的每个主题在所述布隆过滤器占用的比特位数。In an optional implementation manner, the relationship between the number of topic storage bits and the number of topics is as follows: K=T*n; where K is the number of topic storage bits; T is the number of topics; n Is the number of bits occupied by each topic of the block in the bloom filter.
一种可选实施方式中,所述主题存储比特位数与所述布隆过滤器的存储空间的比值为m;m为所述布隆过滤器配置的存储空间使用率。In an optional implementation manner, the ratio of the number of bits of the topic storage bit to the storage space of the bloom filter is m; m is the storage space usage rate configured by the bloom filter.
一种可选实施方式中,所述获取模块301具体用于:确定所述区块中的交易及每个交易的事件;确定所述区块中每个事件的索引参数个数;其中,每个事件的索引参数个数对应于一个主题;将所述区块中各事件的索引参数 个数之和,作为所述主题数量。In an optional implementation manner, the obtaining module 301 is specifically configured to: determine the transaction in the block and the event of each transaction; determine the number of index parameters for each event in the block; wherein, each The number of index parameters of each event corresponds to one topic; the sum of the number of index parameters of each event in the block is used as the number of topics.
本申请实施例提供一种计算机设备,包括程序或指令,当所述程序或指令被执行时,用以执行本申请实施例提供的一种区块链中布隆过滤器的生成方法及任一可选方法。An embodiment of the application provides a computer device, including a program or instruction, when the program or instruction is executed, it is used to execute a method for generating a Bloom filter in a blockchain provided in an embodiment of the application and any one Optional method.
本申请实施例提供一种存储介质,包括程序或指令,当所述程序或指令被执行时,用以执行本申请实施例提供的一种区块链中布隆过滤器的生成方法及任一可选方法。The embodiment of the application provides a storage medium, including a program or instruction, when the program or instruction is executed, it is used to execute a method for generating a bloom filter in a blockchain provided in the embodiment of the application and any one Optional method.
本领域内的技术人员应明白,本申请的实施例可提供为方法、系统、或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, this application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, optical storage, etc.) containing computer-usable program codes.
本申请是参照根据本申请的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。This application is described with reference to the flowcharts and/or block diagrams of the methods, equipment (systems), and computer program products according to the application. It should be understood that each process and/or block in the flowchart and/or block diagram, and the combination of processes and/or blocks in the flowchart and/or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing equipment to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing equipment are generated It is a device that realizes the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing equipment to work in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction device. The device implements the functions specified in one process or multiple processes in the flowchart and/or one block or multiple blocks in the block diagram.
显然,本领域的技术人员可以对本申请进行各种改动和变型而不脱离本申请的范围。这样,倘若本申请的这些修改和变型属于本申请权利要求及其等同技术的范围之内,则本申请也意图包含这些改动和变型在内。Obviously, those skilled in the art can make various changes and modifications to the application without departing from the scope of the application. In this way, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalent technologies, this application is also intended to include these modifications and variations.

Claims (10)

  1. 一种区块链中布隆过滤器的生成方法,其特征在于,包括:A method for generating a Bloom filter in a blockchain, which is characterized in that it includes:
    获取区块的主题数量;Get the number of topics in the block;
    根据所述主题数量,确定存储所述区块的各主题所需要占用的主题存储比特位数;所述主题存储比特位数与所述主题数量呈正相关;According to the number of topics, determine the number of topic storage bits required to store each topic of the block; the number of topic storage bits is positively correlated with the number of topics;
    根据所述主题存储比特位数,生成所述区块的布隆过滤器;所述布隆过滤器的存储空间大于所述主题存储比特位数;所述布隆过滤器的存储空间中各比特位的初始值均为第一预设值;According to the number of bits stored in the theme, the Bloom filter of the block is generated; the storage space of the Bloom filter is greater than the number of bits stored in the theme; each bit in the storage space of the Bloom filter The initial values of the bits are all the first preset values;
    针对所述区块的每个主题,按照预设映射关系将所述主题在所述布隆过滤器中映射的比特位的值由所述第一预设值更新为第二预设值,获得存储所述区块的各主题的布隆过滤器;所述布隆过滤器的存储空间中,值为所述第二预设值的比特位的个数为所述主题存储比特位数;所述布隆过滤器用于确定区块中是否包含查询的主题。For each topic of the block, the value of the bit mapped by the topic in the Bloom filter is updated from the first preset value to a second preset value according to a preset mapping relationship to obtain Store the Bloom filter of each theme of the block; in the storage space of the Bloom filter, the number of bits whose value is the second preset value is the number of bits stored in the theme; The bloom filter is used to determine whether the subject of the query is included in the block.
  2. 如权利要求1所述的方法,其特征在于,所述主题存储比特位数与所述主题数量的关系如下:The method according to claim 1, wherein the relationship between the number of bits in the topic storage and the number of topics is as follows:
    K=T*n;其中,K为所述主题存储比特位数;T为所述主题数量;n为所述区块的每个主题在所述布隆过滤器占用的比特位数。K=T*n; where K is the number of stored bits for the topic; T is the number of topics; n is the number of bits occupied by each topic of the block in the Bloom filter.
  3. 如权利要求1所述的方法,其特征在于,所述主题存储比特位数与所述布隆过滤器的存储空间的比值为m;m为所述布隆过滤器配置的存储空间使用率。The method according to claim 1, wherein the ratio of the number of bits of the theme storage bit to the storage space of the Bloom filter is m; and m is the storage space usage rate configured by the Bloom filter.
  4. 如权利要求1-3任一所述的方法,其特征在于,所述获取区块的主题数量,包括:The method according to any one of claims 1-3, wherein said obtaining the number of topics of the block comprises:
    确定所述区块中的交易及每个交易的事件;Determine the transactions in the block and the events of each transaction;
    确定所述区块中每个事件的索引参数个数;其中,每个事件的索引参数个数对应于一个主题;Determine the number of index parameters for each event in the block; wherein, the number of index parameters for each event corresponds to a topic;
    将所述区块中各事件的索引参数个数之和,作为所述主题数量。The sum of the number of index parameters of each event in the block is used as the number of topics.
  5. 一种区块链中布隆过滤器的生成装置,其特征在于,包括:A device for generating Bloom filters in a blockchain, which is characterized in that it comprises:
    获取模块,用于获取区块的主题数量;Get module, used to get the number of topics in the block;
    处理模块,用于根据所述主题数量,确定存储所述区块的各主题所需要占用的主题存储比特位数;所述主题存储比特位数与所述主题数量呈正相关;根据所述主题存储比特位数,生成所述区块的布隆过滤器;所述布隆过滤器的存储空间大于所述主题存储比特位数;所述布隆过滤器的存储空间中各比特位的初始值均为第一预设值;以及用于针对所述区块的每个主题,按照预设映射关系将所述主题在所述布隆过滤器中映射的比特位的值由所述第一预设值更新为第二预设值,获得存储所述区块的各主题的布隆过滤器;所述布隆过滤器的存储空间中,值为所述第二预设值的比特位的个数为所述主题存储比特位数;所述布隆过滤器用于确定区块中是否包含查询的主题。The processing module is configured to determine, according to the number of topics, the number of topic storage bits needed to store each topic of the block; the number of topic storage bits is positively correlated with the number of topics; storage according to the topic The number of bits, the bloom filter that generates the block; the storage space of the bloom filter is greater than the number of bits stored in the theme; the initial value of each bit in the storage space of the bloom filter is equal Is a first preset value; and for each topic of the block, according to a preset mapping relationship, the bit value of the topic mapped in the bloom filter is set by the first preset The value is updated to the second preset value to obtain the Bloom filter storing each theme of the block; in the storage space of the Bloom filter, the value is the number of bits of the second preset value The number of bits is stored for the topic; the Bloom filter is used to determine whether the block contains the subject of the query.
  6. 如权利要求5所述的装置,其特征在于,所述主题存储比特位数与所述主题数量的关系如下:7. The device of claim 5, wherein the relationship between the number of bits of the theme storage and the number of themes is as follows:
    K=T*n;其中,K为所述主题存储比特位数;T为所述主题数量;n为所述区块的每个主题在所述布隆过滤器占用的比特位数。K=T*n; where K is the number of stored bits for the topic; T is the number of topics; n is the number of bits occupied by each topic of the block in the Bloom filter.
  7. 如权利要求5所述的装置,其特征在于,所述主题存储比特位数与所述布隆过滤器的存储空间的比值为m;m为所述布隆过滤器配置的存储空间使用率。7. The device of claim 5, wherein the ratio of the number of bits of the theme storage bit to the storage space of the Bloom filter is m; and m is the storage space usage rate configured by the Bloom filter.
  8. 如权利要求5-7任一所述的装置,其特征在于,所述获取模块具体用于:7. The device according to any one of claims 5-7, wherein the acquiring module is specifically configured to:
    确定所述区块中的交易及每个交易的事件;Determine the transactions in the block and the events of each transaction;
    确定所述区块中每个事件的索引参数个数;其中,每个事件的索引参数个数对应于一个主题;Determine the number of index parameters for each event in the block; wherein, the number of index parameters for each event corresponds to a topic;
    将所述区块中各事件的索引参数个数之和,作为所述主题数量。The sum of the number of index parameters of each event in the block is used as the number of topics.
  9. 一种计算机设备,其特征在于,包括程序或指令,当所述程序或指令被执行时,如权利要求1至4中任意一项所述的方法被执行。A computer device characterized by comprising a program or instruction, and when the program or instruction is executed, the method according to any one of claims 1 to 4 is executed.
  10. 一种存储介质,其特征在于,包括程序或指令,当所述程序或指令 被执行时,如权利要求1至4中任意一项所述的方法被执行。A storage medium, characterized by comprising a program or instruction, and when the program or instruction is executed, the method according to any one of claims 1 to 4 is executed.
PCT/CN2020/114235 2019-09-26 2020-09-09 Method and device for generating bloom filter in blockchain WO2021057482A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910918040.7 2019-09-26
CN201910918040.7A CN110704438B (en) 2019-09-26 2019-09-26 Method and device for generating bloom filter in blockchain

Publications (1)

Publication Number Publication Date
WO2021057482A1 true WO2021057482A1 (en) 2021-04-01

Family

ID=69196497

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/114235 WO2021057482A1 (en) 2019-09-26 2020-09-09 Method and device for generating bloom filter in blockchain

Country Status (2)

Country Link
CN (1) CN110704438B (en)
WO (1) WO2021057482A1 (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110704438B (en) * 2019-09-26 2023-10-03 深圳前海微众银行股份有限公司 Method and device for generating bloom filter in blockchain
GB2595489A (en) * 2020-05-28 2021-12-01 Nchain Holdings Ltd Probabilistic membership test for blockchain transaction outputs
CN112950211B (en) * 2021-05-14 2021-07-30 腾讯科技(深圳)有限公司 Transaction duplication checking method, device, equipment and medium
CN116341023B (en) * 2023-05-24 2023-08-29 北京百度网讯科技有限公司 Block chain-based service address verification method, device, equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105187468A (en) * 2014-06-11 2015-12-23 苹果公司 Dynamic Bloom Filter Operation For Service Discovery
CN107247773A (en) * 2017-06-07 2017-10-13 北京邮电大学 A kind of method that inquiry is traded in distributed data base based on block chain
US20170344987A1 (en) * 2016-05-24 2017-11-30 Mastercard International Incorporated Method and system for an efficient consensus mechanism for permssioned blockchains using bloom filters and audit guarantees
CN109977261A (en) * 2019-04-02 2019-07-05 北京奇艺世纪科技有限公司 A kind of processing method of request of data, device and server
CN110704438A (en) * 2019-09-26 2020-01-17 深圳前海微众银行股份有限公司 Method and device for generating bloom filter in block chain

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10198325B2 (en) * 2016-05-24 2019-02-05 Mastercard International Incorporated Method and system for desynchronization recovery for permissioned blockchains using bloom filters
US20190079998A1 (en) * 2017-01-31 2019-03-14 Thomas Jay Rush Blockchain data-processing engine
CN107368527B (en) * 2017-06-09 2020-06-30 东南大学 Multi-attribute index method based on data stream
CN107357843B (en) * 2017-06-23 2020-06-16 东南大学 Massive network data searching method based on data stream structure
CN107273556A (en) * 2017-08-23 2017-10-20 上海点融信息科技有限责任公司 Block chain data index method and equipment
CN110097363A (en) * 2019-04-12 2019-08-06 深圳前海微众银行股份有限公司 It is a kind of based on block chain event publication, event subscription method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105187468A (en) * 2014-06-11 2015-12-23 苹果公司 Dynamic Bloom Filter Operation For Service Discovery
US20170344987A1 (en) * 2016-05-24 2017-11-30 Mastercard International Incorporated Method and system for an efficient consensus mechanism for permssioned blockchains using bloom filters and audit guarantees
CN107247773A (en) * 2017-06-07 2017-10-13 北京邮电大学 A kind of method that inquiry is traded in distributed data base based on block chain
CN109977261A (en) * 2019-04-02 2019-07-05 北京奇艺世纪科技有限公司 A kind of processing method of request of data, device and server
CN110704438A (en) * 2019-09-26 2020-01-17 深圳前海微众银行股份有限公司 Method and device for generating bloom filter in block chain

Also Published As

Publication number Publication date
CN110704438A (en) 2020-01-17
CN110704438B (en) 2023-10-03

Similar Documents

Publication Publication Date Title
WO2021057482A1 (en) Method and device for generating bloom filter in blockchain
US10255108B2 (en) Parallel execution of blockchain transactions
US11023458B2 (en) Systems and methods for blockchain interlinking and relationships
US11263211B2 (en) Data partitioning and ordering
CN108389118B (en) Asset management system, method and device and electronic equipment
TWI677228B (en) Method and apparatus for writing transaction data into a blockchain system
WO2021017436A1 (en) Blockchain state data synchronization method and apparatus, and electronic device
WO2021017435A1 (en) Blockchain state data storage method and apparatus, and electronic device
WO2021017421A1 (en) Blockchain state data recovery method and device, and electronic device
US20210006506A1 (en) Allocating virtual resource based on block chain
WO2020258853A1 (en) Blockchain-based hierarchical storage method and apparatus, and electronic device
WO2020082871A1 (en) Method, device and system for executing blockchain transactions in parallel
CN110032598B (en) Method and device for updating field and electronic equipment
CN111898139B (en) Data reading and writing method and device and electronic equipment
CN111597015B (en) Transaction processing method and device, computer equipment and storage medium
WO2020258856A1 (en) Hierarchical storage method and apparatus based on blockchain, and electronic device
CN111338766A (en) Transaction processing method and device, computer equipment and storage medium
CN111444196B (en) Method, device and equipment for generating Hash of global state in block chain type account book
WO2021047541A1 (en) Method and device for obtaining transaction dependency relationship in blockchain
CN110023925A (en) It generates, access and display follow metadata
CN111444192B (en) Method, device and equipment for generating Hash of global state in block chain type account book
WO2021027612A1 (en) Method and apparatus for executing transaction in blockchain
WO2023160077A1 (en) Blockchain data recovery method and apparatus, and electronic device
WO2024001025A1 (en) Pre-execution cache data cleaning method and blockchain node
CN108121807A (en) The implementation method of multi-dimensional index structures OBF-Index under Hadoop environment

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: 20867875

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

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 1205A DATED 250822)

122 Ep: pct application non-entry in european phase

Ref document number: 20867875

Country of ref document: EP

Kind code of ref document: A1