Skip to content

Commit

Permalink
Merge #3100
Browse files Browse the repository at this point in the history
3100: feat: tx-pool entry timestamp r=quake,yangby-cryptape a=zhangsoledad

<!--
Thank you for contributing to nervosnetwork/ckb!

If you haven't already, please read [CONTRIBUTING](https://github.com/nervosnetwork/ckb/blob/develop/CONTRIBUTING.md) document.

If you're unsure about anything, just ask; somebody should be along to answer within a day or two.

PR Title Format:
1. module [, module2, module3]: what's changed
2. *: what's changed
-->

### What is changed and how it works?

Record timestamp when the transaction entered the pool.

### Check List <!--REMOVE the items that are not applicable-->

Tests <!-- At least one of them must be included. -->

- Unit test

### Release note <!-- Choose from None, Title Only and Note. Bugfixes or new features need a release note. -->

```release-note
Title Only: Include only the PR title in the release note.
```



Co-authored-by: zhangsoledad <[email protected]>
  • Loading branch information
bors[bot] and zhangsoledad authored Oct 19, 2021
2 parents cbeef7e + c29f5c8 commit 780ac48
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 2 deletions.
7 changes: 6 additions & 1 deletion rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2500,7 +2500,8 @@ Response
"fee": "0x16923f7dcf",
"ancestors_size": "0x112",
"ancestors_cycles": "0x219",
"ancestors_count": "0x1"
"ancestors_count": "0x1",
"timestamp": "0x17c983e6e44"
}
},
"proposed": {}
Expand Down Expand Up @@ -3939,6 +3940,8 @@ The transaction entry in the pool.

* `fee`: [`Capacity`](#type-capacity) - The transaction fee.

* `timestamp`: [`Uint64`](#type-uint64) - The unix timestamp when entering the Txpool, unit: Millisecond


### Type `PoolTransactionReject`

Expand Down Expand Up @@ -4441,6 +4444,8 @@ Transaction entry info

* `ancestors_count`: [`Uint64`](#type-uint64) - Number of in-tx-pool ancestor transactions

* `timestamp`: [`Uint64`](#type-uint64) - The unix timestamp when entering the Txpool, unit: Millisecond


### Type `TxPoolIds`

Expand Down
3 changes: 2 additions & 1 deletion rpc/src/module/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ pub trait PoolRpc {
/// "fee": "0x16923f7dcf",
/// "ancestors_size": "0x112",
/// "ancestors_cycles": "0x219",
/// "ancestors_count": "0x1"
/// "ancestors_count": "0x1",
/// "timestamp": "0x17c983e6e44"
/// }
/// },
/// "proposed": {}
Expand Down
6 changes: 6 additions & 0 deletions rpc/src/tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ where
fn mock_rpc_response(example: &RpcTestExample, response: &mut RpcTestResponse) {
use ckb_jsonrpc_types::{BannedAddr, Capacity, LocalNode, RemoteNode, Uint64};

let example_tx_hash = format!("{:#x}", EXAMPLE_TX_HASH);

match example.request.method.as_str() {
"local_node_info" => replace_rpc_response::<LocalNode>(example, response),
"get_peers" => replace_rpc_response::<Vec<RemoteNode>>(example, response),
Expand All @@ -579,6 +581,10 @@ fn mock_rpc_response(example: &RpcTestExample, response: &mut RpcTestResponse) {
response.result["chain"] = example.response.result["chain"].clone()
}
"send_alert" => response.error["data"] = example.response.error["data"].clone(),
"get_raw_tx_pool" => {
response.result["pending"][example_tx_hash.as_str()]["timestamp"] =
example.response.result["pending"][example_tx_hash.as_str()]["timestamp"].clone()
}
_ => {}
}
}
Expand Down
5 changes: 5 additions & 0 deletions tx-pool/src/component/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ckb_types::{
core::{cell::ResolvedTransaction, tx_pool::TxEntryInfo, Capacity, Cycle, TransactionView},
packed::{OutPoint, ProposalShortId},
};
use faketime::unix_time_as_millis;
use std::cmp::Ordering;
use std::hash::{Hash, Hasher};

Expand All @@ -26,6 +27,8 @@ pub struct TxEntry {
pub ancestors_cycles: Cycle,
/// ancestors txs count
pub ancestors_count: usize,
/// The unix timestamp when entering the Txpool, unit: Millisecond
pub timestamp: u64,
}

impl TxEntry {
Expand All @@ -40,6 +43,7 @@ impl TxEntry {
ancestors_fee: fee,
ancestors_cycles: cycles,
ancestors_count: 1,
timestamp: unix_time_as_millis(),
}
}

Expand Down Expand Up @@ -109,6 +113,7 @@ impl TxEntry {
ancestors_size: self.ancestors_size as u64,
ancestors_cycles: self.ancestors_cycles as u64,
ancestors_count: self.ancestors_count as u64,
timestamp: self.timestamp,
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions util/jsonrpc-types/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct PoolTransactionEntry {
pub size: Uint64,
/// The transaction fee.
pub fee: Capacity,
/// The unix timestamp when entering the Txpool, unit: Millisecond
pub timestamp: Uint64,
}

impl From<CorePoolTransactionEntry> for PoolTransactionEntry {
Expand All @@ -62,6 +64,7 @@ impl From<CorePoolTransactionEntry> for PoolTransactionEntry {
cycles: entry.cycles.into(),
size: (entry.size as u64).into(),
fee: entry.fee.into(),
timestamp: entry.timestamp.into(),
}
}
}
Expand Down Expand Up @@ -118,6 +121,8 @@ pub struct TxPoolEntry {
pub ancestors_cycles: Uint64,
/// Number of in-tx-pool ancestor transactions
pub ancestors_count: Uint64,
/// The unix timestamp when entering the Txpool, unit: Millisecond
pub timestamp: Uint64,
}

impl From<TxEntryInfo> for TxPoolEntry {
Expand All @@ -129,6 +134,7 @@ impl From<TxEntryInfo> for TxPoolEntry {
ancestors_size: info.ancestors_size.into(),
ancestors_cycles: info.ancestors_cycles.into(),
ancestors_count: info.ancestors_count.into(),
timestamp: info.timestamp.into(),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions util/launcher/src/shared_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ fn register_tx_pool_callback(tx_pool_builder: &mut TxPoolServiceBuilder, notify:
cycles: entry.cycles,
size: entry.size,
fee: entry.fee,
timestamp: entry.timestamp,
};
notify_pending.notify_new_transaction(notify_tx_entry);
}));
Expand All @@ -426,6 +427,7 @@ fn register_tx_pool_callback(tx_pool_builder: &mut TxPoolServiceBuilder, notify:
cycles: entry.cycles,
size: entry.size,
fee: entry.fee,
timestamp: entry.timestamp,
};
notify_proposed.notify_proposed_transaction(notify_tx_entry);
},
Expand Down Expand Up @@ -457,6 +459,7 @@ fn register_tx_pool_callback(tx_pool_builder: &mut TxPoolServiceBuilder, notify:
cycles: entry.cycles,
size: entry.size,
fee: entry.fee,
timestamp: entry.timestamp,
};
notify_reject.notify_reject_transaction(notify_tx_entry, reject);
},
Expand Down
2 changes: 2 additions & 0 deletions util/types/src/core/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ pub struct PoolTransactionEntry {
pub size: usize,
/// Transaction fee
pub fee: Capacity,
/// The unix timestamp when entering the Txpool, unit: Millisecond
pub timestamp: u64,
}
2 changes: 2 additions & 0 deletions util/types/src/core/tx_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ pub struct TxEntryInfo {
pub ancestors_cycles: u64,
/// Number of in-tx-pool ancestor transactions
pub ancestors_count: u64,
/// The unix timestamp when entering the Txpool, unit: Millisecond
pub timestamp: u64,
}

/// Array of transaction ids
Expand Down

0 comments on commit 780ac48

Please sign in to comment.