Text processing method and device based on block chain, electronic equipment and storage medium
By deploying text databases in blockchain nodes and processing hash computing and block consensus mechanisms for pending text, the problem that blockchain technology cannot effectively process text data is solved, and the stable and efficient storage and query of text data is achieved.
Patent Information
- Application Number
- CN202311295866.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-08
- Publication Date
- 2025-04-11
AI Technical Summary
Existing blockchain technology cannot effectively process text data, making it difficult to realize text search and processing in proof-keeping application scenarios.
By deploying a text database in a blockchain node, acquiring the pending text and hashing it, generating a target block, and consensus through multiple blockchain nodes, storing the pending text into the text database, and adding the target block to the blockchain.
It realizes effective storage and query of text data, reduces the storage pressure of a single text database, and improves the stability and reliability of text data processing.
Smart Images

Figure CN119807290A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and specifically to a blockchain-based text processing method, device, electronic device and storage medium. Background Art
[0002] In recent years, blockchain technology has received widespread attention and application. Blockchain is a special database technology that stores and manages data in a decentralized manner. Due to the characteristics of blockchain, it is widely used in cryptocurrency, smart contracts, supply chain management, digital asset trading and other fields, providing new solutions for data security, traceability and trust establishment.
[0003] However, the current blockchain only supports key-value databases (such as leveldb and couchdb) and relational databases (such as MySQL), and does not support text-based databases. Therefore, in some evidence storage application scenarios, it is difficult to process the text involved in the scenario (such as storage, query, etc.). It can be seen that the current blockchain technology cannot effectively process text. Summary of the invention
[0004] The embodiments of the present application provide a blockchain-based text processing method, device, electronic device, and storage medium, which can improve blockchain-based text processing.
[0005] The present application embodiment provides a text processing method based on blockchain, including:
[0006] Get the text to be processed;
[0007] Performing hash calculation on the text to be processed to obtain a hash value;
[0008] Based on the hash value, generate a target block;
[0009] A consensus is reached on the target block through a plurality of blockchain nodes corresponding to the blockchain to obtain a consensus result, wherein each of the plurality of blockchain nodes is provided with a text database;
[0010] When the consensus result is that consensus is reached, the text to be processed is stored in the text database, and the target block is added to the blockchain.
[0011] The embodiment of the present application also provides a text processing device based on blockchain, including:
[0012] A text acquisition unit, used for acquiring the text to be processed;
[0013] A computing unit, used for performing hash calculation on the text to be processed to obtain a hash value;
[0014] A block generation unit, configured to generate a target block based on the hash value;
[0015] A consensus unit, configured to reach a consensus on the target block through a plurality of blockchain nodes corresponding to the blockchain to obtain a consensus result, wherein each of the plurality of blockchain nodes is provided with a text database;
[0016] A processing unit is used to store the to-be-processed text in the text database and add the target block to the blockchain when the consensus result is that the consensus is reached.
[0017] In some embodiments, the processing unit includes:
[0018] A splitting subunit is used to split the text to be processed to obtain a plurality of sub-text data;
[0019] The first storage subunit is used to store the plurality of subtext data in a plurality of text databases respectively.
[0020] In some embodiments, the processing unit further includes:
[0021] a copying subunit, configured to copy each subtext data of the plurality of subtext data to obtain at least one data copy of the subtext data;
[0022] The second storage subunit is used to store the at least one data copy in the multiple text databases respectively.
[0023] In some embodiments, the replication subunit is specifically used for:
[0024] Acquire the data volume of the subtext data and the number of the plurality of text databases;
[0025] Determining the number of times the subtext data is copied according to the data volume of the subtext data, wherein the data volume is negatively correlated with the number of times of copying, and the number of times of copying is less than the number of the plurality of text databases;
[0026] Based on the number of copies, the subtext data is copied to obtain at least one data copy of the subtext data.
[0027] In some embodiments, the second storage subunit is specifically used for:
[0028] Based on the number of replications, at least one target text database is selected from the plurality of text databases, the target text database being a text database that does not include the subtext data in the plurality of text databases;
[0029] The at least one data copy is stored in the at least one target text database respectively.
[0030] The second storage subunit is further configured to: select a text database from the plurality of text databases as a candidate text database;
[0031] Acquire the remaining storage space of the candidate text database;
[0032] When the remaining storage space meets the preset storage condition, the candidate text database is determined as the target text database, and the number of the target text database is recorded;
[0033] A text database other than the target text database is selected from the multiple text databases as a new candidate text database, and based on the new candidate text database, the step of obtaining the remaining storage space of the candidate text database is returned to be executed until the number of the target text databases is equal to the number of replications.
[0034] In some embodiments, the split subunit is specifically used for:
[0035] Acquire the number of the plurality of text databases and the data volume of the text to be processed;
[0036] According to at least one of the number of the plurality of text databases and the data volume of the text to be processed, the text to be processed is split to obtain a plurality of sub-text data.
[0037] In some embodiments, the split subunit is further used to:
[0038] Determining the initial number of splits for the text to be processed according to the data volume of the text to be processed, wherein the number of splits is positively correlated with the data volume of the text to be processed;
[0039] comparing the initial number of splits with the number of the plurality of text databases;
[0040] When the initial split number is less than or equal to the number of the plurality of text databases, determining the initial split number as a target split number;
[0041] Based on the target number of splits, the text to be processed is split to obtain a plurality of sub-text data.
[0042] In some embodiments, the text acquisition unit includes:
[0043] A transaction information acquisition subunit, used to acquire transaction information corresponding to at least one transaction from a transaction pool corresponding to the blockchain;
[0044] A text content recognition subunit, used for performing text content recognition on the transaction information;
[0045] A data volume determination subunit, used for obtaining the data volume of text content when the transaction information contains text content;
[0046] The extraction subunit is used to extract the text content from the transaction information when the data volume of the text content is greater than or equal to a preset data volume, and use the text content as the text to be processed.
[0047] In some embodiments, the blockchain node is further provided with a virtual machine, and the device further comprises:
[0048] A contract search unit, configured to search a preset contract database for a smart contract corresponding to the transaction information through the virtual machine;
[0049] a transaction execution unit, configured to execute the transaction corresponding to the transaction information based on the smart contract when the virtual machine finds the smart contract corresponding to the transaction information, so as to obtain an execution result of the transaction;
[0050] The result determination unit is used to execute, when the execution result is successful, the step of performing text content recognition on the transaction information.
[0051] In some embodiments, the apparatus further comprises:
[0052] A receiving unit, configured to receive a target query request for the text to be processed;
[0053] A verification unit, used to verify the target query request;
[0054] The query unit is used to obtain the to-be-processed text from the text database based on the target query request when the target query request is verified, and output the processed text as a query result.
[0055] In some embodiments, the target query request carries a request timestamp, and the query unit includes:
[0056] A queue acquisition subunit, configured to acquire a query queue in the blockchain node when the target query request is verified, wherein the query queue includes at least one query request arranged in an execution order;
[0057] A queue updating subunit, configured to add the target query request to the last one in the execution order in the query queue when the number of pending query requests in the query queue is less than a preset number threshold, to obtain an updated query queue;
[0058] A request execution subunit, configured to sequentially execute the query requests in the updated query queue based on the execution order;
[0059] A timestamp acquisition subunit, used to acquire a current timestamp when executing the target query request;
[0060] A calculation subunit, configured to calculate a difference between the current timestamp and the request timestamp to obtain a time difference;
[0061] The query subunit is used for acquiring the to-be-processed text from the text database based on the query request when the time difference is less than or equal to a preset difference, and outputting the processed text as a query result.
[0062] In some embodiments, the target query request carries permission information and signature information, the permission information represents the permission level of the object that issues the target query request, and the signature information represents the signature of the object that issues the target query request. The verification unit includes:
[0063] A first verification subunit, used to verify the signature information;
[0064] A second verification subunit is used to verify the authority information when the signature information is verified;
[0065] The verification result determination subunit is used to determine that the target query request has been verified when the authority information has been verified.
[0066] An embodiment of the present application also provides an electronic device, including a memory storing multiple instructions; the processor loads instructions from the memory to execute the steps of any blockchain-based text processing method provided in the embodiment of the present application.
[0067] An embodiment of the present application also provides a computer-readable storage medium, which stores a plurality of instructions, and the instructions are suitable for a processor to load to execute the steps in any one of the blockchain-based text processing methods provided in the embodiments of the present application.
[0068] The embodiments of the present application also provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of any blockchain-based text processing method provided in the embodiments of the present application.
[0069] In the embodiment of the present application, after obtaining the text to be processed, the text to be processed can be hashed to obtain a hash value; then, based on the hash value, a target block is generated; and consensus is reached on the target block through multiple blockchain nodes corresponding to the blockchain to obtain a consensus result, wherein each of the multiple blockchain nodes is provided with a text database; finally, when the consensus result is that the consensus is reached, the text to be processed is stored in the text database, and the target block is added to the blockchain. That is to say, by deploying the text database in the blockchain node in advance, after obtaining the text to be processed, on the one hand, the hash value corresponding to the text to be processed can be added to the blockchain in the form of a block, and on the other hand, the text to be processed can be stored in the text database corresponding to multiple blockchain nodes, which can not only provide a suitable storage environment for the text to be processed and reduce the storage pressure of a single text database, but also can quickly find the text to be processed from the text database through the hash value corresponding to the text to be processed in the blockchain, thereby realizing effective processing of the text to be processed based on the blockchain. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0071] Figure 1a It is a schematic diagram of the structure of the distributed system provided in the embodiment of the present application;
[0072] Figure 1b It is a structural diagram of the block structure provided in an embodiment of the present application;
[0073] Figure 1c It is a flowchart of a text processing method based on blockchain provided in an embodiment of the present application;
[0074] Figure 2a It is a flowchart of a text processing method based on blockchain provided in an embodiment of the present application;
[0075] Figure 2b This is a schematic diagram of the blockchain distributed text database engine system architecture based on Elasticsearch provided in an embodiment of the present application;
[0076] Figure 2c This is a schematic diagram of the blockchain initialization process based on Elasticsearch provided in an embodiment of the present application;
[0077] Figure 2d It is a schematic diagram of a part of the process of recording the hash to the chain and saving the text to be processed to the Elasticsearch database after successfully generating a new block provided by the blockchain of the embodiment of the present application;
[0078] Figure 2e It is another part of the process diagram of the blockchain provided by the embodiment of the present application, in which the hash is recorded on the chain after a new block is successfully generated and the text to be processed is saved in the Elasticsearch database;
[0079] Figure 2f This is another part of the process diagram of the blockchain provided by the embodiment of the present application recording the hash to the chain after successfully generating a new block and saving the text to be processed to the Elasticsearch database;
[0080] Figure 2g This is a flow chart of a user directly accessing Elasticsearch to query large text data stored on a blockchain, as provided in an embodiment of the present application;
[0081] Figure 2h This is a partial flow chart of a user accessing data in Elasticsearch by calling a method in a smart contract provided by an embodiment of the present application;
[0082] Figure 2i This is another part of the flow chart of a user accessing data in Elasticsearch by calling a method in a smart contract provided by an embodiment of the present application;
[0083] Figure 2j This is another part of the flow chart of a user accessing data in Elasticsearch by calling a method in a smart contract provided by an embodiment of the present application;
[0084] Figure 3 It is a structural schematic diagram of a blockchain-based text processing device provided in an embodiment of the present application;
[0085] Figure 4 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0086] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0087] The embodiments of the present application provide a text processing method, device, electronic device and storage medium based on blockchain.
[0088] The blockchain-based text processing device can be integrated into an electronic device, which can be a terminal, a server, or other devices. The terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop, or a personal computer (PC), etc. The server can be a single server or a server cluster composed of multiple servers.
[0089] In some embodiments, the blockchain-based text processing device can also be integrated into multiple electronic devices. For example, the blockchain-based text processing device can be integrated into multiple servers, and the blockchain-based text processing method of the present application can be implemented by multiple servers.
[0090] In some embodiments, the server may also be implemented in the form of a terminal.
[0091] For example, the text processing method based on blockchain of the present application can be applied to a system composed of the above-mentioned electronic devices, wherein the system involved in the embodiment of the present application can be a distributed system formed by connecting a client and multiple nodes (any form of computing devices in the access network, such as a server, a user terminal) through network communication. Specifically, the text processing method based on blockchain can be applied to any one of the multiple nodes.
[0092] Take the distributed system as the blockchain system as an example, see Figure 1a , Figure 1a It is an optional structural diagram of the distributed system 100 provided in the embodiment of the present application applied to the blockchain system, which is formed by multiple nodes 200 (any form of computing devices in the access network, such as servers, user terminals) and clients 300, and a point-to-point network is formed between the nodes 200. The point-to-point network protocol is an application layer protocol running on the Transmission Control Protocol (TCP, Transmission Control Protocol) protocol. In a distributed system, any machine such as a server or a terminal can join and become a node 200, and the node 200 includes a hardware layer, an intermediate layer, an operating system layer, and an application layer. Among them, the above-mentioned nodes can also be called blockchain nodes.
[0093] See also Figure 1a The functions of each node in the blockchain system shown include:
[0094] 1) Routing: a basic function of a node, used to support communication between nodes.
[0095] In addition to the routing function, the node can also have the following functions:
[0096] 2) Applications are deployed in the blockchain to implement specific businesses based on actual business needs, record data related to the implementation of functions to form record data, carry digital signatures in the record data to indicate the source of the task data, and send the record data to other nodes in the blockchain system for other nodes to add the record data to a temporary block when they successfully verify the source and integrity of the record data.
[0097] For example, the services implemented by the application include:
[0098] 2.1) Wallet, used to provide the function of conducting electronic currency transactions, including initiating transactions (i.e., sending the transaction record of the current transaction to other nodes in the blockchain system. After the other nodes successfully verify the transaction, as a response to acknowledge the validity of the transaction, the transaction record data is stored in the temporary block of the blockchain; of course, the wallet also supports querying the remaining electronic currency in the electronic currency address;
[0099] 2.2) Shared ledger, which is used to provide functions such as storage, query and modification of account data. The record data of the operation on the account data is sent to other nodes in the blockchain system. After other nodes verify the validity, as a response to acknowledging the validity of the account data, the record data is stored in a temporary block, and a confirmation can also be sent to the node that initiated the operation.
[0100] 2.3) Smart contracts are computerized protocols that can execute the terms of a contract. They are implemented by deploying code on a shared ledger that is executed when certain conditions are met. The code is used to complete automated transactions based on actual business needs, such as querying the logistics status of the goods purchased by the buyer and transferring the buyer's electronic currency to the merchant's address after the buyer signs for the goods. Of course, smart contracts are not limited to executing contracts for transactions, but can also execute contracts for processing received information.
[0101] 3) Blockchain, including a series of blocks that are connected to each other in the order of their generation. Once a new block is added to the blockchain, it will not be removed. The block records the record data submitted by the nodes in the blockchain system.
[0102] See also Figure 1b , Figure 1bThis is an optional schematic diagram of the block structure provided by an embodiment of the present invention. Each block includes the hash value of the transaction record stored in this block (the hash value of this block) and the hash value of the previous block. Each block is connected by the hash value to form a blockchain. In addition, the block can also include information such as the timestamp when the block was generated. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains relevant information for verifying the validity of its information (anti-counterfeiting) and generating the next block.
[0103] It can be understood that in the specific implementation of this application, related data such as user transaction information, authority information, signature information, etc. are involved. When the following embodiments of this application are applied to specific products or technologies, permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0104] It should be noted that the serial numbers of the following embodiments are not intended to limit the preferred order of the embodiments.
[0105] Embodiment 1
[0106] Artificial Intelligence (AI) is a technology that uses digital computers to simulate human perception of the environment, acquire knowledge, and use knowledge. This technology can enable machines to have functions similar to human perception, reasoning, and decision-making. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, as well as machine learning / deep learning, autonomous driving, smart transportation, and other major directions.
[0107] Elasticsearch: Elasticsearch is an open source distributed search and analysis engine used in full-text search, log storage, data analysis and visualization. It is developed based on the Apache Lucene search engine library and provides a distributed, multi-tenant full-text search engine that can handle PB-level data and provide real-time search and analysis capabilities.
[0108] Elasticsearch distributes data on multiple nodes, each of which can store and process data. It uses a RESTful API-based data storage and retrieval method, which can easily increase or decrease storage nodes to achieve horizontal expansion and high availability of data. At the same time, Elasticsearch provides a flexible document data model, complex query syntax, real-time search and analysis, aggregate statistics, geospatial search and other functions, providing developers with powerful search and analysis capabilities.
[0109] Elasticsearch is mainly used in log search, full-text search, enterprise search, product recommendation, real-time search, data analysis, security detection and other scenarios. It is one of the most popular enterprise-level search engines.
[0110] Hash: Hash, also known as hash, is a method of mapping data of arbitrary length to a fixed-length digital sequence. The hash function converts the input data into a hash value of fixed size that is difficult to reverse. Hash functions are widely used in cryptography, data integrity checking, hash storage, and hash lookup.
[0111] Hash functions have the following characteristics:
[0112] 1. Fixed length: The hash function maps the input data to a hash value of fixed length, usually tens or hundreds of bits.
[0113] 2. Uniqueness: For different input data, the hash function must generate different hash values, so as to avoid hash conflicts as much as possible.
[0114] 3. Irreversibility: Hash function is one-way, that is, it is easy to calculate the hash value, but it is impossible to derive the original data from the hash value.
[0115] 4. Hashability: For slight changes in the input data, the hash value generated by the hash function should be very different, which ensures that the hash function can effectively allocate data locations and reduce hash conflicts.
[0116] Hash functions are often used in scenarios such as file integrity detection, password verification, data encryption, and unique identifier generation. Common hash functions include MD5, SHA-1, and SHA-256. However, with the improvement of computing power and the discovery of security vulnerabilities in hash algorithms, some hash functions are no longer secure, and more secure hash functions are needed to protect data security.
[0117] Transaction: A transaction is the process of transferring value or information using blockchain technology. On the blockchain, transactions are achieved by creating, verifying, and recording blocks of data in a block. A blockchain transaction usually includes the following elements:
[0118] 1. Transaction Participants: The parties involved in a transaction are usually divided into senders and receivers. The sender is the party that initiates the transaction, while the receiver is the party that receives the transaction.
[0119] 2. Asset transfer: The transfer of assets involved in the transaction, which can be digital assets (such as digital securities, etc.).
[0120] 3. Transaction quantity: refers to the number of assets involved in the transaction or the transaction amount.
[0121] 4. Transaction conditions: Transactions may include some additional conditions or rules, such as transaction timestamps, handling fees, smart contract conditions, etc.
[0122] 5. Transaction signature: The transaction must be signed by the sender, and the transaction must be encrypted and signed using its private key to ensure the authenticity and integrity of the transaction.
[0123] 6. Transaction broadcast and verification: Once the transaction is signed by the sender, it will be broadcast to each node in the blockchain network through the network. Each node will independently verify the validity of the transaction, including confirming that the sender's balance is sufficient to pay the transaction fee and checking whether there are any anomalies such as double payment.
[0124] 7. Block Packaging and Consensus: Verified transactions will be packaged into a new block, including other transactions, timestamps, and links to previous blocks. Then, the nodes in the blockchain network reach a consensus on the new block through a consensus algorithm (such as proof of work, proof of stake, etc.), confirm its validity, and add it to the blockchain.
[0125] 8. Transaction records and updates: Once a new block is added to the blockchain, the status of the transaction will also be updated. Each participant will synchronously update their own ledger to reflect the new transaction record.
[0126] Among them, through blockchain transactions, decentralized value transfer can be achieved, ensuring the transparency, security and reliability of transactions. Blockchain transactions have been widely used in cryptocurrency, finance, the Internet of Things, supply chain management and other fields.
[0127] Transaction Pool: The transaction pool (also called Mempool) of a blockchain refers to a collection of transactions that have not been packaged into a block and are waiting to be written into a block. In a blockchain network, each node maintains a transaction pool to store new transactions generated by users. When a user initiates a transaction, the transaction will be broadcast to the entire network. If the transaction complies with the transaction rules and verification rules of the blockchain network, it will be added to the node's transaction pool. Transactions in the transaction pool need to be verified and confirmed before they are packaged into a block.
[0128] Among them, the transaction pool is one of the important components of the blockchain network. While ensuring the smooth processing of transactions, it can also improve the efficiency and performance of the blockchain.
[0129] Contract query: Blockchain contract query is a way to query smart contracts on the blockchain. It allows users to query readable public data in smart contracts or perform some read-only operations without creating new transactions. Smart contracts are a mechanism for implementing automation and programmable logic on the blockchain.
[0130] Among them, the benefit of using contract query is that no changes will be made to the blockchain state, because the query only reads the contract data without executing any transactions. The query results will be returned to the user, and these results can be used to execute specific business logic or as a data source for other applications.
[0131] Contract query is widely used in many blockchain applications, such as querying user account information, smart contract status, etc. It provides an easy way for applications to integrate and interact with external chain data.
[0132] Virtual Machine: A virtual machine (VM) is a software or hardware environment that simulates and runs other operating systems on a physical computer. It divides and isolates computer resources (including processors, memory, storage, and networks, etc.) through virtualization technology, so that each virtual machine can independently run and manage a complete operating system and applications.
[0133] In this embodiment, a text processing method based on blockchain involving blockchain technology is provided, such as Figure 1c As shown, the specific process of the blockchain-based text processing method can be as follows:
[0134] 101. Get the text to be processed.
[0135] Among them, the text to be processed may refer to the text that needs to be stored in the blockchain. For example, the text to be processed may be the text contained in the transaction uploaded to the blockchain node. The text can be used to describe some circumstances of the transaction. When the transaction is recorded on the blockchain, the text contained in the transaction needs to be stored as the text to be processed.
[0136] In some implementations, in step 101, the specific implementation of obtaining the text to be processed may include:
[0137] S1. Obtain transaction information corresponding to at least one transaction from the transaction pool corresponding to the blockchain.
[0138] Among them, transaction information may refer to various data and detailed information related to the transaction. For example, transaction information may include but is not limited to: transaction participant information (such as buyer information and seller information), transaction timestamp (such as the date and time of the transaction, recording the specific time when the transaction starts and ends), transaction amount or quantity (such as the specific number of assets involved or the amount of the transaction), transaction description (such as a brief description of the transaction or additional instructions, including the purpose, conditions, requirements, etc. of the transaction), and transaction status (such as the current status of the transaction, such as pending, confirmed, completed, etc.).
[0139] Among them, each blockchain node in the blockchain system contains a complete blockchain, and each blockchain node maintains a transaction pool. Therefore, in this embodiment, the transaction pool corresponding to the blockchain refers to the transaction pool maintained by the blockchain node corresponding to the blockchain, wherein the blockchain node corresponding to the blockchain refers to the blockchain node that contains the blockchain.
[0140] In some implementations, a batch of transactions may be randomly packaged from the transaction pool, and the transaction information corresponding to each transaction in the batch of transactions may be extracted. The transactions are packaged so that a new block can be generated based on the packaged transactions later.
[0141] In other implementations, the number of transactions included in all transaction pools can be detected in real time. When the number of transactions reaches a transaction number threshold, all transactions included in all transaction pools are packaged, and transaction information corresponding to each transaction in all transactions is retrieved, thereby avoiding storing too many transactions in the transaction pool.
[0142] S2. Perform text content recognition on the transaction information.
[0143] The text content refers to content presented in the form of text. For example, the text content may include but is not limited to: words, letters, numbers, punctuation marks, etc.
[0144] In some implementations, for the transaction information corresponding to each transaction, it may be identified whether there is text content in the transaction information to obtain an identification result.
[0145] S3. When the transaction information includes text content, the data volume of the text content is obtained.
[0146] Among them, the data volume of text content can be measured according to the length and complexity of the text. Among them, the common unit for measuring the data volume of text is byte (Byte) or character count (Character count), so the data volume of text content can be obtained by calculating the bytes or characters of the text content. For example, for plain text, each character usually occupies 1 byte of storage space, so the number of bytes can be equivalent to the number of characters. For example, a sentence containing 100 letters and punctuation marks will have a data volume of 100 bytes. It is understandable that as the text contains more formatting information, styles, links and other elements, the data volume will increase accordingly. If attachments, embedded media or other binary data in the text are considered, the data volume of the text content may be even larger.
[0147] S4. When the data volume of the text content is greater than or equal to the preset data volume, the text content is extracted from the transaction information and used as the text to be processed.
[0148] Exemplarily, the preset data volume may be a preset number of bytes. When the number of bytes of the text content is greater than or equal to the preset number of bytes, it indicates that the write set of the packaged transaction contains a large amount of text storage. At this time, if the packaged transaction is directly stored in the blockchain, a large amount of data will be stored on the blockchain, which will reduce the execution efficiency of the blockchain. Therefore, the text content can be extracted from the transaction information, and the text content can be used as the text to be processed, and an effective storage method can be formulated separately for the text to be processed.
[0149] Among them, the write set of a transaction is a set used to record the modification operations of transactions on data in a blockchain or distributed database system. Each transaction may involve reading or modifying multiple data items during execution. The write set is a set used to record these modification operations, including data items that need to be inserted, updated or deleted and the corresponding operation information. The role of the write set is to provide a basis for verifying and executing transactions. When verifying a transaction, the system will check whether the data items and operations involved in the transaction are consistent with those recorded in the write set to ensure the legitimacy and correctness of the transaction. During the transaction execution phase, the system will update the corresponding data items based on the operation information in the write set.
[0150] In some embodiments, the blockchain node is further provided with a virtual machine. Before step S2, performing text content recognition on the transaction information, the method may further include:
[0151] The virtual machine searches the preset contract database for the smart contract corresponding to the transaction information.
[0152] Among them, the preset contract database pre-stores a plurality of smart contracts, and a mapping relationship between a plurality of smart contracts and a plurality of transactions. Since each transaction has transaction information, the mapping relationship between a transaction and a smart contract can also be regarded as a mapping relationship between transaction information and a smart contract. In this embodiment, a smart contract is used to execute its corresponding transaction.
[0153] When the virtual machine finds the smart contract corresponding to the transaction information, it executes the transaction corresponding to the transaction information based on the smart contract to obtain the execution result of the transaction.
[0154] When the execution result is successful, execute: the step of performing text content recognition on the transaction information.
[0155] In some embodiments, the method may further include: when the virtual machine fails to find a smart contract corresponding to the transaction information, the virtual machine may mark that the smart contract for the transaction corresponding to the transaction information does not exist, and mark the write set for the transaction corresponding to the transaction information as empty.
[0156] The method may further include: when the execution result is execution failure, the virtual machine may also mark the write set of the transaction corresponding to the transaction information as empty.
[0157] Among them, the write set of a transaction is empty, which means that in the blockchain, the write operation of a transaction does not modify any data. In this case, the write set of the transaction does not contain any data items that need to be updated.
[0158] 102. Perform hash calculation on the text to be processed to obtain a hash value.
[0159] In some implementations, a hash calculation may be performed on the text to be processed using a preset hash algorithm to obtain a hash value corresponding to the text to be processed. Optionally, the preset hash algorithm may include, but is not limited to, an MD5 algorithm, a SHA-1 algorithm, a SHA-256 algorithm, and the like.
[0160] 103. Generate a target block based on the hash value.
[0161] In some embodiments, the transaction information and the hash value may be combined to generate a target block. For example, a data structure of the target block may be defined, including a hash value of a previous block of the target block, a hash value of the target block, a timestamp, and transaction information.
[0162] 104. A consensus is reached on the target block through multiple blockchain nodes corresponding to the blockchain to obtain a consensus result, wherein each of the multiple blockchain nodes is provided with a text database.
[0163] Among them, the text database is a database system specifically used to store, retrieve and manage text data. It is widely used in various fields, including search engines, social media analysis, natural language processing, etc. Compared with traditional relational databases, text databases pay more attention to the structuring, analysis and query of text data. Optionally, the text database of this embodiment may include but is not limited to: Elasticsearch, Apache Lucene, MongoDB, etc.
[0164] In some embodiments, each of the multiple blockchain nodes corresponding to the blockchain stores a preset consensus algorithm. After obtaining the target block, the target block can be sent to each of the multiple blockchain nodes, and then the target block is consensused using the preset consensus algorithm to obtain a consensus result. Among them, the preset consensus algorithm includes but is not limited to: Proof of Work (PoW) algorithm, Proof of Stake (PoS) algorithm, Proof of Stake + Weight Proof (DPoS) algorithm, Proof of Authority (PoA) algorithm, weighted voting algorithm, Byzantine fault tolerance algorithm, etc. The specific consensus algorithm to be used can be determined according to actual needs and is not limited here.
[0165] 105. When the consensus result is reached, the text to be processed is stored in the text database, and the target block is added to the blockchain.
[0166] In blockchain, consensus means that each blockchain node in the blockchain network can reach an agreement on the state and transaction history of the blockchain, that is, each node has the same understanding of the data of the blockchain. For example, when consensus is reached, when enough nodes (or according to the agreed rules) vote in favor of the proposed block, consensus is reached. This means that the block is confirmed to be valid and can be added to the end of the blockchain.
[0167] In some implementations, in step 105, the specific implementation of storing the to-be-processed text in the text database may include:
[0168] A1. Split the text to be processed to obtain multiple sub-text data.
[0169] Among them, the sub-text data can be part of the text to be processed. For example, the text to be processed can be composed of a first paragraph of text, a second paragraph of text and a third paragraph of text, wherein each of the first paragraph of text, the second paragraph of text and the third paragraph of text can be used as a sub-text data.
[0170] The data volume of each of the multiple sub-text data obtained by splitting the text to be processed may be the same or different, which is not limited here.
[0171] In some implementations, in step A1, the specific implementation of splitting the text to be processed to obtain multiple sub-text data may include:
[0172] A11. Obtain the number of multiple text databases and the data volume of the text to be processed.
[0173] Among them, since multiple text databases correspond to multiple blockchain nodes one by one, the number of nodes of multiple blockchain nodes can be used as the number of multiple text databases.
[0174] In some implementations, valid nodes among multiple blockchain nodes may be detected in real time, and the number of valid nodes may be used as the number of multiple text databases. The valid nodes may be blockchain nodes that can work normally among the multiple blockchain nodes.
[0175] A12. Split the text to be processed according to at least one of the number of the plurality of text databases and the data volume of the text to be processed to obtain a plurality of sub-text data.
[0176] As an implementation method, the text to be processed can be split according to the number of multiple text databases to obtain multiple sub-text data. For example, if the number of multiple text databases is N, the text to be processed can be split into N sub-text data, where N is a positive integer. Optionally, the data volume of each sub-text data in the N sub-text data can be the same. In this way, the number of sub-text data can match the number of text databases, and each text database can be used during storage, reducing the storage pressure of a single text database.
[0177] As another implementation, the text to be processed can be split according to the data volume of the text to be processed to obtain multiple sub-text data. For example, the data volume of each sub-text data in the multiple text data can be pre-defined to be no more than a specified data volume, and then the quotient of the data volume of the text to be processed and the specified data volume can be used as the number of multiple sub-text data. For example, the data volume of the text to be processed is x, the specified data volume is y, and y is less than x. The quotient (x / y) of the data volume of the text to be processed and the specified data volume can be rounded to N, and then the text to be processed can be split into N sub-text data. This ensures that the data volume of each sub-text data is within an appropriate range.
[0178] The designated data volume may be determined according to the remaining storage space of the text database. For example, the designated data volume does not exceed the remaining storage space of the text database with the smallest remaining storage space among the multiple text databases.
[0179] In some implementations, in step A12, according to at least one of the number of multiple text databases and the data volume of the text to be processed, the specific implementation of splitting the text to be processed to obtain multiple sub-text data may include:
[0180] A121. Determine the initial number of splits for the text to be processed based on the data volume of the text to be processed, wherein the number of splits is positively correlated with the data volume of the text to be processed.
[0181] As an example, a split coefficient k can be pre-set, and the data volume of the text to be processed*k=the initial split number, where k is greater than 0 and less than 1, and the split coefficient k can satisfy the initial split number to be a positive integer. The split coefficient k can be customized according to actual needs and is not limited here.
[0182] As another example, multiple different data volume ranges can be preset, each data volume range corresponds to a reference split number, and when the data volume of the to-be-processed text is within a certain data volume range, the reference split number corresponding to the data volume range can be used as the initial split number. The larger the upper or lower limit of the data volume range, the larger the corresponding reference split number.
[0183] A122. Compare the number of initial splits with the number of multiple text databases.
[0184] For example, if the number of initial splits is N1 and the number of multiple text databases is M1, then the size relationship between N1 and M1 can be compared, where N1 and M1 are positive integers.
[0185] A123. When the initial split number is less than or equal to the number of the multiple text databases, the initial split number is determined as the target split number.
[0186] Continuing with the above example, for example, if N1≤M1, N1 can be determined as the target split number.
[0187] A124. Split the text to be processed based on the target split quantity to obtain multiple sub-text data.
[0188] Using the above example, the text to be processed can be split into N1 pieces to obtain N1 sub-text data, wherein the data volume of each sub-text data in the N1 sub-text data can be the same.
[0189] A2. Store the plurality of sub-text data in a plurality of text databases respectively.
[0190] In some implementations, each sub-text data in the plurality of sub-text data may be stored in a text database.
[0191] In this embodiment, when splitting the text to be processed, if the data volume of the text to be processed is larger, the number of splits is larger, thereby reducing the storage pressure of a single text database. If the data volume of the text to be processed is smaller, the number of splits is smaller, so as to avoid using all databases for storage when there is a small amount of data, increasing unnecessary storage operations, and improving storage efficiency.
[0192] In some implementations, after the step of “storing the plurality of subtext data in a plurality of text databases respectively”, the method may further include:
[0193] B1. For each sub-text data among the plurality of sub-text data, copy the sub-text data to obtain at least one data copy of the sub-text data.
[0194] In some implementations, in step B1, the specific implementation of duplicating the subtext data to obtain at least one data copy of the subtext data may include:
[0195] B11. Obtain the data volume of the sub-text data and the number of multiple text databases.
[0196] B12. Determine the number of times the sub-text data is copied according to the data volume of the sub-text data, wherein the data volume is negatively correlated with the number of copies, and the number of copies is less than the number of the multiple text databases.
[0197] In some embodiments, different data volume ranges of sub-text data can be pre-set to correspond to different reference replication times. When the data volume of the sub-text data is within a certain data volume range, the reference replication times corresponding to the data volume range can be used as the replication times. The larger the upper or lower limit of the data volume range, the smaller the corresponding reference replication times. Exemplarily, for example, different data volume ranges may include (0-a1), (a1-a2), (a2-a3), a1<a2<a3, wherein the data volume range (0-a1) corresponds to the replication times Z1 in advance, the data volume range (a1-a2) corresponds to the replication times Z2 in advance, and the data volume range (a2-a3) corresponds to the replication times Z3 in advance, wherein Z1>Z2>Z3.
[0198] B13. Based on the number of copies, copy the subtext data to obtain at least one data copy of the subtext data.
[0199] Exemplarily, for example, if the number of replications corresponding to the sub-text data 1 is Z2, the sub-text data 1 may be replicated Z2 times, thereby obtaining Z2 data copies of the sub-text data 1.
[0200] In this embodiment, the number of times the sub-text data is copied is determined based on the data volume of the sub-text data, wherein the data volume is negatively correlated with the number of copies, and the number of copies is less than the number of multiple text databases. This can avoid excessive copying of sub-text data with a large data volume, thereby increasing the storage pressure of the text database when subsequently storing data copies in the text database.
[0201] B2. Store at least one data copy in multiple text databases respectively.
[0202] In some implementations, in step B2, a specific implementation of storing at least one data copy in a plurality of text databases may include:
[0203] B21. Based on the number of replications, at least one target text database is selected from the multiple text databases, where the target text database is a text database that does not include subtext data among the multiple text databases.
[0204] Continuing with the above example, for sub-text data 1, the corresponding number of replications is Z2, then Z2 target text databases can be screened out from multiple text databases, wherein the target text database is a text database that does not include sub-text data 1 among the multiple text databases.
[0205] In some implementations, in step B21, based on the number of replications, a specific implementation of selecting at least one target text database from multiple text databases may include:
[0206] B211. Select a text database from multiple text databases as a candidate text database.
[0207] Continuing with the above example, and continuing to explain with the sub-text data 1, any text database that does not include the sub-text data 1 can be selected from multiple text databases as a candidate text database.
[0208] B212. Obtain the remaining storage space of the candidate text database.
[0209] B213. When the remaining storage space meets the preset storage condition, the candidate text database is determined as the target text database, and the number of the target text database is recorded.
[0210] Continuing with the above example, the remaining storage space of the candidate text database can be compared with the data volume of sub-text data 1. If the data volume of sub-text data 1 is less than or equal to the remaining storage space of the candidate text database, it can be determined that the remaining storage space meets the preset storage conditions, and the candidate text database is determined as the target text database, and the number of the target text database is increased by 1 to obtain the number of the new target text database. This ensures that the data copy of sub-text data 1 can be effectively stored in the target text database.
[0211] B214. Select a text database other than the target text database from the multiple text databases as a new candidate text database, and return to execute the step of obtaining the remaining storage space of the candidate text database based on the new candidate text database until the number of target text databases is equal to the number of replications.
[0212] Continuing with the above example, steps B211 to B213 may be re-executed, and the number of target text databases corresponding to sub-text data 1 is equal to the number of replications corresponding to sub-text data 1.
[0213] Similarly, the sub-text data other than the sub-text data 1 among the multiple sub-text data can also determine their corresponding target text databases in the above manner, so it will not be described in detail here.
[0214] B22. Store at least one data copy in at least one target text database.
[0215] In this embodiment, the sub-text data is copied and stored in different target text databases respectively, so that when a blockchain node corresponding to a text database fails, the sub-text data can still be queried normally.
[0216] In some implementations, after step 105, the method may further include:
[0217] C1. Receive a target query request for the text to be processed.
[0218] C2. Verify the target query request.
[0219] In some implementations, the target query request carries permission information and signature information, the permission information represents the permission level of the object that issues the target query request, and the signature information represents the signature of the object that issues the target query request. In step C2, the specific implementation of verifying the target query request may include:
[0220] C21. Verify the signature information.
[0221] Wherein, verifying the signature information refers to verifying the signature information by using the public key to determine whether the information is a correct signature of the original data. In this embodiment, the signature information can be used to verify the authenticity and integrity of the transaction.
[0222] C22. When the signature information is verified, the authority information is verified.
[0223] Verifying permission information refers to confirming whether a user or entity is authorized by checking whether it has the permission to perform an operation or access a resource. Permission verification is one of the common security mechanisms in information systems, which is used to protect system resources from unauthorized access.
[0224] C23. When the authority information verification is passed, it is determined that the target query request verification is passed.
[0225] C3. When the target query request is verified, the text to be processed is obtained from the text database based on the target query request.
[0226] In some implementations, the target query request may also carry a hash value corresponding to the text to be processed or key information corresponding to the text to be processed, and the key information may include at least one of a keyword and a key sentence. When the target query request is verified, the text to be processed may be found in the text database based on the hash value or keyword in the target query request.
[0227] In some implementations, a specific implementation of obtaining the to-be-processed text from a text database based on a target query request may include:
[0228] The data in the text database is queried by directly accessing the text database through an external interface.
[0229] Alternatively, data in the text database can be accessed by calling methods in the corresponding smart contract in the blockchain node.
[0230] In some implementations, the target query request carries a request timestamp. In step C3, when the target query request is verified, a specific implementation of obtaining the to-be-processed text from the text database based on the query request may include:
[0231] C31. When the target query request is verified, a query queue in the blockchain node is obtained, where the query queue includes at least one query request arranged in execution order.
[0232] Exemplarily, the query queue may include: query request 1, query request 2, and query request 3 arranged in execution order.
[0233] C32. When the number of pending query requests in the query queue is less than a preset number threshold, the target query request is added to the last one in the execution order in the query queue to obtain an updated query queue.
[0234] The preset number threshold may be an upper limit on the number of query requests that can be temporarily stored in the query queue.
[0235] Continuing with the above example, if the preset quantity threshold is 4, the target query request can be added to the last one in the execution order in the query queue to obtain an updated query queue (such as query request 1, query request 2, query request 3, target query request).
[0236] When the number of query requests to be processed in the query queue is greater than or equal to a preset number threshold, first error information representing query congestion may be returned to the object that issued the target query request.
[0237] C33. Based on the execution order, the query requests in the updated query queue are executed in sequence.
[0238] C34. When the target query request is executed, the current timestamp is obtained.
[0239] C35. Calculate the difference between the current timestamp and the requested timestamp to obtain the time difference.
[0240] C36. When the time difference is less than or equal to a preset difference, the text to be processed is obtained from the text database based on the query request.
[0241] When the time difference is greater than a preset difference, second error information indicating a query timeout may be returned to the object that issued the target query request.
[0242] As can be seen from the above, the current blockchain only supports key-value databases (such as leveldb and couchdb) and relational databases (such as MySQL), and does not support text-based databases, so it is difficult to implement text search problems in evidence storage application scenarios. For example, a user hopes to search for articles containing the word "blockchain" in all blogs on the chain through the external interface of the blockchain node or the contract SDK. If there is no text database, this becomes almost impossible. After obtaining the text to be processed, the embodiment of the present application can perform a hash calculation on the text to be processed to obtain a hash value; then, based on the hash value, generate a target block; and reach a consensus on the target block through multiple blockchain nodes corresponding to the blockchain to obtain a consensus result, wherein each of the multiple blockchain nodes is provided with a text database; finally, when the consensus result is a consensus, the text to be processed is stored in the text database, and the target block is added to the blockchain. That is to say, by deploying the text database in the blockchain node in advance, after obtaining the text to be processed, on the one hand, the hash value corresponding to the text to be processed can be added to the blockchain in the form of a block, and on the other hand, the text to be processed can be stored in the text database corresponding to multiple blockchain nodes. This not only provides a suitable storage environment for the text to be processed and reduces the storage pressure of a single text database, but also allows the text to be quickly found from the text database through the hash value corresponding to the text to be processed in the blockchain, thereby achieving effective processing of the text to be processed based on the blockchain. In addition, each piece of data can be stored in multiple nodes to avoid data inaccessibility caused by the downtime of a certain node, and improve the stability of text data processing.
[0243] Embodiment 2
[0244] The method described in the above embodiment will be further described in detail below.
[0245] In this embodiment, the method of the embodiment of the present application is described in detail by taking the application of the blockchain-based text processing method to an electronic device as an example, wherein the electronic device can be a node among multiple blockchain nodes (such as a master node) or a client that is communicatively connected to multiple blockchain nodes.
[0246] like Figure 2a As shown, the specific process of a text processing method based on blockchain is as follows:
[0247] 201. The electronic device obtains the text to be processed.
[0248] Before step 201, the method may further include deploying a text database in each blockchain node. The following description will be made by taking the Elasticsearch database as an example of the text database.
[0249] For example, for each blockchain node, the following can be deployed in the blockchain node: Figure 2b The following figure shows the system architecture of the blockchain distributed text database engine based on Elasticsearch.
[0250] The system architecture may include a network module, an authentication module, a query service module, a transaction pool module, a block scheduling module, a virtual machine module, a consensus module and a storage module.
[0251] Among them, the network module is a module for blockchain nodes to interact with the external network. This module can have the following functions:
[0252] a) Transactions are uploaded to the blockchain. Users send transactions and hope that the transactions will be executed by the contract, packaged into new blocks, and stored in the blockchain ledger and database.
[0253] b) Data query: Users send query statements, hoping to directly query the data in Elasticsearch.
[0254] c) Contract query: The user sends a call to a read-only contract method, hoping to query and process the data in Elasticsearch through the contract and then return it.
[0255] The authentication module refers to the module that the blockchain uses to verify the permissions of requests. This module can have the following functions:
[0256] a) Signature verification: The module in which the blockchain verifies the requested signature.
[0257] b) Authority verification: the platform determines the authority of the requester's identity, that is, whether he has the authority to perform the requested operation.
[0258] The query service module refers to a module that responds to requests from the network module and performs query services.
[0259] The transaction pool module refers to a module that caches transactions and executes them. This module can have the following functions:
[0260] a) Transaction packaging refers to packaging all transactions of the next block into the block scheduling module for execution;
[0261] Among them, the block scheduling module refers to the module that schedules transactions in the block and generates new blocks. This module can have the following functions:
[0262] a) Transaction distribution and scheduling: scheduling and distributing the transactions to be executed in the current block to the virtual machine module for execution;
[0263] b) Block generation, a module that generates a new block after executing all transactions in the current block;
[0264] The virtual machine module refers to the transaction execution module, which can have the following functions:
[0265] a) Contract repository, which stores the code repository of all smart contracts.
[0266] b) Contract process, the runtime state of the contract startup, where the contract process can include the following two parts:
[0267] i.Elasticsearch SDK, the contract accesses Elasticsearch interfaces, such as query and storage.
[0268] ii.Elasticsearch client, the client that actually accesses the storage module Elasticsearch.
[0269] Among them, the consensus module refers to the module for blockchain nodes to perform consensus voting.
[0270] The storage module refers to the module in which the blockchain node stores blockchain data. The storage module may include the following parts:
[0271] a) Elasticsearch distributed text database, a database used to store large blockchain texts.
[0272] b) Status database, a database for storing the latest variable status (excluding large text).
[0273] c) Blockchain ledger, a text file used to store blocks.
[0274] See also Figure 2c After the system architecture is determined, the blockchain initialization process based on Elasticsearch can be performed. In this embodiment, the blockchain can be a consortium chain, such as Figure 2c As shown, the process may include the following steps:
[0275] 1. Start.
[0276] 2. Determine the roles and number of alliance chain nodes and the communication methods and protocols between nodes.
[0277] Among them, in the alliance chain, the role of the node can be determined according to its functions and responsibilities. The following are some common alliance chain node roles: Validation node: The validation node is responsible for verifying and confirming new transactions and adding them to the blockchain. Validation nodes usually need to execute consensus algorithms to ensure the consistency and security of the blockchain. Consensus node: Consensus nodes are special nodes responsible for executing consensus algorithms and play a key role in the alliance chain. They coordinate the nodes in the network to reach consensus, decide which transactions will be included in the block, and ensure data consistency between all nodes. Gateway node: Gateway nodes are used to connect the alliance chain and the external network, allowing data to enter and exit. They process requests from the external network and forward them to the appropriate node for processing. At the same time, the gateway node is also responsible for exposing the data of the alliance chain to the external network. Smart contract node: Smart contract nodes execute and manage smart contracts on the alliance chain. They process transactions related to smart contracts and share updates on the contract status with other nodes. Boot node: Boot nodes play an important role in the startup process of the alliance chain. They are responsible for initializing and configuring newly joined nodes and helping nodes join the existing alliance chain network.
[0278] 3. Configure the Elasticsearch node on each blockchain node, including the name of the cluster, the node discovery method, the consensus algorithm and other information.
[0279] 4. Configure Elasticsearch index for storing and querying blockchain data.
[0280] 5. Configure Elasticsearch performance optimization, including index sharding and replication, caching, query optimization, etc.
[0281] 6. Configure Elasticsearch detection and alerts to detect the status and performance of the cluster and to identify and resolve problems in a timely manner.
[0282] 7. Start the Elasticsearch node and specify the node role and configuration file.
[0283] 8. Verify the cluster. You can use the Elasticsearch API or command line tools to verify the status and health of the cluster.
[0284] 9. Is Elasticsearch working properly? If yes, go to 11; otherwise, go to 10.
[0285] 10. Returns an error indicating that the Elasticsearch deployment failed. Go to 14.
[0286] 11. Set the configuration of the alliance chain node, including the IP, port, certificate and block configuration of the node access.
[0287] 12. Set the Elasticsearch related configuration of the alliance chain node, including access IP, port, etc.
[0288] 13. Start all nodes of the alliance chain.
[0289] 14. The end.
[0290] The specific implementation of step 201 may include:
[0291] Obtain transaction information corresponding to at least one transaction from the transaction pool corresponding to the blockchain;
[0292] Perform text content recognition on transaction information;
[0293] When the transaction information contains text content, obtain the data volume of the text content;
[0294] When the data volume of the text content is greater than or equal to the preset data volume, the text content is extracted from the transaction information and used as the text to be processed.
[0295] Among them, the blockchain node is also equipped with a virtual machine, and before the text content recognition of the transaction information is performed, it also includes:
[0296] Search the preset contract database for the smart contract corresponding to the transaction information through the virtual machine;
[0297] When the virtual machine finds the smart contract corresponding to the transaction information, it executes the transaction corresponding to the transaction information based on the smart contract to obtain the execution result of the transaction;
[0298] When the execution result is successful, execute: the step of performing text content recognition on the transaction information.
[0299] 202. The electronic device performs hash calculation on the text to be processed to obtain a hash value.
[0300] 203. The electronic device generates a target block based on the hash value.
[0301] 204. The electronic device reaches a consensus on the target block through multiple blockchain nodes corresponding to the blockchain to obtain a consensus result, wherein a text database is set in each of the multiple blockchain nodes.
[0302] 205. When the consensus result is that the consensus is reached, the electronic device stores the text to be processed in the text database and adds the target block to the blockchain.
[0303] The specific implementation of step 205 may include:
[0304] The electronic device splits the text to be processed to obtain a plurality of sub-text data;
[0305] The electronic device stores the plurality of subtext data in a plurality of text databases respectively.
[0306] The specific implementation of splitting the text to be processed to obtain multiple sub-text data may include:
[0307] Get the number of multiple text databases and the data volume of the text to be processed.
[0308] The text to be processed is split according to at least one of the number of the plurality of text databases and the data volume of the text to be processed to obtain a plurality of sub-text data.
[0309] The specific implementation of splitting the text to be processed to obtain multiple sub-text data according to at least one of the number of multiple text databases and the data volume of the text to be processed may include:
[0310] According to the data volume of the text to be processed, the initial number of splits for the text to be processed is determined, wherein the number of splits is positively correlated with the data volume of the text to be processed.
[0311] Compare the number of initial splits to the number of multiple text databases.
[0312] When the initial split number is less than or equal to the number of the plurality of text databases, the initial split number is determined as the target split number.
[0313] Based on the target split quantity, the text to be processed is split to obtain multiple sub-text data.
[0314] After storing the plurality of sub-text data in the plurality of text databases respectively, the following steps may also be included:
[0315] For each subtext data among the plurality of subtext data, the subtext data is copied to obtain at least one data copy of the subtext data.
[0316] At least one data copy is stored in a plurality of text databases respectively.
[0317] The step of copying the subtext data to obtain at least one data copy of the subtext data may include:
[0318] Acquire the data volume of the sub-text data and the number of multiple text databases; determine the number of times the sub-text data is copied according to the data volume of the sub-text data, wherein the data volume is negatively correlated with the number of copies, and the number of copies is less than the number of multiple text databases; and copy the sub-text data based on the number of copies to obtain at least one data copy of the sub-text data.
[0319] The step of storing at least one data copy in a plurality of text databases may include:
[0320] Based on the number of replications, at least one target text database is selected from the multiple text databases, where the target text database is a text database that does not include subtext data among the multiple text databases; and at least one data replica is stored in the at least one target text database.
[0321] Among them, based on the number of replications, the step of selecting at least one target text database from the multiple text databases may include: selecting a text database from the multiple text databases as a candidate text database; obtaining the remaining storage space of the candidate text database; when the remaining storage space meets a preset storage condition, determining the candidate text database as a target text database, and recording the number of target text databases; selecting a text database other than the target text database from the multiple text databases as a new candidate text database, and returning to execute the step of obtaining the remaining storage space of the candidate text database based on the new candidate text database, until the number of target text databases is equal to the number of replications.
[0322] In practical applications, as an example, the specific implementation process of step 201 to step 205 can be as follows: Figure 2d , Figure 2e , Figure 2f As shown, Figure 2d , Figure 2e , Figure 2f The flowchart shows the process of recording the hash on the blockchain and saving the text to be processed to the Elasticsearch database after successfully generating a new block. The process may include the following steps 1 to 32:
[0323] 1. Start.
[0324] 2. The user sends the transaction to the blockchain node.
[0325] 3. The blockchain node network module identifies the type as transaction on-chain.
[0326] 4. Did the signature verification pass? If yes, go to step 6; otherwise, go to step 5.
[0327] 5. Returns error indicating signature verification failed. Go to 32.
[0328] 6. Did the permission verification pass? If yes, go to 8; otherwise, go to 7.
[0329] 7. Returns an error indicating that the user does not have permission to perform this operation. Go to 32.
[0330] 8. The blockchain node puts the transaction into the transaction pool.
[0331] 9. The blockchain master node block scheduling module starts to generate new blocks.
[0332] 10. The block scheduling module packages a batch of transactions from the transaction pool as all transactions in the new block ready for execution.
[0333] 11. The block scheduling module distributes and schedules transactions to the virtual machine module for execution according to a certain scheduling algorithm.
[0334] 12. Does the virtual machine module search the contract warehouse to see if there is a contract corresponding to the transaction? If yes, go to 14, otherwise go to 13.
[0335] 13. The virtual machine module marks that the contract for this transaction does not exist. Go to 18.
[0336] 14. The virtual machine module starts the contract process to execute the current transaction.
[0337] 15. Is the execution result correct? If yes, go to 18; otherwise, go to 16.
[0338] 16. The virtual machine module marks the transaction as failed. Go to 18.
[0339] 17. Does the write set of this transaction contain a large text storage? If yes, go to 19; otherwise, go to 21.
[0340] 18. The block scheduling module marks the write set of this transaction as empty. Go to 21.
[0341] 19. The block scheduling module calculates the hash value of the text and uses the hash value to replace the large text to be written into the block.
[0342] 20. The block scheduling module establishes a mapping between hash values and large texts and puts them into the cache.
[0343] 21. The block scheduling module packages the transaction into a block.
[0344] 22. The block scheduling module calculates the metadata of the block, such as hash value, timestamp, etc.
[0345] 23. The consensus module sends the above blocks to all slave nodes for verification.
[0346] 24. Do all nodes reach a consensus? If yes, go to 26, otherwise go to 25.
[0347] 25. Discard the block and return a consensus failure error. Go to 32.
[0348] 26. The master node traverses all the big text hashes in the block.
[0349] 27. The master node finds the large text corresponding to the hash from the cache and stores it in the Elasticsearch node.
[0350] 28. Wait for multiple Elasticsearch nodes to successfully synchronize large text copies.
[0351] 29. The master node deletes the corresponding cache.
[0352] 30. All nodes save the latest data to the state database.
[0353] 31. All nodes append the new block to the blockchain ledger.
[0354] 32. The end.
[0355] 206. The electronic device receives a target query request for the text to be processed.
[0356] 207. The electronic device verifies the target query request.
[0357] 208. When the target query request is verified to be successful, the electronic device obtains the text to be processed from the text database based on the target query request, and outputs the processed text as a query result.
[0358] The target query request carries a request timestamp. When the target query request is verified, the specific implementation method of obtaining the to-be-processed text from the text database based on the query request and outputting the processed text as the query result may include:
[0359] When the target query request is verified, a query queue in the blockchain node is obtained, and the query queue includes at least one query request arranged in execution order; when the number of pending query requests in the query queue is less than a preset number threshold, the target query request is added to the last one in the execution order in the query queue to obtain an updated query queue; based on the execution order, the query requests in the updated query queue are executed in sequence; when the target query request is executed, the current timestamp is obtained; the difference between the current timestamp and the request timestamp is calculated to obtain the time difference; when the time difference is less than or equal to the preset difference, the text to be processed is obtained from the text database based on the query request, and the processed text is output as a query result.
[0360] The target query request carries permission information and signature information, the permission information represents the permission level of the object that issues the target query request, and the signature information represents the signature of the object that issues the target query request. The specific implementation method for verifying the target query request may include:
[0361] The signature information is verified; when the signature information is verified successfully, the permission information is verified; when the permission information is verified successfully, it is determined that the target query request is verified successfully.
[0362] In practical applications, as an example, the specific implementation process of step 206 to step 208 can be as follows: Figure 2g As shown, Figure 2g The process of a user directly accessing Elasticsearch to query large text data stored on the blockchain is shown. The process may include the following steps 1 to 17:
[0363] 1. Get Started
[0364] 2. The user sends the keyword request to the blockchain node
[0365] 3. The blockchain node network module identifies the type as data query
[0366] 4. Did the signature verification pass? If yes, go to step 6, otherwise go to step 5
[0367] 5. Returns an error indicating signature verification failed. Go to step 17
[0368] 6. Did the permission verification pass? If yes, go to step 8, otherwise go to step 7
[0369] 7. Returns an error indicating that the user does not have permission to perform this operation. Go to 17
[0370] 8. Is the queue in the query service module full? If yes, go to 9, otherwise go to 10
[0371] 9. Returns query congestion error. Go to 17
[0372] 10. Put the above requests into a queue and execute them one by one. There may be multiple queues for load balancing.
[0373] 11. The query service module takes out the requests one by one
[0374] 12. Does the current timestamp minus the timestamp of the above request exceed the threshold? If yes, go to step 13, otherwise go to step 14
[0375] 13. Returns a query timeout error. Go to 17
[0376] 14. Access the Elasticsearch distributed text database of the storage module
[0377] 15. The storage module returns the results to the query service module
[0378] 16. The query service module returns the query results to the user.
[0379] Among them, in step 16, the query service module returns the query result to the user. The specific implementation of the query service module may include: the query result may be first returned to the network module, and then the network module returns the query result to the user.
[0380] 17. End
[0381] In practical applications, as another example, the specific implementation process of step 206 to step 208 can be as follows: Figure 2h , Figure 2i , Figure 2j As shown, Figure 2h , Figure 2i , Figure 2j The figure shows the process of a user accessing data in Elasticsearch by calling a method in a smart contract. The process may include the following steps 1 to 26:
[0382] 1. Start.
[0383] 2. The user sends the keyword request to be queried to the blockchain node.
[0384] 3. The blockchain node network module recognizes the type as contract query.
[0385] 4. Did the signature verification pass? If yes, go to step 6; otherwise, go to step 5.
[0386] 5. Returns an error indicating signature verification failed. Go to 25.
[0387] 6. Did the permission verification pass? If yes, go to 8; otherwise, go to 7.
[0388] 7. Returns an error indicating that the user does not have permission to perform this operation. Go to 25.
[0389] 8. Is the queue in the query service module full? If yes, go to 9; otherwise, go to 10.
[0390] 9. Returns query congestion error. Go to 24.
[0391] 10. Put the above requests into a queue and execute them one by one. There may be multiple queues for load balancing.
[0392] 11. The query service module takes out the requests one by one.
[0393] 12. Does the current timestamp minus the timestamp of the request exceed the threshold? If yes, go to 13; otherwise, go to 14.
[0394] 13. A query timeout error is returned. Go to 24.
[0395] 14. The virtual machine module starts the corresponding contract process according to the contract information in the request.
[0396] 15. The contract process calls a query method with complex logic to query statements that are not written into the blockchain.
[0397] 16. The contract process executes the contract statements in sequence.
[0398] 17. Is the current statement a return statement? If yes, go to 23; otherwise, go to 18.
[0399] 18. Is the current statement a call to the Elasticsearch SDK? If yes, go to 19; otherwise, go to 22.
[0400] 19. The contract process starts the Elasticsearch client.
[0401] 20. The client accesses the Elasticsearch distributed text database of the storage module.
[0402] 21. The storage module returns the result to the contract process client. Go to 16.
[0403] 22. The contract process executes the current normal statement. Go to 16.
[0404] 23. The contract process returns the results to the query service module.
[0405] 24. The query service module returns the result to the network module.
[0406] 25. The network module returns the result to the user.
[0407] 26. The end.
[0408] It can be seen that the blockchain-based text processing method provided in this embodiment establishes a blockchain distributed text database architecture based on Elasticsearch, which constitutes the overall framework of the blockchain text database, supports storage when blocks are generated, and supports direct data query and query through contracts. At the same time, the Elasticsearch database in this embodiment is distributed and deployed in multiple nodes. Each node does not need to store all the data, which reduces the storage pressure. At the same time, each piece of data will be stored in multiple nodes to avoid data inaccessibility caused by a node crash. In addition, it can ensure that the smart contracts and external users of the blockchain can query text data through Elasticsearch, while ensuring the authenticity and reliability of the data through the blockchain. The Elasticsearch database is naturally built with the help of the multi-nodes of the blockchain to ensure the reliability and stability of the data. It can be widely reused in industrial applications.
[0409] Embodiment 3
[0410] In order to better implement the above method, the embodiment of the present application also provides a text processing device based on blockchain, which can be integrated in an electronic device, which can be a terminal, a server and other devices. Among them, the terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop, a personal computer and other devices; the server can be a single server or a server cluster composed of multiple servers.
[0411] For example, in this embodiment, the method of the embodiment of the present application will be described in detail by taking the blockchain-based text processing device specifically integrated into the blockchain-based text processing as an example.
[0412] For example, Figure 3 As shown, the text processing device based on blockchain may include a text acquisition unit 301, a calculation unit 302, a block generation unit 303, a consensus unit 304 and a processing unit 305, wherein:
[0413] A text acquisition unit 301 is used to acquire the text to be processed;
[0414] A calculation unit 302 is used to perform hash calculation on the text to be processed to obtain a hash value;
[0415] A block generation unit 303, used to generate a target block based on the hash value;
[0416] A consensus unit 304 is used to reach a consensus on the target block through multiple blockchain nodes corresponding to the blockchain to obtain a consensus result, wherein each of the multiple blockchain nodes is provided with a text database;
[0417] The processing unit 305 is used to store the text to be processed in the text database and add the target block to the blockchain when the consensus result is that the consensus is reached.
[0418] In some embodiments, the processing unit 305 includes:
[0419] A split sub-unit is used to split the text to be processed to obtain multiple sub-text data;
[0420] The first storage subunit is used to store the plurality of subtext data in the plurality of text databases respectively.
[0421] In some embodiments, the processing unit 305 further includes:
[0422] a copy subunit, for copying the subtext data for each of the plurality of subtext data, to obtain at least one data copy of the subtext data;
[0423] The second storage subunit is used to store at least one data copy in a plurality of text databases respectively.
[0424] In some embodiments, the replication subunit is specifically used for:
[0425] Acquire the data volume of the sub-text data and the number of multiple text databases;
[0426] Determining the number of times the subtext data is copied according to the data volume of the subtext data, wherein the data volume is negatively correlated with the number of copies, and the number of copies is less than the number of the plurality of text databases;
[0427] Based on the number of replications, the subtext data is replicated to obtain at least one data copy of the subtext data.
[0428] In some embodiments, the second storage subunit is specifically used for:
[0429] Based on the number of replications, at least one target text database is selected from the plurality of text databases, where the target text database is a text database that does not include the subtext data in the plurality of text databases;
[0430] The at least one data copy is stored in at least one target text database respectively.
[0431] The second storage subunit is further specifically used to: select a text database from the multiple text databases as a candidate text database;
[0432] Obtaining the remaining storage space of the candidate text database;
[0433] When the remaining storage space meets the preset storage condition, the candidate text database is determined as the target text database, and the number of the target text database is recorded;
[0434] A text database other than the target text database is selected from the multiple text databases as a new candidate text database, and the step of obtaining the remaining storage space of the candidate text database is returned to be executed based on the new candidate text database until the number of target text databases is equal to the number of replications.
[0435] In some embodiments, the split subunit is specifically used for:
[0436] Obtain the number of multiple text databases and the data volume of text to be processed;
[0437] The text to be processed is split according to at least one of the number of the plurality of text databases and the data volume of the text to be processed to obtain a plurality of sub-text data.
[0438] In some embodiments, the split subunit is further used to:
[0439] According to the data volume of the text to be processed, determining the initial number of splits for the text to be processed, wherein the number of splits is positively correlated with the data volume of the text to be processed;
[0440] Compare the number of initial splits to the number of multiple text databases;
[0441] When the initial split number is less than or equal to the number of the multiple text databases, determining the initial split number as the target split number;
[0442] Based on the target split quantity, the text to be processed is split to obtain multiple sub-text data.
[0443] In some embodiments, the text acquisition unit 301 includes:
[0444] A transaction information acquisition subunit, used to acquire transaction information corresponding to at least one transaction from a transaction pool corresponding to the blockchain;
[0445] A text content recognition subunit, used for performing text content recognition on transaction information;
[0446] A data volume determination subunit, used for obtaining the data volume of the text content when the transaction information contains text content;
[0447] The extraction subunit is used to extract the text content from the transaction information when the data volume of the text content is greater than or equal to the preset data volume, and use the text content as the text to be processed.
[0448] In some embodiments, the blockchain node is further provided with a virtual machine, and the device further comprises:
[0449] A contract search unit, used to search a preset contract database for a smart contract corresponding to the transaction information through a virtual machine;
[0450] A transaction execution unit, configured to execute the transaction corresponding to the transaction information based on the smart contract when the virtual machine finds the smart contract corresponding to the transaction information, so as to obtain the execution result of the transaction;
[0451] The result determination unit is used to execute, when the execution result is successful, the step of performing text content recognition on the transaction information.
[0452] In some embodiments, the apparatus further comprises:
[0453] A receiving unit, used for receiving a target query request for the text to be processed;
[0454] A verification unit, used for verifying the target query request;
[0455] The query unit is used to obtain the text to be processed from the text database based on the target query request when the target query request is verified, and output the processed text as the query result.
[0456] In some embodiments, the target query request carries a request timestamp, and the query unit includes:
[0457] A queue acquisition subunit, configured to acquire a query queue in a blockchain node when a target query request is verified, wherein the query queue includes at least one query request arranged in an execution order;
[0458] A queue updating subunit, configured to add the target query request to the last one in the execution order in the query queue when the number of pending query requests in the query queue is less than a preset number threshold, to obtain an updated query queue;
[0459] A request execution subunit, used for sequentially executing the query requests in the updated query queue based on the execution order;
[0460] The timestamp acquisition subunit is used to obtain the current timestamp when executing the target query request;
[0461] The calculation subunit is used to calculate the difference between the current timestamp and the request timestamp to obtain the time difference;
[0462] The query subunit is used to obtain the text to be processed from the text database based on the query request when the time difference is less than or equal to the preset difference, and output the processed text as the query result.
[0463] In some embodiments, the target query request carries permission information and signature information, the permission information represents the permission level of the object that issues the target query request, and the signature information represents the signature of the object that issues the target query request. The verification unit includes:
[0464] A first verification subunit, used to verify the signature information;
[0465] The second verification subunit is used to verify the authority information when the signature information verification passes;
[0466] The verification result determination subunit is used to determine whether the target query request has been verified successfully when the authority information has been verified successfully.
[0467] In specific implementation, the above units can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units can refer to the previous method embodiments, which will not be repeated here.
[0468] From the above, it can be seen that the blockchain-based text processing device of this embodiment consists of.
[0469] Therefore, the embodiments of the present application can improve blockchain-based text processing.
[0470] Embodiment 4
[0471] The embodiment of the present application also provides an electronic device, which can be a terminal, a server, etc. The terminal can be a mobile phone, a tablet computer, a smart Bluetooth device, a laptop, a personal computer, etc. The server can be a single server or a server cluster composed of multiple servers, etc.
[0472] In some embodiments, the blockchain-based text processing device can also be integrated into multiple electronic devices. For example, the blockchain-based text processing device can be integrated into multiple servers, and the blockchain-based text processing method of the present application can be implemented by multiple servers.
[0473] In this embodiment, the electronic device of this embodiment is an electronic device as an example for detailed description, for example, Figure 4 As shown, it shows a schematic diagram of the structure of the electronic device involved in the embodiment of the present application, specifically:
[0474] The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, an input module 404, and a communication module 405. Those skilled in the art will appreciate that Figure 4 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0475] The processor 401 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 402 and calling data stored in the memory 402, it performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. In some embodiments, the processor 401 may include one or more processing cores; in some embodiments, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401.
[0476] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0477] The electronic device also includes a power supply 403 for supplying power to various components. In some embodiments, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 403 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0478] The electronic device may further include an input module 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0479] The electronic device may further include a communication module 405. In some embodiments, the communication module 405 may include a wireless module. The electronic device may perform short-range wireless transmission through the wireless module of the communication module 405, thereby providing the user with wireless broadband Internet access. For example, the communication module 405 may be used to help the user send and receive emails, browse web pages, and access streaming media.
[0480] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 401 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402 to implement various functions.
[0481] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0482] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0483] To this end, an embodiment of the present application provides a computer-readable storage medium, in which multiple instructions are stored, and the instructions can be loaded by a processor to execute the steps of any blockchain-based text processing method provided in the embodiment of the present application.
[0484] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0485] According to one aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method provided in the above embodiment.
[0486] Since the instructions stored in the storage medium can execute the steps in any blockchain-based text processing method provided in the embodiments of the present application, the beneficial effects that can be achieved by any blockchain-based text processing method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0487] The above is a detailed introduction to a blockchain-based text processing method, device, electronic device and computer-readable storage medium provided in the embodiments of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the ideas of the present application, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A text processing method based on blockchain, characterized in that: The method comprises: Get the text to be processed; Performing hash calculation on the text to be processed to obtain a hash value; Based on the hash value, generate a target block; A consensus is reached on the target block through a plurality of blockchain nodes corresponding to the blockchain to obtain a consensus result, wherein each of the plurality of blockchain nodes is provided with a text database; When the consensus result is that consensus is reached, the text to be processed is stored in the text database, and the target block is added to the blockchain.
2. The text processing method based on blockchain according to claim 1 is characterized in that: The step of storing the to-be-processed text in the text database comprises: Splitting the text to be processed to obtain multiple sub-text data; The plurality of subtext data are stored in a plurality of text databases respectively.
3. The text processing method based on blockchain according to claim 2 is characterized in that: After storing the plurality of subtext data in a plurality of text databases respectively, the method further comprises: For each subtext data among the plurality of subtext data, copy the subtext data to obtain at least one data copy of the subtext data; The at least one data copy is stored in the plurality of text databases respectively.
4. The text processing method based on blockchain according to claim 3 is characterized in that: The step of copying the subtext data to obtain at least one data copy of the subtext data includes: Acquire the data volume of the subtext data and the number of the plurality of text databases; Determining the number of times the subtext data is copied according to the data volume of the subtext data, wherein the data volume is negatively correlated with the number of times of copying, and the number of times of copying is less than the number of the plurality of text databases; Based on the number of copies, the subtext data is copied to obtain at least one data copy of the subtext data.
5. The text processing method based on blockchain according to claim 4 is characterized in that: The storing the at least one data copy in the plurality of text databases respectively includes: Based on the number of replications, at least one target text database is selected from the plurality of text databases, the target text database being a text database that does not include the subtext data in the plurality of text databases; The at least one data copy is stored in the at least one target text database respectively.
6. The text processing method based on blockchain according to claim 5 is characterized in that: The step of selecting at least one target text database from the plurality of text databases based on the number of replications comprises: Selecting a text database from the multiple text databases as a candidate text database; Acquire the remaining storage space of the candidate text database; When the remaining storage space meets the preset storage condition, the candidate text database is determined as the target text database, and the number of the target text database is recorded; A text database other than the target text database is selected from the multiple text databases as a new candidate text database, and based on the new candidate text database, the step of obtaining the remaining storage space of the candidate text database is returned to be executed until the number of the target text databases is equal to the number of replications.
7. The text processing method based on blockchain according to claim 2 is characterized in that: The text to be processed is split to obtain a plurality of sub-text data, including: Acquire the number of the plurality of text databases and the data volume of the text to be processed; According to at least one of the number of the plurality of text databases and the data volume of the text to be processed, the text to be processed is split to obtain a plurality of sub-text data.
8. The text processing method based on blockchain according to claim 7 is characterized in that: The step of splitting the text to be processed according to at least one of the number of the plurality of text databases and the data volume of the text to be processed to obtain a plurality of sub-text data includes: Determining the initial number of splits for the text to be processed according to the data volume of the text to be processed, wherein the number of splits is positively correlated with the data volume of the text to be processed; comparing the initial number of splits with the number of the plurality of text databases; When the initial split number is less than or equal to the number of the plurality of text databases, determining the initial split number as a target split number; Based on the target number of splits, the text to be processed is split to obtain a plurality of sub-text data.
9. The blockchain-based text processing method according to any one of claims 1 to 8, characterized in that: The step of obtaining the text to be processed includes: Obtaining transaction information corresponding to at least one transaction from a transaction pool corresponding to the blockchain; Performing text content recognition on the transaction information; When the transaction information includes text content, obtaining the data volume of the text content; When the data volume of the text content is greater than or equal to the preset data volume, the text content is extracted from the transaction information and used as the text to be processed.
10. The text processing method based on blockchain according to claim 9 is characterized in that: The blockchain node is also provided with a virtual machine, and before the text content recognition of the transaction information is performed, it also includes: Searching, through the virtual machine, a preset contract database for a smart contract corresponding to the transaction information; When the virtual machine finds the smart contract corresponding to the transaction information, the transaction corresponding to the transaction information is executed based on the smart contract to obtain the execution result of the transaction; When the execution result is successful, execute: the step of performing text content recognition on the transaction information.
11. The blockchain-based text processing method according to any one of claims 1 to 8, characterized in that: After storing the to-be-processed text in the text database and adding the target block to the blockchain, the process further includes: Receiving a target query request for the text to be processed; Verifying the target query request; When the target query request is verified, the to-be-processed text is acquired from the text database based on the target query request, and the processed text is output as a query result.
12. The text processing method based on blockchain according to claim 11, characterized in that: The target query request carries a request timestamp, and when the target query request is verified, the to-be-processed text is obtained from the text database based on the query request, and the processed text is output as a query result, including: When the target query request is verified, obtaining a query queue in the blockchain node, wherein the query queue includes at least one query request arranged in execution order; When the number of pending query requests in the query queue is less than a preset number threshold, adding the target query request to the last one in the execution order in the query queue to obtain an updated query queue; Based on the execution order, sequentially execute the query requests in the updated query queue; When the target query request is executed, the current timestamp is obtained; Calculate the difference between the current timestamp and the request timestamp to obtain a time difference; When the time difference is less than or equal to a preset difference, the to-be-processed text is acquired from the text database based on the query request, and the processed text is output as a query result.
13. The text processing method based on blockchain according to claim 11, characterized in that: The target query request carries permission information and signature information, the permission information represents the permission level of the object that issues the target query request, and the signature information represents the signature of the object that issues the target query request. The verifying the target query request includes: Verifying the signature information; When the signature information is verified, the authority information is verified; When the authority information verification is passed, it is determined that the target query request verification is passed.
14. A text processing device based on blockchain, characterized in that: include: A text acquisition unit, used for acquiring the text to be processed; A computing unit, used for performing hash calculation on the text to be processed to obtain a hash value; A block generation unit, configured to generate a target block based on the hash value; A consensus unit, configured to reach a consensus on the target block through a plurality of blockchain nodes corresponding to the blockchain to obtain a consensus result, wherein each of the plurality of blockchain nodes is provided with a text database; A processing unit is used to store the to-be-processed text in the text database and add the target block to the blockchain when the consensus result is that the consensus is reached.
15. An electronic device, characterized in that: It includes a processor and a memory, wherein the memory stores a plurality of instructions; the processor loads instructions from the memory to execute the steps in the blockchain-based text processing method according to any one of claims 1 to 13.
16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the blockchain-based text processing method according to any one of claims 1 to 13.
17. A computer program product, characterized in that The method comprises a computer program / instruction, which, when executed by a processor, implements the steps of the blockchain-based text processing method according to any one of claims 1 to 13.
Citation Information
Cited By
Data processing method and system based on block chain, and related product
CN121029886A