Disclosure of Invention
In view of the above-mentioned deficiencies or inadequacies in the prior art, it would be desirable to provide a transaction broadcast method, a computer device, and a storage medium that reduce redundant communications during a transaction broadcast to reduce consumption of network bandwidth and reduce the probability of network congestion.
In a first aspect, the present invention provides a transaction broadcasting method for a blockchain node, including:
when the current node is started, prompting a current user to select to configure the current node as a first-class node or a second-class node:
responding to the configuration of the current node as a first type node, and performing broadcast transaction according to an original configured transaction broadcast mechanism;
in response to the current node configuration being a second type node:
searching and connecting a first number of first type nodes; and the number of the first and second groups,
in response to receiving the first transaction, forwarding the first transaction to each first type node to which the current node is connected that does not broadcast the first transaction to the current node.
In a second aspect, the present invention provides another transaction broadcasting method suitable for a blockchain node, including:
when a current node is started, scanning a first node number configured as a first type node and a second node number configured as a second type node in a current block chain network;
judging whether the ratio of the first node quantity to the second node quantity is smaller than a first threshold value:
if yes, configuring the current node as a first type node, and performing broadcast transaction according to an original configured transaction broadcast mechanism;
if not, configuring the current node as a second type node; and the number of the first and second groups,
searching and connecting a first number of first type nodes;
in response to receiving the first transaction, forwarding the first transaction to each first type node to which the current node is connected that does not broadcast the first transaction to the current node.
In a third aspect, the present invention also provides a computer device comprising one or more processors and a memory, wherein the memory contains instructions executable by the one or more processors to cause the one or more processors to perform a transaction broadcast method provided according to embodiments of the present invention.
In a fourth aspect, the present invention also provides a storage medium storing a computer program that causes a computer to execute the transaction broadcasting method provided according to the embodiments of the present invention.
According to the transaction broadcasting method, the computer equipment and the storage medium provided by the embodiments of the invention, the nodes in the block chain network are classified into the first class of nodes for normal broadcast transaction and the second class of nodes which do not participate in broadcast transaction and only carry out necessary forwarding for the broadcast transaction, so that redundant communication in the transaction broadcasting process is greatly reduced, network bandwidth consumption in the transaction broadcasting process is reduced, and the probability of network congestion is reduced;
the transaction broadcasting method, the computer device and the storage medium provided by some embodiments of the present invention further balance the number of second type nodes connected to each first type node by configuring a connection strategy of the second type nodes to the first type nodes, thereby further reducing the network congestion probability;
the transaction broadcasting method, the computer device, and the storage medium provided by some embodiments of the present invention further scan the number of two types of nodes in the current block chain network when the node is started, and select which type of node the current node is configured as according to the ratio of the two types of nodes, thereby ensuring that the problems of poor effects of reducing bandwidth consumption and reducing network congestion probability due to imbalance of the ratio of the two types of nodes, or the problems of influenced normal broadcasting of transactions and other risks, etc. are avoided.
Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the present invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
Fig. 1 is a flowchart of a transaction broadcasting method according to an embodiment of the present invention.
As shown in fig. 1, in this embodiment, the present invention provides a transaction broadcasting method suitable for a blockchain node, including:
s11: when the current node is started, prompting a current user to select to configure the current node as a first-class node or a second-class node:
s13: responding to the configuration of the current node as a first type node, and performing broadcast transaction according to an original configured transaction broadcast mechanism;
in response to the current node configuration being a second type node:
s15: searching and connecting a first number of first type nodes; and the number of the first and second groups,
s17: in response to receiving the first transaction, forwarding the first transaction to each first type node to which the current node is connected that does not broadcast the first transaction to the current node.
Specifically, the method is exemplarily illustrated below by taking an example that a certain blockchain network includes 500 nodes, at a certain time point, 450 nodes are online, 300 nodes are configured as first-class nodes, 150 nodes are configured as second-class nodes, and a node a controlled by a and a node b controlled by b start to be online at this time.
When the node a is started, executing step S11, prompting the user A to select a first type node configuring the node a as a normal broadcast transaction, or a second type node which does not participate in the broadcast transaction and only performs necessary forwarding for the broadcast transaction;
the user A selects to configure the node a as a second type node in consideration of poor network bandwidth conditions of the equipment for operating the node a, and triggers the node a to execute the step S15;
in step S15, node a finds 5 first type nodes in the blockchain network: the nodes c-g are connected with the nodes c-g respectively;
in step S17, when node a receives the transaction tx1 broadcast by node d, node a determines whether nodes c, e, f, g have broadcast tx1 to the current node:
otherwise, tx1 is forwarded to nodes c, e, f, g.
When the node b is started, the step S11 is also executed to prompt the user b to select to configure the node b as the first type node or the second type node;
the user B selects to configure the node b as a first type node, and triggers the node b to execute the step S13;
in step S13, the node b performs broadcast transaction according to the originally configured transaction broadcast mechanism. In particular, the transaction broadcast mechanism may be configured as any one of the transaction broadcast mechanisms commonly used in the art.
The above embodiment exemplifies that the first number is configured to be 5, and the above method is applied to a blockchain network including 500 nodes, and in further embodiments, a person skilled in the art may configure the first number to be any integer greater than 1 (and usually not greater than 10) according to actual needs, and may apply the above method to any different-scale and different-type blockchain network, and may achieve the same technical effect.
In the embodiment, the nodes in the block chain network are classified into the first class of nodes for normal broadcast transaction and the second class of nodes which do not participate in the broadcast transaction and only carry out necessary forwarding for the broadcast transaction, so that redundant communication in the transaction broadcasting process is greatly reduced, network bandwidth consumption in the transaction broadcasting process is reduced, and the probability of network congestion is reduced.
In a preferred embodiment, the step S15 includes:
searching a second number of first-class nodes, and respectively acquiring the number of second-class nodes connected with each searched node; wherein the second number is greater than the first number;
and connecting the nodes with the least number of the second type nodes connected in each searched node, and circulating the current step until the first number of nodes are connected or the first type nodes need to be searched continuously.
Specifically, the node a is also used to search and connect the first type of nodes, where the first number is 5 and the second number is 10 as an example:
the node a finds 10 first-class nodes h1-h10, and respectively obtains the number of second-class nodes respectively connected with h1-h 10: the node h1 is currently connected with 3 second class nodes, the node h2 is currently connected with 7 second class nodes, and the … … node h10 is currently connected with 5 second class nodes;
the node a requests to connect the node h1 with the least number of second-class nodes in the searched nodes h1-h 10:
and (3) continuing connecting the node h5 with the least second type of node in the rest nodes h2-h10 after the connection is successful:
connection failure continues … …;
until the node a is successfully connected with 5 first-class nodes; or the like, or, alternatively,
node a is only connected to 4 nodes in nodes h1-h10, and the first type of node needs to be searched continuously, and the above process is repeated.
The above embodiment further balances the number of the second type nodes connected to each first type node by configuring the connection strategy of the second type nodes to the first type nodes, thereby further reducing the network congestion probability.
In the methods shown in fig. 1, since the node configuration is that the first type node or the second type node is selected subjectively by the user, it may cause:
too many users select to configure the nodes as the first type of nodes and too few second type of nodes, so that the effects of reducing bandwidth consumption and reducing network congestion probability are poor; or the like, or, alternatively,
too many users choose to configure the nodes as the second-class nodes, which results in too few nodes normally participating in the broadcast transaction, and further results in the influence on the normal broadcast of the transaction, or provides risks such as cheating environments for only a few first-class nodes.
In view of the above problems, the present invention further provides a solution as shown in fig. 2.
Fig. 2 is a flowchart of another transaction broadcasting method according to an embodiment of the present invention. As shown in fig. 2, in this embodiment, the present invention further provides another transaction broadcasting method suitable for a blockchain node, including:
s21: when a current node is started, scanning a first node number configured as a first type node and a second node number configured as a second type node in a current block chain network;
s22: judging whether the ratio of the first node quantity to the second node quantity is smaller than a first threshold value:
if yes, go to step S23: configuring a current node as a first type node, and carrying out broadcast transaction according to an original configured transaction broadcast mechanism;
otherwise, step S25 is executed: configuring the current node as a second type node; and the number of the first and second groups,
s26: searching and connecting a first number of first type nodes;
s27: in response to receiving the first transaction, forwarding the first transaction to each first type node to which the current node is connected that does not broadcast the first transaction to the current node.
Preferably, the searching and connecting the first number of first type nodes includes:
searching a second number of first-class nodes, and respectively acquiring the number of second-class nodes connected with each searched node; wherein the second number is greater than the first number;
and connecting the nodes with the least number of the second type nodes connected in each searched node, and circulating the current step until the first number of nodes are connected or the first type nodes need to be searched continuously.
Specifically, the method shown in fig. 2 differs from the method shown in fig. 1 in that:
in the method shown in fig. 1, at the time of node startup, the user of the control node is prompted by the node to select to configure the current node as a first class node or a second class node;
in the method shown in fig. 2, when a node is started, the node automatically scans the number of the first type node and the second type node of the current block chain network, and automatically determines to configure the current node as the first type node or the second type node according to the number ratio of the two types of nodes.
Take the first threshold configuration as 1 for example:
when the node c is scanned into the current block chain network when being started, the number of the first class nodes is 280, and the number of the second class nodes is 220, if the 280:220 is judged to be larger than a first threshold value (1), the node c is configured as the second class node;
when the node d is scanned into the current blockchain network when being started, the number of the first class nodes is 240, and the number of the second class nodes is 260, and if the number 240:260 is judged to be smaller than a first threshold (1), the node d is configured as the first class node.
After the nodes are configured as the first type nodes, the principle of step S23 is the same as that of step S13, and is not described again;
after the nodes are configured as the second type nodes, the principle of steps S26-S27 is the same as that of steps S15-S17, and the description is omitted.
The embodiment further ensures that the problems of poor effects of reducing bandwidth consumption and network congestion probability caused by the unbalanced proportion of the two types of nodes, influence on normal broadcasting of transactions and other risks and the like are avoided.
Fig. 3 is a schematic structural diagram of a computer device according to an embodiment of the present invention.
As shown in fig. 3, as another aspect, the present application also provides a computer apparatus 300 including one or more Central Processing Units (CPUs) 301 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)302 or a program loaded from astorage section 308 into a Random Access Memory (RAM) 303. In the RAM303, various programs and data necessary for the operation of the apparatus 300 are also stored. The CPU301, ROM302, and RAM303 are connected to each other via abus 304. An input/output (I/O)interface 305 is also connected tobus 304.
The following components are connected to the I/O interface 305: aninput portion 306 including a keyboard, a mouse, and the like; anoutput section 307 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; astorage section 308 including a hard disk and the like; and acommunication section 309 including a network interface card such as a LAN card, a modem, or the like. Thecommunication section 309 performs communication processing via a network such as the internet. Adrive 310 is also connected to the I/O interface 305 as needed. Aremovable medium 311 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on thedrive 310 as necessary, so that a computer program read out therefrom is mounted into thestorage section 308 as necessary.
In particular, according to an embodiment of the present disclosure, the method described in any of the above embodiments may be implemented as a computer software program. For example, embodiments of the present disclosure include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program comprising program code for performing any of the methods described above. In such an embodiment, the computer program may be downloaded and installed from a network through thecommunication section 309, and/or installed from theremovable medium 311.
As yet another aspect, the present application also provides a computer-readable storage medium, which may be the computer-readable storage medium included in the apparatus of the above-described embodiment; or it may be a separate computer readable storage medium not incorporated into the device. The computer readable storage medium stores one or more programs for use by one or more processors in performing the methods described in the present application.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units or modules described in the embodiments of the present application may be implemented by software or hardware. The described units or modules may also be provided in a processor, for example, each unit may be a software program provided in a computer or a mobile intelligent device, or may be a separately configured hardware device. Wherein the designation of a unit or module does not in some way constitute a limitation of the unit or module itself.
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention herein disclosed is not limited to the particular combination of features described above, but also encompasses other arrangements formed by any combination of the above features or their equivalents without departing from the spirit of the present application. For example, the above features may be replaced with (but not limited to) features having similar functions disclosed in the present application.