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

Commit

Permalink
Sending transactions in chunks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Drwięga committed Jan 9, 2017
1 parent 71e6e24 commit 57fa4b8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sync/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ const MAX_NEW_HASHES: usize = 64;
const MAX_TX_TO_IMPORT: usize = 512;
const MAX_NEW_BLOCK_AGE: BlockNumber = 20;
const MAX_TRANSACTION_SIZE: usize = 300*1024;
// Maximal number of transactions in sent in single packet.
const MAX_TRANSACTIONS_TO_PROPAGATE: usize = 64;
// Min number of blocks to be behind for a snapshot sync
const SNAPSHOT_RESTORE_THRESHOLD: BlockNumber = 100000;
const SNAPSHOT_MIN_PEERS: usize = 3;
Expand Down Expand Up @@ -1991,7 +1993,10 @@ impl ChainSync {
}

// Get hashes of all transactions to send to this peer
let to_send = all_transactions_hashes.difference(&peer_info.last_sent_transactions).cloned().collect::<HashSet<_>>();
let to_send = all_transactions_hashes.difference(&peer_info.last_sent_transactions)
.take(MAX_TRANSACTIONS_TO_PROPAGATE)
.cloned()
.collect::<HashSet<_>>();
if to_send.is_empty() {
return None;
}
Expand All @@ -2007,7 +2012,11 @@ impl ChainSync {
}
}

peer_info.last_sent_transactions = all_transactions_hashes.clone();
peer_info.last_sent_transactions = all_transactions_hashes
.intersection(&peer_info.last_sent_transactions)
.chain(&to_send)
.cloned()
.collect();
Some((*peer_id, to_send.len(), packet.out()))
})
.collect::<Vec<_>>()
Expand Down

0 comments on commit 57fa4b8

Please sign in to comment.