Skip to content

Commit

Permalink
add clear verify queue rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Aug 23, 2024
1 parent 3bd5fed commit 7bfc1e1
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
32 changes: 32 additions & 0 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -4748,6 +4749,37 @@ Response
}
```

<a id="pool-clear_tx_verify_queue"></a>
#### 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
}
```

<a id="pool-get_raw_tx_pool"></a>
#### Method `get_raw_tx_pool`
* `get_raw_tx_pool(verbose)`
Expand Down
36 changes: 36 additions & 0 deletions rpc/src/module/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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<bool>) -> Result<RawTxPool> {
let tx_pool = self.shared.tx_pool_controller();

Expand Down
12 changes: 12 additions & 0 deletions tx-pool/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub(crate) enum Message {
GetTransactionWithStatus(Request<Byte32, GetTransactionWithStatusResult>),
NewUncle(Notify<UncleBlockView>),
ClearPool(Request<Arc<Snapshot>, ()>),
ClearVerifyQueue(Request<(), ()>),
GetAllEntryInfo(Request<(), TxPoolEntryInfo>),
GetAllIds(Request<(), TxPoolIds>),
SavePool(Request<(), ()>),
Expand Down Expand Up @@ -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<TxPoolEntryInfo, AnyError> {
send_message!(self, GetAllEntryInfo, ())
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7bfc1e1

Please sign in to comment.