Blockchain transaction cancellation method, device and blockchain transaction system
By receiving transaction cancellation requests in the blockchain network, deleting the target transaction and storing its hash, and broadcasting the cancellation event, the problems of high transaction cancellation costs and Nonce waste are solved, and more flexible transaction cancellation is achieved.
Patent Information
- Application Number
- CN202510002505.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-02
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2045-01-02
AI Technical Summary
The process of canceling transactions in a blockchain network is costly and wasteful of nonce, limiting transaction flexibility.
The transaction is canceled by receiving a transaction cancellation request, deleting the target transaction and storing its hash in the canceled transaction cache pool, and broadcasting the transaction cancellation event to other nodes in the blockchain network.
It reduces the cost of canceling transactions, avoids the waste of Nonce, and improves the flexibility of transaction cancellation.
Smart Images

Figure CN119402502B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application belong to the field of blockchain technology, and in particular, relate to a blockchain transaction cancellation method, device, and blockchain transaction system. Background Art
[0002] Transactions initiated by users on a blockchain may need to be canceled. For example, a user might miscalculate fees or make a mistake when setting up a transaction and wish to reverse it. However, the process for canceling transactions in existing blockchain networks has numerous drawbacks, primarily high cancellation costs and the waste of a single-use, non-reusable random number (Nonce).
[0003] Specifically, canceling a transaction in existing blockchain networks typically requires the user to initiate a new transaction to overwrite the one being canceled. However, initiating a new transaction incurs a higher cost to overwrite the original one, making the cancellation process expensive. Furthermore, each transaction consumes the user's account nonce, and canceling a transaction by initiating a new transaction to overwrite the original one consumes an additional nonce. In frequently interacting smart contracts, this waste of nonce also limits the flexibility of future transactions. Summary of the Invention
[0004] In view of this, embodiments of the present application provide a blockchain transaction cancellation method, device, and blockchain transaction system to improve the flexibility of transaction cancellation operations.
[0005] A first aspect of an embodiment of the present application provides a blockchain transaction cancellation method, comprising:
[0006] receiving a transaction cancellation request, wherein the transaction cancellation request carries a transaction hash of a target transaction to be canceled;
[0007] Deleting the target transaction from the local transaction pool of the target node, where the target node is the node in the blockchain that initiated the target transaction;
[0008] Storing the transaction hash of the target transaction in the cancel transaction cache pool of the target node;
[0009] Generate a transaction cancellation event for the target transaction, and broadcast the transaction cancellation event to other nodes in the blockchain.
[0010] Optionally, receiving a transaction cancellation request includes:
[0011] A transaction cancellation request for the initiated target transaction is received through a transaction cancellation interface of the target node, wherein the transaction cancellation interface is constructed based on a remote procedure call transmission protocol, and each node in the blockchain is configured with the transaction cancellation interface.
[0012] Optionally, deleting the target transaction from the local transaction pool of the target node includes:
[0013] extracting signature information from the transaction cancellation request, and verifying the transaction cancellation request based on the signature information;
[0014] When the transaction cancellation request is verified, the target transaction corresponding to the transaction hash is deleted from the local transaction pool of the target node.
[0015] Optionally, storing the transaction hash of the target transaction in a canceled transaction cache pool of the target node includes:
[0016] Determine the transaction cancellation time;
[0017] Based on the transaction cancellation time, the transaction hash of the target transaction is stored in a local canceled transaction cache pool of the target node, where the canceled transaction cache pool is constructed using a key-value pair structure.
[0018] Optionally, after storing the transaction hash of the target transaction in the cancel transaction cache pool of the target node, the method further includes:
[0019] The transaction hash of the canceled target transaction and the corresponding transaction cancellation time are persistently stored.
[0020] Optionally, it also includes:
[0021] When the target node starts, traverse the transaction cancellation data in the persistent storage, wherein the transaction cancellation data is keyed by information including the transaction cancellation time;
[0022] According to the transaction cancellation time, the transaction cancellation data within the target time range is loaded into the local transaction cancellation cache pool of the target node.
[0023] Optionally, generating a transaction cancellation event for the target transaction and broadcasting the transaction cancellation event to other nodes in the blockchain includes:
[0024] Generate a transaction cancellation event based on the transaction hash of the target transaction and the corresponding transaction cancellation time, and add the transaction cancellation event to a broadcast queue;
[0025] The transaction cancellation event is broadcast to other nodes in the blockchain through the broadcast queue, where the transaction cancellation event carries a transaction hash that uniquely identifies the target transaction.
[0026] Optionally, after generating a transaction cancellation event for the canceled target transaction and broadcasting the transaction cancellation event to other nodes in the blockchain, the method further includes:
[0027] Receiving feedback information returned by other nodes in the blockchain regarding the transaction cancellation event;
[0028] If the feedback information returned by other nodes all indicates that the target transaction has been canceled, it is confirmed that the target transaction has been canceled successfully.
[0029] A second aspect of an embodiment of the present application provides a blockchain transaction cancellation device, comprising:
[0030] A receiving module, configured to receive a transaction cancellation request, wherein the transaction cancellation request carries a transaction hash of a target transaction to be canceled;
[0031] A deletion module, configured to delete the target transaction from the local transaction pool of a target node, where the target node is the node in the blockchain that initiated the target transaction;
[0032] A storage module, configured to store the transaction hash of the target transaction in a canceled transaction cache pool of the target node;
[0033] A broadcast module is configured to generate a transaction cancellation event for the target transaction and broadcast the transaction cancellation event to other nodes in the blockchain.
[0034] A third aspect of an embodiment of the present application provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the computer device implements the method described in the first aspect above to cancel a target transaction.
[0035] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium. When the computer program is executed by a computer, the method described in the first aspect above is implemented to cancel the target transaction.
[0036] A fifth aspect of the embodiments of the present application provides a computer program product, including a computer program. When the computer program is run, the method described in the first aspect is executed to cancel the target transaction.
[0037] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0038] In an embodiment of the present application, by receiving a transaction cancellation request, the target node can delete the target transaction corresponding to the transaction hash carried in the transaction cancellation request from the local transaction pool, and store the transaction hash of the target transaction in the cancellation transaction cache pool. Then, the target node can generate a transaction cancellation event for the target transaction, and broadcast the transaction cancellation event to other nodes in the blockchain, requesting other nodes to perform the same cancellation operation as the target node, thereby achieving successful cancellation of the target transaction. In an embodiment of the present application, a request to cancel the target transaction is broadcast to each node in the blockchain through a full network broadcast mechanism, thereby ensuring the consistency of the cancellation operation in the distributed network. The entire cancellation operation process does not require the initiation of a new transaction to cover the target transaction to be canceled, thereby avoiding the cost of initiating a new transaction and significantly reducing the cost of users canceling transactions. Since there is no need to initiate a new transaction, the waste of Nonce value is avoided, which improves the flexibility of transaction cancellation. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] To more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present application, and those skilled in the art can derive other drawings based on these drawings without inventive effort.
[0040] Figure 1 This is a schematic diagram of a blockchain transaction cancellation method provided by an embodiment of the present application;
[0041] Figure 2 This is a comparative schematic diagram of a blockchain transaction cancellation method provided in an embodiment of the present application;
[0042] Figure 3 This is a schematic diagram of a blockchain transaction cancellation device provided by an embodiment of the present application;
[0043] Figure 4 This is a schematic diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] In the following description, specific details such as specific system structures and technologies are provided for the purpose of illustration rather than limitation to facilitate a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid obstructing the description of the present application with unnecessary details.
[0045] The technical solution of this application is described below through specific embodiments.
[0046] Reference Figure 1 , which shows a schematic diagram of a blockchain transaction cancellation method provided by an embodiment of the present application, which may specifically include the following steps:
[0047] S101: Receive a transaction cancellation request, where the transaction cancellation request carries a transaction hash of a target transaction to be canceled.
[0048] It should be noted that this method can be applied to blockchains, that is, this method can be used to cancel transactions that need to be canceled in the blockchain. The above-mentioned cancellation operation can be specifically performed by a target node in the blockchain. The target node can be a node that receives the target transaction initiated by the user and receives the transaction cancellation request initiated by the user. The various operations performed by the target node can be implemented based on a computer device. Therefore, the execution subject of the embodiment of the present application can be a target node or a computer device that implements the various functions of the target node. By executing the various steps of the method provided in the embodiment of the present application, the target node or computer device can cancel the transaction initiated in the blockchain, thereby improving the flexibility of the transaction cancellation operation.
[0049] In an embodiment of the present application, a transaction cancellation request may be initiated by a user who wishes to cancel an already initiated transaction. This request may be used to request the target node to revoke or cancel the initiated transaction, such as the target transaction. The transaction cancellation request may include the transaction hash (TransactionHash) of the target transaction to be canceled. The transaction hash can be used to uniquely identify a transaction.
[0050] Furthermore, to enhance security, the transaction cancellation request may also include the signature of the user initiating the request. This signature can be used in subsequent steps to verify the legitimacy of the transaction request. For example, by verifying the signature, it can be confirmed whether the user initiating the transaction request is the same user who initiated the target transaction to be canceled.
[0051] The transaction cancellation request initiated by the user can be received by the target node. Typically, the target node that receives the transaction cancellation request can be the same node that received the initiated target transaction.
[0052] In one possible implementation of an embodiment of the present application, a target node can receive a transaction cancellation request for an initiated target transaction via a configured transaction cancellation interface. In one example, the transaction cancellation interface can be an interface constructed based on a remote procedure call (RPC) transmission protocol. Specifically, the transaction cancellation interface can be constructed based on an RPC protocol in JSON (JavaScript Object Notation) format. Each node in the blockchain can be configured with this type of transaction cancellation interface according to the same protocol. In this way, when a user initiates a transaction cancellation request, any node can receive the corresponding request through the transaction cancellation interface.
[0053] JSON-RPC is a lightweight RPC protocol that uses the JSON format to transmit requests and responses. It supports method calls and parameter passing, and implements interaction between clients and servers through simple HTTP communication.
[0054] S102: Delete the target transaction from the local transaction pool of the target node, where the target node is the node that initiated the target transaction in the blockchain.
[0055] For an initiated target transaction, upon receiving it, the target node can add it to its local transaction pool and broadcast it to other nodes in the blockchain. Therefore, unless the target transaction is canceled or on-chain, the target node's local transaction pool will store relevant information about the target transaction.
[0056] When the target node receives a transaction cancellation request, it can delete the target transaction corresponding to the request from the local transaction pool.
[0057] In one possible implementation of the present embodiment, when a target node receives a transaction cancellation request, it can extract the transaction hash included in the request. Since the transaction hash uniquely identifies a transaction, the target node can use the transaction hash to locate the target transaction to be canceled in the local transaction pool and delete it.
[0058] In another possible implementation of the embodiment of the present application, the transaction cancellation request may also carry the user's signature information. The target node can verify the legitimacy of the received transaction cancellation request through the signature information, and delete the corresponding target transaction from the local transaction pool after the verification is passed.
[0059] Specifically, upon receiving a transaction cancellation request, the target node can extract the signature information and transaction hash from the request and verify the request based on the signature information. For example, the node can verify whether the user initiating the transaction cancellation request is the same user who initiated the target transaction, thereby confirming the legitimacy of the transaction cancellation request. If the transaction cancellation request passes verification, the target node can delete the target transaction corresponding to the transaction hash from its local transaction pool.
[0060] S103: Store the transaction hash of the target transaction in the cancel transaction cache pool of the target node.
[0061] In an embodiment of the present application, for a target transaction that has been deleted from the local transaction pool, the target node may store its transaction hash in a canceled transaction cache pool, which may be used to record or store relevant information of canceled or to-be-cancelled transactions.
[0062] In one possible implementation of an embodiment of the present application, the transaction cancellation cache pool can be constructed using a key-value pair structure. For example, a map structure can be used to construct the transaction cancellation cache pool in memory. A map is a data structure frequently used to store key-value pairs and is implemented based on a hash table. Its search, insertion, and deletion operations are highly efficient, typically completing in O(1) time, making it suitable for use as an efficient memory cache and enabling fast querying. Therefore, constructing a transaction cancellation cache pool based on a map structure can provide fast transaction status query capabilities.
[0063] In an embodiment of the present application, the transaction hash stored in the canceled transaction cache pool may include time information, which may be the target transaction's cancellation time. Therefore, when storing the target transaction's transaction hash in the target node's canceled transaction cache pool, the target node may first determine the target transaction's cancellation time. This transaction cancellation time may be the time when the user initiates the transaction cancellation request, the time when the target node receives the transaction request, or the time when the target node deletes the target transaction from its local transaction pool. This embodiment of the present application is not limited to this.
[0064] After determining the transaction cancellation time, the target node may store the transaction hash of the target transaction in a local canceled transaction cache pool of the target node based on the transaction cancellation time.
[0065] In one possible implementation of the present embodiment, to achieve data persistence and prevent data loss after a node restart or crash, the target node may also persist the relevant information of the target transaction stored in the canceled transaction cache. Specifically, the target node may persistently store the transaction hash of the canceled target transaction and the corresponding transaction cancellation time.
[0066] In embodiments of the present application, a key-value store database can be used as persistent storage. In one example, a LevelDB database can be used as persistent storage. LevelDB is a high-performance, embedded key-value store database that uses a Log-Structured Merge Tree (LSM Tree) as its underlying structure, supporting fast random read and write operations and data persistence.
[0067] In one possible implementation of the present application, when a key-value storage database is used as persistent storage, the stored transaction cancellation data may be keyed by information containing the transaction cancellation time. For example, the key may include the transaction hash of the target transaction and the corresponding transaction cancellation time. For example, the key may be in the format yyyy-mm-dd:transactionHash . yyyy-mm-dd is an example of a transaction cancellation time, representing the year, month, and day when the target transaction was canceled.
[0068] In this way, by persistently storing the transaction hash of the canceled target transaction, both performance and reliability can be taken into account, ensuring that the record of the canceled transaction will not be lost even when an abnormality occurs in the system.
[0069] For example, when the target node starts, the transaction cancellation data in the persistent storage can be traversed and, based on the transaction cancellation time, the transaction cancellation data within the target time range can be loaded into the local transaction cancellation cache pool of the target node. In this way, the transaction cancellation data that meets the time requirements can be loaded into the transaction cancellation cache pool again to provide fast query capabilities for transaction cancellation data and reduce query latency.
[0070] S104: Generate a transaction cancellation event for the target transaction, and broadcast the transaction cancellation event to other nodes in the blockchain.
[0071] In this embodiment of the present application, through the aforementioned processing of S101-S104, the target node has deleted the target transaction to be canceled from its local transaction pool. To successfully cancel the target transaction, the target node also needs to broadcast the cancellation information to other nodes in the blockchain, requesting them to perform the same operation to completely cancel the target transaction.
[0072] In an embodiment of the present application, the target node may generate a transaction cancellation event for the target transaction and broadcast the transaction cancellation event to other nodes in the blockchain.
[0073] In an embodiment of the present application, a structure can be defined to represent a transaction cancellation event. The structure can include information such as a transaction hash and a transaction cancellation time. In this way, a transaction cancellation event can be generated based on the transaction hash of the target transaction and the corresponding transaction cancellation time.
[0074] This transaction cancellation event can be added to a broadcast queue, which then broadcasts it to other nodes in the blockchain. Because the transaction cancellation event can carry a transaction hash that uniquely identifies the target transaction, upon receiving the transaction cancellation event broadcast by the target node, each node can query the corresponding target transaction based on the transaction hash and perform the same cancellation operation as the target transaction. For example, upon querying the target transaction, each node can delete the target transaction from its local transaction pool and store the deleted target transaction's transaction hash, along with the transaction cancellation time, in a local canceled transaction cache pool.
[0075] In one possible implementation of the embodiment of the present application, the target node may broadcast the transaction cancellation event to other nodes using an existing blockchain network protocol, for example, using a DevP2P protocol to broadcast the transaction cancellation event, which is not limited in the embodiment of the present application.
[0076] In an embodiment of the present application, after the target node broadcasts the transaction cancellation event to other nodes in the blockchain, it can also receive feedback information returned by other nodes regarding the transaction cancellation event. If the feedback information returned by other nodes all indicates that the target transaction has been canceled, that is, each node has deleted the corresponding target transaction in the local transaction pool, then the target node can confirm that the target transaction has been successfully canceled.
[0077] In an embodiment of the present application, by receiving a transaction cancellation request, the target node can delete the target transaction corresponding to the transaction hash carried in the transaction cancellation request from the local transaction pool, and store the transaction hash of the target transaction in the cancellation transaction cache pool. Then, the target node can generate a transaction cancellation event for the target transaction, and broadcast the transaction cancellation event to other nodes in the blockchain, requesting other nodes to perform the same cancellation operation as the target node, thereby achieving successful cancellation of the target transaction. The embodiment of the present application transmits the request to cancel the target transaction in the form of a broadcast to each node in the blockchain through a full network broadcast mechanism, thereby ensuring the consistency of the cancellation operation in the distributed network. The entire cancellation operation process does not require the initiation of a new transaction to cover the target transaction to be canceled, avoiding the cost of initiating a new transaction, and significantly reducing the cost of users canceling transactions. Since there is no need to initiate a new transaction, the waste of Nonce value is also avoided, which improves the flexibility of transaction cancellation.
[0078] It should be noted that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0079] To facilitate understanding, the following introduces the blockchain transaction cancellation method provided in an embodiment of the present application with a complete example, and compares it with the transaction cancellation method in the prior art to illustrate the beneficial effects of the blockchain transaction cancellation method provided in an embodiment of the present application.
[0080] like Figure 2 , which is a comparative schematic diagram of a blockchain transaction cancellation method provided by an embodiment of the present application. Figure 2 The difference between the process of canceling a transaction to be canceled by applying the blockchain transaction cancellation method provided in the embodiment of the present application and the process of canceling a blockchain transaction by applying the existing technology is compared. Figure 2 Part (a) is a schematic diagram of the execution process of canceling blockchain transactions in the prior art. Figure 2 Part (b) is a schematic diagram of the execution process of the blockchain transaction cancellation method provided in the application embodiment.
[0081] Reference Figure 2 As shown in part (a) of , after a user initiates a transaction, for example Figure 2 If you want to cancel transaction 1 shown in part (a) of the example, the entire operation process may include the following steps:
[0082] Step 1: The user initiates a transaction 1, involving Figure 2 The steps numbered 1.1-1.3 in part (a) of FIG.
[0083] 1.1, Constructing Transaction 1: The user initiates an initial transaction through the account, such as Transaction 1;
[0084] 1.2, Send Transaction 1: The blockchain node, for example, the target node, receives Transaction 1 and adds it to the local transaction pool;
[0085] 1.3, Broadcast Transaction 1: The target node broadcasts Transaction 1 to other nodes in the blockchain.
[0086] Step 2: The user initiates a request to cancel transaction 1, involving Figure 2 The steps numbered 1.4-1.6 in part (a) of FIG.
[0087] 1.4, Cancel Transaction 1: The user initiates a request to cancel Transaction 1 through his account;
[0088] 1.5, Sending a higher-fee transaction 2: In order to cancel the initiated transaction 1, the target node needs to send a higher-fee transaction 2 and add transaction 2 to the local transaction pool; the Nonce value of transaction 2 is the same as that of transaction 1;
[0089] 1.6, Broadcast Transaction 2: The target node broadcasts Transaction 2 to other nodes in the blockchain.
[0090] Step 3: Execute the operation of canceling transaction 1, involving Figure 2 The steps numbered 1.7-1.9 in part (a) of the present invention are as follows.
[0091] 1.7, Transaction 2 is on-chain: Since Transaction 2 has a higher fee, the blockchain will perform an on-chain operation on Transaction 2, causing Transaction 1 to fail.
[0092] 1.8, Query Transaction: The target node can query the cancellation result of transaction 1;
[0093] 1.9. Return the transaction execution result information: After transaction 2 is successfully uploaded to the chain, it means that transaction 2 has been successfully executed. In other words, the cancellation operation of transaction 1 is successful and transaction 1 is canceled.
[0094] So far, according to Figure 2 The execution process of canceling the transaction shown in part (a) is completed.
[0095] Reference Figure 2 As shown in part (b), the blockchain transaction cancellation method provided in the embodiment of the present application is applied to cancel a transaction initiated by the user, such as canceling Figure 2 For transaction 1 shown in part (b) of the example, the entire operation process can include the following steps:
[0096] Step 1: The user initiates a transaction 1, involving Figure 2 The steps in part (b) are numbered 2.1-2.3.
[0097] 2.1, Constructing Transaction 1: The user initiates an initial transaction through the account, such as Transaction 1;
[0098] 2.2, Sending Transaction 1: The blockchain node, for example, the target node, receives Transaction 1 and adds it to the local transaction pool;
[0099] 2.3, Broadcast Transaction 1: The target node broadcasts Transaction 1 to other nodes in the blockchain.
[0100] The above steps 2.1-2.3 are the same as the process of initiating a transaction in the prior art, for example Figure 2 The steps 1.1-1.3 in part (a) are the same.
[0101] Step 2: The user initiates a request to cancel transaction 1, involving Figure 2 The steps numbered 2.4-2.5 in part (b) of FIG.
[0102] 2.4-2.5, Initiate a request to cancel transaction 1: The user initiates a transaction cancellation request through the account, requesting to cancel the execution of transaction 1;
[0103] The user can submit a request to cancel transaction 1 to the target node through the account, that is, the user initiates the transaction cancellation request in the above embodiments to the target node. The target node can receive the request through the configured transaction cancellation interface.
[0104] In the embodiment of the present application, each node in the blockchain can be configured with a transaction cancellation interface, which can be constructed based on the JSON-RPC protocol. The parameter definition of the transaction cancellation interface can be expressed as follows:
[0105]
[0106] According to the above parameter design, the user can cancel a transaction by initiating the following request through the account, for example: Figure 2 Transaction 1 in part (b):
[0107] curl -X POST http: / / localhost:8545 -H "Content-Type: application / json" -d '{
[0108] "jsonrpc": "2.0",
[0109] "method": "eth_cancelTransaction",
[0110] "params": [
[0111] {
[0112] "transactionHash": "0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef1234",
[0113] "from": "0xAbcdef1234567890Abcdef1234567890Abcdef12",
[0114] "signature": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
[0115] }
[0116] ],
[0117] "id": 1
[0118] }'
[0119] The transaction cancellation request carries the transaction hash (TransactionHash) and signature information (Signature) of the transaction 1 to be canceled.
[0120] By comparison Figure 2 As can be seen from parts (a) and (b) of the embodiment, when canceling a transaction using the method provided in the embodiment of the present application, there is no need to construct a new transaction with a higher fee.
[0121] Step 3: The target node executes the operation of canceling transaction 1, involving Figure 2 Step 2.6 in part (b) of FIG.
[0122] 2.6. Delete Transaction 1 and add the transaction hash to the cache pool: After receiving the transaction cancellation request, the target node can delete the to-be-cancelled transaction 1 from the local transaction pool and store the transaction hash of the transaction 1 in the canceled transaction cache pool.
[0123] In an embodiment of the present application, upon receiving a transaction cancellation request, the target node may first verify the legitimacy of the request. The legitimacy verification of the transaction cancellation request may be achieved using the signature information carried in the request.
[0124] If the validity verification of the transaction cancellation request passes, the target node can delete the transaction 1 to be canceled from the local transaction pool and store the transaction hash of the deleted transaction 1 in the cancellation transaction cache pool.
[0125] In this embodiment, when constructing a transaction cancellation cache pool, a map structure can be used as an in-memory cache to provide fast transaction status query capabilities. Furthermore, to achieve data persistence and prevent data loss after node restarts or crashes, LevelDB can be used as the underlying storage. This design balances performance and reliability, ensuring that records of transaction cancellations are not lost even in the event of a system anomaly.
[0126] In one example, a map structure is used as an in-memory cache. A map can be maintained in memory with the transaction hash as the key and the transaction cancellation time as the value. This allows for rapid processing and querying of recently canceled transactions based on the transaction cancellation time.
[0127] In another example, a LevelDB structure can be used for persistent storage. Transaction cancellation data can be grouped and stored by date, with the key formatted as yyyy-mm-dd:transactionHash to ensure efficient querying based on date. The transaction cancellation data value stores detailed information about the canceled transaction, including the transaction hash and cancellation time.
[0128] In a possible implementation of the embodiment of the present application, a storage and cleanup process for the transaction cancellation buffer pool and persistent storage is also provided.
[0129] Storage Logic
[0130] When a transaction is canceled, it can:
[0131] ① Update the memory cache, that is, update the local transaction cancellation cache pool, and add the transaction hash transactionHash and transaction cancellation time of the canceled transaction to the map. For example, Figure 2 The transaction hash and transaction cancellation time of transaction 1 canceled in part (b) are stored in the map.
[0132] ② Write the transaction cancellation data to the persistent storage LevelDB. The key of the transaction cancellation data can be yyyy-mm-dd:transactionHash, and the value is the detailed information of the transaction cancellation.
[0133] Regular cleanup strategy
[0134] You can perform cleanup tasks according to a set period, such as once a day. The specific steps may include:
[0135] ① Get the current date and calculate the date range to be retained (such as "today" and "yesterday").
[0136] ② Traverse the keys in LevelDB and check whether the date part is within the reserved range:
[0137] ③ If it is within the range, retain the corresponding transaction cancellation data.
[0138] ④ If it is not within the range, delete the corresponding key-value pair, that is, delete the transaction cancellation data that is not within the corresponding date range from the persistent storage.
[0139] ⑤ Clear all deleted transactionHash in the memory cache.
[0140] Reload data
[0141] ① When the node starts, it loads the transaction cancellation data within a set time range (for example, the last two days) from the persistent storage LevelDB into the memory cache.
[0142] ② Traverse the keys in the persistent storage LevelDB and extract data that matches the date range.
[0143] ③ Load this data into the map to reduce the time delay of the first query.
[0144] Step 4: The target node broadcasts the transaction cancellation event to other nodes to complete the cancellation of transaction 1, involving Figure 2 Part (b) is numbered as step 2.7.
[0145] 2.7, Broadcasting transaction cancellation events: The target node can generate a corresponding transaction cancellation event for canceling transaction 1 and broadcast it to other nodes in the blockchain.
[0146] In this embodiment of the present application, a structure may be defined to represent a transaction cancellation event. The structure may include the following information:
[0147] Transaction Hash: Unique identifier of the canceled transaction. For example, the transaction hash that identifies transaction 1.
[0148] Cancellation initiator (from): The account address that initiates the cancellation operation.
[0149] Transaction cancellation time (timestamp): the specific time when the transaction was canceled.
[0150] When a user requests to cancel a transaction through the transaction cancellation interface and the request is successfully verified, the target node can generate a transaction cancellation event and add it to the broadcast queue. Through the broadcast queue, the transaction cancellation event is broadcast to other nodes in the blockchain to notify other nodes that the transaction has been canceled.
[0151] In the embodiment of the present application, the existing P2P network protocol of the blockchain (such as DevP2P) can be used for broadcasting. After receiving the broadcasted transaction cancellation event, each other node can process the received event in each node and update the local transaction pool and canceled transaction cache pool.
[0152] Step 5: Transaction status query, involving Figure 2 The steps numbered 2.8-2.9 in part (b) of FIG.
[0153] 2.8-2.9, Transaction Status Query: The target node can first check the blockchain status. If the transaction has already been posted, the cancellation operation has failed and the transaction buffer pool needs to be cleared and the status returned to "Posted on Chain". Otherwise, the "Cancelled Transaction Cache Pool" is checked. If the hash is found, the status returns to "Cancelled", confirming that the transaction has been canceled.
[0154] The embodiments of the present application provide a new transaction cancellation mechanism by introducing the node's "transaction cancellation interface", the network-wide "transaction cancellation event broadcast" and the "cancelled transaction cache pool". Users do not need to send new transactions with higher fees to cancel the original transactions, which not only reduces the cost of user transaction cancellation, but also avoids the consumption of Nonce values, thereby improving the flexibility of transaction cancellation.
[0155] Reference Figure 3 , shows a schematic diagram of a blockchain transaction cancellation device provided by an embodiment of the present application, which may specifically include a receiving module 301, a deletion module 302, a storage module 303, and a broadcasting module 304, wherein:
[0156] A receiving module 301 is configured to receive a transaction cancellation request, wherein the transaction cancellation request carries a transaction hash of a target transaction to be canceled;
[0157] A deletion module 302 is configured to delete the target transaction from the local transaction pool of a target node, where the target node is the node in the blockchain that initiated the target transaction.
[0158] The storage module 303 is configured to store the transaction hash of the target transaction in the canceled transaction cache pool of the target node;
[0159] The broadcast module 304 is configured to generate a transaction cancellation event for the target transaction and broadcast the transaction cancellation event to other nodes in the blockchain.
[0160] In a possible implementation of the embodiment of the present application, the receiving module 301 may be specifically configured to:
[0161] A transaction cancellation request for the initiated target transaction is received through a transaction cancellation interface of the target node, wherein the transaction cancellation interface is constructed based on a remote procedure call transmission protocol, and each node in the blockchain is configured with the transaction cancellation interface.
[0162] In a possible implementation of the embodiment of the present application, the deletion module 302 may be specifically configured to:
[0163] extracting signature information from the transaction cancellation request, and verifying the transaction cancellation request based on the signature information;
[0164] When the transaction cancellation request is verified, the target transaction corresponding to the transaction hash is deleted from the local transaction pool of the target node.
[0165] In a possible implementation of the embodiment of the present application, the storage module 303 may be specifically configured to:
[0166] Determine the transaction cancellation time;
[0167] Based on the transaction cancellation time, the transaction hash of the target transaction is stored in a local canceled transaction cache pool of the target node, where the canceled transaction cache pool is constructed using a key-value pair structure.
[0168] In a possible implementation of the embodiment of the present application, the storage module 303 may also be used to:
[0169] The transaction hash of the canceled target transaction and the corresponding transaction cancellation time are persistently stored.
[0170] In a possible implementation of the embodiment of the present application, the apparatus may further include a loading module, which may be specifically configured to:
[0171] When the target node starts, traverse the transaction cancellation data in the persistent storage, wherein the transaction cancellation data is keyed by information including the transaction cancellation time;
[0172] According to the transaction cancellation time, the transaction cancellation data within the target time range is loaded into the local transaction cancellation cache pool of the target node.
[0173] In a possible implementation of the embodiment of the present application, the broadcast module 304 may be specifically configured to:
[0174] Generate a transaction cancellation event based on the transaction hash of the target transaction and the corresponding transaction cancellation time, and add the transaction cancellation event to a broadcast queue;
[0175] The transaction cancellation event is broadcast to other nodes in the blockchain through the broadcast queue, where the transaction cancellation event carries a transaction hash that uniquely identifies the target transaction.
[0176] In a possible implementation of the embodiment of the present application, the apparatus may further include a confirmation module, which may be specifically configured to:
[0177] Receiving feedback information returned by other nodes in the blockchain regarding the transaction cancellation event;
[0178] If the feedback information returned by other nodes all indicates that the target transaction has been canceled, it is confirmed that the target transaction has been canceled successfully.
[0179] The present application provides a blockchain transaction cancellation device. This device can be a computer device described in the aforementioned embodiments, or one or more units or modules in a computer device capable of implementing the relevant functions. This device can be used to implement the various steps described in the aforementioned method embodiments.
[0180] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment part.
[0181] Reference Figure 4 , shows a schematic diagram of a computer device provided by an embodiment of the present application. Figure 4 As shown, the computer device 400 in the embodiment of the present application includes: a processor 410, a memory 420, and a computer program 421 stored in the memory 420 and executable on the processor 410. When the processor 410 executes the computer program 421, the steps in each embodiment of the above-mentioned blockchain transaction cancellation method are implemented, such as Figure 1 Alternatively, when the processor 410 executes the computer program 421, the functions of the modules / units in the above-mentioned device embodiments are realized, for example, Figure 3 Functions of modules 301 to 304 are shown.
[0182] Exemplarily, the computer program 421 may be divided into one or more modules / units, which are stored in the memory 420 and executed by the processor 410 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of performing specific functions, which may be used to describe the execution process of the computer program 421 in the computer device 400. For example, the computer program 421 may be divided into a receiving module, a deletion module, a storage module, and a broadcasting module, with the specific functions of each module being as follows:
[0183] A receiving module, configured to receive a transaction cancellation request, wherein the transaction cancellation request carries a transaction hash of a target transaction to be canceled;
[0184] A deletion module, configured to delete the target transaction from the local transaction pool of a target node, where the target node is the node in the blockchain that initiated the target transaction;
[0185] A storage module, configured to store the transaction hash of the target transaction in a canceled transaction cache pool of the target node;
[0186] A broadcast module is configured to generate a transaction cancellation event for the target transaction and broadcast the transaction cancellation event to other nodes in the blockchain.
[0187] The computer device 400 may be a device capable of implementing the functions of each step in the aforementioned method embodiments. The computer device 400 may be a desktop computer, a cloud server, or other devices. The computer device 400 may include, but is not limited to, a processor 410 and a memory 420. It will be understood by those skilled in the art that Figure 4 This is merely an example of the computer device 400 and does not constitute a limitation of the computer device 400 . The computer device 400 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device 400 may also include input and output devices, network access devices, buses, etc.
[0188] The processor 410 may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0189] The memory 420 may be an internal storage unit of the computer device 400, such as a hard drive or memory of the computer device 400. The memory 420 may also be an external storage device of the computer device 400, such as a plug-in hard drive, a Smart Media Card (SMC), a Secure Digital (SD) card, a flash memory card, etc. equipped on the computer device 400. Furthermore, the memory 420 may include both an internal storage unit of the computer device 400 and an external storage device. The memory 420 is used to store the computer program 421 and other programs and data required by the computer device 400. The memory 420 may also be used to temporarily store data that has been output or is about to be output.
[0190] An embodiment of the present application also discloses a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the method described in the aforementioned embodiments is implemented to cancel a target transaction.
[0191] An embodiment of the present application further discloses a computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium. When the computer program is executed by a computer, the method described in the aforementioned embodiments is implemented to cancel a target transaction.
[0192] An embodiment of the present application further discloses a computer program product, including a computer program. When the computer program is run on a computer, the computer is caused to execute the method described in the aforementioned embodiments to cancel a target transaction.
[0193] An embodiment of the present application also discloses a blockchain transaction system, which may include multiple blockchain nodes. Any node can execute the methods described in the aforementioned embodiments to cancel the target transaction initiated by the node.
[0194] The above embodiments are intended only to illustrate the technical solutions of the present application and are not intended to limit them. Although the present application has been described in detail with reference to the above embodiments, those skilled in the art should understand that they may still modify the technical solutions described in the above embodiments or replace some of the technical features therein with equivalents; and such modifications or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present application and should be included within the scope of protection of the present application.
Claims
1. A blockchain transaction cancellation method, characterized in that: include: Receive a transaction cancellation request through a configured transaction cancellation interface. The transaction cancellation request carries the transaction hash of the target transaction to be canceled and is used to request cancellation of the initiated target transaction. The transaction cancellation interface is constructed based on the Remote Procedure Call (RPC) transport protocol and is configured on each node in the blockchain. Deleting the target transaction corresponding to the transaction cancellation request from the local transaction pool of the target node, where the target node is the node that initiated the target transaction in the blockchain; Storing the transaction hash of the target transaction in the target node's canceled transaction cache pool, and persistently storing the canceled transaction hashes and corresponding transaction cancellation times of the target transaction. Both the canceled transaction cache pool and persistent storage are constructed using a key-value pair structure to provide fast query of the target transaction's transaction status. Generate a transaction cancellation event for the target transaction, broadcast the transaction cancellation event to other nodes in the blockchain, and request the other nodes to perform the same operation as the target node to cancel the target transaction.
2. The method according to claim 1, characterized in that The receiving a transaction cancellation request through the configured transaction cancellation interface includes: A transaction cancellation request for the initiated target transaction is received through a transaction cancellation interface of the target node.
3. The method according to claim 1 or 2, characterized in that The deleting the target transaction corresponding to the transaction cancellation request from the local transaction pool of the target node includes: extracting signature information from the transaction cancellation request, and verifying the transaction cancellation request based on the signature information; When the transaction cancellation request is verified, the target transaction corresponding to the transaction hash is deleted from the local transaction pool of the target node.
4. The method according to claim 3, characterized in that Storing the transaction hash of the target transaction in the canceled transaction cache pool of the target node includes: Determine the transaction cancellation time; Based on the transaction cancellation time, the transaction hash of the target transaction is stored in a local canceled transaction cache pool of the target node.
5. The method according to claim 1, wherein Also includes: When the target node starts, traverse the transaction cancellation data in the persistent storage, wherein the transaction cancellation data is keyed by information including the transaction cancellation time; According to the transaction cancellation time, the transaction cancellation data within the target time range is loaded into the local transaction cancellation cache pool of the target node.
6. The method according to any one of claims 1 or 2 or 4 to 5, characterized in that Generating a transaction cancellation event for the target transaction and broadcasting the transaction cancellation event to other nodes in the blockchain includes: Generate a transaction cancellation event based on the transaction hash of the target transaction and the corresponding transaction cancellation time, and add the transaction cancellation event to a broadcast queue; The transaction cancellation event is broadcast to other nodes in the blockchain through the broadcast queue, where the transaction cancellation event carries a transaction hash that uniquely identifies the target transaction.
7. The method according to claim 6, characterized in that After generating a transaction cancellation event for the canceled target transaction and broadcasting the transaction cancellation event to other nodes in the blockchain, the method further includes: Receiving feedback information returned by other nodes in the blockchain regarding the transaction cancellation event; If the feedback information returned by other nodes all indicates that the target transaction has been canceled, it is confirmed that the target transaction has been canceled successfully.
8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the computer device is caused to implement the method according to any one of claims 1 to 7.
9. A computer program product comprising a computer program, characterized in that When the computer program is executed, the method according to any one of claims 1 to 7 is performed.
Citation Information
Patent Citations
Transaction quick confirmation method based on licensing chain
CN107481011A
Block chain transaction deletion method and system
CN113592639A