fix after merge
This commit is contained in:
parent
d331dfde32
commit
f20cdeb49a
|
@ -123,7 +123,7 @@ impl ConnectionFilter {
|
|||
}
|
||||
|
||||
/// Check if transaction should be sent to this connection && optionally update filter
|
||||
pub fn filter_transaction(&mut self, transaction_hash: &H256, transaction: &Transaction, transaction_fee_rate: u64) -> bool {
|
||||
pub fn filter_transaction(&mut self, transaction_hash: &H256, transaction: &Transaction, transaction_fee_rate: Option<u64>) -> bool {
|
||||
// check if transaction is known
|
||||
if self.last_transactions.contains_key(transaction_hash) {
|
||||
return false;
|
||||
|
@ -131,8 +131,10 @@ impl ConnectionFilter {
|
|||
|
||||
// check if transaction fee rate is high enough for this peer
|
||||
if let Some(fee_rate) = self.fee_rate {
|
||||
if transaction_fee_rate < fee_rate {
|
||||
return false;
|
||||
if let Some(transaction_fee_rate) = transaction_fee_rate {
|
||||
if transaction_fee_rate < fee_rate {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,13 +522,13 @@ pub mod tests {
|
|||
|
||||
let mut filter = ConnectionFilter::with_filterload(&default_filterload());
|
||||
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, 1000));
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, None));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, None));
|
||||
|
||||
filter.add(&make_filteradd(&*tx1.hash()));
|
||||
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, 1000));
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, None));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -539,13 +541,13 @@ pub mod tests {
|
|||
|
||||
let mut filter = ConnectionFilter::with_filterload(&default_filterload());
|
||||
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, 1000));
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, None));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, None));
|
||||
|
||||
filter.add(&make_filteradd(&tx1_out_data));
|
||||
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, 1000));
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, None));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -557,13 +559,13 @@ pub mod tests {
|
|||
|
||||
let mut filter = ConnectionFilter::with_filterload(&default_filterload());
|
||||
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, 1000));
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, None));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, None));
|
||||
|
||||
filter.add(&make_filteradd(&tx1_previous_output));
|
||||
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, 1000));
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, None));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -576,13 +578,13 @@ pub mod tests {
|
|||
|
||||
let mut filter = ConnectionFilter::with_filterload(&default_filterload());
|
||||
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, 1000));
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, None));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, None));
|
||||
|
||||
filter.add(&make_filteradd(&tx1_input_data));
|
||||
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, 1000));
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, None));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -592,23 +594,23 @@ pub mod tests {
|
|||
|
||||
let mut filter = ConnectionFilter::default();
|
||||
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(filter.filter_transaction(&tx2.hash(), &tx2, 2000));
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, Some(1000)));
|
||||
assert!(filter.filter_transaction(&tx2.hash(), &tx2, Some(2000)));
|
||||
|
||||
filter.set_fee_rate(1500);
|
||||
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(filter.filter_transaction(&tx2.hash(), &tx2, 2000));
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, Some(1000)));
|
||||
assert!(filter.filter_transaction(&tx2.hash(), &tx2, Some(2000)));
|
||||
|
||||
filter.set_fee_rate(3000);
|
||||
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, 2000));
|
||||
assert!(!filter.filter_transaction(&tx1.hash(), &tx1, Some(1000)));
|
||||
assert!(!filter.filter_transaction(&tx2.hash(), &tx2, Some(2000)));
|
||||
|
||||
filter.set_fee_rate(0);
|
||||
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, 1000));
|
||||
assert!(filter.filter_transaction(&tx2.hash(), &tx2, 2000));
|
||||
assert!(filter.filter_transaction(&tx1.hash(), &tx1, Some(1000)));
|
||||
assert!(filter.filter_transaction(&tx2.hash(), &tx2, Some(2000)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -989,7 +989,8 @@ impl<T> SynchronizationClientCore<T> where T: TaskExecutor {
|
|||
let block_header_and_ids: Vec<_> = indexed_blocks.into_iter()
|
||||
.filter_map(|b| if self.peers.filter(peer_index).filter_block(&b.hash()) {
|
||||
let prefilled_transactions_indexes = b.transactions().enumerate()
|
||||
.filter(|&(_, (h, t))| self.peers.filter_mut(peer_index).filter_transaction(h, t))
|
||||
// we do not filter by fee rate here, because it only reasonable for non-mined transactions
|
||||
.filter(|&(_, (h, t))| self.peers.filter_mut(peer_index).filter_transaction(h, t, None))
|
||||
.map(|(idx, _)| idx)
|
||||
.collect();
|
||||
Some(build_compact_block(b, prefilled_transactions_indexes))
|
||||
|
@ -1031,7 +1032,7 @@ impl<T> SynchronizationClientCore<T> where T: TaskExecutor {
|
|||
.filter_map(|peer_index| {
|
||||
let inventory: Vec<_> = new_transactions.iter()
|
||||
.filter(|&&(ref h, tx, tx_fee_rate)| {
|
||||
self.peers.filter_mut(peer_index).filter_transaction(h, tx, tx_fee_rate)
|
||||
self.peers.filter_mut(peer_index).filter_transaction(h, tx, Some(tx_fee_rate))
|
||||
})
|
||||
.map(|&(ref h, _, _)| InventoryVector {
|
||||
inv_type: InventoryType::MessageTx,
|
||||
|
@ -2264,6 +2265,7 @@ pub mod tests {
|
|||
sync.on_peer_block(2, test_data::block_h2());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relay_new_block_after_sendcmpct() {
|
||||
// TODO
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue