From 7f318c03645b120a489746cd2258c0ed5bd6a7e4 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 21 Apr 2023 16:17:38 +0800 Subject: [PATCH 1/4] feat: add `time_added_to_pool` field to `get_transaction` Signed-off-by: Eval EXEC --- tx-pool/src/service.rs | 2 ++ util/jsonrpc-types/src/blockchain.rs | 4 ++++ util/types/src/core/tx_pool.rs | 20 ++++++++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tx-pool/src/service.rs b/tx-pool/src/service.rs index c1c66141e1..1155321178 100644 --- a/tx-pool/src/service.rs +++ b/tx-pool/src/service.rs @@ -900,11 +900,13 @@ async fn process(mut service: TxPoolService, message: Message) { Ok(TransactionWithStatus::with_proposed( Some(entry.transaction().clone()), entry.cycles, + entry.timestamp, )) } else if let Some(entry) = tx_pool.get_entry_from_pending_or_gap(&id) { Ok(TransactionWithStatus::with_pending( Some(entry.transaction().clone()), entry.cycles, + entry.timestamp, )) } else if let Some(ref recent_reject_db) = tx_pool.recent_reject { let recent_reject_result = recent_reject_db.get(&hash); diff --git a/util/jsonrpc-types/src/blockchain.rs b/util/jsonrpc-types/src/blockchain.rs index ba274a064a..a546e31e75 100644 --- a/util/jsonrpc-types/src/blockchain.rs +++ b/util/jsonrpc-types/src/blockchain.rs @@ -525,6 +525,8 @@ pub struct TransactionWithStatusResponse { pub transaction: Option>, /// The transaction consumed cycles. pub cycles: Option, + /// If the transaction is in tx-pool, `time_added_to_pool` represent when it enter the tx-pool. unit: Millisecond + pub time_added_to_pool: Option, /// The Transaction status. pub tx_status: TxStatus, } @@ -540,6 +542,7 @@ impl TransactionWithStatusResponse { .map(|tx| ResponseFormat::hex(tx.data().as_bytes())), tx_status: t.tx_status.into(), cycles: t.cycles.map(Into::into), + time_added_to_pool: t.time_added_to_pool.map(Into::into), }, ResponseFormatInnerType::Json => TransactionWithStatusResponse { transaction: t @@ -547,6 +550,7 @@ impl TransactionWithStatusResponse { .map(|tx| ResponseFormat::json(TransactionView::from(tx))), tx_status: t.tx_status.into(), cycles: t.cycles.map(Into::into), + time_added_to_pool: t.time_added_to_pool.map(Into::into), }, } } diff --git a/util/types/src/core/tx_pool.rs b/util/types/src/core/tx_pool.rs index 269cee6204..d5b41e1d4d 100644 --- a/util/types/src/core/tx_pool.rs +++ b/util/types/src/core/tx_pool.rs @@ -161,24 +161,36 @@ pub struct TransactionWithStatus { pub tx_status: TxStatus, /// The transaction verification consumed cycles pub cycles: Option, + /// If the transaction is in tx-pool, `time_added_to_pool` represent when it enter the tx-pool. unit: Millisecond + pub time_added_to_pool: Option, } impl TransactionWithStatus { /// Build with pending status - pub fn with_pending(tx: Option, cycles: core::Cycle) -> Self { + pub fn with_pending( + tx: Option, + cycles: core::Cycle, + time_added_to_pool: u64, + ) -> Self { Self { tx_status: TxStatus::Pending, transaction: tx, cycles: Some(cycles), + time_added_to_pool: Some(time_added_to_pool), } } /// Build with proposed status - pub fn with_proposed(tx: Option, cycles: core::Cycle) -> Self { + pub fn with_proposed( + tx: Option, + cycles: core::Cycle, + time_added_to_pool: u64, + ) -> Self { Self { tx_status: TxStatus::Proposed, transaction: tx, cycles: Some(cycles), + time_added_to_pool: Some(time_added_to_pool), } } @@ -192,6 +204,7 @@ impl TransactionWithStatus { tx_status: TxStatus::Committed(hash), transaction: tx, cycles, + time_added_to_pool: None, } } @@ -201,6 +214,7 @@ impl TransactionWithStatus { tx_status: TxStatus::Rejected(reason), transaction: None, cycles: None, + time_added_to_pool: None, } } @@ -210,6 +224,7 @@ impl TransactionWithStatus { tx_status: TxStatus::Unknown, transaction: None, cycles: None, + time_added_to_pool: None, } } @@ -219,6 +234,7 @@ impl TransactionWithStatus { tx_status, transaction: None, cycles, + time_added_to_pool: None, } } From d0f0ad153c89beb4ebbffc1e415854eff726df71 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 21 Apr 2023 17:18:13 +0800 Subject: [PATCH 2/4] docs: re-execute `make gen-rpc-doc` Signed-off-by: Eval EXEC --- rpc/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rpc/README.md b/rpc/README.md index 6d9fcde3c9..abfcbe8fec 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -6936,6 +6936,8 @@ The JSON view of a transaction as well as its status. * `cycles`: [`Cycle`](#type-cycle) `|` `null` - The transaction consumed cycles. +* `time_added_to_pool`: [`Uint64`](#type-uint64) `|` `null` - If the transaction is in tx-pool, `time_added_to_pool` represent when it enter the tx-pool. unit: Millisecond + * `tx_status`: [`TxStatus`](#type-txstatus) - The Transaction status. From d439f72eb726d22d8ed248bb8fee067773db4119 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 24 Apr 2023 23:26:07 +0800 Subject: [PATCH 3/4] test: reset time_added_to_pool value in `test_rpc_examples` --- rpc/src/module/chain.rs | 1 + rpc/src/tests/examples.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/rpc/src/module/chain.rs b/rpc/src/module/chain.rs index 4e5a7b0ed3..9700e5d17f 100644 --- a/rpc/src/module/chain.rs +++ b/rpc/src/module/chain.rs @@ -614,6 +614,7 @@ pub trait ChainRpc { /// "witnesses": [] /// }, /// "cycles": "0x219", + /// "time_added_to_pool" : "0x187b3d137a1", /// "tx_status": { /// "block_hash": null, /// "status": "pending", diff --git a/rpc/src/tests/examples.rs b/rpc/src/tests/examples.rs index e91fa1e097..1164278acd 100644 --- a/rpc/src/tests/examples.rs +++ b/rpc/src/tests/examples.rs @@ -625,6 +625,10 @@ fn mock_rpc_response(example: &RpcTestExample, response: &mut RpcTestResponse) { response.result["current_time"] = example.response.result["current_time"].clone(); response.result["work_id"] = example.response.result["work_id"].clone(); } + "get_transaction" => { + response.result["time_added_to_pool"] = + example.response.result["time_added_to_pool"].clone(); + } "tx_pool_info" => { response.result["last_txs_updated_at"] = example.response.result["last_txs_updated_at"].clone() From 59a95385203bb15ebfa6a41700140bb3b2303d1b Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Mon, 24 Apr 2023 23:47:55 +0800 Subject: [PATCH 4/4] docs: re-execute `make gen-rpc-doc` --- rpc/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/rpc/README.md b/rpc/README.md index abfcbe8fec..32cc6f3eb3 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -878,6 +878,7 @@ Response "witnesses": [] }, "cycles": "0x219", + "time_added_to_pool" : "0x187b3d137a1", "tx_status": { "block_hash": null, "status": "pending",