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

rpc(ChainRpc): Add time_added_to_pool field for ChainRpcImpl::get_transaction #3949

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
3 changes: 3 additions & 0 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ Response
"witnesses": []
},
"cycles": "0x219",
"time_added_to_pool" : "0x187b3d137a1",
"tx_status": {
"block_hash": null,
"status": "pending",
Expand Down Expand Up @@ -6936,6 +6937,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.


Expand Down
1 change: 1 addition & 0 deletions rpc/src/module/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ pub trait ChainRpc {
/// "witnesses": []
/// },
/// "cycles": "0x219",
/// "time_added_to_pool" : "0x187b3d137a1",
/// "tx_status": {
/// "block_hash": null,
/// "status": "pending",
Expand Down
4 changes: 4 additions & 0 deletions rpc/src/tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions tx-pool/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions util/jsonrpc-types/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ pub struct TransactionWithStatusResponse {
pub transaction: Option<ResponseFormat<TransactionView>>,
/// The transaction consumed cycles.
pub cycles: Option<Cycle>,
/// 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<Uint64>,
/// The Transaction status.
pub tx_status: TxStatus,
}
Expand All @@ -540,13 +542,15 @@ 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
.transaction
.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),
},
}
}
Expand Down
20 changes: 18 additions & 2 deletions util/types/src/core/tx_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,36 @@ pub struct TransactionWithStatus {
pub tx_status: TxStatus,
/// The transaction verification consumed cycles
pub cycles: Option<core::Cycle>,
/// 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<u64>,
}

impl TransactionWithStatus {
/// Build with pending status
pub fn with_pending(tx: Option<core::TransactionView>, cycles: core::Cycle) -> Self {
pub fn with_pending(
tx: Option<core::TransactionView>,
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<core::TransactionView>, cycles: core::Cycle) -> Self {
pub fn with_proposed(
tx: Option<core::TransactionView>,
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),
}
}

Expand All @@ -192,6 +204,7 @@ impl TransactionWithStatus {
tx_status: TxStatus::Committed(hash),
transaction: tx,
cycles,
time_added_to_pool: None,
}
}

Expand All @@ -201,6 +214,7 @@ impl TransactionWithStatus {
tx_status: TxStatus::Rejected(reason),
transaction: None,
cycles: None,
time_added_to_pool: None,
}
}

Expand All @@ -210,6 +224,7 @@ impl TransactionWithStatus {
tx_status: TxStatus::Unknown,
transaction: None,
cycles: None,
time_added_to_pool: None,
}
}

Expand All @@ -219,6 +234,7 @@ impl TransactionWithStatus {
tx_status,
transaction: None,
cycles,
time_added_to_pool: None,
}
}

Expand Down