Blockchain-based data processing method, device, and readable storage medium
A blockchain-based data processing method includes: assigning, in response to that a first request message with a sequence number n has a first prepared certificate, a sequence number n+1 to a second request message; associatively storing the first request message and a first response result corresponding to the first request message in response to that the second request message has a second prepared certificate; performing in parallel a request operation corresponding to the second request message while associatively storing the first request message and the first response result, to obtain a second response result corresponding to the second request message; and returning, to a client, a first initial response message generated based on the second response result, for the client to determine a first request execution result corresponding to the second request message based on the first initial response message and a backup initial response message.
1 . A blockchain-based data processing method, a blockchain network comprising a master node having consensus permission and one or more backup nodes having the consensus permission, the method being performed by the master node and comprising:
assigning, in response to a first request message having a sequence number n and a first prepared certificate, a sequence number n+1 to a second request message, n being a positive integer;
associatively storing the first request message and a first response result corresponding to the first request message to a ledger file in response to the second request message having a second prepared certificate, the first response result being obtained by performing an operation corresponding to the first request message in response to the first request message having the first prepared certificate; performing in parallel a request operation corresponding to the second request message while associatively storing the first request message and the first response result to the ledger file, to obtain a second response result corresponding to the second request message and store the second response result to a cache file; and
returning, to a client that initiates the second request message, a first initial response message generated based on the second response result, for the client to determine a first request execution result corresponding to the second request message based on the first initial response message and a backup initial response message returned by each of the one or more backup nodes.
2 . The method according to claim 1 , further comprising:
obtaining the second request message, and determining request status of the second request message; and
obtaining, in response to the request status being a request response state, the second response result corresponding to the second request message from the cache file, and returning, to the client, a second initial response message generated based on the second response result, for the client to determine a second request execution result corresponding to the second request message based on the second initial response message and a backup initial response message returned by the each of the one or more backup nodes, the request response state indicating that the second request message exists in the blockchain network and the master node has performed the request operation corresponding to the second request message;
obtaining, in response to the request status being a request write state, the second response result corresponding to the second request message from the ledger file, and returning, to the client, a completed response message generated based on the second response result, for the client to determine a third request execution result corresponding to the second request message based on the completed response message and a backup completed response message returned by the each of the one or more backup nodes, the request write state indicating that the second request message exists in the blockchain network and the master node has associatively stored the second request message and the second response result to the ledger file; and
performing, in response to the request status being a request initial state, the operation of assigning the sequence number n+1 to the second request message, the request initial state indicating that the second request message does not exist in the blockchain network.
3 . The method according to claim 2 , wherein the determining the request status of the second request message comprises:
determining a request hash corresponding to the second request message, and comparing the request hash with a cache request hash in the cache file, a request message corresponding to the cache request hash in the cache file being a request message for which a request operation has been performed;
determining, in response to the cache file including a cache request hash that is the same as the request hash, that the request status of the second request message is the request response state;
comparing, in response to the cache file not including a cache request hash that is the same as the request hash, the request hash with a write request hash in the ledger file, a request message corresponding to the write request hash in the ledger file being a request message that has been stored;
determining, in response to the ledger file including a write request hash that is the same as the request hash, that the request status of the second request message is the request write state; and
determining, in response to the ledger file not including a write request hash that is the same as the request hash, that the request status of the second request message is the request initial state.
4 . The method according to claim 2 , wherein the returning, to the client, the completed response message generated based on the second response result comprises:
generating a completed response identifier for the second request message based on the second response result;
determining the completed response identifier, a first view number of the blockchain network, a request timestamp corresponding to the second request message, a client identifier corresponding to the client, a master node identifier, and the second response result as to-be- signed completed response information;
signing the to-be-signed completed response information by using a master node private key, to obtain first signature information; and
generating the completed response message that carries the first signature information and the to-be-signed completed response information, and transmitting the completed response message to the client, the first signature information causing the client to determine validity of the completed response message.
5 . The method according to claim 1 , wherein the returning, to the client, the first initial response message generated based on the second response result comprises:
generating an initial response identifier for the second request message based on the second response result;
determining the initial response identifier, a first view number of the blockchain network, a request timestamp corresponding to the second request message, a client identifier corresponding to the client, a master node identifier, and the second response result as to-be- signed initial response information;
signing the to-be-signed initial response information by using a master node private key, to obtain second signature information; and
generating the first initial response message that carries the second signature information and the to-be-signed initial response information, and transmitting the first initial response message to the client, the second signature information causing the client to determine validity of the first initial response message.
6 . The method according to claim 1 , wherein generating the second prepared certificate corresponding to the second request message comprises:
generating a pre-prepare message based on the sequence number n+ 1 assigned to the second request message and the second request message;
broadcasting the pre-prepare message to the one or more backup nodes, for the one or more backup nodes to check the pre-prepare message to obtain a first check result, the first check result causing the backup node to generate, in response to the first check result being successful, a prepare message corresponding to the second request message; and
obtaining the prepare message returned by the one or more backup nodes, and generating the second prepared certificate corresponding to the second request message based on the obtained prepare message.
7 . The method according to claim 6 , wherein the generating a pre-prepare message based on the sequence number n+ 1 assigned to the second request message and the second request message comprises:
packaging the second request message to obtain a to-be-verified block, and determining a block hash value of the to-be-verified block as a block digest of the to-be-verified block;
generating a pre-prepare identifier corresponding to the to-be-verified block, and determining the pre-prepare identifier, a first view number of the blockchain network, the sequence number n+1, and the block digest as to-be-signed pre-prepare information;
signing the to-be-signed pre-prepare information by using a master node private key, to obtain third signature information; and
generating the pre-prepare message that carries the third signature information and the to-be-verified block.
8 . The method according to claim 6 , wherein the prepare message carries fourth signature information; the fourth signature information is generated by signing the prepare message using a backup node private key by a backup node that generates the prepare message; and
the generating the second prepared certificate corresponding to the second request message based on the obtained prepare message comprises:
for a prepare message:
performing signature verification on the fourth signature information carried by the prepare message by using a backup node public key corresponding to the backup node that generates the prepare message, to obtain a signature verification result corresponding to the fourth signature information;
checking the prepare message in response to the signature verification result corresponding to the fourth signature information being successful, to obtain a second check result;
adding the prepare message to a log database in response to the second check result being successful; and
combining, in response to the log database comprising prepare messages respectively corresponding to 2f backup nodes, the pre-prepare message and the 2f prepare messages into the second prepared certificate corresponding to the second request message, the 2f backup nodes belonging to 3f backup nodes, f being a positive integer, f representing a maximum quantity of invalid backup nodes, 3f representing a total quantity of backup nodes having consensus permission in the blockchain network, and both the invalid backup nodes and the 2f backup nodes belonging to the 3f backup nodes.
9 . A blockchain-based data processing method, the method being performed by a client, and the method comprising:
transmitting a second request message to nodes having consensus permission in a blockchain network, for a master node in the nodes having consensus permission to perform the following operations: assigning, in response to a first request message with a sequence number n having a first prepared certificate, a sequence number n+1 to the second request message, n being a positive integer; associatively storing the first request message and a first response result corresponding to the first request message to a ledger file in response to the second request message having a second prepared certificate, the first response result being obtained by performing an operation corresponding to the first request message in response to the first request message having the first prepared certificate;
performing in parallel a request operation corresponding to the second request message while associatively storing the first request message and the first response result to the ledger file, to obtain a second response result corresponding to the second request message and store the second response result to a cache file; generating a first initial response message for the second request message based on the second response result; and
obtaining the first initial response message returned by the master node, and determining a first request execution result corresponding to the second request message based on the first initial response message and a backup initial response message returned by a backup node in the nodes having consensus permission in the blockchain network.
10 . The method according to claim 9 , wherein the first initial response message and the backup initial response message carry to-be-signed initial response information, and the to-be-signed initial response information comprises a request timestamp of the second request message and the second response result; and
the determining the first request execution result corresponding to the second request message based on the first initial response message and the backup initial response message returned by the backup node in the nodes having consensus permission in the blockchain network comprises:
performing signature verification on the first initial response message to obtain a signature verification result corresponding to the first initial response message, and adding, to a candidate initial response set corresponding to an initial response identifier in response to the signature verification result of the first initial response message being successful, the request timestamp of the second request message and the second response result as a candidate initial response;
performing signature verification on the backup initial response message to obtain a signature verification result corresponding to the backup initial response message, and adding, to the candidate initial response set corresponding to the initial response identifier in response to the signature verification result corresponding to the backup initial response message being successful, the request timestamp and the second response result as a candidate initial response; and
determining the first request execution result corresponding to the second request message based on the candidate initial response set.
11 . The method according to claim 10 , wherein the determining the first request execution result corresponding to the second request message based on the candidate initial response set comprises:
determining, in a first request processing cycle in response to (2f+1) same candidate initial responses existing in the candidate initial response set, that the first request execution result corresponding to the second request message is successful; and
determining, in response to (2f+1) same candidate initial responses not existing in the candidate initial response set, that the first request execution result corresponding to the second request message is unsuccessful.
12 . The method according to claim 11 , further comprising:
determining an updated timestamp corresponding to the second request message based on the first request processing cycle in response to the first request execution result being unsuccessful;
retransmitting the second request message at a time point corresponding to the updated timestamp to (3f+1) nodes having consensus permission, for the (3f+1) nodes having consensus permission to separately determine request status of the second request message, a request state Hi causing a node Ji to determine an actual response result corresponding to the second request message, the actual response result causing the node Ji to generate an actual response message, i being a positive integer, i being less than or equal to 3f+1, the request state Hi belonging to (3f+1) request states, and the node Ji being a node at which the request state Hi is located in the (3f+1) nodes having consensus permission; and
obtaining the actual response message returned by the node Ji, and determining a request update execution result corresponding to the second request message based on the actual response message.
13 . The method according to claim 12 , wherein the determining the request update execution result corresponding to the second request message based on the actual response message comprises:
determining the request timestamp of the second request message and the actual response result as a candidate completed response in response to the actual response message comprising a completed response identifier;
adding the candidate completed response to a candidate completed response set corresponding to the completed response identifier, the candidate completed response set comprising L candidate completed responses, L being a positive integer, and L being less than or equal to 3f+1; and
determining a third request execution result corresponding to the second request message based on the candidate completed response set.
14 . The method according to claim 13 , wherein the determining a third request execution result corresponding to the second request message based on the candidate completed response set comprises:
determining, in a second request processing cycle in response to (f+1) same candidate completed responses existing in the candidate completed response set, that the third request execution result corresponding to the second request message is successful; and
determining, in response to (f+1) same candidate completed responses not existing in the candidate completed response set, that the third request execution result corresponding to the second request message is unsuccessful.
15 . A non-transitory computer-readable storage medium, the computer-readable storage medium storing a computer program, and the computer program being adapted to be loaded and executed by a processor, to enable the processor of a master node to perform:
assigning, in response to a first request message having a sequence number n and a first prepared certificate, a sequence number n+1 to a second request message, n being a positive integer;
associatively storing the first request message and a first response result corresponding to the first request message to a ledger file in response to the second request message having a second prepared certificate, the first response result being obtained by performing an operation corresponding to the first request message in response to the first request message having the first prepared certificate; performing in parallel a request operation corresponding to the second request message while associatively storing the first request message and the first response result to the ledger file, to obtain a second response result corresponding to the second request message and store the second response result to a cache file; and
returning, to a client that initiates the second request message, a first initial response message generated based on the second response result, for the client to determine a first request execution result corresponding to the second request message based on the first initial response message and a backup initial response message returned by each of the one or more backup nodes.
16 . The storage medium according to claim 15 , wherein the computer program further causes the processor to perform:
obtaining the second request message, and determining request status of the second request message; and
obtaining, in response to the request status being a request response state, the second response result corresponding to the second request message from the cache file, and returning, to the client, a second initial response message generated based on the second response result, for the client to determine a second request execution result corresponding to the second request message based on the second initial response message and a backup initial response message returned by the each of the one or more backup nodes, the request response state indicating that the second request message exists in the blockchain network and the master node has performed the request operation corresponding to the second request message;
obtaining, in response to the request status being a request write state, the second response result corresponding to the second request message from the ledger file, and returning, to the client, a completed response message generated based on the second response result, for the client to determine a third request execution result corresponding to the second request message based on the completed response message and a backup completed response message returned by the each of the one or more backup nodes, the request write state indicating that the second request message exists in the blockchain network and the master node has associatively stored the second request message and the second response result to the ledger file; and
performing, in response to the request status being a request initial state, the operation of assigning the sequence number n+1 to the second request message, the request initial state indicating that the second request message does not exist in the blockchain network.
17 . The storage medium according to claim 16 , wherein the determining the request status of the second request message comprises:
determining a request hash corresponding to the second request message, and comparing the request hash with a cache request hash in the cache file, a request message corresponding to the cache request hash in the cache file being a request message for which a request operation has been performed;
determining, in response to the cache file including a cache request hash that is the same as the request hash, that the request status of the second request message is the request response state;
comparing, in response to the cache file not including a cache request hash that is the same as the request hash, the request hash with a write request hash in the ledger file, a request message corresponding to the write request hash in the ledger file being a request message that has been stored;
determining, in response to the ledger file including a write request hash that is the same as the request hash, that the request status of the second request message is the request write state; and
determining, in response to the ledger file not including a write request hash that is the same as the request hash, that the request status of the second request message is the request initial state.
18 . The storage medium according to claim 16 , wherein the returning, to the client, the completed response message generated based on the second response result comprises:
generating a completed response identifier for the second request message based on the second response result;
determining the completed response identifier, a first view number of the blockchain network, a request timestamp corresponding to the second request message, a client identifier corresponding to the client, a master node identifier, and the second response result as to-be- signed completed response information;
signing the to-be-signed completed response information by using a master node private key, to obtain first signature information; and
generating the completed response message that carries the first signature information and the to-be-signed completed response information, and transmitting the completed response message to the client, the first signature information causing the client to determine validity of the completed response message.
19 . The storage medium according to claim 15 , wherein the returning, to the client, the first initial response message generated based on the second response result comprises:
generating an initial response identifier for the second request message based on the second response result;
determining the initial response identifier, a first view number of the blockchain network, a request timestamp corresponding to the second request message, a client identifier corresponding to the client, a master node identifier, and the second response result as to-be- signed initial response information;
signing the to-be-signed initial response information by using a master node private key, to obtain second signature information; and
generating the first initial response message that carries the second signature information and the to-be-signed initial response information, and transmitting the first initial response message to the client, the second signature information causing the client to determine validity of the first initial response message.
20 . The storage medium according to claim 15 , wherein generating the second prepared certificate corresponding to the second request message comprises:
generating a pre-prepare message based on the sequence number n+1 assigned to the second request message and the second request message;
broadcasting the pre-prepare message to the one or more backup nodes, for the one or more backup nodes to check the pre-prepare message to obtain a first check result, the first check result causing the backup node to generate, in response to the first check result being successful, a prepare message corresponding to the second request message; and
obtaining the prepare message returned by the one or more backup nodes, and generating the second prepared certificate corresponding to the second request message based on the obtained prepare message.