Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(RPC): add RPC to clear verify queue #4609

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Removes all transactions from the verification queue.
/// Remove 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
Loading