Skip to content

Commit

Permalink
feat: tx-pool entry timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad committed Oct 19, 2021
1 parent cab368f commit 12a341e
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": "0x616e33d3"
}
},
"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) - Local time when entering the Txpool, unit: second


### 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) - Local time when entering the Txpool, unit: second


### 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": "0x616e33d3"
/// }
/// },
/// "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;
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,
/// Local time when entering the Txpool, unit: second
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_secs(),
}
}

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,
/// Local time when entering the Txpool, unit: second
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,
/// Local time when entering the Txpool, unit: second
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,
/// Local time when entering the Txpool, unit: second
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,
/// Local time when entering the Txpool, unit: second
pub timestamp: u64,
}

/// Array of transaction ids
Expand Down

0 comments on commit 12a341e

Please sign in to comment.