Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In the public chain, the nodes can freely join and leave the block chain network, the nodes can join in consensus, data in the whole network can be read, and transactions can be sent without limitation. A federation chain is a block chain network that verifies and authorizes admission of nodes. The alliance chain block chain network is a distributed ledger node network which has known node identities and authenticates and authorizes the node identities. The technology of the alliance chain has its own specialized software design and source code engineering implementation. The mainstream alliance chain items include super book Fabric, R3 Corda, Qurom, BCOS and other items, which use different architectural designs, system models, component models and programming languages, including Go language, C + + language and Kotlin language under the Java system. The mainstream public link items include Bitcoin, Ethereum and the like, and the Account models are different, wherein Bitcoin is a UXTO Account model, Ethereum is an Account Account model, programming languages are different, Bitcoin is developed in a C + + language, and Ethereum is developed in a Go language. If the project of the public chain is to be transformed into the alliance chain, a great deal of effort is required. The same problem exists in the process of modifying the existing mainstream alliance chain into the alliance chain project. The same code is used to meet the requirements of the public chain and the alliance chain project at the same time, and the technical problem to be solved is urgent.
In view of the deficiency of the prior art, fig. 1 is a schematic structural diagram of a block chain node provided in the present invention, and as shown in fig. 1, ablock chain node 100 includes:
thenetwork layer 110 is connected with network layers of other block chain nodes in the block chain and used for acquiring to-be-processed transaction data in the block chain;
theconsensus layer 120 is connected with thenetwork layer 110 and used for determining a consensus result of the transaction data to be processed;
anapplication layer 130 connected with theconsensus layer 120 and including astandard module 131 and anextension module 132; thestandard module 131 is configured to process the transaction data to be processed based on the standard service processing logic and the consensus result; theexpansion module 132 is configured to process the transaction data to be processed based on the extra service processing logic; theextension module 132 corresponds to the type of blockchain; the additional business processing logic is business processing logic other than the standard business processing logic.
Specifically, the nodes of the public chain and the federation chain can be analyzed, the common part of the nodes is realized by using a universal module, and the difference part of the nodes is completed by using independent modules. Different modules are called according to the type of blockchain. Therefore, theblockchain node 100 can be functionally decoupled and then divided into three layers, namely anetwork layer 110, aconsensus layer 120 and anapplication layer 130. And the layers are connected by adopting an interface protocol.
Thenetwork layers 110 of the nodes in the blockchain are interconnected to obtain the transaction data to be processed in the blockchain. The transaction data to be processed is the transaction data submitted by the user through the terminal, the transaction data to be processed needs to be packaged into blocks, and after consensus, a block chain is generated. The business type corresponding to the transaction data to be processed can be commodity transaction, energy transaction, financial transaction and the like. The embodiment of the present invention does not specifically limit the service type of the transaction data to be processed. For example, when the service type corresponding to the transaction data to be processed is an energy transaction, the transaction data to be processed may include a transaction id (identity document), seller personal information, buyer personal information, an energy type, seller energy storage amount, energy transaction amount, bidding times, bidding duration, bargaining price, transaction amount, transaction time, and the like.
Theconsensus layer 120 is coupled to thenetwork layer 110 for determining a consensus result for the pending transaction data. Consensus refers to the process by whichblockchain nodes 100 in a blockchain validate and validate submitted transaction data to be processed to allow the generation of new blocks. The consensus method comprises agent consensus and whole member consensus. The agent consensus is to select a plurality of nodes from all nodes in the blockchain network as agent nodes, so that all nodes in the agent network agree on the block. The global consensus is performed for all nodes in the blockchain network to agree on the block. The consensus algorithm adopted by the consensus layer includes pow (Proof Of work), pos (Proof Of stamp), dpos (delayed Proof Of stamp), BFT (Byzantine Fault Tolerance), and the like.
The traffic processing logic in the blockchain may include standard traffic processing logic and additional traffic processing logic. Theapplication layer 130 is connected to theconsensus layer 120, and adopts a modular architecture, which is composed ofstandard modules 131 andextension modules 132. Theapplication layer 130 processes the consensus result through thestandard module 131 to determine the state of the blockchain. If the transaction data to be processed passes the consensus, thestandard module 131 adds the block generated by the transaction data to be processed into the block chain according to the consensus result and the standard service processing logic, and updates the state of the block chain. The state of the block chain specifically refers to the state of each node. When a node in the blockchain performs a transaction, the state of the node changes. For example, consensus algorithms require a node to achieve consensus at intervals, which is a state at intervals from the perspective of a state machine. For another example, when a block appears in the block chain, after each node recognizes the block, and processes the transaction data corresponding to the block, a block is newly added to the node, so as to update the state. For another example, the blockchain is an energy trading market, and the state changes once after each energy trading is finished, and is an ongoing reinforcement learning process of "state-action-reward", wherein the state is a market environment, the action is a trade, and the reward is a utility obtained by two trading parties.
Theapplication layer 130 processes the pending transaction data via theextension module 132, such as settling transaction fees based on the pending transaction data, and the like.
The number of theextension modules 132 may be plural, and the configuration may be selected according to the type of the block chain. Types of blockchains include public chains and federation chains. For example, if the blockchain is a public chain, theextension module 132 may include a certification module and a cost module, and if the blockchain is a federation chain, theextension module 132 may include a node authorization module.
Thestandard module 131 in thenetwork layer 110, theconsensus layer 120, and theapplication layer 130 provides a standardized basic template for building the blockchain, and is a basic standard framework for blockchain development, the specific characteristics of the blockchain are determined by theextension module 132 in theapplication layer 130, and the built blockchain can be used for both a federation chain and a public chain by adding and deleting the third-party extension module 132.
The block chain node provided by the embodiment of the invention comprises a network layer, a consensus layer and an application layer, wherein the network layer is used for acquiring to-be-processed transaction data in a block chain, the consensus layer is used for determining a consensus result of the to-be-processed transaction data, the application layer is used for processing the consensus result, determining the state of the block chain and processing the to-be-processed transaction data, and an extension module in the application layer is determined by the type of the block chain.
Based on the above embodiment, the standard business processing logic includes validating and executing the transaction data to be processed based on the consensus result, and updating the state of the blockchain.
Specifically, thestandard module 131 is configured to verify and execute the transaction data to be processed based on the consensus result, and determine the state of the blockchain; theexpansion module 132 is configured to process the transaction data to be processed based on the additional business processing logic.
The state of the block chain specifically refers to the state of each node. When a node in the blockchain performs a transaction, the state of the node changes. Thestandard module 131 is mainly used for verifying and executing the transaction data to be processed according to the consensus result, and determining the state of the block chain.
Theexpansion module 132 is mainly used for processing transaction data to be processed based on additional business processing logic. The extra business processing logic is used for expressing a processing method or a processing mode of the transaction data to be processed, and is a supplement to the standard business processing logic. Since the service types of the transaction data to be processed are different for different types of blockchains, the type of theextension module 132 is different according to the type of blockchain.
Based on any of the above embodiments, the application layer uses a finite state machine model.
In particular, a finite state machine is a tool used for modeling the behavior of an object, and the role of the finite state machine is mainly to describe the state sequence that the object experiences in the life cycle of the object and how to respond to various events from the outside world. In the block chain, each node can be regarded as a state machine, the whole network is changed dynamically, and the dynamic state of the whole network can be grasped through the state machine. The nodes may be used to generate the tiles and may also perform various actions based on the tiles, such as transactions, verifications, broadcasts, and so on. Each node has a different state and the network node part of the block chain can be described explicitly by a state machine.
The state data in the state machine describes the current state of the blockchain system. The transactions of the blockchain are propagated and identified through the network, and then the execution of a state transfer function in the state machine is triggered, so that the state of the blockchain is changed. Through a consensus mechanism, each blockchain node executes the same transaction sequence from the same initial state to achieve the same final state.
Based on any of the above embodiments, theapplication layer 130 further performs validity check on the transaction data to be processed based on the current state of theblockchain node 100, and the transaction data to be processed is stored in the transaction queue pool.
Specifically, the user may store the pending transaction data in the transaction queue pool according to an RPC (Remote Procedure Call) service through the client. The implementation can be realized by adopting a queue and a buffer.
Theapplication layer 130 checks the validity of the transaction data to be processed according to the current state of theblock chain node 100, identifies valid transactions and invalid transactions, theconsensus layer 120 receives the valid transactions, packs the valid transactions into blocks, performs consensus by using a BFT algorithm, and then triggers theapplication layer 130 to change the current state of the block chain.
Theexpansion module 132 includes at least one of a certification module, a fee module, and a node authorization module according to any of the above embodiments.
Specifically, the certification module, the cost module, and the node authorization module may be determined according to the type of the blockchain.
The evidence-passing module is used for confirming whether the transaction has native evidence. A pass is a digital form of a rights voucher that represents an inherent and inherent value. The authenticity, tamper resistance, privacy protection and other capabilities of the certificate are guaranteed by cryptography. The certificate must be able to flow in a network so that it can be verified anytime and anywhere.
The fee module is used for settling fees in the transaction process. For example, the fee module may be used to settle transaction fees when transaction processing requires a fee to be made by a procedure.
For public links, node authorization is not required as nodes can freely join and leave the blockchain network. And for the alliance chain, the admission of the node can be verified and authorized through the node authorization module. Therefore, when building a blockchain, if the type of the blockchain is a federation chain, a node authorization module needs to be added.
Based on any of the above embodiments, the node authorization module is configured to:
determining an authorization result of each node in the block chain based on the authorization node list;
the authorized node list stores authorized nodes and connection information between the authorized nodes in a binary tree mapping data structure.
In particular, the node authorization module may determine the authorization result of each node in the blockchain according to the authorized node list. The authorized node list includes authorized nodes and connection information between the authorized nodes, and the connection information can be stored in the blockchain node as a configuration file. The storage may be in the form of a binary tree mapping data structure.
The use method of the node authorization module comprises the following steps:
firstly, adding an authorized node list capable of participating in a network node of a alliance chain, and using the authorized node list as a configuration file;
and secondly, reading the configured authorized node list in the node starting process, wherein the node connection information comprises an address and a public key, and storing the connection node list by using binary tree mapping. The network node list provided in the configuration file is an initial value of the binary tree mapping;
thirdly, an administrator account exists in the alliance chain network, the new node is dynamically added into the binary tree mapping data structure by sending the node adding message type, and the new node is synchronized to other trusted nodes;
and fourthly, adding a function for judging whether the nodes allow connection or not according to the node connection list. And if the node is in the node authorization list, allowing the node to connect and join the block chain network to form the point-to-point communication network. And if the node identity is not in the authorization list of the node participating in the alliance chain, refusing the connection, joining and synchronization of illegal nodes.
Based on any of the above embodiments, thenetwork layer 110 is implemented based on LibP2P, and is further configured to implement message broadcasting, event subscription publishing, and node self-discovery in a blockchain.
In particular, LibP2P is a modular network stack that allows developers to easily build large, robust P2P networks by combining various transport and P2P protocols.
Through thebuild network layer 110 of LibP2P, message broadcasting, event subscription publishing, and node self-discovery may be implemented in a blockchain. The architecture of LibP2P includes a node routing module, a connection processing module, a distributed record storage module, and a discovery module. Wherein the node routing module is configured to determine which nodes to use for routing the specified message. This routing mechanism can be done recursively even in broadcast/multicast mode. The connection processing module is responsible for the creation, maintenance and destruction of the connection between the management nodes, including protocol multiplexing, stream multiplexing and connection relaying, and performs multiplexing transmission at the same time. The distributed record storage module is used for recording various information related to the nodes, and is convenient for connection management and content addressing. The discovery module is used to discover and identify other nodes in the network.
Libp2p integrates various transport protocols and point-to-point protocols, and its main role is to discover nodes and contents and to enable different network protocols to smoothly transfer data between each other.
Based on any of the above embodiments, theconsensus layer 120 is further configured to generate a block corresponding to the pending transaction data based on the pending transaction data.
Specifically, the user may initiate a transaction request to theblockchain node 100 in the blockchain network through the terminal, and submit the pending transaction data. Theconsensus layer 120 in theblock chain node 100 performs corresponding data processing according to the transaction data to be processed, for example, requests other block chain link points to perform consensus processing on the transaction data to be processed, so as to generate a block corresponding to the transaction data to be processed.
Based on any of the above embodiments, an embodiment of the present invention provides a blockchain system, which includes a plurality of blockchain nodes, and the type of the blockchain system is a public chain or a federation chain.
Specifically, the embodiment of the present invention provides a blockchain system that supports both public and alliance chains. The block chain system achieves the purpose of simultaneously supporting the alliance chain and the public chain in a low-cost and high-flexibility mode by adding and deleting third-party extension modules on the basis of the same code base according to the design concept of a layering and decoupling framework.
Fig. 2 is a schematic diagram of a homologous amphibious blockchain node provided in the present invention, and as shown in fig. 2, the node is a basic unit of a blockchain distributed network networking. The nodes of the homologous amphibious block chain are composed of a basic service part and an extended service part, wherein the basic service part comprises a network service part and a consensus service part, the extended service part is a state machine application part, is a modular framework and is composed of a standard module and an extended module.
The basic service provides uniform standardized service for the state machine application, and the state machine application is subjected to function expansion by adding or deleting a third-party module by an expansion module.
The network layer for providing basic service is realized by engineering provided by LibP2P, provides functions of interconnection among nodes, message broadcasting, message receiving and sending, event subscription and publishing, node self-discovery and the like, is responsible for data communication in the whole block chain network, and provides basic network service for the consensus layer. The consensus layer is a consensus engine, is realized by adopting a BFT consensus algorithm, and is responsible for consensus on messages, transactions and votes and packaging blocks. The consensus engine provides certainty for the transaction, and enables the state machine to execute the same transaction sequence from the same initial state through the interface protocol, and the same final state is achieved. The consensus engine mainly handles two types of tasks: the system comprises consensus logic and network logic, wherein the consensus logic provides support for state machine application, and the network logic relies on a network layer to process consensus and external services.
The state machine application providing extended services provides validation, execution and state updating of transactions by the standard module, and additional business logic processing by the extended module.
The network layer, the consensus layer and the state machine application carry out layered decoupling and contract constraint through an interface protocol. The interface protocol is a universal interface, is connected with a consensus engine and a state machine, and adopts a message request and response mode of a client and a server to maintain a deterministic finite state machine.
The external client submits the transaction to a transaction queue pool through the RPC service, and the transaction queue pool receives a message sent by the client, wherein the message contains the transaction which is unprocessed and unconfirmed. The realization mode of the transaction queue pool comprises a queue and a buffer, and a memory is used as a main storage mode from the perspective of transaction performance. And the state machine checks the validity of the transactions in the transaction queue pool through the state data, identifies valid transactions and invalid transactions, receives the valid transactions by the consensus layer, packs the valid transactions into blocks to perform BFT consensus and then triggers the state change of the state machine.
The network layer, the consensus layer, the state machine application and the standard module thereof provide a standardized basic template for the building of the block chain, the basic standard framework is developed for the block chain, and the specific characteristics of the block chain are determined by the expansion module.
Control of the nodes is the key and primary basis for distinguishing public and federation chains. Differences between the federation chain and the public chain include node joining control and authority, whether there is a commission for transaction processing, the transaction cost is required, and whether there is a native pass.
The common part of the alliance chain and the public chain is realized by a general network layer, a common identification layer, a state machine application and a standard module, and the different part is completed by an additional independent module. The two functions of transaction commission and native currency evidence in the public chain use independent modules for source code development, and belong to the part of an extension module.
In the public chain, a node authorization module is not needed, and when the homologous codes are used as the alliance chain, the limitation that the node authorization module is added to increase the nodes is needed. The node authorization module is realized by two methods: CA (digital certificate) mechanism and authorized node list mechanism. The authorized node list mechanism has been set forth in the foregoing embodiments. Here, the CA mechanism is explained.
The CA mechanism implementation method comprises the following steps:
constructing a CA root certificate service; when a node joins, a digital certificate is required to be applied to a CA, and the digital certificate is used as the node identity; the existing nodes in the network verify the authenticity and validity of the digital certificates of the existing nodes through the root certificates and decide whether to accept or reject the connection.
Based on any of the above embodiments, fig. 3 is a schematic flow chart of the block chain construction method provided by the present invention, and as shown in fig. 3, the method is applied to a block chain node, and includes:
step 310, determining the type of the block chain to be constructed.
Specifically, the types of blockchains to be constructed may be classified into public chains and federation chains.
And step 320, determining an expansion module in the application layer of the block chain node based on the type of the block chain to be constructed.
Specifically, for example, if the type of the block chain to be constructed is a public chain, it may be determined that the expansion module in the block chain link point application layer includes a certification module and a cost module; if the type of the block chain to be constructed is a federation chain, it can be determined that the expansion module in the block chain link point application layer includes a certification module, a cost module and a node authorization module.
Step 330, determining the block chain node based on the expansion module, the standard module, the network layer and the consensus layer.
Specifically, an application layer of the blockchain node can be determined according to the extension module and the standard module, and then the structure of the blockchain node can be determined according to the network layer and the consensus layer.
Step 340, determining a block chain to be constructed based on a plurality of block chain nodes.
Specifically, a plurality of block chain nodes are connected to obtain a block chain to be constructed.
The standard modules in the network layer, the consensus layer and the application layer provide a standardized basic template for building the block chain, the standard template is a basic standard framework developed for the block chain, and the specific characteristics of the block chain are determined by the expansion module in the application layer.
According to the block chain construction method provided by the embodiment of the invention, the expansion module in the block chain node application layer is determined according to the type of the block chain to be constructed, and then the block chain node is determined according to the expansion module, the standard module, the network layer and the consensus layer, so that the block chain is constructed.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and includes commands for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.