Method and apparatus for editing block chain
This application provides a method and an apparatus for editing a block chain. The method for editing a block chain includes: A first node receives a request message used to request to edit data, and performs endorsement on the request message to generate an endorsement result. Further, the first node sends the endorsement result to each of at least one second node, where the at least one second node belongs to a second node set. The node with the endorsement function in the block chain performs endorsement on an editing request, and sends an endorsement result to a node with an editing function, to implement block chain editing while improving security assurance.
1 . A method of editing a blockchain, comprising:
receiving, by a first node, a request message, wherein the request message requests to edit data, and the data comprise a transaction or a block in the blockchain;
performing, by the first node, endorsement on the request message to generate an endorsement result; and
sending, by the first node, the endorsement result to each of one or more second nodes in a second node set, wherein
the first node is any one of a plurality of first nodes configured to perform an endorsement function in the blockchain,
each of the one or more second nodes is configured to perform an editing function in the blockchain,
each of the one or more second nodes knows a private key slice corresponding to the second node, and a public key corresponding to the second node set,
the public key is determined based on one or more public key slices each respectively corresponding to one of the one or more second nodes, and
the method further comprises verifying, by the first node, a hash collision based on a first hash value and a first random number, wherein
the first hash value and the first random number are obtained based on one or more second hash values and one or more second random numbers, and
each of the one or more second nodes is configured to calculate, based on the private key slice corresponding to the second node,
one of the one or more second hash values, and
one of the one or more second random numbers.
2 . The method according to claim 1 , wherein the method further comprises:
determining, by the first node, that the request message has permission to request to edit the data.
3 . The method according to claim 1 , wherein before the sending, by the first node, the endorsement result to each of the one or more second nodes, the method further comprises:
determining, by the first node, the second node set based on
the data, or
an identifier, wherein the identifier is carried in the request message, and the identifier indicates the second node set.
4 . The method according to claim 1 , wherein before the receiving, by the first node, the request message, the method further comprises:
receiving, by the first node, the data; and
verifying, by the first node, the data based on the public key, wherein the verifying comprises performing hash calculation and signing based on the public key.
5 . The method according to claim 4 , wherein before the verifying, by the first node, the data based on the public key, the method further comprises:
determining, by the first node, the second node set; and
determining, by the first node, the public key based on the second node set.
6 . The method according to claim 5 , wherein the determining, by the first node, the second node set comprises:
determining, by the first node, the second node set based on
preconfigured information, wherein the preconfigured information indicates that the data correspond to the second node set, or
an identifier carried in the request message, wherein the identifier indicates the second node set.
7 . The method according to claim 1 , wherein the method further comprises:
sending, by the first node, a response message to a client that sent the request message, wherein the response message comprises an editing result corresponding to the data.
8 . The method according to claim 1 , wherein the blockchain comprises a consortium blockchain.
9 . A method of editing a blockchain, comprising:
sending, by a client, a request message to each of a plurality of first nodes, wherein the request message requests to edit data, the data comprise a block or a transaction in the blockchain, the request message comprises an identifier, and the identifier indicates a second node set; and
receiving, by the client, a response message from each of the plurality of first nodes, wherein the response message comprises an editing result corresponding to the data, wherein
each of the plurality of first nodes is configured to perform an endorsement function in the blockchain,
the second node set comprises one or more second nodes each of which is configured to perform an editing function in the blockchain,
each of the one or more second nodes knows a private key slice corresponding to the second node, and a public key corresponding to the second node set,
the public key is determined based on one or more public key slices each respectively corresponding to one of the one or more second nodes,
each of the plurality of first nodes is configured to
perform endorsement on the request message to generate an endorsement result,
send the endorsement result to each of the one or more second nodes in the second node set, and
verify a hash collision based on a first hash value and a first random number,
the first hash value and the first random number are obtained based on one or more second hash values and one or more second random numbers, and
each of the one or more second nodes is configured to calculate, based on the private key slice corresponding to the second node,
one of the one or more second hash values, and
one of the one or more second random numbers.
10 . The method according to claim 9 , wherein before the sending, by the client, the request message to each of the plurality of first nodes, the method further comprises:
sending, by the client, the data to each of the plurality of first nodes; and
receiving, by the client, a verification result from each of the plurality of first nodes, wherein
the verification result comprises a result of performing hash calculation and signing based on the public key.
11 . A method of editing a blockchain, wherein the blockchain comprises a second node set, the second node set comprises a plurality of second nodes each of which is configured to perform an editing function in the blockchain, the method is performed by each second node of the plurality of second nodes, and the method comprises:
generating, by the second node, a private key slice and a public key slice that correspond to the second node;
sending, by the second node, the public key slice corresponding to the second node to other second nodes than the second node in the second node set;
receiving, by the second node, a public key slice that corresponds to each of the other second nodes and that is sent by said each of the other second nodes;
calculating, by the second node, a public key corresponding to the second node set based on the public key slice corresponding to each of the plurality of second nodes in the second node set;
sending, by the second node, the public key to a plurality of nodes in the blockchain;
receiving, by the second node, an endorsement result that is of a request message and that is sent by each of a plurality of first nodes, wherein each of the plurality of first nodes is configured to perform an endorsement function in the blockchain, the request message requests to edit data, and the data comprise a transaction or a block in the blockchain;
in response to determining that a quantity of the received endorsement results satisfies a preset value, calculating, by the second node based on the private key slice corresponding to the second node, a second hash value and a second random number that correspond to the second node;
receiving, by the second node, a second hash value and a second random number that correspond to each of the other second nodes and that are sent by said each of the other second nodes:
calculating, by the second node, a first hash value and a first random number based on the second hash value and the second random number that correspond to each of the plurality of second nodes in the second node set; and
sending, by the second node, the first hash value and the first random number to the plurality of first nodes in the blockchain, wherein each of the plurality of first nodes is configured to verify a hash collision based on the first hash value and the first random number.