Skip to content

Commit

Permalink
fix tests and remove timestamp in sort key
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jul 20, 2023
1 parent 459189a commit 8ffeeab
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
21 changes: 13 additions & 8 deletions test/src/specs/tx_pool/get_raw_tx_pool.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{Node, Spec};
use ckb_jsonrpc_types::{RawTxPool, TxPoolIds};
use ckb_jsonrpc_types::RawTxPool;
use ckb_logger::info;
use ckb_types::prelude::Unpack;
use ckb_types::{prelude::Unpack, H256};

pub struct GetRawTxPool;

Expand All @@ -21,13 +21,18 @@ impl Spec for GetRawTxPool {
txs_hash.push(node0.rpc_client().send_transaction(tx.data().into()));
});

let raw_tx_pool = RawTxPool::Ids(TxPoolIds {
pending: txs_hash.iter().map(Unpack::unpack).collect(),
proposed: Vec::new(),
});
let mut pending: Vec<H256> = txs_hash.iter().map(Unpack::unpack).collect();
pending.sort();
let result = node0.rpc_client().get_raw_tx_pool(None);
assert_eq!(raw_tx_pool, result);

match result {
RawTxPool::Ids(ids) => {
assert_eq!(0, ids.proposed.len());
let mut ids = ids.pending;
ids.sort();
assert_eq!(ids, pending);
}
_ => panic!("get_raw_tx_pool(true) should return entries"),
}
match node0.rpc_client().get_raw_tx_pool(Some(true)) {
RawTxPool::Ids(_ids) => {
panic!("get_raw_tx_pool(true) should return entries");
Expand Down
2 changes: 1 addition & 1 deletion tx-pool/src/component/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl From<&TxEntry> for AncestorsScoreSortKey {
id: entry.proposal_short_id(),
ancestors_fee: entry.ancestors_fee,
ancestors_weight,
timestamp: entry.timestamp,
//timestamp: entry.timestamp,
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions tx-pool/src/component/score_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub struct AncestorsScoreSortKey {
pub id: ProposalShortId,
pub ancestors_fee: Capacity,
pub ancestors_weight: u64,
pub timestamp: u64,
}

impl AncestorsScoreSortKey {
Expand Down Expand Up @@ -43,12 +42,7 @@ impl Ord for AncestorsScoreSortKey {
if self_weight == other_weight {
// if fee rate weight is same, then compare with ancestor weight
if self.ancestors_weight == other.ancestors_weight {
if self.timestamp == other.timestamp {
self.id.raw_data().cmp(&other.id.raw_data())
} else {
// NOTE: we use timestamp to compare, so the order is reversed
self.timestamp.cmp(&other.timestamp).reverse()
}
self.id.raw_data().cmp(&other.id.raw_data())
} else {
self.ancestors_weight.cmp(&other.ancestors_weight)
}
Expand Down
4 changes: 2 additions & 2 deletions tx-pool/src/component/tests/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ fn test_fill_proposals() {

let mut ret = HashSet::new();
pool.fill_proposals(1, &HashSet::new(), &mut ret, &Status::Pending);
assert_eq!(ret, HashSet::from_iter(vec![id1.clone()]));
assert_eq!(ret.len(), 1);

let mut ret = HashSet::new();
pool.fill_proposals(2, &HashSet::new(), &mut ret, &Status::Pending);
assert_eq!(ret, HashSet::from_iter(vec![id1.clone(), id2.clone()]));
assert_eq!(ret.len(), 2);

let mut ret = HashSet::new();
let mut exclusion = HashSet::new();
Expand Down
2 changes: 0 additions & 2 deletions tx-pool/src/component/tests/score_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ fn test_min_fee_and_weight() {
id: ProposalShortId::new([0u8; 10]),
ancestors_fee: Capacity::shannons(ancestors_fee),
ancestors_weight,
timestamp: 0,
};
key.min_fee_and_weight()
})
Expand Down Expand Up @@ -75,7 +74,6 @@ fn test_ancestors_sorted_key_order() {
id: ProposalShortId::new(id),
ancestors_fee: Capacity::shannons(ancestors_fee),
ancestors_weight,
timestamp: 0,
}
})
.collect::<Vec<_>>();
Expand Down

0 comments on commit 8ffeeab

Please sign in to comment.