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

Fix rebroadcast panic #4084

Merged
merged 6 commits into from
Jan 9, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixing 'simplify'
Tomasz Drwięga committed Jan 9, 2017
commit 1a3c30e0e52c1132ee80dd13b8f1045003be86aa
26 changes: 23 additions & 3 deletions sync/src/chain.rs
Original file line number Diff line number Diff line change
@@ -2085,9 +2085,9 @@ impl ChainSync {

if !is_syncing && !enacted.is_empty() && !self.peers.is_empty() {
// Select random peer to re-broadcast transactions to.
let peer = random::new().get_rng(0, self.peers.len());
trace!(target: "sync", "Re-broadcasting transactions to random peer.");
self.peers.get_mut(peer).map(|mut peer_info|
let peer = random::new().gen_range(0, self.peers.len());
trace!(target: "sync", "Re-broadcasting transactions to a random peer.");
self.peers.values_mut().nth(peer).map(|mut peer_info|
peer_info.last_sent_transactions.clear()
);
}
@@ -2550,6 +2550,26 @@ mod tests {
assert_eq!(0x02, io.packets[0].packet_id);
}

#[test]
fn does_not_fail_for_no_peers() {
let mut client = TestBlockChainClient::new();
client.add_blocks(100, EachBlockWith::Uncle);
client.insert_transaction_to_queue();
// Sync with no peers
let mut sync = ChainSync::new(SyncConfig::default(), &client);
let queue = RwLock::new(VecDeque::new());
let ss = TestSnapshotService::new();
let mut io = TestIo::new(&mut client, &ss, &queue, None);
let peer_count = sync.propagate_new_transactions(&mut io);
sync.chain_new_blocks(&mut io, &[], &[], &[], &[], &[], &[]);
// Try to propagate same transactions for the second time
let peer_count2 = sync.propagate_new_transactions(&mut io);

assert_eq!(0, io.packets.len());
assert_eq!(0, peer_count);
assert_eq!(0, peer_count2);
}

#[test]
fn propagates_transactions_without_alternating() {
let mut client = TestBlockChainClient::new();