Disclosure of Invention
The invention aims to provide a method and equipment for realizing a block chain for running an intelligent contract.
In order to solve the above problem, the present invention provides a method for implementing a blockchain for running an intelligent contract, including:
dividing the block chain link point roles into a client, an accounting node and a common node group;
storing a set of public and private keys at the client, setting the client for initiating a transaction;
saving a group of key pairs at the accounting node, setting the accounting node as a storage distributed account book, and operating an intelligent contract and verifying a transaction;
storing a group of key pairs in the consensus nodes, setting the consensus nodes as a storage distributed account book, operating an intelligent contract, verifying transactions, sequencing a plurality of transactions in a block and achieving sequenced consensus among all the consensus nodes;
the client packs the intelligent contract calling instruction into a transaction proposal and initiates the transaction proposal to a plurality of accounting nodes;
each accounting node verifies the validity of the transaction proposal, executes the transaction proposal verified to be valid, and returns the proposal result to the client;
the client side waits for a plurality of accounting nodes to respond to the transaction proposal, compares the proposal results, re-initiates the transaction proposal if the proposal results are inconsistent, and submits the proposal results to a consensus node group if the proposal results are consistent;
the common identification node group collects the proposal result, verifies the validity of the proposal result, adds a serial number to the proposal result verified to be valid, packs the proposal result into an undetermined block when the serial number reaches a preset serial number threshold or the waiting time for collecting the proposal result reaches a preset time threshold, sends the undetermined block to the accounting node, verifies the transaction proposal in the undetermined block, packs the transaction proposal only containing successful verification into a block to be added to a block chain after the transaction proposal failed to be verified is eliminated, verifies the transaction proposal in the undetermined block after the accounting node receives the undetermined block of the common identification node, packs the transaction proposal only containing successful verification into a block to be added to the block chain after the transaction proposal failed to be verified is eliminated.
Further, in the above method, before the client packages the smart contract invocation instruction into a transaction proposal and initiates the transaction proposal to the plurality of accounting nodes, the method further includes:
dividing the corresponding operating systems of the client, the accounting nodes and the consensus node group into six parts including a data layer, a network layer, a consensus layer, a contract layer, an authorization layer and an application layer;
the data layer is set to comprise a key value database and a database management module, and is used for storing block data and data generated by intelligent contracts and providing an interface for increasing, deleting, modifying and checking the intelligent contract data, the data layer defines the structure of a distributed account book in the block chain, the account book consists of a block chain and a world state, wherein the block chain is a traceable linked list consisting of blocks, the blocks consist of block heads, block data and metadata, the blocks consist of transaction proposals, and the transaction proposals have two types: the method comprises the steps of deploying transaction and calling transaction, wherein the deploying transaction is a record for writing an intelligent contract file into a block, and the record content comprises a file source code, a deployer, a version number, configuration information and a transaction unique identifier; the calling transaction is the record of the intelligent contract calling process, and the record content comprises the block height of the intelligent contract source code, the transaction unique identifier, the intelligent contract method name, the calling parameter and the digital signatures of a transaction initiator and an executor; the world state is a set of states of all intelligent contracts, and the state is an expression mode of the intelligent contracts for finally operating the database; the intelligent contract operation result is represented by a read-write set, the read-write set consists of a read set and a write set, and the write set is a set of states generated by one-time calling of the intelligent contract;
the method comprises the steps that a network layer is set to manage a point-to-point network, the network layer comprises a data transmission protocol, a node exploration module, a data synchronization module and a broadcast transaction module, wherein the data transmission protocol is a final consistency algorithm and realizes a Gossip protocol and is used for synchronizing data of each node of a block chain, the synchronization process is a flow of sending, receiving, updating, sending back again and updating again in a synchronization period, one node is randomly selected in each period, and finally the data are spread to all nodes; the node exploration module manages a list of known node IP addresses in the network, the list is manually input when a blockchain network is deployed, when a new node joins the network, the exploration module generates an exploration message, the exploration message comprises authorization obtained by the node in the blockchain network and the known node list, the authorization is given by the authorization layer, the data transmission protocol sends and receives the exploration message, a receiver node is selected from the node list, an exploration message is broadcasted to the receiver, the exploration module of the receiver compares the local known node list after receiving the message, if the exploration message comprises a local node IP, the IP is added to the local node list, if the exploration message does not comprise the local node IP, the local list is not updated, an exploration response is sent back to a sender of the exploration message after the comparison is completed, and the exploration response content comprises the authorization of the node and the updated known node list, after receiving the exploration response, the receiver updates the local node list in the same way according to the response content, and then sends back a response message of the exploration response, and the receiver updates the node list again; the data synchronization module sends and receives data synchronization messages, the synchronization messages are divided into synchronization block heights and synchronization block data, the synchronization block heights comprise the local block heights of nodes and digital signatures of messages, the synchronization block data comprise block contents needing to be updated and digital signatures of the messages, the synchronization messages are broadcast to other nodes according to a data transmission protocol, the nodes send the synchronization block height messages at regular time, and when the receiver block heights are found to be larger than the block heights of the nodes, the synchronization block data messages are sent to obtain the latest blocks; the broadcast transaction module is divided into a client side, an accounting node side and a consensus node side, and provides different functions for different roles. The client side sends a transaction proposal generated by the application layer to the accounting node, the accounting node side sends an operation result back to the client side, the client side processes the result into a transaction message and sends the transaction message to the consensus node, the transaction message comprises a processing result of the accounting node and a digital signature of the message, and the consensus node side receives the transaction message and sends the consensus result to the accounting node after processing;
setting the consensus layer to enable all consensus nodes to form a consensus node group, wherein the consensus node group receives a transaction initiated by a client and sorts a plurality of transactions through a consensus algorithm, and the consensus algorithm is realized by a PBFT algorithm;
setting the contract layer to comprise an intelligent contract packaging and running system, a contract code checker and a transaction circulation module, wherein for the deployment transaction, the contract code checker performs static scanning on the intelligent contract code to intercept a malicious program, the packaging and running system checks whether the intelligent contract can be run by the system after checking, and the transaction circulation module sends the intelligent contract file to the network layer for processing after checking; for calling transaction, the contract code checker scans the intelligent contract code statically to intercept malicious programs, inputs input parameters contained in the transaction into the packaging and operating system after checking, the packaging and operating system operates the intelligent contract code and then outputs an operation result to the transaction circulation module, and the circulation module processes the operation result into a read-write set with a version number and sends the read-write set to a network layer for processing;
the authorization layer is set to comprise a digital certificate issuing mechanism and a node registration and verification module, wherein the authorization layer authorizes the node to join the block chain network and verifies the validity of the node;
the method comprises the steps that the application layer is set to comprise digital certificate and key management, a client side SDK, a command line interface and a remote calling interface, wherein the application layer provides an interactive mode of the client side and a block chain, and provides an application authorization API, a transaction proposal API, an authorization result callback API, an execution intelligent contract API and an execution result callback API for the client side in a code calling and command line mode.
Further, in the above method, the digital certificate issuing authority is commonly maintained by the related organizations participating in the smart contract, the digital certificate issuing authority holds a group of key pairs, the key pairs are generated by an ECDSA algorithm, the public keys in the key pairs held by the digital certificate issuing authority inform all nodes in the network, the private key in the key pair is owned by the issuing authority, the nodes can join the block chain network after being granted with the digital certificate and the private key by the digital certificate issuing authority, the digital signature algorithm ensures that the digital certificate and the private key cannot be forged, the digital signature uses a group of key pairs, the key pair used by the digital signature is signed and issued by the digital certificate issuing authority, the nodes need to apply for authorization to the digital certificate issuing authority before joining the network, the digital certificate issuing authority generates a group of key pairs for the nodes after applying, and the public keys and the node information are stored as the digital certificate, the digital certificate signing and issuing organization uses a private key of the digital certificate signing and issuing organization to digitally sign the certificate, the signed digital certificate and a node private key are stored by nodes, the nodes carry the digital certificate on all messages broadcasted in a network and use the private key of the digital certificate signing and digitally sign the messages, other nodes check the validity of a sender after receiving the broadcast, the check is divided into certificate validity check and certificate holding check, the certificate validity check is to check whether the certificate is generated by the digital certificate signing and issuing organization, an ECC algorithm is used to verify whether the content of the digital certificate is signed by the digital certificate signing and issuing organization, the certificate holding check ensures that the nodes obtain the certificate from the digital certificate signing and issuing organization but not copy the certificates of other nodes, and the ECC algorithm is used to verify whether the broadcast content and the broadcasted digital signature accord with a public key in the digital certificate.
Further, in the method, the client side SDK is divided into Java SDK, PHP SDK, Go SDK, and corresponds to the client sides implemented by different programming languages, respectively, and the client side SDK converts the codes of the different programming languages into JSON character strings and sends the JSON character strings to the remote invocation interface; the command line interface converts the input of the command line into a JSON character string and sends the JSON character string to the remote calling interface; the receiving and output data formats of the remote calling interface are JSON character strings, and data are transmitted through an HTTP (hyper text transport protocol), wherein for an application authorization API (application program interface), the received data are analyzed into application information and sent to a network layer, and the API is called back to notify a client through an authorization result; and for the transaction proposal API, analyzing the received data into an intelligent contract calling instruction, generating a transaction proposal digital signature by using a private key and attaching a digital certificate as a transaction proposal message to be sent to a network layer, and calling back the API to notify the client through the execution result after the local account book of the node is updated.
According to another aspect of the present invention, there is also provided a block chain implementation device for running an intelligent contract, including:
the client is used for packaging the intelligent contract calling instruction into a transaction proposal, initiating the transaction proposal to a plurality of accounting nodes, waiting for the plurality of accounting nodes to respond to the transaction proposal, comparing the proposal results, if the proposal results are not consistent, reinitiating the transaction proposal, and if the proposal results are consistent, submitting the proposal results to a consensus node group;
the system comprises a bookkeeping node, a block chain and a block chain, wherein the bookkeeping node is used for storing a group of key pairs, storing a distributed account book, operating an intelligent contract and verifying transactions, and is used for verifying the validity of a transaction proposal and executing the transaction proposal verified as valid, returning a proposal result to a client, verifying the transaction proposal in a pending block after the bookkeeping node receives the pending block of a common node, and packaging the transaction proposal only containing successful verification into a block after rejecting the transaction proposal failed verification to be added to the block chain;
the consensus node is used for storing a group of key pairs, storing a distributed account book, operating an intelligent contract, verifying transactions, sequencing a plurality of transactions in a block and achieving sequenced consensus among all the consensus nodes; the consensus node group is used for collecting the proposal result, verifying the validity of the proposal result, adding a serial number to the proposal result verified to be valid, packing the proposal result into an undetermined block when the serial number reaches a preset serial number threshold or the waiting time for collecting the proposal result reaches a preset time threshold, sending the undetermined block to the accounting node, verifying the transaction proposal in the undetermined block, and packing the transaction proposal only containing successful verification into a block after removing the transaction proposal failed in verification to be added to a block chain.
Further, the above apparatus further includes:
the data layer comprises a key value database and a database management module, the data layer is used for storing block data and data generated by intelligent contracts and providing an interface for increasing, deleting, modifying and checking the intelligent contract data, the data layer defines the structure of a distributed account book in a block chain, the account book consists of the block chain and world states, the block chain is a traceable linked list consisting of blocks, the blocks consist of block heads, block data and metadata, the blocks consist of transaction proposals, and the transaction proposals have two types: the method comprises the steps of deploying transaction and calling transaction, wherein the deploying transaction is a record for writing an intelligent contract file into a block, and the record content comprises a file source code, a deployer, a version number, configuration information and a transaction unique identifier; the calling transaction is the record of the intelligent contract calling process, and the record content comprises the block height of the intelligent contract source code, the transaction unique identifier, the intelligent contract method name, the calling parameter and the digital signatures of a transaction initiator and an executor; the world state is a set of states of all intelligent contracts, and the state is an expression mode of the intelligent contracts for finally operating the database; the intelligent contract operation result is represented by a read-write set, the read-write set consists of a read set and a write set, and the write set is a set of states generated by one-time calling of the intelligent contract;
the network layer is used for managing a point-to-point network and comprises a data transmission protocol, a node exploration module, a data synchronization module and a broadcast transaction module, wherein the data transmission protocol is a final consistency algorithm and realizes a Gossip protocol and is used for synchronizing data of each node of a block chain; a node discovery module for managing a list of known node IP addresses in the network, the list being manually entered when a blockchain network is deployed, the discovery module generating a discovery message when a new node joins the network, the discovery message including an authorization obtained by the node in the blockchain network and a list of known nodes, the authorization being given by said authorization layer, the data transfer protocol sending and receiving the discovery message, selecting a recipient node from the list of nodes, and broadcasting a discovery message to the recipient, the recipient's discovery module comparing the list of known nodes after receiving the message, adding an IP to the list of local nodes if the discovery message includes a locally unavailable IP, and not updating the local list if the IP is not included, sending back a discovery response to the sender of the discovery message after the comparison is completed, the discovery response including the node's own authorization and the updated list of known nodes, after receiving the exploration response, the receiver updates the local node list in the same way according to the response content, and then sends back a response message of the exploration response, and the receiver updates the node list again; the data synchronization module is used for sending and receiving data synchronization messages, the synchronization messages are divided into synchronization block heights and synchronization block data, the synchronization block heights comprise the local block heights of the nodes and digital signatures of the messages, the synchronization block data comprise block contents to be updated and digital signatures of the messages, the synchronization messages are broadcast to other nodes according to a data transmission protocol, the nodes send the synchronization block height messages at regular time, and when the receiver block heights are found to be larger than the block heights of the nodes, the synchronization block data messages are sent to obtain the latest blocks; the broadcast transaction module is used for being divided into a client side, an accounting node side and a consensus node side and providing different functions for different roles. The client side sends a transaction proposal generated by the application layer to the accounting node, the accounting node side sends an operation result back to the client side, the client side processes the result into a transaction message and sends the transaction message to the consensus node, the transaction message comprises a processing result of the accounting node and a digital signature of the message, and the consensus node side receives the transaction message and sends the consensus result to the accounting node after processing;
the system comprises a consensus layer and a consensus layer, wherein the consensus layer is used for enabling all consensus nodes to form a consensus node group, the consensus node group receives a transaction initiated by a client and sequences a plurality of transactions through a consensus algorithm, and the consensus algorithm is realized by a PBFT algorithm;
the contract layer comprises an intelligent contract packaging and operating system, a contract code checker and a transaction flow module, wherein for the deployment transaction, the contract code checker performs static scanning on the intelligent contract code to intercept a malicious program, the packaging and operating system checks whether the intelligent contract can be operated by the system after checking, and the transaction flow module sends the intelligent contract file to the network layer for processing after checking; for calling transaction, the contract code checker scans the intelligent contract code statically to intercept malicious programs, inputs input parameters contained in the transaction into the packaging and operating system after checking, the packaging and operating system operates the intelligent contract code and then outputs an operation result to the transaction circulation module, and the circulation module processes the operation result into a read-write set with a version number and sends the read-write set to a network layer for processing;
the authorization layer comprises a digital certificate issuing mechanism and a node registration and verification module, wherein the authorization layer authorizes the node and is used for joining the block chain network and verifying the validity of the node;
and the application layer comprises digital certificate and key management, a client SDK, a command line interface and a remote calling interface, wherein the application layer is used for providing an interactive mode of the client and the block chain, and providing an application authorization API, a transaction proposal API, an authorization result callback API, an execution intelligent contract API and an execution result callback API for the client in a code calling and command line mode.
Further, in the above device, the digital certificate issuing authority is commonly maintained by related organizations participating in the smart contract, the digital certificate issuing authority holds a group of key pairs, the key pairs are generated by an ECDSA algorithm, public keys in the key pairs held by the digital certificate issuing authority inform all nodes in the network, a private key in the key pair is owned by the issuing authority, the nodes can join the blockchain network only after being granted with the digital certificate and the private key by the digital certificate issuing authority, the digital certificate and the private key are guaranteed not to be forged by the digital signature algorithm, the digital signature uses a group of key pairs, the key pair used by the digital signature is signed and issued by the digital certificate issuing authority, the nodes need to apply for authorization to the digital certificate issuing authority before joining the network, the digital certificate issuing authority generates a group of key pairs for the nodes after applying, and the public keys and the node information are stored as the digital certificate, the digital certificate signing and issuing organization uses a private key of the digital certificate signing and issuing organization to digitally sign the certificate, the signed digital certificate and a node private key are stored by nodes, the nodes carry the digital certificate on all messages broadcasted in a network and use the private key of the digital certificate signing and digitally sign the messages, other nodes check the validity of a sender after receiving the broadcast, the check is divided into certificate validity check and certificate holding check, the certificate validity check is to check whether the certificate is generated by the digital certificate signing and issuing organization, an ECC algorithm is used to verify whether the content of the digital certificate is signed by the digital certificate signing and issuing organization, the certificate holding check ensures that the nodes obtain the certificate from the digital certificate signing and issuing organization but not copy the certificates of other nodes, and the ECC algorithm is used to verify whether the broadcast content and the broadcasted digital signature accord with a public key in the digital certificate.
Further, in the above device, the client SDK is divided into Java SDK, PHP SDK, Go SDK, and corresponds to clients implemented in different programming languages, respectively, and the client SDK is configured to convert codes of different programming languages into JSON character strings and send the JSON character strings to the remote invocation interface; the command line interface is used for converting the input of the command line into a JSON character string and sending the JSON character string to the remote calling interface; the receiving and output data formats of the remote calling interface are JSON character strings and are used for transmitting data through an HTTP (hyper text transport protocol), wherein for an application authorization API (application programming interface), the received data is analyzed into application information and sent to a network layer, and the API is called back to notify a client through an authorization result; and for the transaction proposal API, analyzing the received data into an intelligent contract calling instruction, generating a transaction proposal digital signature by using a private key and attaching a digital certificate as a transaction proposal message to be sent to a network layer, and calling back the API to notify the client through the execution result after the local account book of the node is updated.
According to another aspect of the present application, there is also provided a computer readable medium having computer readable instructions stored thereon, the computer readable instructions being executable by a processor to implement the method of any one of the above.
According to another aspect of the present application, there is also provided an apparatus for information processing at a network device, the apparatus comprising a memory for storing computer program instructions and a processor for executing the program instructions, wherein the computer program instructions, when executed by the processor, trigger the apparatus to perform any of the methods described above.
Compared with the prior art, the intelligent contract calling instruction is packaged into the transaction proposal through the client, and the transaction proposal is initiated to a plurality of accounting nodes; each accounting node verifies the validity of the transaction proposal, executes the transaction proposal verified to be valid, and returns the proposal result to the client; the client side waits for a plurality of accounting nodes to respond to the transaction proposal, compares the proposal results, re-initiates the transaction proposal if the proposal results are inconsistent, and submits the proposal results to a consensus node group if the proposal results are consistent; the consensus node group collects the proposal results, verifies the validity of the proposal results, adds sequence numbers to the proposal results verified to be valid, when the sequence number reaches a preset sequence number threshold or the waiting time for collecting the proposal result reaches a preset time threshold, packaging the proposed results into a pending block, sending the pending block to the accounting node, meanwhile, the transaction proposal in the pending block is verified, the transaction proposal which only contains successful verification is packed into a block and added to a block chain after the transaction proposal which fails verification is eliminated, meanwhile, after the bookkeeping node receives the undetermined block of the consensus node, the transaction proposal in the undetermined block is verified, the transaction proposal only containing successful verification is packed into a block to be added to the block chain after the transaction proposal with failed verification is removed, the process of operating the intelligent contract by the block chain is optimized, and the server burden of operating the block chain node can be effectively reduced.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below.
As shown in fig. 1, the present invention provides a method for implementing a blockchain for running an intelligent contract, including:
step S1, dividing the block chain link point roles into a client, an accounting node and a common node group;
step S2, storing a set of public and private keys at the client, and setting the client for initiating a transaction;
step S3, saving a group of key pairs in the accounting node, setting the accounting node as a storage distributed ledger, and operating intelligent contracts and verifying transactions;
step S4, a group of key pairs are stored in the consensus node, the consensus node is set to store a distributed account book, an intelligent contract is operated, the transaction is verified, a plurality of transactions in the block are sequenced, and the sequenced consensus is achieved among all the consensus nodes;
step S5, the client packs the intelligent contract calling instruction into a transaction proposal and initiates the transaction proposal to a plurality of accounting nodes;
step S6, each accounting node verifies the validity of the transaction proposal, executes the transaction proposal verified to be valid, and returns the proposal result to the client;
step S7, the client end waits for a plurality of accounting nodes to respond the transaction proposal, compares the proposal results, re-initiates the transaction proposal if the proposal results are not consistent, and submits the proposal results to a consensus node group if the proposal results are consistent;
step S8, the consensus node group collects the proposal result, verifies the validity of the proposal result, adds a serial number to the proposal result verified to be valid, packs the proposal result into an undetermined block when the serial number reaches a preset serial number threshold or the waiting time for collecting the proposal result reaches a preset time threshold, sends the undetermined block to the accounting node, verifies the transaction proposal in the undetermined block, packs the transaction proposal only containing successful verification into a block to be added to a block chain after removing the transaction proposal with failed verification, verifies the transaction proposal in the undetermined block after receiving the undetermined block of the consensus node, packs the transaction proposal only containing successful verification into a block to be added to the block chain after removing the transaction proposal with failed verification.
The client packs the intelligent contract calling instruction into a transaction proposal and initiates the transaction proposal to a plurality of accounting nodes; each accounting node verifies the validity of the transaction proposal, executes the transaction proposal verified to be valid, and returns the proposal result to the client; the client side waits for a plurality of accounting nodes to respond to the transaction proposal, compares the proposal results, re-initiates the transaction proposal if the proposal results are inconsistent, and submits the proposal results to a consensus node group if the proposal results are consistent; and the consensus node group collects the proposal result, verifies the validity of the proposal result, adds a serial number to the proposal result verified to be valid, packs the proposal result into a pending block when the serial number reaches a preset serial number threshold or the waiting time for collecting the proposal result reaches a preset time threshold, sends the pending block to the accounting node, verifies the transaction proposal in the pending block, packs the transaction proposal only containing successful verification into a block to be added to the block chain after removing the transaction proposal failed in verification, and simultaneously carries out the same verification operation and packs the transaction proposal into a block to be added to the block chain after receiving the pending block of the consensus node.
The block chain is realized by using a Go programming language, the intelligent contract running environment is Golang running, and the information broadcasted on the block chain is an intelligent contract execution instruction and result.
In an embodiment of the method for implementing a blockchain of running intelligent contracts, in step S5, the client packages an intelligent contract invocation instruction into a transaction proposal, and before initiating the transaction proposal to a plurality of accounting nodes, the method further includes:
dividing the corresponding operating systems of the client, the accounting nodes and the consensus node group into six parts including a data layer, a network layer, a consensus layer, a contract layer, an authorization layer and an application layer;
the data layer is set to comprise a key value database and a database management module, and is used for storing block data and data generated by intelligent contracts and providing an interface for increasing, deleting, modifying and checking the intelligent contract data, the data layer defines the structure of a distributed account book in the block chain, the account book consists of a block chain and a world state, wherein the block chain is a traceable linked list consisting of blocks, the blocks consist of block heads, block data and metadata, the blocks consist of transaction proposals, and the transaction proposals have two types: the method comprises the steps of deploying transaction and calling transaction, wherein the deploying transaction is a record for writing an intelligent contract file into a block, and the record content comprises a file source code, a deployer, a version number, configuration information and a transaction unique identifier; the calling transaction is the record of the intelligent contract calling process, and the record content comprises the block height of the intelligent contract source code, the transaction unique identifier, the intelligent contract method name, the calling parameter and the digital signatures of a transaction initiator and an executor; the world state is a set of states of all intelligent contracts, and the state is an expression mode of the intelligent contracts for finally operating the database; the intelligent contract operation result is represented by a read-write set, the read-write set consists of a read set and a write set, wherein the write set is a set of states generated by one-time calling of the intelligent contract, and the Data structure of the Block can be shown as a Block Header (Block Header), Data (Data) and metadata (Meta Data) in FIG. 2;
the network layer is arranged to manage a peer-to-peer network, the network layer comprising a data transmission protocol, a node discovery module, a data synchronization module and a broadcast transaction module, wherein,
the data transmission protocol is a final consistency algorithm, realizes a Gossip protocol and is used for synchronizing data of each node of a block chain, the synchronization process is a flow of sending, receiving, updating, sending back again and updating again in a synchronization period, each period randomly selects one node, and finally the data is transmitted to all nodes;
the node exploration module manages a list of known node IP addresses in the network, the list is manually input when a blockchain network is deployed, when a new node joins the network, the exploration module generates an exploration message, the exploration message comprises authorization obtained by the node in the blockchain network and the known node list, the authorization is given by the authorization layer, the data transmission protocol sends and receives the exploration message, a receiver node is selected from the node list, an exploration message is broadcasted to the receiver, the exploration module of the receiver compares the local known node list after receiving the message, if the exploration message comprises a local node IP, the IP is added to the local node list, if the exploration message does not comprise the local node IP, the local list is not updated, an exploration response is sent back to a sender of the exploration message after the comparison is completed, and the exploration response content comprises the authorization of the node and the updated known node list, after receiving the exploration response, the receiver updates the local node list in the same way according to the response content, and then sends back a response message of the exploration response, and the receiver updates the node list again;
the data synchronization module sends and receives data synchronization messages, the synchronization messages are divided into synchronization block heights and synchronization block data, the synchronization block heights comprise the local block heights of nodes and digital signatures of messages, the synchronization block data comprise block contents needing to be updated and digital signatures of the messages, the synchronization messages are broadcast to other nodes according to a data transmission protocol, the nodes send the synchronization block height messages at regular time, and when the receiver block heights are found to be larger than the block heights of the nodes, the synchronization block data messages are sent to obtain the latest blocks;
the broadcast transaction module is divided into a client side, an accounting node side and a consensus node side, and provides different functions for different roles. The client side sends a transaction proposal generated by the application layer to the accounting node, the accounting node side sends an operation result back to the client side, the client side processes the result into a transaction message and sends the transaction message to the consensus node, the transaction message comprises a processing result of the accounting node and a digital signature of the message, and the consensus node side receives the transaction message and sends the consensus result to the accounting node after processing;
the consensus layer is arranged to enable all consensus nodes to form a consensus node group, the consensus node group receives a transaction initiated by a client and sequences a plurality of transactions through a consensus algorithm, the consensus algorithm is realized by a PBFT algorithm, and the consensus node group can ensure that the sequencing of each transaction inside the node group is consistent;
setting the contract layer to comprise an intelligent contract packaging and running system, a contract code checker and a transaction circulation module, wherein for the deployment transaction, the contract code checker performs static scanning on the intelligent contract code to intercept a malicious program, the packaging and running system checks whether the intelligent contract can be run by the system after checking, and the transaction circulation module sends the intelligent contract file to the network layer for processing after checking; for calling transaction, the contract code checker scans the intelligent contract code statically to intercept malicious programs, inputs input parameters contained in the transaction into the packaging and operating system after checking, the packaging and operating system operates the intelligent contract code and then outputs an operation result to the transaction circulation module, and the circulation module processes the operation result into a read-write set with a version number and sends the read-write set to a network layer for processing;
the authorization layer is set to comprise a digital certificate issuing mechanism and a node registration and verification module, wherein the authorization layer authorizes the node to join the block chain network and verifies the validity of the node; the digital certificate signing and issuing organization is commonly maintained by related organizations participating in an intelligent contract, the digital certificate signing and issuing organization holds a group of key pairs, the key pairs are generated by an ECDSA algorithm, public keys in the key pairs held by the digital certificate signing and issuing organization inform all nodes in a network, a private key in the key pair is owned by the signing and issuing organization only, the nodes can be added into a block chain network after being granted with a digital certificate and a private key by the digital certificate signing and issuing organization, the digital certificate and the private key cannot be forged by the digital signature algorithm, the digital signature uses a group of key pairs, the key pair used by the digital signature is signed and issued by the digital certificate signing and issuing organization, the nodes are required to apply for authorization to the digital certificate signing and issuing organization before being added into the network, the digital certificate signing and issuing organization generates a group of key pairs for the nodes after applying, and stores the public key and the node information as a digital certificate, the digital certificate signing and issuing organization uses a private key of the digital certificate signing and issuing organization to digitally sign the certificate, the signed digital certificate and a node private key are stored by nodes, the nodes carry the digital certificate on all messages broadcasted in a network and use the private key of the digital certificate signing and digitally sign the messages, other nodes check the legality of a sender after receiving the broadcast, the check is divided into certificate validity check and certificate holding check, the certificate validity check is to check whether the certificate is generated by the digital certificate signing and issuing organization, an ECC algorithm is used to verify whether the content of the digital certificate is signed by the digital certificate signing and issuing organization, the certificate holding check ensures that the nodes obtain the certificate from the digital certificate signing and issuing organization but not copy the certificates of other nodes, and the ECC algorithm is used to verify whether the broadcast content and the broadcasted digital signature conform to the public key in the digital certificate;
setting the application layer to comprise digital certificate and key management, a client SDK, a command line interface and a remote calling interface, wherein the application layer provides an interactive mode of the client and a block chain, and provides an application authorization API, a transaction proposal API, an authorization result callback API, an execution intelligent contract API and an execution result callback API to the client in a code calling and command line mode;
the client side SDK is divided into Java SDK, PHP SDK and Go SDK which respectively correspond to client sides realized by different programming languages, and converts codes of different programming languages into JSON character strings and sends the JSON character strings to a remote calling interface; the command line interface converts the input of the command line into a JSON character string and sends the JSON character string to the remote calling interface; the receiving and output data format of the remote calling interface is JSON character string, and transmits data through HTTP protocol, wherein,
for the application authorization API, analyzing the received data into application information, sending the application information to the network layer, and calling back the API to notify the client through an authorization result; and for the transaction proposal API, analyzing the received data into an intelligent contract calling instruction, generating a transaction proposal digital signature by using a private key and attaching a digital certificate as a transaction proposal message to be sent to a network layer, and calling back the API to notify the client through the execution result after the local account book of the node is updated.
According to another aspect of the present invention, there is also provided a block chain implementation device for running an intelligent contract, including:
the client is used for packaging the intelligent contract calling instruction into a transaction proposal, initiating the transaction proposal to a plurality of accounting nodes, waiting for the plurality of accounting nodes to respond to the transaction proposal, comparing the proposal results, if the proposal results are not consistent, reinitiating the transaction proposal, and if the proposal results are consistent, submitting the proposal results to a consensus node group;
the system comprises a bookkeeping node, a block chain and a block chain, wherein the bookkeeping node is used for storing a group of key pairs, storing a distributed account book, operating an intelligent contract and verifying transactions, and is used for verifying the validity of a transaction proposal and executing the transaction proposal verified as valid, returning a proposal result to a client, verifying the transaction proposal in a pending block after the bookkeeping node receives the pending block of a common node, and packaging the transaction proposal only containing successful verification into a block after rejecting the transaction proposal failed verification to be added to the block chain;
the consensus node is used for storing a group of key pairs, storing a distributed account book, operating an intelligent contract, verifying transactions, sequencing a plurality of transactions in a block and achieving sequenced consensus among all the consensus nodes; the consensus node group is used for collecting the proposal result, verifying the validity of the proposal result, adding a serial number to the proposal result verified to be valid, packing the proposal result into an undetermined block when the serial number reaches a preset serial number threshold or the waiting time for collecting the proposal result reaches a preset time threshold, sending the undetermined block to the accounting node, verifying the transaction proposal in the undetermined block, and packing the transaction proposal only containing successful verification into a block after removing the transaction proposal failed in verification to be added to a block chain.
In an embodiment of the block chain implementation device for running the intelligent contract, the block chain implementation device includes:
the data layer comprises a key value database and a database management module, the data layer is used for storing block data and data generated by intelligent contracts and providing an interface for increasing, deleting, modifying and checking the intelligent contract data, the data layer defines the structure of a distributed account book in a block chain, the account book consists of the block chain and world states, the block chain is a traceable linked list consisting of blocks, the blocks consist of block heads, block data and metadata, the blocks consist of transaction proposals, and the transaction proposals have two types: the method comprises the steps of deploying transaction and calling transaction, wherein the deploying transaction is a record for writing an intelligent contract file into a block, and the record content comprises a file source code, a deployer, a version number, configuration information and a transaction unique identifier; the calling transaction is the record of the intelligent contract calling process, and the record content comprises the block height of the intelligent contract source code, the transaction unique identifier, the intelligent contract method name, the calling parameter and the digital signatures of a transaction initiator and an executor; the world state is a set of states of all intelligent contracts, and the state is an expression mode of the intelligent contracts for finally operating the database; the intelligent contract operation result is represented by a read-write set, the read-write set consists of a read set and a write set, and the write set is a set of states generated by one-time calling of the intelligent contract;
the network layer is used for managing a point-to-point network and comprises a data transmission protocol, a node exploration module, a data synchronization module and a broadcast transaction module, wherein the data transmission protocol is a final consistency algorithm and realizes a Gossip protocol and is used for synchronizing data of each node of a block chain; a node discovery module for managing a list of known node IP addresses in the network, the list being manually entered when a blockchain network is deployed, the discovery module generating a discovery message when a new node joins the network, the discovery message including an authorization obtained by the node in the blockchain network and a list of known nodes, the authorization being given by said authorization layer, the data transfer protocol sending and receiving the discovery message, selecting a recipient node from the list of nodes, and broadcasting a discovery message to the recipient, the recipient's discovery module comparing the list of known nodes after receiving the message, adding an IP to the list of local nodes if the discovery message includes a locally unavailable IP, and not updating the local list if the IP is not included, sending back a discovery response to the sender of the discovery message after the comparison is completed, the discovery response including the node's own authorization and the updated list of known nodes, after receiving the exploration response, the receiver updates the local node list in the same way according to the response content, and then sends back a response message of the exploration response, and the receiver updates the node list again; the data synchronization module is used for sending and receiving data synchronization messages, the synchronization messages are divided into synchronization block heights and synchronization block data, the synchronization block heights comprise the local block heights of the nodes and digital signatures of the messages, the synchronization block data comprise block contents to be updated and digital signatures of the messages, the synchronization messages are broadcast to other nodes according to a data transmission protocol, the nodes send the synchronization block height messages at regular time, and when the receiver block heights are found to be larger than the block heights of the nodes, the synchronization block data messages are sent to obtain the latest blocks; the broadcast transaction module is used for being divided into a client side, an accounting node side and a consensus node side and providing different functions for different roles. The client side sends a transaction proposal generated by the application layer to the accounting node, the accounting node side sends an operation result back to the client side, the client side processes the result into a transaction message and sends the transaction message to the consensus node, the transaction message comprises a processing result of the accounting node and a digital signature of the message, and the consensus node side receives the transaction message and sends the consensus result to the accounting node after processing;
the system comprises a consensus layer and a consensus layer, wherein the consensus layer is used for enabling all consensus nodes to form a consensus node group, the consensus node group receives a transaction initiated by a client and sequences a plurality of transactions through a consensus algorithm, and the consensus algorithm is realized by a PBFT algorithm;
the contract layer comprises an intelligent contract packaging and operating system, a contract code checker and a transaction flow module, wherein for the deployment transaction, the contract code checker performs static scanning on the intelligent contract code to intercept a malicious program, the packaging and operating system checks whether the intelligent contract can be operated by the system after checking, and the transaction flow module sends the intelligent contract file to the network layer for processing after checking; for calling transaction, the contract code checker scans the intelligent contract code statically to intercept malicious programs, inputs input parameters contained in the transaction into the packaging and operating system after checking, the packaging and operating system operates the intelligent contract code and then outputs an operation result to the transaction circulation module, and the circulation module processes the operation result into a read-write set with a version number and sends the read-write set to a network layer for processing;
the authorization layer comprises a digital certificate issuing mechanism and a node registration and verification module, wherein the authorization layer authorizes the node and is used for joining the block chain network and verifying the validity of the node;
and the application layer comprises digital certificate and key management, a client SDK, a command line interface and a remote calling interface, wherein the application layer is used for providing an interactive mode of the client and the block chain, and providing an application authorization API, a transaction proposal API, an authorization result callback API, an execution intelligent contract API and an execution result callback API for the client in a code calling and command line mode.
In one embodiment of the block chain implementation device for operating the intelligent contract, the digital certificate issuing authority is commonly maintained by related organizations participating in the intelligent contract, the digital certificate issuing authority holds a group of key pairs, the key pairs are generated by an ECDSA algorithm, public keys in the key pairs held by the digital certificate issuing authority inform all nodes in a network, private keys in the key pairs only have the issuing authority, the nodes can be added into the block chain network after being granted with digital certificates and private keys by the digital certificate issuing authority, the digital certificates and the private keys are guaranteed to be unforgeable by a digital signature algorithm, the digital signatures use a group of key pairs, the key pairs used by the digital signatures are signed and issued by the digital certificate issuing authority, the nodes need to apply for authorization to the digital certificate issuing authority before adding into the network, and the digital certificate issuing authority generates a group of key pairs for the nodes after applying, the public key and the node information are stored as a digital certificate, a digital certificate signing authority uses a self private key to digitally sign the certificate, the signed digital certificate and the node private key are stored by the node, the node carries the digital certificate on all messages broadcast in the network and uses the self private key to digitally sign the messages, and the other nodes check the legality of the sender after receiving the broadcast, wherein the check comprises certificate validity check and certificate holding check, the certificate validity check is to check whether the certificate is generated by the digital certificate issuing authority, an ECC algorithm is used for verifying whether the content of the digital certificate is signed by the digital certificate issuing authority, the certificate holding check ensures that the nodes obtain the certificate from the digital certificate issuing authority instead of copying the certificates of the other nodes, and the ECC algorithm is used for verifying whether the broadcast content and the broadcast digital signature conform to the public key in the digital certificate.
In an embodiment of the block chain implementation device for running the intelligent contract, the client SDK is divided into Java SDK, PHP SDK and Go SDK, and corresponds to clients implemented by different programming languages, respectively, and the client SDK is used for converting codes of different programming languages into JSON character strings and sending the JSON character strings to the remote call interface; the command line interface is used for converting the input of the command line into a JSON character string and sending the JSON character string to the remote calling interface; the receiving and output data formats of the remote calling interface are JSON character strings and are used for transmitting data through an HTTP (hyper text transport protocol), wherein for an application authorization API (application programming interface), the received data is analyzed into application information and sent to a network layer, and the API is called back to notify a client through an authorization result; and for the transaction proposal API, analyzing the received data into an intelligent contract calling instruction, generating a transaction proposal digital signature by using a private key and attaching a digital certificate as a transaction proposal message to be sent to a network layer, and calling back the API to notify the client through the execution result after the local account book of the node is updated.
According to another aspect of the present application, there is also provided a computer readable medium having computer readable instructions stored thereon, the computer readable instructions being executable by a processor to implement the method of any one of the above.
According to another aspect of the present application, there is also provided an apparatus for information processing at a network device, the apparatus comprising a memory for storing computer program instructions and a processor for executing the program instructions, wherein the computer program instructions, when executed by the processor, trigger the apparatus to perform any of the methods described above.
For details of the embodiments of the apparatuses and the storage medium, reference may be made to corresponding parts of the embodiments of the methods, and details are not described herein again.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It will be apparent to those skilled in the art that various changes and modifications may be made in the invention without departing from the spirit and scope of the invention. Thus, if such modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include such modifications and variations.