Disclosure of Invention
The embodiment of the application provides a data processing method, device and equipment based on a blockchain and a readable storage medium, which can improve the safety and stability of the blockchain.
In one aspect, an embodiment of the present application provides a data processing method based on a blockchain, including:
If the first block with the block height of X is successfully uplink, a block attribute object list is obtained; the block attribute object list includes one or more block attribute objects;
obtaining block attribute data corresponding to one or more block attribute objects respectively according to the first block, and carrying out hash processing on the one or more block attribute data to obtain a random hash value;
Acquiring a consensus node index matched with the random hash value from the consensus node list as a target consensus node index; the consensus node list comprises at least two consensus node indexes;
and determining the consensus node corresponding to the target consensus node index as a master node for generating the block with the block height of X+1.
In one aspect, an embodiment of the present application provides a data processing apparatus based on a blockchain, including:
The acquisition module is used for acquiring a block attribute object list if the first block uplink with the block height of X is determined to be successful; the block attribute object list includes one or more block attribute objects;
The first hash module is used for acquiring block attribute data corresponding to one or more block attribute objects respectively according to the first block, and carrying out hash processing on the one or more block attribute data to obtain a random hash value;
The index determining module is used for acquiring the consensus node index matched with the random hash value from the consensus node list as a target consensus node index; the consensus node list comprises at least two consensus node indexes;
and the node determining module is used for determining the consensus node corresponding to the target consensus node index as a master node for generating the block with the block height of X+1.
Wherein the first hash module comprises:
The splicing unit is used for carrying out data splicing processing on the one or more block attribute data according to the position sequence of the one or more block attribute objects in the block attribute object list to obtain block attribute spliced data;
the first hash unit is used for carrying out hash operation on the block attribute spliced data to obtain a random hash value.
Wherein, the index determination module includes:
the modulus operation unit is used for determining the number of the consensus node indexes contained in the consensus node list and taking the number as a target index number;
The modulus operation unit is also used for carrying out modulus operation on the target index number through the random hash value to obtain a random node index;
and the index acquisition unit is used for acquiring the same common node index as the random node index in the common node list as a target common node index.
Wherein the one or more block attribute objects include a block hash, a parent block hash, a block timestamp, a master node identification, a block height, a block size, a transaction set root hash, a master node signature;
a first hash module comprising:
And the second hash unit is used for acquiring block attribute data respectively corresponding to the block hash, the father block hash, the block time stamp, the master node identifier, the block height, the block size, the transaction set root hash and the master node signature from the first block if the first block is not the originating block, and carrying out hash processing on the acquired multiple block attribute data to obtain a random hash value.
Wherein, above-mentioned data processing apparatus still includes:
the second hash module is used for determining that block attribute data respectively corresponding to the parent block hash, the transaction set root hash, the main node identifier and the main node signature are default null data if the first block is an originating block;
the second hash module is further used for acquiring block attribute data corresponding to the block hash, the block timestamp, the block height and the block size from the first block;
The second hash module is further used for performing hash processing on the acquired plurality of block attribute data to obtain a random hash value.
The consensus node list further comprises consensus node identifiers which respectively have a mapping relation with at least two consensus node indexes; a consensus node identifier for uniquely identifying a consensus node that participates in the first block consensus process;
A node determination module comprising:
The identification acquisition unit is used for acquiring the consensus node identification with the mapping relation with the target consensus node index from the consensus node list as the target consensus node identification;
and the node determining unit is used for determining the consensus node corresponding to the target consensus node identifier as a master node for generating the block with the block height of X+1.
Wherein, above-mentioned data processing apparatus still includes:
the identification acquisition module is used for acquiring the identification of the corresponding consensus node of at least two consensus nodes participating in the consensus process of the first block;
The identification ordering module is used for ordering the at least two consensus node identifications according to a preset ordering rule to obtain the ordered at least two consensus node identifications;
The identification numbering module is used for carrying out index numbering processing on the at least two sequenced consensus node identifications to obtain a consensus node index respectively mapped by each consensus node identification;
And the list generation module is used for generating a consensus node list according to the at least two sequenced consensus node identifiers and the consensus node indexes respectively mapped by each consensus node identifier.
The preset ordering rules comprise dictionary ordering rules; the dictionary ordering rules include a character ordering order;
An identification ordering module, comprising:
The first sequencing unit is used for traversing at least two consensus node identifiers and acquiring a kth consensus node identifier; k is a positive integer less than or equal to the total number of at least two consensus node identities;
The first ordering unit is further used for acquiring an ith character in the kth consensus node identifier as a first character; i is a positive integer less than or equal to the number of characters contained in the kth consensus node identifier;
the first sequencing unit is also used for acquiring the identical consensus node identifier of the ith-1 character and the ith-1 character of the k-1 consensus node identifiers in the k-1 consensus node identifiers after sequencing, and taking the identical consensus node identifier as a target sequencing consensus node identifier;
the first ordering unit is further used for taking the ith character in each target ordering consensus node identifier as a second character;
The first ordering unit is further used for determining the insertion position of the first character in the second character according to the character arrangement sequence if the second character does not have the same character as the first character;
the first sequencing unit is further used for inserting the kth consensus node identifier into the k-1 consensus node identifiers after sequencing according to the insertion position to obtain k consensus node identifiers after sequencing;
The first sorting unit is further configured to continuously obtain the (i+1) th character in the kth consensus node identifier if the second character has the same character as the first character.
Wherein the preset ordering rule comprises a time ordering rule;
An identification ordering module, comprising:
The second ordering unit is used for acquiring node uplink time stamps corresponding to at least two consensus nodes respectively according to the time ordering rule; the node uplink timestamp refers to a system timestamp when the consensus node joins the blockchain network;
The second ordering unit is further configured to order the at least two common node identifiers according to the size sequence of the node uplink timestamps corresponding to the at least two common node identifiers, so as to obtain the ordered at least two common node identifiers.
Wherein, above-mentioned data processing apparatus still includes:
The transaction acquisition module is used for acquiring an attribute list update transaction; the attribute list update transaction includes a block attribute object to be updated;
The attribute list acquisition module is used for calling an attribute list update contract according to the attribute list update transaction if the attribute list update transaction consensus is determined to pass, and acquiring a block attribute object list through the attribute list update contract;
And the attribute list updating module is used for updating the block attribute object list according to the block attribute object to be updated to obtain a new block attribute object list.
The block attribute object to be updated comprises a block attribute object to be added and a block attribute object to be deleted;
An attribute list update module comprising:
the deleting unit is used for deleting the block attribute object which is the same as the block attribute object to be deleted from the block attribute object list to obtain an intermediate block attribute object list;
and the adding unit is used for adding the block attribute object to be added to the middle block attribute object list to obtain a new block attribute object list.
In one aspect, an embodiment of the present application provides a computer device, including: a processor, a memory, a network interface;
The processor is connected to the memory and the network interface, where the network interface is used to provide a data communication network element, the memory is used to store a computer program, and the processor is used to call the computer program to execute the method in the embodiment of the present application.
In one aspect, embodiments of the present application provide a computer readable storage medium having a computer program stored therein, the computer program being adapted to be loaded by a processor and to perform a method according to embodiments of the present application.
In one aspect, embodiments of the present application provide a computer program product or computer program comprising computer instructions stored in a computer-readable storage medium, the computer instructions being read from the computer-readable storage medium by a processor of a computer device, the computer instructions being executed by the processor, causing the computer device to perform a method according to an embodiment of the present application.
In the embodiment of the application, if the first block with the block height of X is successfully uplink, a block attribute object list can be obtained, wherein the block attribute object list comprises one or more block attribute objects; then, block attribute data corresponding to one or more block attribute objects can be obtained according to the first block, and the one or more block attribute data are subjected to hash processing, so that a random hash value can be obtained; then, in a consensus node list comprising at least two consensus node indexes, acquiring the consensus node index matched with the random hash value as a target consensus node index; finally, the consensus node corresponding to the target consensus node index is determined as the master node for generating the block with the block height of X+1. According to the method provided by the embodiment of the application, the master node is determined based on the block attribute data related to the block with the previous block height, and the block attribute data related to the block with the previous block height can only be obtained based on the block with the previous block height and cannot be predicted, so that the determination of the master node cannot be predicted in advance, the attack difficulty of the master node is greatly improved, and the safety and the stability of a block chain are improved.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
For ease of understanding, the following simple explanation of partial nouns is first made:
1. Blockchain (Block chain): in a narrow sense, the blockchain is a chain data structure taking a block as a basic unit, and the block uses a digital abstract to verify the transaction history acquired before, so that the blockchain is suitable for the requirements of tamper resistance and expandability in a distributed accounting scene; in a broad sense, blockchain also refers to distributed accounting techniques implemented by blockchain structures, including distributed consensus, privacy and security protection, point-to-point communication techniques, network protocols, smart contracts, and the like.
The goal of the blockchain is to implement a distributed data logging ledger that allows only additions and not deletions. The basic structure of the ledger floor is a linear linked list. The linked list is formed by serially connecting blocks, the Hash value of the preceding block is recorded in the following blocks, and whether each block (and the transaction in the block) is legal or not can be rapidly checked by calculating the Hash value. If a node in the network proposes to add a new block, a consensus acknowledgement must be made for the block via a consensus mechanism.
2. Block (block): the data packet carrying transaction data on the blockchain network is a data structure marked with a timestamp and a hash value corresponding to a preceding block, and the block verifies and confirms the transaction in the block through a consensus mechanism of the network. The Block includes a Block Header (Block Header) and a Block Body (Block Body), where the Block Header can record meta information of the current Block and includes data such as a current version number, a hash value corresponding to a previous Block, a timestamp, a random number, a hash value of a Merkle Root (Merkle Root), and the like. The block may record detailed data generated over a period of time, including all transaction records or other information generated during the creation of the block for which the current block is verified, and may be understood as a representation of the ledger. In addition, the detailed data of the block may include generating a unique Merkle Root record in the block header through a hash process of the merck tree (MERKLE TREE).
The successor Block, also called Parent Block (Parent Block), is a Block chain that performs temporal ordering by recording the hash value corresponding to the Block and the hash value corresponding to the Parent Block in the Block header.
3. Hash value (hash): also called information characteristic value or eigenvalue, hash value is generated by converting input data of arbitrary length into a password by hash algorithm and performing fixed output, and original input data cannot be retrieved by decrypting the hash value, which is a one-way encryption function. In a blockchain, each block (except the initial block) contains a hash value of the successor block, which is the potential core foundation and most important aspect in blockchain technology, which preserves the authenticity of the recorded and viewed data, as well as the integrity of the blockchain as a whole.
4. Smart contract (Smart Contract): the concept of intelligent contracts has three major elements of commitment, agreement and digital form, so that the application range of the blockchain can be expanded to all links of transaction, payment, settlement and clearing in the financial industry. Intelligent contracts refer to the immediate execution of corresponding contract terms when a pre-programmed condition is triggered, the working principle of which is similar to the if-then statement of a computer program.
Referring to fig. 1, fig. 1 is a schematic diagram of a blockchain network according to an embodiment of the present application. The blockchain network as shown in fig. 1 may include, but is not limited to, a blockchain network to which the federated chain corresponds. The blockchain network may include a plurality of blockchain nodes, and the plurality of blockchain nodes may include a blockchain node 10a, a blockchain node 10b, a blockchain node 10c, a blockchain node 10d, …, and a blockchain node 10n. Each blockchain node can receive data sent by the outside during normal operation, perform blockchain uplink processing based on the received data, and also can send the data to the outside. To ensure data interworking between the various blockchain nodes, a data connection may exist between each blockchain node, such as between blockchain node 10a and blockchain node 10b, between blockchain node 10a and blockchain node 10c, and between blockchain node 10b and blockchain node 10 c.
It will be appreciated that data or block transfer may be performed between the blockchain nodes via the data connections described above. The blockchain network may implement data connection between blockchain nodes based on node identifiers, and for each blockchain node in the blockchain network, each blockchain node may store node identifiers of other blockchain nodes having a connection relationship with itself, so as to broadcast the acquired data or generated blocks to other blockchain nodes according to the node identifiers of the other blockchain nodes, for example, the blockchain node 10a may maintain a node identifier list as shown in table 1, where the node identifier list stores node names and node identifiers of the other nodes:
TABLE 1
| Node name | Node identification |
| Node 10a | AAA.AAA.AAA.AAA |
| Node 10b | BBB.BBB.BBB.BBB |
| Node 10c | CCC.CCC.CCC.CCC |
| Node 10d | DDD.DDD.DDD.DDD |
| … | … |
| Node 10n | EEE.EEE.EEE.EEE |
The node identifier may be a protocol (Internet Protocol, IP) address of the interconnection between networks, and any other information that can be used to identify the node in the blockchain network, and the IP address is only illustrated in table 1. For example, the blockchain node 10a may send information (e.g., a block) to the blockchain node 10b through the node identification bbb.bbb.bbb.bbb.bbb, and the blockchain node 10b may determine that the information was sent by the blockchain node 10a through the node identification aaa.aaa.aaa.
In a blockchain, a block must be consensus-passed through consensus nodes in the blockchain network before the block is uplink, and the block can be added to the blockchain after the consensus passes. It will be appreciated that when a blockchain is used in some contexts of a government or commercial establishment, not all participating nodes in the blockchain (i.e., blockchain nodes in the blockchain network described above) have sufficient resources and necessity to become consensus nodes of the blockchain. For example, in the blockchain network shown in fig. 1, blockchain node 10a, blockchain node 10b, blockchain node 10c, and blockchain node 10d may be considered as consensus nodes in the blockchain network. The consensus nodes in the blockchain network participate in consensus, namely, consensus is carried out on the blocks (comprising a batch of transactions), namely, voting is carried out on the blocks; while non-consensus nodes do not participate in consensus, but will help propagate block and vote messages, and synchronize status with each other, etc.
It will be appreciated that when the blockchain network employs a bayer consensus mechanism to achieve the consensus of the blocks, the assembly of the blocks and initiation of the consensus is typically done by the master node (also referred to as the out-block node). In the embodiment of the present application, the blockchain network as shown in fig. 1 may adopt a bayer consensus mechanism to realize the block consensus, and at this time, the blockchain node with the consensus function, for example, the blockchain node 10a, needs to determine the master node corresponding to the block corresponding to the next block height after determining that the block uplink of the current block height is successful, so as to complete the consensus operation of the block corresponding to the next block height. Specifically, if the first block with the block height X is successfully uplink, the blockchain node 10a obtains a blockattribute object list, where the blockattribute object list may include one or more blockattribute objects, for example, a blockhash, a parent blockhash, a blocksize, and so on; then, the blockchain node 10a may acquire, according to the first block, the blockattribute data corresponding to the one or more blockattribute objects, and perform hash processing on the one or more blockattribute data to obtain a random hash value; then, the blockchain node 10a may acquire the consensus node index matching the random hash value from the consensus node list including at least two consensus node indexes as the target consensus node index, and finally, determine the consensus node corresponding to the target consensus node index as the master node for generating the block with the block height of x+1.
It should be understood that the above data connection is not limited to a connection manner, and may be directly or indirectly connected through a wired communication manner, may be directly or indirectly connected through a wireless communication manner, or may be connected through other connection manners, which is not limited herein.
It will be appreciated that the data processing method provided by the embodiments of the present application may be performed by a computer device, including but not limited to the blockchain node (which may be a terminal or a server) described above. The server may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, basic cloud computing services such as big data and artificial intelligence platforms. The terminal may be, but is not limited to, a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, etc.
It is to be appreciated that embodiments of the present application may be applied to a variety of scenarios including, but not limited to, cloud technology, artificial intelligence, intelligent transportation, etc. For example, the block link point system may perform consensus on some driving behavior data, road track data, and the like sent by the vehicle-mounted terminal, and store the consensus on the vehicle-mounted terminal after the consensus passes.
It will be appreciated that in the specific embodiments of the present application, related data such as transaction data, status data, etc. are referred to, and when the above embodiments of the present application are applied to specific products or technologies, user permissions or consents are required, and the collection, use and processing of related data is required to comply with relevant laws and regulations and standards of relevant countries and regions.
In order to facilitate understanding of the above-mentioned determination process of the master node, please refer to fig. 2, fig. 2 is a schematic diagram of a scenario of a data processing method based on a blockchain according to an embodiment of the present application. The blockchain node 20 shown in fig. 2 may be any blockchain node in the blockchain network shown in fig. 1, e.g., the blockchain node 20 is the blockchain node 10b. For convenience of description, in the embodiment corresponding to fig. 2, a block with a block height X is named as a block X, and the block height X is named as a block height X, where X is a positive integer. For example, a block with a block height of 1 is named block 1, and a block with a block height of 1 is described as block height 1; the block with the block height m is named as the block m, the block height m is described as the block height m, and the corresponding blocks of other block heights are named as well, and the detailed description is omitted herein.
As shown in fig. 2, after the blockchain node 20 writes the block m into the blockchain 21, it determines that the blockchain m is successfully uplinked, at this time, the blockchain node 20 needs to determine the master node of the next block height (i.e. the blockchain node for generating the block m+1), the blockchain node 20 will first acquire the blockattribute object list 22, where the blockattribute object list 22 may include the blockattribute object 1, the blockattribute objects 2, …, and the blockattribute object n, where the blockattribute object may be selected according to the actual situation, for example, the blockattribute object 1 may be a blockhash, the blockattribute object 2 may be a parent blockhash, and the blockattribute object n may be a blocksize. Then, the blockchain node 20 may obtain, according to the block m, a specific value corresponding to each of the block attribute objects in the block attribute object list 22, thereby obtaining n pieces of block attribute data. Then, the blockchain node 20 hashes the n pieces of blockattribute data to obtain a random hash value. Then, the blockchain node 20 may obtain the target consensus node index matched with the random hash value from the consensus node list 23, and take the target consensus node corresponding to the target consensus node index as the master node of the next blockheight. The common node list 23 may include a common node index 1, common node indexes 2 and …, and a common node index k, where each common node index may correspond to one common node. The matching process of the random hash value and the consensus node index may be described in detail in step S103 in the embodiment corresponding to fig. 3 below.
Therefore, in the embodiment of the application, the selection of the master node can obtain the related block attribute data only by relying on the block with the previous block height, but the block attribute data in the block with the previous block height, such as block hash, block size and the like, have randomness and are unpredictable, so that the selection of the master node is not easy to determine, and is difficult to attack, thereby improving the safety and stability of the block chain.
Further, referring to fig. 3, fig. 3 is a flowchart of a data processing method based on a blockchain according to an embodiment of the present application. The data processing method may be performed by a blockchain node (e.g., any blockchain node in the blockchain network in the embodiment described above with respect to fig. 1). The present data processing method will be described below by taking the block link point execution as an example. The data processing method based on the blockchain at least comprises the following steps of S101 to S104:
Step S101, if the first block uplink with the block height X is determined to be successful, a block attribute object list is obtained; the tile attribute object list includes one or more tile attribute objects.
Specifically, the block attribute object refers to a random or non-fixed data type related to a block, and the block attribute data (e.g., specific values) corresponding to different block attribute objects may provide different information, where the block attribute data corresponding to the block attribute objects are generally different in different blocks.
In particular, the one or more tile attribute objects may include a tile hash (blockHash). The blocks in the blockchain all have block hashes, which are hashes of the agreed blocks after each consensus is completed, and are hashes for the generation of the whole block information, which is the characteristic that the blockchain is called invariable and the data is credible, so that the block hashes of each block are different as long as the block in the blockchain changes the block hashes.
Specifically, one or more tile attribute objects may include a parent tile hash (preBlockHash). One piece of information contained in a block in the blockchain is the parent block hash, i.e., the hash address of the last block. The block chain is formed by arranging the block chains one by one in sequence, and each page has a page number just like a real account book, so that the content which you want to find can be found by the page number; in the blockchain, the information after the settlement of the previous block can be found through the hash value of the father block. The present block hash is the parent block hash of the next block, so there is one and only one parent block hash for each block, and the parent block hashes for each block are all different.
In particular, one or more tile attribute objects may include a tile timestamp (timestamp). When the master node generates the block according to the current time stamp, the time stamp is contained in the block information and then broadcast to all nodes for consensus, so that after a block is subjected to consensus and submitted, the time stamp of the block is non-tamperable, and the block time stamp of each block chain is different and is increased continuously because the block chain is a process of adding to the back of the block.
In particular, the one or more tile attribute objects may include a tile timestamp and may include a master node identification (Identity document, ID). The block in the blockchain contains a message, namely a master node ID (nodeID), which indicates who the block is generated from, and in the bayer consensus, the master node of the block is a very important message, and generates the block, and the master node of the block must be set to its own node ID, and when the slave node receives the block, it needs to verify that the block required for the current consensus is generated by the master node, instead of voting on the block generated by any node. All nodes vote only on the generated block of the master node in the current consensus, so the master node id is also important information in the block.
In particular, one or more tile attribute objects may include a tile height (blockHeight). Each block has an information that is the block height, which starts from 0 and is incremented, each time the height of the block is based on the height of the last block plus one, so the heights of the blocks in the blockchain are incremented all the time.
Specifically, one or more tile attribute objects may include a tile size (blockSize). The size of a block refers to the size of the entire block data volume, and is typically different for each block, depending on the number of transactions the block is packed in, and other various information.
In particular, the one or more tile attribute objects may include a transaction set root hash (txRootHash). The most important content in the block is that the transaction is packed, the purpose of the packing block is that the packing transaction is carried out, the consensus achieved by the blockchain is that the result achieved by the transaction execution result is the consensus achieved by the blockchain, and the transaction packed by each block is different, because the transaction after being packed is not allowed to be repeatedly packed, or the historical blocks of the whole blockchain cannot contain the same transaction, and therefore the transaction root hash generated by each block according to the transaction set is also different.
In particular, one or more tile attribute objects may include a master node signature (blockSignature). In order to prevent the tampering of the block, the master node signs the block when generating the block, and the slave node needs to verify the signature generated by the master node when receiving the block sent by the master node, so that the block is ensured to be generated by the master node, and the signature of the master node is inconsistent because the content of the blocks at each height is different.
It will be appreciated that there may be a number of random or non-uniform content in each tile, and that the list of tile attribute objects may include other random or non-uniform tile attribute objects in addition to one or more of the above-described tile hash, parent tile hash, tile timestamp, master node identification, tile height, tile size, transaction set root hash, master node signature, as the application is not limited in this regard.
Step S102, obtaining block attribute data corresponding to the one or more block attribute objects according to the first block, and performing hash processing on the one or more block attribute data to obtain a random hash value.
Specifically, the obtaining, according to the first block, block attribute data corresponding to one or more block attribute objects, and performing hash processing on the one or more block attribute data, to obtain a feasible implementation process of the random hash value may be: performing data splicing processing on one or more block attribute data according to the position sequence of one or more block attribute objects in the block attribute object list to obtain block attribute spliced data; and carrying out hash operation on the block attribute spliced data to obtain a random hash value. For example, when one or more tile attribute objects include a tile hash (blockHash), a parent tile hash (preBlockHash), a tile generation timestamp (timestamp), a master node ID (nodeID), a tile block height (blockHeight), a tile size (blockSize), a transaction set root hash (txRootHash), a master node signature (blockSignature), the process of the hash operation may be expressed as formula (1) below:
randomHash = sha256 (blockHash + preBlockHash + timestamp + nodeID + blockSize + txRootHash + blockSignature) formula (1)
Wherein randomHash is a random hash value, blockHash, preBlockHash, timestamp, nodeID, blockSize, txRootHash, blockSignature is block attribute data corresponding to the block attribute object, and sha256 is a hash algorithm for generating a random hash value with a length of 256 bits.
Specifically, when the one or more block attribute objects include a block hash, a parent block hash, a block timestamp, a master node identifier, a block height, a block size, a transaction set root hash, and a master node signature, the first block obtains block attribute data corresponding to the one or more block attribute objects, and performs hash processing on the one or more block attribute data to obtain a feasible implementation process of the random hash value, which may be: if the first block is not the originating block, block attribute data corresponding to the block hash, the father block hash, the block timestamp, the master node identifier, the block height, the block size, the transaction set root hash and the master node signature are obtained from the first block, and hash processing is performed on the obtained plurality of block attribute data to obtain a random hash value.
Optionally, if the first block is an originating block, determining that block attribute data corresponding to the parent block hash, the transaction set root hash, the master node identifier and the master node signature are default null data; obtaining block attribute data corresponding to block hash, block timestamp, block height and block size from the first block; and carrying out hash processing on the acquired attribute data of the plurality of blocks to obtain a random hash value.
For ease of understanding, please refer to fig. 4, fig. 4 is a schematic diagram of a data structure of a blockchain according to an embodiment of the present application. As shown in FIG. 4, the blockchain 41 includes a block 0 and a block 1, wherein the block 0 is an created block in the blockchain 41. It will be appreciated that an created block in a blockchain refers to a block in the blockchain that has a block height of 0, i.e., the first block in the blockchain. As shown in fig. 4, the block 0 is not signed by the parent block hash, the transaction set root hash, the master node id, and the master node, so that when the block attribute data is acquired according to the block 0, the block attribute data corresponding to the parent block hash, the transaction set root hash, the master node id, and the master node signature of the created block can be set as default null data. From block 1, the block may include block attribute data corresponding to the block hash, parent block hash, block timestamp, master node identifier, block height, block size, transaction set root hash, and master node signature, respectively.
Step S103, obtaining a consensus node index matched with the random hash value from a consensus node list as a target consensus node index; the list of consensus nodes includes at least two consensus node indices.
Specifically, in the consensus node list, the consensus node index matched with the random hash value is obtained as a feasible implementation process of the target consensus node index, which may be: determining the number of the indexes of the consensus nodes contained in the consensus node list as a target index number; performing modular operation on the target index number through the random hash value to obtain a random node index; and acquiring the same consensus node index as the random node index from the consensus node list as a target consensus node index. The consensus node index included in the consensus node list may be a continuous natural number from 0, for example, the consensus node list may include a consensus node index 0, a consensus node index 1, and a consensus node index 2, where the target index number is 3, and assuming that the random hash value is 4569, the 4569 performs a modulo operation on 3, that is, dividing 4569 by 3, and taking the remainder, where the remainder is 0, and the random node index is 0, and the target consensus node index is the consensus node index 0.
Step S104, determining the consensus node corresponding to the target consensus node index as a master node for generating the block with the block height of X+1.
Specifically, in the consensus node list, one consensus node index may be mapped with one consensus node identifier, where the consensus node identifier is used to uniquely identify one consensus node, and the blockchain node may acquire the mapped consensus node identifier through the target consensus node index, so as to determine the consensus node corresponding to the consensus node identifier as the master node.
Optionally, the blockchain node may acquire an attribute list update transaction; the attribute list update transaction includes a block attribute object to be updated; if the attribute list updating transaction consensus is determined to pass, calling an attribute list updating contract according to the attribute list updating transaction, and acquiring a block attribute object list through the attribute list updating contract; and updating the block attribute object list according to the block attribute object to be updated to obtain a new block attribute object list. The block attribute object to be updated comprises a block attribute object to be added and a block attribute object to be deleted; the updating process is performed on the block attribute object list according to the attribute object to be updated to obtain a feasible implementation process of the new block attribute object list, which may be: deleting the block attribute object which is the same as the block attribute object to be deleted from the block attribute object list to obtain an intermediate block attribute object list; and adding the block attribute object to be added to the middle block attribute object list to obtain a new block attribute object list.
According to the method provided by the embodiment of the application, when a new main node is determined, the block attribute data generated randomly is acquired through the block with the previous block height, so that the main node with each height becomes more random, an attacker cannot predict the main node, the attack cost of the main node is higher, and meanwhile, the selection of the main node is fairer, so that the safety and stability of the Bayesian consensus are greatly improved.
Further, referring to fig. 5, fig. 5 is a flowchart of a data processing method based on a blockchain according to an embodiment of the present application. The data processing method is used to generate the list of consensus nodes applied in the embodiment corresponding to fig. 3, and the data processing method may be performed by a blockchain node (e.g., any blockchain node in the blockchain network in the embodiment corresponding to fig. 1). The present data processing method will be described below by taking the block link point execution as an example. The blockchain-based data processing method at least includes the following steps S201 to S204:
step S201, obtaining the identification of the consensus node corresponding to at least two consensus nodes participating in the consensus process of the first block.
Specifically, one common node identifier is used for uniquely identifying one common node in the blockchain, in other words, the common node identifiers corresponding to different common nodes are different.
Step S202, sorting at least two consensus node identifiers according to a preset sorting rule, and obtaining at least two sorted consensus node identifiers.
Specifically, the preset ordering rule comprises a dictionary ordering rule; the dictionary ordering rules include a character ordering order; sequencing the at least two consensus node identifiers according to a preset sequencing rule to obtain a feasible implementation process of the sequenced at least two consensus node identifiers, wherein the feasible implementation process can be as follows: traversing at least two consensus node identifiers to obtain a kth consensus node identifier; k is a positive integer less than or equal to the total number of at least two consensus node identities; acquiring an ith character in a kth consensus node identifier as a first character; i is a positive integer less than or equal to the number of characters contained in the kth consensus node identifier; the method comprises the steps of obtaining the identical consensus node identifiers of the ith-1 character and the ith-1 character of the k-th consensus node identifiers in the k-1 consensus node identifiers after sequencing, and taking the identical consensus node identifiers as target sequencing consensus node identifiers; taking the ith character in each target sequencing consensus node identifier as a second character; if the second character has no character identical to the first character, determining the insertion position of the first character in the second character according to the character arrangement sequence; inserting the kth consensus node identifier into the k-1 consensus node identifiers after sequencing according to the insertion position to obtain k consensus node identifiers after sequencing; if the second character is the same as the first character, the (i+1) th character in the kth consensus node identifier is continuously acquired. The character arrangement sequence can be 16-system character size sequence, or can be alphabetic sequence + numerical sequence, or can be set according to actual conditions. For ease of understanding, it is assumed that at least two consensus node identifiers comprise "qa123", "qb123", "rs890", "asjd1", where the alphabetic order is alphabetic + numeric order, i.e., between letters and numbers, with letters having precedence over numbers; comparing priorities from letter to letter according to an alphabetical order; the numbers are compared with each other according to the order of the numbers. Firstly, acquiring 'qa 123', wherein the second consensus node identifier 'qb 123' can be directly acquired without sorting the one consensus node identifier, and at the moment, firstly comparing the 1 st character in the two consensus node identifiers, and continuously comparing the 2 nd character in the two consensus node identifiers because of q, and acquiring 2 ordered consensus node identifiers as 'qa 123' and 'qb 123' because 'a' is positioned before 'b' in the alphabetical order; Then, the third consensus node identifier "rs890" is continuously acquired, and the first character is still compared, because the first character of the third consensus node identifier is different from the first character of the ordered 2 consensus node identifiers, the "rs890" can be directly determined to be positioned behind the "qb123" according to the alphabetical order, and the ordered 3 consensus node identifiers are obtained as "qa123", "qb123" and "rs890"; finally, the fourth consensus node identifier "asjd1" is obtained, and the first character is still compared, because the first character of the fourth consensus node identifier is different from the first character of the 3 sequenced consensus node identifiers, it can be determined that "asjd" should be located before "qa123" directly according to the alphabetical order, and the 3 sequenced consensus node identifiers are "asjd", "qa123", "qb123" and "rs890".
Specifically, the preset ordering rule includes a time ordering rule; sequencing the at least two consensus node identifiers according to a preset sequencing rule to obtain a feasible implementation process of the sequenced at least two consensus node identifiers, wherein the feasible implementation process can be as follows: acquiring node uplink time stamps corresponding to at least two consensus nodes respectively according to a time ordering rule; the node uplink timestamp refers to a system timestamp when the consensus node joins the blockchain network; and sequencing the at least two consensus node identifiers according to the size sequence of the node uplink time stamps corresponding to the at least two consensus nodes respectively to obtain the sequenced at least two consensus node identifiers. It will be appreciated that the smaller the node uplink timestamp, the earlier the corresponding consensus node will join the blockchain network.
And step S203, carrying out index numbering processing on the at least two sequenced consensus node identifiers to obtain the consensus node index respectively mapped by each consensus node identifier.
Specifically, the index numbering process may be to perform serial natural number numbering on at least two sorted common node identifiers from 0, that is, the common node index may include 0, 1,2, …, and N-1. Wherein N is the number of the consensus node identifiers contained in the at least two consensus node identifiers.
Step S204, generating a consensus node list according to the at least two sequenced consensus node identifiers and the consensus node index mapped by each consensus node identifier.
Obviously, by the method provided by the embodiment of the application, the mapping relation between the consensus node identification and the consensus node index can be set according to actual conditions, so that the difficulty of master node prediction is further improved, and the consensus safety and stability are greatly improved.
Referring to fig. 6, fig. 6 is a schematic structural diagram of a data processing apparatus based on a blockchain according to an embodiment of the present application. The data processing apparatus 1 may be a computer program (comprising program code) running on a computer device, for example the data processing apparatus 1 is an application software; the data processing apparatus 1 may be adapted to perform the corresponding steps in the data processing method provided by the embodiment of the application. As shown in fig. 6, the data processing apparatus 1 may include: the node determining module 104 includes an obtaining module 101, a first hash module 102, an index determining module 103, and a node determining module 102.
An obtaining module 101, configured to obtain a block attribute object list if it is determined that the first block uplink with the block height X is successful; the block attribute object list includes one or more block attribute objects;
A first hash module 102, configured to obtain, according to a first block, block attribute data corresponding to one or more block attribute objects, and perform hash processing on the one or more block attribute data to obtain a random hash value;
An index determining module 103, configured to obtain, from the consensus node list, a consensus node index that matches the random hash value as a target consensus node index; the consensus node list comprises at least two consensus node indexes;
The node determining module 104 is configured to determine a consensus node corresponding to the target consensus node index as a master node for generating a block with a block height of x+1.
The specific implementation manner of the obtaining module 101, the first hash module 102, the index determining module 103, and the node determining module 104 may refer to the description of the step S101 to the step S104 in the embodiment corresponding to the above fig. 3, and the description is not repeated here.
Wherein the first hash module 102 includes: a concatenation unit 1021 and a first hash unit 1022.
A stitching unit 1021, configured to perform data stitching processing on one or more block attribute data according to the position sequence of the one or more block attribute objects in the block attribute object list, to obtain block attribute stitching data;
The first hash unit 1022 is configured to perform a hash operation on the block attribute spliced data to obtain a random hash value.
The specific implementation manner of the splicing unit 1021 and the first hash unit 1022 may refer to the description of step S102 in the embodiment corresponding to fig. 3, and will not be described herein.
Wherein, the index determining module 103 includes: the modulo arithmetic unit 1031 and the index acquisition unit 1032.
A modulo arithmetic unit 1031 for determining the number of common node indexes included in the common node list as a target index number;
The modulo operation unit 1031 is further configured to perform modulo operation on the target index number by using the random hash value, to obtain a random node index;
the index obtaining unit 1032 is configured to obtain, as the target common node index, the common node index identical to the random node index in the common node list.
The specific implementation manner of the modulo arithmetic unit 1031 and the index obtaining unit 1032 may refer to the description of step S103 in the embodiment corresponding to fig. 3, and the description is not repeated here.
Wherein the one or more block attribute objects include a block hash, a parent block hash, a block timestamp, a master node identification, a block height, a block size, a transaction set root hash, a master node signature;
The first hash module 102 includes: a second hash unit 1023.
The second hash unit 1023 is configured to obtain, if the first block is not an originating block, block attribute data corresponding to the block hash, the parent block hash, the block timestamp, the master node identifier, the block height, the block size, the transaction set root hash, and the master node signature from the first block, and hash the obtained plurality of block attribute data to obtain a random hash value.
The specific implementation manner of the second hash unit 1023 may refer to the description of step S102 in the embodiment corresponding to fig. 3, and will not be repeated here.
Wherein, the above-mentioned data processing apparatus 1, further include: a second hash module 105.
The second hash module 105 is configured to determine that block attribute data corresponding to the parent block hash, the transaction set root hash, the master node identifier, and the master node signature are default null data if the first block is an originating block;
The second hash module 105 is further configured to obtain block attribute data corresponding to the block hash, the block timestamp, the block height, and the block size from the first block;
The second hash module 105 is further configured to perform hash processing on the acquired plurality of block attribute data to obtain a random hash value.
The specific implementation manner of the second hash module 105 may refer to the optional description of step S102 in the embodiment corresponding to fig. 3, which is not described herein.
The consensus node list further comprises consensus node identifiers which respectively have a mapping relation with at least two consensus node indexes; a consensus node identifier for uniquely identifying a consensus node that participates in the first block consensus process;
the node determination module 104 includes: the identification acquisition unit 1041 and the node determination unit 1042.
An identifier obtaining unit 1041, configured to obtain, from the consensus node list, a consensus node identifier having a mapping relationship with the target consensus node index, as a target consensus node identifier;
the node determining unit 1042 is configured to determine the target consensus node identifier as a master node for generating a block with a block height of x+1.
The specific implementation manner of the identifier obtaining unit 1041 and the node determining unit 1042 may refer to the description of step S104 in the embodiment corresponding to fig. 3, and the description is not repeated here.
Wherein, the above-mentioned data processing apparatus 1, further include: an identification acquisition module 106, an identification ordering module 107, an identification numbering module 108, and a list generation module 109.
The identifier obtaining module 106 is configured to obtain the identifiers of the consensus nodes corresponding to the at least two consensus nodes participating in the consensus process of the first block;
the identifier ordering module 107 is configured to order the at least two consensus node identifiers according to a preset ordering rule, so as to obtain ordered at least two consensus node identifiers;
the identification number module 108 is configured to perform index number processing on the at least two sequenced consensus node identifications to obtain a consensus node index mapped by each consensus node identification respectively;
the list generating module 109 is configured to generate a consensus node list according to the sorted at least two consensus node identifiers and the consensus node index mapped by each consensus node identifier.
The specific implementation manner of the identifier obtaining module 106, the identifier sorting module 107, the identifier numbering module 108, and the list generating module 109 may refer to the description of the steps S201 to S204 in the embodiment corresponding to fig. 5, and the description thereof will not be repeated here.
The preset ordering rules comprise dictionary ordering rules; the dictionary ordering rules include a character ordering order;
The identification ordering module 107 includes: the first sorting unit 1071.
A first ordering unit 1071, configured to traverse at least two consensus node identifiers and obtain a kth consensus node identifier; k is a positive integer less than or equal to the total number of at least two consensus node identities;
The first ordering unit 1071 is further configured to obtain an ith character in the kth consensus node identifier as a first character; i is a positive integer less than or equal to the number of characters contained in the kth consensus node identifier;
the first ordering unit 1071 is further configured to obtain, from the k-1 th consensus node identifiers after ordering, a consensus node identifier in which the i-1 th character is the same as the i-1 th character of the k-th consensus node identifier, as a target ordering consensus node identifier;
The first ordering unit 1071 is further configured to use an ith character in each target ordering consensus node identifier as a second character;
The first sorting unit 1071 is further configured to determine, if the second character has no character identical to the first character, an insertion position of the first character in the second character according to the character arrangement sequence;
The first ordering unit 1071 is further configured to insert the kth consensus node identifier into the ordered k-1 consensus node identifiers according to the insertion position, so as to obtain the ordered k consensus node identifiers;
The first ordering unit 1071 is further configured to, if the second character has the same character as the first character, continue to obtain the i+1th character in the kth consensus node identifier.
The specific implementation of the first ordering unit 1071 may refer to the description of step S202 in the embodiment corresponding to fig. 3, and the detailed description is omitted here.
Wherein the preset ordering rule comprises a time ordering rule;
the identification ordering module 107 includes: a second ordering unit 1072.
A second ordering unit 1072, configured to obtain node uplink timestamps corresponding to at least two consensus nodes respectively according to a time ordering rule; the node uplink timestamp refers to a system timestamp when the consensus node joins the blockchain network;
the second ordering unit 1072 is further configured to order the at least two common node identifiers according to the size sequence of the node uplink timestamps corresponding to the at least two common node identifiers, so as to obtain the ordered at least two common node identifiers.
The specific implementation of the second sorting unit 1072 may refer to the description of step S202 in the embodiment corresponding to fig. 3, and the detailed description is omitted here.
Wherein, the above-mentioned data processing apparatus 1, further include: a transaction acquisition module 110, an attribute list acquisition module 111, and an attribute list update module 112.
A transaction acquisition module 110 for acquiring an attribute list update transaction; the attribute list update transaction includes a block attribute object to be updated;
The attribute list obtaining module 111 is configured to, if it is determined that the attribute list update transaction consensus passes, invoke an attribute list update contract according to the attribute list update transaction, and obtain a block attribute object list through the attribute list update contract;
The attribute list updating module 112 is configured to update the block attribute object list according to the block attribute object to be updated to obtain a new block attribute object list.
The specific implementation manner of the transaction obtaining module 110, the attribute list obtaining module 111, and the attribute list updating module 112 may refer to the optional description of step S104 in the embodiment corresponding to fig. 3, which is not repeated here.
The block attribute object to be updated comprises a block attribute object to be added and a block attribute object to be deleted;
The attribute list update module 112 includes: deletion unit 1121 and addition unit 1122.
A deleting unit 1121, configured to delete, in the block attribute object list, a block attribute object identical to the block attribute object to be deleted, to obtain an intermediate block attribute object list;
the adding unit 1122 is configured to add the block attribute object to be added to the intermediate block attribute object list, to obtain a new block attribute object list.
The specific implementation manner of the deleting unit 1121 and the adding unit 1122 may refer to the optional description of step S104 in the embodiment corresponding to fig. 3, which is not repeated here.
Referring to fig. 7, fig. 7 is a schematic structural diagram of a computer device according to an embodiment of the application. As shown in fig. 7, the data processing apparatus 1 in the embodiment corresponding to fig. 6 described above may be applied to a computer device 1000, and the computer device 1000 may include: processor 1001, network interface 1004, and memory 1005, and in addition, the above-described computer device 1000 may further include: a user interface 1003, and at least one communication bus 1002. Wherein the communication bus 1002 is used to enable connected communication between these components. The user interface 1003 may include a Display (Display), a Keyboard (Keyboard), and the optional user interface 1003 may further include a standard wired interface, a wireless interface, among others. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (non-volatile memory), such as at least one disk memory. The memory 1005 may also optionally be at least one storage device located remotely from the processor 1001. As shown in fig. 7, an operating system, a network communication module, a user interface module, and a device control application may be included in a memory 1005, which is a type of computer-readable storage medium.
In the computer device 1000 shown in fig. 7, the network interface 1004 may provide a network communication network element; while user interface 1003 is primarily used as an interface for providing input to a user; and the processor 1001 may be used to invoke a device control application stored in the memory 1005 to implement:
it should be understood that the computer device 1000 described in the embodiments of the present application may perform the description of the data processing method in any of the foregoing embodiments corresponding to fig. 3 and 5, and will not be repeated herein. In addition, the description of the beneficial effects of the same method is omitted.
Furthermore, it should be noted here that: the embodiment of the present application further provides a computer readable storage medium, in which the computer program executed by the aforementioned data processing apparatus 1 is stored, and the computer program includes program instructions, when executed by the aforementioned processor, can execute the description of the data processing method in any of the foregoing embodiments corresponding to fig. 3 and 5, and therefore, the description will not be repeated here. In addition, the description of the beneficial effects of the same method is omitted. For technical details not disclosed in the embodiments of the computer-readable storage medium according to the present application, please refer to the description of the method embodiments of the present application.
The computer readable storage medium may be the data processing apparatus provided in any one of the foregoing embodiments or an internal storage unit of the computer device, for example, a hard disk or a memory of the computer device. The computer readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart memory card (SMART MEDIA CARD, SMC), a Secure Digital (SD) card, a flash memory card (FLASH CARD), etc. that are provided on the computer device. Further, the computer-readable storage medium may also include both internal storage units and external storage devices of the computer device. The computer-readable storage medium is used to store the computer program and other programs and data required by the computer device. The computer-readable storage medium may also be used to temporarily store data that has been output or is to be output.
Furthermore, it should be noted here that: embodiments of the present application also provide a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer readable storage medium and executes the computer instructions to cause the computer device to perform the method provided by any of the corresponding embodiments of fig. 3 and 5 above.
The terms first, second and the like in the description and in the claims and drawings of embodiments of the application are used for distinguishing between different objects and not for describing a particular sequential order. Furthermore, the term "include" and any variations thereof is intended to cover a non-exclusive inclusion. For example, a process, method, apparatus, article, or device that comprises a list of steps or elements is not limited to the list of steps or modules but may, in the alternative, include other steps or modules not listed or inherent to such process, method, apparatus, article, or device.
Those of ordinary skill in the art will appreciate that the elements and algorithm steps described in connection with the embodiments disclosed herein may be embodied as electronic hardware, as a computer software, or in a combination of the two, and that the elements and steps of the examples have been generally described in terms of network elements in the foregoing description to clearly illustrate the interchangeability of hardware and software. Whether these network elements are implemented in hardware or software depends on the specific application and design constraints of the solution. The skilled person may use different methods for implementing the described network elements for each specific application, but such implementation should not be considered to be beyond the scope of the present application.
The foregoing disclosure is illustrative of the present application and is not to be construed as limiting the scope of the application, which is defined by the appended claims.