From b660f902bf6d8eb62420699ed314293d552862ed Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Thu, 23 Mar 2023 11:35:17 +0800 Subject: [PATCH] feat: RPC tx_pool_info add tx_size_limit and max_tx_pool_size --- rpc/README.md | 12 +++++++-- rpc/src/module/pool.rs | 21 ++++------------ rpc/src/service_builder.rs | 4 +-- rpc/src/tests/examples.rs | 6 ++--- rpc/src/tests/mod.rs | 6 ++--- tx-pool/src/pool.rs | 33 ------------------------ tx-pool/src/service.rs | 7 ++++-- util/jsonrpc-types/src/pool.rs | 30 +++++++++++++++++++++- util/launcher/src/lib.rs | 1 - util/types/src/core/tx_pool.rs | 46 +++++++++++++++++++++++++++++++++- 10 files changed, 101 insertions(+), 65 deletions(-) diff --git a/rpc/README.md b/rpc/README.md index f3800eeb653..2a99fb7f506 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -4435,14 +4435,16 @@ Response "jsonrpc": "2.0", "result": { "last_txs_updated_at": "0x0", - "min_fee_rate": "0x0", + "min_fee_rate": "0x3e8", + "max_tx_pool_size": "0xaba9500", "orphan": "0x0", "pending": "0x1", "proposed": "0x0", "tip_hash": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40", "tip_number": "0x400", "total_tx_cycles": "0x219", - "total_tx_size": "0x112" + "total_tx_size": "0x112", + "tx_size_limit": "0x7d000" } } ``` @@ -6916,6 +6918,12 @@ Transaction pool information. * `last_txs_updated_at`: [`Timestamp`](#type-timestamp) - Last updated time. This is the Unix timestamp in milliseconds. +* `tx_size_limit`: [`Uint64`](#type-uint64) - Limiting transactions to tx_size_limit + + Transactions with a large size close to the block size limit may not be packaged, because the block header and cellbase are occupied, so the tx-pool is limited to accepting transaction up to tx_size_limit. + +* `max_tx_pool_size`: [`Uint64`](#type-uint64) - Total limit on the size of transactions in the tx-pool + ### Type `TxStatus` diff --git a/rpc/src/module/pool.rs b/rpc/src/module/pool.rs index 7013787e377..d2832c734b8 100644 --- a/rpc/src/module/pool.rs +++ b/rpc/src/module/pool.rs @@ -161,14 +161,16 @@ pub trait PoolRpc { /// "jsonrpc": "2.0", /// "result": { /// "last_txs_updated_at": "0x0", - /// "min_fee_rate": "0x0", + /// "min_fee_rate": "0x3e8", + /// "max_tx_pool_size": "0xaba9500", /// "orphan": "0x0", /// "pending": "0x1", /// "proposed": "0x0", /// "tip_hash": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40", /// "tip_number": "0x400", /// "total_tx_cycles": "0x219", - /// "total_tx_size": "0x112" + /// "total_tx_size": "0x112", + /// "tx_size_limit": "0x7d000" /// } /// } /// ``` @@ -276,7 +278,6 @@ pub trait PoolRpc { pub(crate) struct PoolRpcImpl { shared: Shared, - min_fee_rate: core::FeeRate, well_known_lock_scripts: Vec, well_known_type_scripts: Vec, } @@ -284,7 +285,6 @@ pub(crate) struct PoolRpcImpl { impl PoolRpcImpl { pub fn new( shared: Shared, - min_fee_rate: core::FeeRate, mut extra_well_known_lock_scripts: Vec, mut extra_well_known_type_scripts: Vec, ) -> PoolRpcImpl { @@ -298,7 +298,6 @@ impl PoolRpcImpl { PoolRpcImpl { shared, - min_fee_rate, well_known_lock_scripts, well_known_type_scripts, } @@ -449,17 +448,7 @@ impl PoolRpc for PoolRpcImpl { let tx_pool_info = get_tx_pool_info.unwrap(); - Ok(TxPoolInfo { - tip_hash: tx_pool_info.tip_hash.unpack(), - tip_number: tx_pool_info.tip_number.into(), - pending: (tx_pool_info.pending_size as u64).into(), - proposed: (tx_pool_info.proposed_size as u64).into(), - orphan: (tx_pool_info.orphan_size as u64).into(), - total_tx_size: (tx_pool_info.total_tx_size as u64).into(), - total_tx_cycles: tx_pool_info.total_tx_cycles.into(), - min_fee_rate: self.min_fee_rate.as_u64().into(), - last_txs_updated_at: tx_pool_info.last_txs_updated_at.into(), - }) + Ok(tx_pool_info.into()) } fn clear_tx_pool(&self) -> Result<()> { diff --git a/rpc/src/service_builder.rs b/rpc/src/service_builder.rs index c72953d0ef1..19372ce8a0c 100644 --- a/rpc/src/service_builder.rs +++ b/rpc/src/service_builder.rs @@ -15,7 +15,7 @@ use ckb_network_alert::{notifier::Notifier as AlertNotifier, verifier::Verifier use ckb_pow::Pow; use ckb_shared::shared::Shared; use ckb_sync::SyncShared; -use ckb_types::{core::FeeRate, packed::Script}; +use ckb_types::packed::Script; use ckb_util::Mutex; use jsonrpc_core::RemoteProcedure; use std::sync::Arc; @@ -52,13 +52,11 @@ impl<'a> ServiceBuilder<'a> { pub fn enable_pool( mut self, shared: Shared, - min_fee_rate: FeeRate, extra_well_known_lock_scripts: Vec