Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit e978df2

Browse files
committed
Merge propagate_new_pooled_tx_hashes into propagate_new_transactions
1 parent 1e12537 commit e978df2

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

ethcore/sync/src/chain/propagator.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,23 @@ impl SyncPropagator {
9191
sent
9292
}
9393

94-
/// propagate new known pool hashes to all peers
95-
pub fn propagate_new_pooled_tx_hashes(sync: &mut ChainSync, io: &mut dyn SyncIo) -> usize {
96-
/// Recommended limit from the spec.
97-
const LIMIT: usize = 4096;
94+
/// propagates new transactions to all peers
95+
pub fn propagate_new_transactions<F: FnMut() -> bool>(sync: &mut ChainSync, io: &mut dyn SyncIo, mut should_continue: F) -> usize {
96+
const NEW_POOLED_HASHES_LIMIT: usize = 4096;
97+
98+
// Early out if nobody to send to.
99+
if sync.peers.is_empty() {
100+
return 0;
101+
}
98102

103+
// propagate just hashes to newer peers
99104
trace!(target: "sync", "Sending NewPooledTransactionsHashes to {:?}", sync.peers.keys());
100-
let mut affected_peers = 0;
101105
for (peer_id, peer) in &mut sync.peers {
102106
let mut affected = false;
103107
let mut packet = RlpStream::new();
104108
packet.begin_unbounded_list();
105109
if let Some(s) = &mut peer.unsent_pooled_hashes {
106-
for item in s.drain().take(LIMIT) {
110+
for item in s.drain().take(NEW_POOLED_HASHES_LIMIT) {
107111
affected = true;
108112
packet.append(&item);
109113
}
@@ -113,23 +117,9 @@ impl SyncPropagator {
113117
packet.finalize_unbounded_list();
114118

115119
SyncPropagator::send_packet(io, *peer_id, NewPooledTransactionHashesPacket, packet.out());
116-
affected_peers += 1;
117120
}
118121
}
119122

120-
affected_peers
121-
}
122-
123-
/// propagates new transactions to all peers
124-
pub fn propagate_new_transactions<F: FnMut() -> bool>(sync: &mut ChainSync, io: &mut dyn SyncIo, mut should_continue: F) -> usize {
125-
// Early out if nobody to send to.
126-
if sync.peers.is_empty() {
127-
return 0;
128-
}
129-
130-
// propagate just hashes to newer peers
131-
SyncPropagator::propagate_new_pooled_tx_hashes(sync, io);
132-
133123
let transactions = io.chain().transactions_to_propagate();
134124
if transactions.is_empty() {
135125
return 0;

0 commit comments

Comments
 (0)