From 7bfc1e1e16e6c612008fc2226432dcf21efebaab Mon Sep 17 00:00:00 2001 From: yukang Date: Fri, 23 Aug 2024 21:12:27 +0800 Subject: [PATCH] add clear verify queue rpc --- rpc/README.md | 32 ++++++++++++++++++++++++++++++++ rpc/src/module/pool.rs | 36 ++++++++++++++++++++++++++++++++++++ tx-pool/src/service.rs | 12 ++++++++++++ 3 files changed, 80 insertions(+) diff --git a/rpc/README.md b/rpc/README.md index b769033c7d..c94b79d98e 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -109,6 +109,7 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1. * [Method `remove_transaction`](#pool-remove_transaction) * [Method `tx_pool_info`](#pool-tx_pool_info) * [Method `clear_tx_pool`](#pool-clear_tx_pool) + * [Method `clear_tx_verify_queue`](#pool-clear_tx_verify_queue) * [Method `get_raw_tx_pool`](#pool-get_raw_tx_pool) * [Method `get_pool_tx_detail_info`](#pool-get_pool_tx_detail_info) * [Method `tx_pool_ready`](#pool-tx_pool_ready) @@ -4748,6 +4749,37 @@ Response } ``` + +#### Method `clear_tx_verify_queue` +* `clear_tx_verify_queue()` + +* result: `null` + +Removes all transactions from the verification queue. + +###### Examples + +Request + +```json +{ + "id": 42, + "jsonrpc": "2.0", + "method": "clear_tx_verify_queue", + "params": [] +} +``` + +Response + +```json +{ + "id": 42, + "jsonrpc": "2.0", + "result": null +} +``` + #### Method `get_raw_tx_pool` * `get_raw_tx_pool(verbose)` diff --git a/rpc/src/module/pool.rs b/rpc/src/module/pool.rs index 9fe30b357e..a9e65da1c3 100644 --- a/rpc/src/module/pool.rs +++ b/rpc/src/module/pool.rs @@ -322,6 +322,33 @@ pub trait PoolRpc { #[rpc(name = "clear_tx_pool")] fn clear_tx_pool(&self) -> Result<()>; + /// Removes all transactions from the verification queue. + /// + /// ## Examples + /// + /// Request + /// + /// ```json + /// { + /// "id": 42, + /// "jsonrpc": "2.0", + /// "method": "clear_tx_verify_queue", + /// "params": [] + /// } + /// ``` + /// + /// Response + /// + /// ```json + /// { + /// "id": 42, + /// "jsonrpc": "2.0", + /// "result": null + /// } + /// ``` + #[rpc(name = "clear_tx_verify_queue")] + fn clear_tx_verify_queue(&self) -> Result<()>; + /// Returns all transaction ids in tx pool as a json array of string transaction ids. /// ## Params /// @@ -662,6 +689,15 @@ impl PoolRpc for PoolRpcImpl { Ok(()) } + fn clear_tx_verify_queue(&self) -> Result<()> { + let tx_pool = self.shared.tx_pool_controller(); + tx_pool + .clear_verify_queue() + .map_err(|err| RPCError::custom(RPCError::Invalid, err.to_string()))?; + + Ok(()) + } + fn get_raw_tx_pool(&self, verbose: Option) -> Result { let tx_pool = self.shared.tx_pool_controller(); diff --git a/tx-pool/src/service.rs b/tx-pool/src/service.rs index cb9c3939f7..83621e465e 100644 --- a/tx-pool/src/service.rs +++ b/tx-pool/src/service.rs @@ -110,6 +110,7 @@ pub(crate) enum Message { GetTransactionWithStatus(Request), NewUncle(Notify), ClearPool(Request, ()>), + ClearVerifyQueue(Request<(), ()>), GetAllEntryInfo(Request<(), TxPoolEntryInfo>), GetAllIds(Request<(), TxPoolIds>), SavePool(Request<(), ()>), @@ -322,6 +323,11 @@ impl TxPoolController { send_message!(self, ClearPool, new_snapshot) } + /// Clears the tx-verify-queue. + pub fn clear_verify_queue(&self) -> Result<(), AnyError> { + send_message!(self, ClearVerifyQueue, ()) + } + /// TODO(doc): @zhangsoledad pub fn get_all_entry_info(&self) -> Result { send_message!(self, GetAllEntryInfo, ()) @@ -914,6 +920,12 @@ async fn process(mut service: TxPoolService, message: Message) { error!("Responder sending clear_pool failed {:?}", e) }; } + Message::ClearVerifyQueue(Request { responder, .. }) => { + service.verify_queue.write().await.clear(); + if let Err(e) = responder.send(()) { + error!("Responder sending clear_verify_queue failed {:?}", e) + }; + } Message::GetPoolTxDetails(Request { responder, arguments: tx_hash,