Misc docs and renames …and one less clone (#11556)

* Misc docs and renames
…and one less clone

* unused import

* Docs

* Update ethcore/src/client/client.rs

Co-Authored-By: Niklas Adolfsson <niklasadolfsson1@gmail.com>

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
David
2020-03-10 23:58:54 +01:00
committed by GitHub
parent e88ac4dbcf
commit 5be4924672
9 changed files with 24 additions and 16 deletions

View File

@@ -675,7 +675,7 @@ impl SyncHandler {
}
/// Called when peer sends us new transactions
pub fn on_peer_transactions(sync: &ChainSync, io: &mut dyn SyncIo, peer_id: PeerId, r: &Rlp) -> Result<(), PacketDecodeError> {
pub fn on_peer_transactions(sync: &ChainSync, io: &mut dyn SyncIo, peer_id: PeerId, tx_rlp: Rlp) -> Result<(), PacketDecodeError> {
// Accept transactions only when fully synced
if !io.is_chain_queue_empty() || (sync.state != SyncState::Idle && sync.state != SyncState::NewBlocks) {
trace!(target: "sync", "{} Ignoring transactions while syncing", peer_id);
@@ -686,11 +686,11 @@ impl SyncHandler {
return Ok(());
}
let item_count = r.item_count()?;
let item_count = tx_rlp.item_count()?;
trace!(target: "sync", "{:02} -> Transactions ({} entries)", peer_id, item_count);
let mut transactions = Vec::with_capacity(item_count);
for i in 0 .. item_count {
let rlp = r.at(i)?;
let rlp = tx_rlp.at(i)?;
let tx = rlp.as_raw().to_vec();
transactions.push(tx);
}

View File

@@ -762,7 +762,7 @@ impl ChainSync {
self.transactions_stats.stats()
}
/// Updates transactions were received by a peer
/// Updates the set of transactions recently sent to this peer to avoid spamming.
pub fn transactions_received(&mut self, txs: &[UnverifiedTransaction], peer_id: PeerId) {
if let Some(peer_info) = self.peers.get_mut(&peer_id) {
peer_info.last_sent_transactions.extend(txs.iter().map(|tx| tx.hash()));

View File

@@ -68,7 +68,7 @@ impl SyncRequester {
let mut rlp = RlpStream::new_list(hashes.len());
trace!(target: "sync", "{} <- GetBlockBodies: {} entries starting from {:?}, set = {:?}", peer_id, hashes.len(), hashes.first(), set);
for h in &hashes {
rlp.append(&h.clone());
rlp.append(h);
}
SyncRequester::send_request(sync, io, peer_id, PeerAsking::BlockBodies, GetBlockBodiesPacket, rlp.out());
let peer = sync.peers.get_mut(&peer_id).expect("peer_id may originate either from on_packet, where it is already validated or from enumerating self.peers. qed");

View File

@@ -128,7 +128,7 @@ impl SyncSupplier {
TransactionsPacket => {
let res = {
let sync_ro = sync.read();
SyncHandler::on_peer_transactions(&*sync_ro, io, peer, &rlp)
SyncHandler::on_peer_transactions(&*sync_ro, io, peer, rlp)
};
if res.is_err() {
// peer sent invalid data, disconnect.