Blockchain transaction synchronization method and apparatus, storage medium, controller, and product
By determining the interval between transactions in the blockchain transaction pool and using a classification model to determine the transaction category, the problems of high code complexity and excessive transaction broadcasting during blockchain transaction synchronization are solved, resulting in performance improvement and reduced I/O.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MIDEA NETWORK INFORMATION SERVICE (SHENZHEN) CO LTD
- Filing Date
- 2024-03-05
- Publication Date
- 2026-08-04
AI Technical Summary
Existing technologies for blockchain transaction synchronization involve complex code implementations and a large number of transaction broadcasts, leading to performance degradation and increased disk I/O.
By determining the interval between transactions to be synchronized in the transaction pool and using a pre-trained classification model to determine the transaction category based on transaction characteristics, it can decide whether to broadcast the transaction and reduce unnecessary transaction broadcasts.
While reducing code implementation complexity, it effectively reduces the number of transaction broadcasts, lowers disk I/O calls, and improves blockchain network performance.
Smart Images

Figure CN118245864B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of blockchain technology, and in particular to a blockchain transaction synchronization method, apparatus, storage medium, controller, and product. Background Technology
[0002] When using a peer-to-peer (P2P) protocol to synchronize blockchain transactions and blocks, it is necessary to periodically synchronize transactions that have not yet been packaged in the transaction pool. During transaction synchronization, the relevant technologies employ certain predetermined rules to sort the transactions to be synchronized, resulting in complex code logic and making it difficult for business logic to determine which transactions need to be broadcast. Summary of the Invention
[0003] This invention aims to at least partially address one of the technical problems in related technologies. To this end, one objective of this invention is to propose a blockchain transaction synchronization method that reduces both code implementation complexity and the number of transaction broadcasts.
[0004] The second objective of this invention is to provide a blockchain transaction synchronization device.
[0005] A third objective of this invention is to provide a computer-readable storage medium.
[0006] The fourth objective of this invention is to provide a controller.
[0007] The fifth objective of this invention is to provide a computer program product.
[0008] To achieve the above objectives, a first aspect of the present invention proposes a blockchain transaction synchronization method, the method comprising: determining the transactions to be synchronized in the current round in the transaction pool; calculating the interval between the transactions to be synchronized and their last broadcast; if the interval is greater than a preset time threshold, broadcasting the transactions to be synchronized; if the interval is less than or equal to the preset time threshold, using a pre-trained classification model to obtain the category of the transactions to be synchronized based on their transaction characteristics, and broadcasting the transactions to be synchronized when it is determined to broadcast them based on their category.
[0009] According to the blockchain transaction synchronization method of the present invention, it is determined whether to broadcast the transaction to be synchronized based on the interval between the transaction to be synchronized in the transaction pool and its last broadcast. When the corresponding interval is greater than a preset time threshold, a pre-trained classification model is used to determine whether the transaction to be synchronized needs to be broadcast based on the transaction characteristics of the transaction to be synchronized. This reduces the complexity of code implementation and the number of transaction broadcasts.
[0010] In addition, the blockchain transaction synchronization method proposed in the above embodiments of the present invention may also have the following additional technical features:
[0011] According to an embodiment of the present invention, the training process of the classification model includes: acquiring a sample dataset, the sample dataset including multiple transaction samples, the transaction samples including transaction features and labels; dividing the sample dataset to obtain a training sample dataset and a test sample dataset; establishing a pre-trained classification model; training the pre-trained classification model using the training sample dataset, and testing the trained classification model using the test sample dataset; and obtaining the pre-trained classification model when the test results meet preset conditions.
[0012] According to one embodiment of the present invention, the transaction features include at least one of the following: transaction pool source, latest interval timestamp of local node block, highest block number of local node, highest block interval timestamp in the blockchain, highest block number in the blockchain, transaction generation interval time, transaction entry interval timestamp, number of transaction synchronizations, total number of blockchain nodes, number of P2P current node linked to other nodes, and last transaction sending interval time.
[0013] According to one embodiment of the present invention, the label includes positive samples and negative samples, and the step of obtaining the sample dataset includes: determining, based on the transaction characteristics of the transaction sample, whether the transaction sample exists in a transaction pool or has formed a block, and marking the label corresponding to the transaction sample as a negative sample; determining, based on the transaction characteristics of the transaction sample, whether the transaction sample is the first transaction synchronization, or whether the time since the transaction sample first entered the transaction pool is greater than a preset time, or whether a target node exists in the propagation path corresponding to the transaction sample, and marking the label corresponding to the transaction sample as a positive sample.
[0014] According to one embodiment of the present invention, determining to broadcast the transaction to be synchronized based on the category includes: if the category is a positive sample, then determining to broadcast the transaction to be synchronized; if the category is a negative sample, then determining not to broadcast the transaction to be synchronized.
[0015] According to one embodiment of the present invention, determining the transactions to be synchronized in the current round in the transaction pool includes: counting the number of transactions to be synchronized in the transaction pool; if the number of transactions is greater than a preset number threshold, then obtaining a target number of transactions to be synchronized from the transaction pool based on the transaction synchronization point to determine the transactions to be synchronized in the current round, and updating the transaction synchronization point; if the number of transactions is less than or equal to the preset number threshold, then taking the transactions to be synchronized in the transaction pool as the transactions to be synchronized in the current round based on the transaction synchronization point, and updating the transaction synchronization point to empty.
[0016] To achieve the above objectives, a second aspect of the present invention provides a blockchain transaction synchronization device, the device comprising: an acquisition module for determining the transactions to be synchronized in the current round in the transaction pool; and a synchronization module for calculating the interval between the transactions to be synchronized and the previous round of broadcasting. If the interval is greater than a preset time threshold, the transactions to be synchronized are broadcast; if the interval is less than or equal to the preset time threshold, a pre-trained classification model is used to obtain the category of the transactions to be synchronized based on their transaction characteristics, and the transactions to be synchronized are broadcast when it is determined to broadcast based on the category.
[0017] To achieve the above objectives, a third aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, it implements the blockchain transaction synchronization method as proposed in the first aspect of the present invention.
[0018] To achieve the above objectives, a fourth aspect of the present invention provides a controller, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, it implements the blockchain transaction synchronization method as proposed in the first aspect of the present invention.
[0019] To achieve the above objectives, a fifth aspect of the present invention provides a computer program product that, when run on an electronic device, causes the electronic device to execute the blockchain transaction synchronization method as proposed in the first aspect of the present invention.
[0020] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description
[0021] Figure 1 This is a flowchart of a blockchain transaction synchronization method according to an embodiment of the present invention;
[0022] Figure 2 This is a flowchart of the training process of a classification model according to an embodiment of the present invention;
[0023] Figure 3 This is a schematic diagram of a blockchain transaction synchronization device according to an embodiment of the present invention;
[0024] Figure 4 This is a structural block diagram of the controller according to an embodiment of the present invention. Detailed Implementation
[0025] Embodiments of the present invention are described in detail below, examples of which are illustrated in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain the present invention, and should not be construed as limiting the present invention.
[0026] Before describing the specific embodiments of this application, for ease of understanding, commonly used technical terms will first be introduced:
[0027] Transaction pool: In a blockchain, transactions are synchronized with other nodes and cached. The master node is used to cut transactions. It is usually a linked list, which makes it easy to add transactions at the beginning and end. An additional cache is added to check if a transaction is not in the transaction pool.
[0028] Block pool: In a blockchain, it is used to synchronize transactions with other nodes, and to pull and cache transactions synchronized from other nodes.
[0029] Ancient transactions: Transactions that occurred more than a certain threshold are called ancient transactions. Non-ancient transactions will not be broadcast at regular intervals.
[0030] Broadcast transactions: When a new transaction enters the blockchain, the node that receives the transaction for the first time will broadcast the transaction to a certain number of other nodes.
[0031] Synchronized transactions: In order to avoid missing transactions during transaction broadcasting, a certain number of ancient transactions from a certain transaction pool are periodically synchronized to a random node.
[0032] Transaction synchronization point: The transaction hash corresponding to the start point of the next round of synchronization of transactions on the blockchain node.
[0033] In blockchain networks, transactions and blocks need to be synchronized. The relevant technology uses a peer-to-peer (P2P) protocol for this synchronization. P2P protocols typically employ transaction pools for transaction synchronization and block pools for block synchronization.
[0034] When using a peer-to-peer (P2P) protocol to synchronize transactions and blocks: 1. When a new transaction arrives, it is added to the transaction pool and then broadcast directly to a certain number of other nodes. Other nodes receiving the broadcast add the transaction to their local transaction pool, facilitating rapid block formation through rapid new transaction broadcasting. 2. Periodically, some ancient transactions are taken from the node's own transaction pool according to a certain sorting method and randomly unicast to another node. Other nodes receiving these transactions check if they have been written to disk locally. If not, they add them to their local transaction pool to synchronize any wandering transactions missed by the new broadcast. 3. After the master node executes the broadcast block, it also cleans up the transactions contained in the new block in its transaction pool. 4. When a slave node executes a block, if it finds that the block pool is missing blocks, it will proactively retrieve blocks from nodes with higher block times than its own.
[0035] The above methods of simultaneously transmitting blocks and transactions result in duplication. Transaction synchronization may be performed multiple times, and transactions may be continuously passed between nodes before a block is formed. Entering a transaction pool requires checking its existence; direct checks can increase disk I / O when dealing with large amounts of data. Lagging nodes may have many ancient transactions in their transaction pools, leading to excessive synchronization and impacting the performance of other nodes. If the master node's block execution lags, transactions accumulate in the transaction pools of various nodes, resulting in extensive mutual synchronization and deduplication, which can further degrade performance. When the number of transactions in the transaction pool is large, each round of transaction synchronization requires balancing the quantity and timing of transactions to be synchronized.
[0036] To address the issues of increased disk I / O and multiple synchronizations of transactions and blocks caused by determining whether to synchronize transactions in the transaction pool in the above methods, embodiments of the present invention provide a blockchain transaction synchronization method, apparatus, storage medium, controller, and product. The following description, in conjunction with the appendix, details these aspects. Figure 1-4 The present invention provides a detailed description of the blockchain transaction synchronization method, apparatus, storage medium, controller, and product according to specific implementation methods.
[0037] Figure 1 This is a flowchart of a blockchain transaction synchronization method according to an embodiment of the present invention. Figure 1 As shown, blockchain transaction synchronization methods may include:
[0038] S101, determine the transactions to be synchronized in the current round in the transaction pool.
[0039] In this embodiment of the invention, when there are transactions to be synchronized in the synchronization transaction pool, the transactions to be synchronized in the current round are determined according to the number of transactions to be synchronized in the transaction pool.
[0040] Specifically, when the number of transactions to be synchronized in the transaction pool is less than a preset threshold, only one round of broadcasting is needed to synchronize all transactions in the transaction pool. When the number of transactions to be synchronized in the transaction pool exceeds the preset threshold, multiple rounds of broadcasting are required to synchronize all transactions in the transaction pool.
[0041] S102, calculate the interval between the transaction to be synchronized and its last broadcast.
[0042] Specifically, the interval between the last broadcast of a transaction to be synchronized and its current status is calculated, and this interval is compared with a preset time threshold to determine whether the transaction to be synchronized is an ancient transaction. If the interval is greater than the preset time threshold, the transaction to be synchronized is an ancient transaction and needs to be broadcast. If the interval is less than or equal to the preset time threshold, the transaction to be synchronized is not an ancient transaction.
[0043] S103. If the interval time is greater than the preset time threshold, the transaction to be synchronized will be broadcast.
[0044] For transactions to be synchronized that have an interval longer than a preset time threshold, the transaction to be synchronized is broadcast directly.
[0045] S104. If the interval is less than or equal to a preset time threshold, the pre-trained classification model is used to obtain the category of the transaction to be synchronized based on its transaction characteristics. When the category determines the transaction to be synchronized to be broadcast, the transaction to be synchronized is broadcast.
[0046] For transactions to be synchronized with an interval time less than or equal to a preset time threshold, this embodiment of the invention uses a pre-trained classification model to determine whether to broadcast the transaction based on its transaction characteristics.
[0047] Specifically, the transaction features of the transaction to be synchronized are input into a pre-trained classification model, which outputs the category of the transaction to be synchronized. Based on the category of the transaction to be synchronized, it can be determined whether to synchronize the transaction. If it is determined that the transaction to be synchronized should be broadcast based on the category, the transaction to be synchronized is broadcast.
[0048] The classification model in this embodiment of the invention can be a K-Nearest Neighbor (KNN) model. The KNN model determines the state of a sample based on the states of its k nearest neighbors; that is, the KNN model determines whether a transaction to be synchronized needs to be broadcast based on the states of its k nearest neighbors. It should be noted that the classification model in this embodiment of the invention can also be other classification machine learning models.
[0049] In the embodiment of the present invention, during transaction synchronization, it determines whether to broadcast a transaction to be synchronized based on the interval between the transaction to be synchronized and its last broadcast in the transaction pool. If the corresponding interval is greater than a preset time threshold, a pre-trained classification model is used to determine whether the transaction to be synchronized needs to be broadcast based on the transaction characteristics of the transaction to be synchronized. This reduces the complexity of code implementation and the number of transaction broadcasts.
[0050] In one embodiment of the present invention, such as Figure 2 As shown, the training process of a classification model may include:
[0051] S201, Obtain the sample dataset, which includes multiple transaction samples. Each transaction sample includes transaction features and labels.
[0052] S202, the sample dataset is divided into training sample dataset and test sample dataset;
[0053] S203, Establish a pre-trained classification model;
[0054] S204. Train the pre-trained classification model using the training sample dataset, and test the trained classification model using the test sample dataset.
[0055] S205, when the test results meet the preset conditions, a trained classification model is obtained.
[0056] As a specific example, a large number of transactions are obtained from multiple transaction pools as transaction samples, forming a sample dataset. The transaction samples in the sample dataset include transaction features and labels. The obtained sample dataset is divided, for example, into a training sample dataset and a test sample dataset in an 8:2 ratio. A K-nearest neighbor model (pre-trained classification model) is built. The training sample data (transaction features and labels of each transaction sample in the training sample dataset) is sequentially input into the built K-nearest neighbor model to train it. After training, the test sample data (transaction features and labels of each transaction sample in the test sample dataset) is sequentially input into the trained classification model to test it. If the test results meet preset conditions, the trained classification model is recorded as a trained classification model. If the test results do not meet the preset conditions, the K-nearest neighbor model continues to be trained until the test results meet the preset conditions.
[0057] In this embodiment of the invention, a pre-trained classification model is used to determine the value of a transaction to be synchronized to other nodes. If the model predicts a value of 1 (positive sample), the transaction needs to be broadcast to other nodes. If the value is determined to be 0 (negative sample), the transaction is not synchronized to other nodes.
[0058] In one embodiment of the present invention, the transaction features include at least one of the following: transaction pool source, latest interval timestamp of local node block, highest block number of local node, highest block interval timestamp in the blockchain, highest block number in the blockchain, transaction generation interval time, transaction entry interval timestamp, number of transaction synchronizations, total number of blockchain nodes, number of P2P nodes currently linked to other nodes, and last transaction sending interval time.
[0059] Specifically, when acquiring a large number of transactions from multiple transaction pools, the aforementioned transaction features are obtained for each transaction. This allows the classification model to be trained based on the transaction features and their corresponding labels when training the classification model using the training sample dataset. Table 1 below illustrates the reasons for using and maintaining these transaction features.
[0060] Table 1. Reasons for using and maintenance methods of each transaction feature.
[0061]
[0062] In one embodiment of the present invention, the labeling includes positive samples and negative samples, and obtaining the sample dataset may include:
[0063] Based on the transaction characteristics of the transaction sample, determine whether the transaction sample exists in the transaction pool or has formed a block, and mark the corresponding label of the transaction sample as a negative sample.
[0064] Based on the transaction characteristics of the transaction sample, if the transaction sample is determined to be the first transaction synchronization, or the time since the transaction sample first entered the transaction pool is greater than a preset time, or there is a target node in the propagation path corresponding to the transaction sample, the label corresponding to the transaction sample is marked as a positive sample.
[0065] Specifically, when labeling each transaction sample, the positive or negative value of the label corresponding to the transaction sample can be determined according to preset rules.
[0066] For example, when labeling acquired transaction samples, if the transaction characteristics of the sample indicate that the transaction has been broadcast, and the counterparty node determines that the transaction sample exists in the transaction pool or has already formed a block, then the label corresponding to the transaction sample is marked as a negative sample. If a target node exists in the propagation path corresponding to the transaction sample, meaning that the current transaction synchronization of the sample is on the propagation path that forms a block, then the label corresponding to the transaction sample is marked as a positive sample. It should be noted that the transaction propagation path is additionally recorded in the transaction. If the transaction synchronization is determined to be a negative sample after block execution, and if the transaction sample is synchronized for the first time, or if the time since its first entry into the transaction pool is greater than a certain threshold, then the label corresponding to the transaction sample is marked as a positive sample.
[0067] Feasible implementation involves using online traffic to additionally record transaction statistics (including transaction characteristics) in the transaction pool. Specifically, during block execution, the block write time is recorded. When peer nodes receive a transaction, if the transaction is already in the transaction pool or has been packaged into a block, an additional log is recorded, and a UUID is added as a unique identifier to the p2p transmission field. If the receiver determines that the transaction already exists or has been packaged, the transaction synchronization is considered a negative sample. During block execution, the transaction execution time is recorded. If the transaction synchronization occurs after the transaction is packaged, it is considered a negative sample. If the node synchronizing the transaction is on the critical node path during transaction packaging, the transaction synchronization is considered a positive sample; otherwise, it is marked as unknown.
[0068] In one embodiment of the present invention, using a pre-trained classification model to obtain the category of the transaction to be synchronized based on its transaction characteristics may include:
[0069] The transaction features of the transactions to be synchronized are input into a pre-trained classification model to obtain the category of the transactions to be synchronized.
[0070] Specifically, the transaction features of the transaction to be synchronized are input into a pre-trained classification model. The pre-trained classification model outputs the category (positive or negative sample) of the transaction based on its features. If the output is a positive sample, it means that broadcasting is required. If the output is a negative sample, it means that broadcasting is not required at this time.
[0071] In one embodiment of the present invention, determining whether to broadcast transactions to be synchronized based on category may include:
[0072] If the category is a positive sample, then it is determined that the transaction to be synchronized will be broadcast;
[0073] If the category is a negative sample, then it is determined that the transaction to be synchronized will not be broadcast.
[0074] Specifically, when the output of the pre-trained classification model is a positive sample, the transaction to be synchronized is broadcast. When the output of the pre-trained classification model is a negative sample, the transaction to be synchronized is not broadcast.
[0075] In one embodiment of the present invention, determining the transactions to be synchronized in the current round in the transaction pool includes:
[0076] Count the number of transactions waiting to be synchronized in the transaction pool;
[0077] If the number of transactions exceeds the preset threshold, the target number of transactions to be synchronized is obtained from the transaction pool based on the transaction synchronization point to determine the transactions to be synchronized in the current round, and the transaction synchronization point is updated.
[0078] If the number of transactions is less than or equal to the preset threshold, then the transactions to be synchronized in the transaction pool will be used as the transactions to be synchronized in the current round based on the transaction synchronization point, and the transaction synchronization point will be updated to empty.
[0079] In this embodiment of the invention, when the number of transactions to be synchronized in the transaction pool is small, such as less than a preset threshold, all transactions to be synchronized in the transaction pool are taken as the current round of transactions to be synchronized during transaction synchronization. Then, starting from the beginning of the transaction pool, the method described above is used to determine whether the transactions to be synchronized need to be broadcast.
[0080] In this embodiment of the invention, when the number of transactions to be synchronized in the transaction pool is large, such as exceeding a preset threshold, multiple rounds of broadcasting are performed on the transactions to be synchronized in the transaction pool. To ensure that all transactions to be synchronized have the opportunity to be broadcast and to avoid multiple rounds of synchronization of the same batch of transactions, the synchronization position of the next round of transactions is recorded in each round of broadcasting.
[0081] Specifically, the system retrieves a target number of transactions to be synchronized from the transaction pool based on the transaction synchronization point, determines the transactions to be synchronized in the current round from the retrieved transactions, and updates the transaction synchronization point.
[0082] As a specific example, configure the upper limit of the number of transactions in each round of synchronization, such as setting it to a preset threshold 'a'. During initial synchronization, the transaction synchronization point is recorded as the starting position of the transaction pool, and the transactions to be synchronized in the current round are retrieved from the starting position of the transaction pool. Specifically, attempt to retrieve a+1 (target number) transactions to be synchronized. If a+1 transactions are retrieved, the first a transactions are used as the transactions to be synchronized in the current round; that is, only the first a transactions are synchronized in this round. The last transaction is marked as the synchronization point for the next round, thus updating the transaction synchronization point. During the next round of transaction synchronization, the transactions to be synchronized in the current round are retrieved from the updated transaction synchronization point, and the transaction synchronization point is updated, and the transactions are synchronized using the above method. If the number of retrieved transactions is less than a+1, the transactions to be synchronized in the transaction pool are used as the transactions to be synchronized in the current round based on the transaction synchronization point, and the transactions to be synchronized in the current round are synchronized using the above method. At the same time, the transaction synchronization point is updated to empty, that is, the next round of transaction synchronization point is marked as empty, so that when synchronizing the transactions to be synchronized in the transaction pool, synchronization will start from the beginning position of the transaction pool.
[0083] In this embodiment of the invention, while broadcasting the transactions to be synchronized in the current round in the transaction pool, the start point of transaction synchronization (the transaction hash corresponding to the start point of the next round of synchronized transactions of the blockchain node) is also recorded. The next round of synchronized transactions will start from the start point of transaction synchronization and proceed backwards, avoiding the fact that the transactions synchronized in multiple rounds are the same batch of transactions, and ensuring that all transactions to be synchronized have the opportunity to be broadcast.
[0084] In order to quickly predict the results, this embodiment of the invention adopts the simplest KNN model, and the time feature adopts relative time. The obtained samples are divided into training set and test set. Through the pre-constructed KNN model, when synchronizing transactions online, if the transaction distance from the previous round of broadcast is greater than a certain threshold, it is broadcast directly; otherwise, the corresponding feature is used to calculate the transaction synchronization value and determine whether to synchronize the transaction.
[0085] The blockchain transaction synchronization method of this invention determines whether to broadcast a transaction to be synchronized based on the interval between its last broadcast and the current interval. If the interval exceeds a preset threshold, a pre-trained classification model is used to determine whether the transaction needs to be broadcast based on its characteristics. During transaction broadcasting, the broadcast transaction point is recorded for each round. The next broadcast starts from this transaction point, ensuring all transactions have a chance to be broadcast and preventing multiple rounds of synchronization from involving the same batch of transactions. This invention reduces code complexity while also reducing block, transaction synchronization network, and disk I / O calls.
[0086] This invention provides a blockchain transaction synchronization device.
[0087] The blockchain transaction synchronization device 100 includes an acquisition module 10 and a synchronization module 20.
[0088] The acquisition module 10 is used to determine the transactions to be synchronized in the current round in the transaction pool; the synchronization module 20 is used to calculate the interval between the transaction to be synchronized and the previous round of broadcast. If the interval is greater than a preset time threshold, the transaction to be synchronized is broadcast. If the interval is less than or equal to the preset time threshold, a pre-trained classification model is used to obtain the category of the transaction to be synchronized based on its transaction characteristics. When it is determined that the transaction to be synchronized should be broadcast based on its category, the transaction to be synchronized is broadcast.
[0089] It should be noted that other specific embodiments of the blockchain transaction synchronization device provided in the embodiments of the present invention can be found in other specific embodiments of the blockchain transaction synchronization method of the above embodiments of the present invention.
[0090] The blockchain transaction synchronization device of this invention determines whether to broadcast a transaction to be synchronized based on the interval between the transaction to be synchronized and its last broadcast in the transaction pool. When the interval is greater than a preset time threshold, a pre-trained classification model is used to determine whether the transaction to be synchronized needs to be broadcast based on its transaction characteristics. This reduces the complexity of code implementation and the number of transactions broadcast.
[0091] This invention provides a computer-readable storage medium.
[0092] In this embodiment, a computer program is stored on a computer-readable storage medium, and when the computer program is executed by a processor, it implements the blockchain transaction synchronization method described above.
[0093] This invention provides a controller.
[0094] In this embodiment, the controller may include a memory and a processor. The memory stores a computer program. The computer program, when executed by the processor, implements the blockchain transaction synchronization method described above.
[0095] Figure 4 This is a structural block diagram of the controller according to an embodiment of the present invention.
[0096] like Figure 4 As shown, the controller 500 includes a processor 501 and a memory 503. The processor 501 and the memory 503 are connected, for example, via a bus 502. Optionally, the controller 500 may also include a transceiver 504. It should be noted that in practical applications, the transceiver 504 is not limited to one, and the structure of the controller 500 does not constitute a limitation on the embodiments of the present invention.
[0097] Processor 501 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this invention. Processor 501 may also be a combination that implements computational functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0098] Bus 502 may include a pathway for transmitting information between the aforementioned components. Bus 502 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 502 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 4 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0099] The memory 503 stores a computer program corresponding to the blockchain transaction synchronization method of the above embodiments of the present invention. This computer program is controlled and executed by the processor 501. The processor 501 executes the computer program stored in the memory 503 to implement the content shown in the foregoing method embodiments. Figure 4The controller 500 shown is merely an example and should not be construed as limiting the functionality and scope of use of embodiments of the present invention.
[0100] The computer-readable storage medium and controller of this invention, by utilizing the above-mentioned blockchain transaction synchronization method, reduce the complexity of code implementation while also reducing block, transaction synchronization network, and disk I / O calls.
[0101] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable medium may be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.
[0102] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0103] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0104] In the description of this invention, it should be understood that the terms "center," "longitudinal," "lateral," "length," "width," "thickness," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," "outer," "clockwise," "counterclockwise," "axial," "radial," and "circumferential" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing this invention and simplifying the description, and are not intended to indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this invention.
[0105] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this invention, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0106] In this invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," "linking," and "fixing," etc., should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral part; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal communication of two components or the interaction between two components, unless otherwise explicitly limited. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.
[0107] In this invention, unless otherwise explicitly specified and limited, "above" or "below" the second feature can mean that the first feature is in direct contact with the second feature, or that the first feature is in indirect contact with the second feature through an intermediate medium. Furthermore, "above," "over," and "on top" of the second feature can mean that the first feature is directly above or diagonally above the second feature, or simply that the first feature is at a higher horizontal level than the second feature. "Below," "below," and "under" the second feature can mean that the first feature is directly below or diagonally below the second feature, or simply that the first feature is at a lower horizontal level than the second feature.
[0108] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.
Claims
1. A blockchain transaction synchronization method, characterized in that, The method includes: Identify the transactions to be synchronized in the current round within the transaction pool; Calculate the time interval between the transaction to be synchronized and its last broadcast. If the interval time is greater than a preset time threshold, the transaction to be synchronized is broadcast. If the interval is less than or equal to the preset time threshold, a pre-trained classification model is used to determine the category of the transaction to be synchronized based on its transaction characteristics. When it is determined to broadcast the transaction based on its category, the transaction is broadcast. The pre-trained classification model is trained using a sample dataset, which includes multiple transaction samples. Each transaction sample includes transaction characteristics and labels. The labels include positive and negative samples. Based on the transaction characteristics, it is determined that the transaction sample exists in a transaction pool or has formed a block, and the label corresponding to the transaction sample is marked as a negative sample. Based on the transaction characteristics, it is determined that the transaction sample is the first transaction to be synchronized, or that the time since the transaction sample first entered the transaction pool is greater than a preset time, or that a target node exists in the propagation path corresponding to the transaction sample, and the label corresponding to the transaction sample is marked as a positive sample. The step of determining to broadcast the transaction to be synchronized based on the category includes: If the category is a positive sample, then it is determined that the transaction to be synchronized will be broadcast; If the category is a negative sample, then it is determined that the transaction to be synchronized will not be broadcast; The process of determining the transactions to be synchronized in the current round in the transaction pool includes: Count the number of transactions waiting to be synchronized in the transaction pool; If the number of transactions exceeds a preset threshold, the target number of transactions to be synchronized is obtained from the transaction pool based on the transaction synchronization point to determine the transactions to be synchronized in the current round, and the transaction synchronization point is updated. If the number of transactions is less than or equal to a preset threshold, then the transactions to be synchronized in the transaction pool are taken as the transactions to be synchronized in the current round according to the transaction synchronization point, and the transaction synchronization point is updated to empty. 2.The method of claim 1, wherein, The training process of the classification model includes: Obtain the sample dataset; The sample dataset is divided into a training sample dataset and a test sample dataset; Build a pre-trained classification model; The pre-trained classification model is trained using the training sample dataset, and the trained classification model is tested using the test sample dataset. When the test results meet the preset conditions, the pre-trained classification model is obtained. 3.The method of claim 2, wherein, The transaction characteristics include at least one of the following: transaction pool source, latest interval timestamp of local node block, highest block number of local node, highest block interval timestamp in the blockchain, highest block number in the blockchain, transaction generation interval, transaction entry interval timestamp, number of transaction synchronizations, total number of blockchain nodes, number of P2P nodes currently linked to other nodes, and last transaction sending interval. 4.A blockchain transaction synchronization apparatus characterized by comprising: The device includes: The acquisition module is used to determine the transactions to be synchronized in the current round in the transaction pool; The synchronization module is used to calculate the interval between the transaction to be synchronized and the previous broadcast. If the interval is greater than a preset time threshold, the transaction to be synchronized is broadcast. If the interval is less than or equal to the preset time threshold, a pre-trained classification model is used to determine the category of the transaction to be synchronized based on its transaction characteristics. When it is determined to broadcast the transaction to be synchronized based on its category, the transaction is broadcast. The pre-trained classification model is trained using a sample dataset, which includes multiple transaction samples. Each transaction sample includes transaction characteristics and labels. The labels include positive and negative samples. Based on the transaction characteristics of the transaction sample, it is determined whether the transaction sample exists in a transaction pool or has formed a block, and the label corresponding to the transaction sample is marked as a negative sample. Based on the transaction characteristics of the transaction sample, it is determined whether the transaction sample is the first transaction synchronized, or whether the time since the transaction sample first entered the transaction pool is greater than a preset time, or whether a target node exists in the propagation path corresponding to the transaction sample, and the label corresponding to the transaction sample is marked as a positive sample. The synchronization module is used to: determine to broadcast the transaction to be synchronized when the category is a positive sample; and determine not to broadcast the transaction to be synchronized when the category is a negative sample. The acquisition module is used to: count the number of transactions to be synchronized in the transaction pool; if the number of transactions is greater than a preset threshold, then obtain a target number of transactions to be synchronized from the transaction pool according to the transaction synchronization point to determine the transactions to be synchronized in the current round, and update the transaction synchronization point; if the number of transactions is less than or equal to the preset threshold, then take the transactions to be synchronized in the transaction pool as the transactions to be synchronized in the current round according to the transaction synchronization point, and update the transaction synchronization point to empty.
5. A computer-readable storage medium having stored thereon a computer program, characterized in that, When the computer program is executed by the processor, it implements the blockchain transaction synchronization method as described in any one of claims 1-3.
6. A controller comprising a memory, a processor, the memory having stored thereon a computer program, characterized in that, When the computer program is executed by the processor, it implements the blockchain transaction synchronization method as described in any one of claims 1-3.
7. A computer program product, characterised in that, When the computer program product is run on an electronic device, the electronic device performs the blockchain transaction synchronization method as described in any one of claims 1-3.