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

Commit 5be4924

Browse files
dvdplmniklasad1
andauthored
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>
1 parent e88ac4d commit 5be4924

File tree

9 files changed

+24
-16
lines changed

9 files changed

+24
-16
lines changed

ethcore/engine/src/engine.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ pub trait Engine: Sync + Send {
399399
self.machine().verify_transaction_basic(t, header)
400400
}
401401

402-
/// Performs pre-validation of RLP decoded transaction before other processing
402+
/// Performs pre-validation of RLP encoded transaction before other
403+
/// processing: check length against `max_transaction_size` and decode the
404+
/// RLP.
403405
fn decode_transaction(&self, transaction: &[u8]) -> Result<UnverifiedTransaction, transaction::Error> {
404406
self.machine().decode_transaction(transaction)
405407
}

ethcore/machine/src/machine.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ impl Machine {
364364
Ok(())
365365
}
366366

367-
/// Performs pre-validation of RLP decoded transaction before other processing
367+
/// Performs pre-validation of RLP encoded transaction before other
368+
/// processing: check length against `max_transaction_size` and decode the
369+
/// RLP.
368370
pub fn decode_transaction(&self, transaction: &[u8]) -> Result<UnverifiedTransaction, transaction::Error> {
369371
let rlp = Rlp::new(&transaction);
370372
if rlp.as_raw().len() > self.params().max_transaction_size {

ethcore/src/client/client.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,7 +2186,7 @@ impl IoClient for Client {
21862186
fn queue_transactions(&self, transactions: Vec<Bytes>, peer_id: usize) {
21872187
trace_time!("queue_transactions");
21882188
let len = transactions.len();
2189-
self.queue_transactions.queue(&self.io_channel.read(), len, move |client| {
2189+
self.queue_transactions.enqueue(&self.io_channel.read(), len, move |client| {
21902190
trace_time!("import_queued_transactions");
21912191

21922192
let txs: Vec<UnverifiedTransaction> = transactions
@@ -2231,7 +2231,7 @@ impl IoClient for Client {
22312231

22322232
let queued = self.queued_ancient_blocks.clone();
22332233
let lock = self.ancient_blocks_import_lock.clone();
2234-
self.queue_ancient_blocks.queue(&self.io_channel.read(), 1, move |client| {
2234+
self.queue_ancient_blocks.enqueue(&self.io_channel.read(), 1, move |client| {
22352235
trace_time!("import_ancient_block");
22362236
// Make sure to hold the lock here to prevent importing out of order.
22372237
// We use separate lock, cause we don't want to block queueing.
@@ -2265,7 +2265,7 @@ impl IoClient for Client {
22652265
}
22662266

22672267
fn queue_consensus_message(&self, message: Bytes) {
2268-
match self.queue_consensus_message.queue(&self.io_channel.read(), 1, move |client| {
2268+
match self.queue_consensus_message.enqueue(&self.io_channel.read(), 1, move |client| {
22692269
if let Err(e) = client.engine().handle_message(&message) {
22702270
debug!(target: "poa", "Invalid message received: {}", e);
22712271
}
@@ -2798,7 +2798,11 @@ impl IoChannelQueue {
27982798
}
27992799
}
28002800

2801-
pub fn queue<F>(&self, channel: &IoChannel<ClientIoMessage<Client>>, count: usize, fun: F) -> EthcoreResult<()> where
2801+
/// Try to to add an item to the queue for deferred processing by the IO
2802+
/// client. Messages take the form of `Fn` closures that carry a `Client`
2803+
/// reference with them. Enqueuing a message can fail if the queue is full
2804+
/// or if the `send()` on the `IoChannel` fails.
2805+
pub fn enqueue<F>(&self, channel: &IoChannel<ClientIoMessage<Client>>, count: usize, fun: F) -> EthcoreResult<()> where
28022806
F: Fn(&Client) + Send + Sync + 'static,
28032807
{
28042808
let queue_size = self.currently_queued.load(AtomicOrdering::Relaxed);

ethcore/src/test_helpers/test_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ impl BlockChainClient for TestBlockChainClient {
937937
impl IoClient for TestBlockChainClient {
938938
fn queue_transactions(&self, transactions: Vec<Bytes>, _peer_id: usize) {
939939
// import right here
940-
let txs = transactions.into_iter().filter_map(|bytes| Rlp::new(&bytes).as_val().ok()).collect();
940+
let txs = transactions.iter().filter_map(|bytes| Rlp::new(bytes).as_val().ok()).collect();
941941
self.miner.import_external_transactions(self, txs);
942942
}
943943

ethcore/sync/src/chain/handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ impl SyncHandler {
675675
}
676676

677677
/// Called when peer sends us new transactions
678-
pub fn on_peer_transactions(sync: &ChainSync, io: &mut dyn SyncIo, peer_id: PeerId, r: &Rlp) -> Result<(), PacketDecodeError> {
678+
pub fn on_peer_transactions(sync: &ChainSync, io: &mut dyn SyncIo, peer_id: PeerId, tx_rlp: Rlp) -> Result<(), PacketDecodeError> {
679679
// Accept transactions only when fully synced
680680
if !io.is_chain_queue_empty() || (sync.state != SyncState::Idle && sync.state != SyncState::NewBlocks) {
681681
trace!(target: "sync", "{} Ignoring transactions while syncing", peer_id);
@@ -686,11 +686,11 @@ impl SyncHandler {
686686
return Ok(());
687687
}
688688

689-
let item_count = r.item_count()?;
689+
let item_count = tx_rlp.item_count()?;
690690
trace!(target: "sync", "{:02} -> Transactions ({} entries)", peer_id, item_count);
691691
let mut transactions = Vec::with_capacity(item_count);
692692
for i in 0 .. item_count {
693-
let rlp = r.at(i)?;
693+
let rlp = tx_rlp.at(i)?;
694694
let tx = rlp.as_raw().to_vec();
695695
transactions.push(tx);
696696
}

ethcore/sync/src/chain/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ impl ChainSync {
762762
self.transactions_stats.stats()
763763
}
764764

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

ethcore/sync/src/chain/requester.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl SyncRequester {
6868
let mut rlp = RlpStream::new_list(hashes.len());
6969
trace!(target: "sync", "{} <- GetBlockBodies: {} entries starting from {:?}, set = {:?}", peer_id, hashes.len(), hashes.first(), set);
7070
for h in &hashes {
71-
rlp.append(&h.clone());
71+
rlp.append(h);
7272
}
7373
SyncRequester::send_request(sync, io, peer_id, PeerAsking::BlockBodies, GetBlockBodiesPacket, rlp.out());
7474
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");

ethcore/sync/src/chain/supplier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl SyncSupplier {
128128
TransactionsPacket => {
129129
let res = {
130130
let sync_ro = sync.read();
131-
SyncHandler::on_peer_transactions(&*sync_ro, io, peer, &rlp)
131+
SyncHandler::on_peer_transactions(&*sync_ro, io, peer, rlp)
132132
};
133133
if res.is_err() {
134134
// peer sent invalid data, disconnect.

ethcore/types/src/io_message.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ pub enum ClientIoMessage<C> {
3737
FeedBlockChunk(H256, Bytes),
3838
/// Take a snapshot for the block with given number.
3939
TakeSnapshot(u64),
40-
/// Execute wrapped closure
40+
/// Execute wrapped Fn closure
4141
Execute(Callback<C>),
4242
}
4343

4444
impl<C> ClientIoMessage<C> {
45-
/// Create new `ClientIoMessage` that executes given procedure.
45+
/// Create new `ClientIoMessage` that can execute the wrapped Fn closure.
4646
pub fn execute<F: Fn(&C) + Send + Sync + 'static>(fun: F) -> Self {
4747
ClientIoMessage::Execute(Callback(Box::new(fun)))
4848
}
4949
}
5050

51-
/// A function to invoke in the client thread.
51+
/// A wrapper around an Fn closure to invoke in the client thread.
5252
pub struct Callback<C>(pub Box<dyn Fn(&C) + Send + Sync>);
5353

5454
impl<C> fmt::Debug for Callback<C> {

0 commit comments

Comments
 (0)