This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Avoid broadcasting transactions to peers that send them #3796
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e1ade5b
Maintaining a list of transactions propagated from other peers
704054e
Merge branch 'master' into tx-broadcast
e66157f
fixing test
aaf6da4
Returning persistent node id
19ca9ad
Prevent broadcasting transactions to peer that send them.
b5020d3
Fixing Light context API
1e86386
fixing tests
b56f12a
Merge branch 'master' into tx-broadcast
83d9bc1
Fixing test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,8 @@ pub struct TransactionStats { | |
pub first_seen: u64, | ||
/// Peers it was propagated to. | ||
pub propagated_to: BTreeMap<H512, usize>, | ||
/// Peers that propagated the transaction back. | ||
pub received_from: BTreeMap<H512, usize>, | ||
} | ||
|
||
/// Peer connection information | ||
|
@@ -144,7 +146,7 @@ pub struct EthSync { | |
network: NetworkService, | ||
/// Main (eth/par) protocol handler | ||
sync_handler: Arc<SyncProtocolHandler>, | ||
/// Light (les) protocol handler | ||
/// Light (les) protocol handler | ||
light_proto: Option<Arc<LightProtocol>>, | ||
/// The main subprotocol name | ||
subprotocol_name: [u8; 3], | ||
|
@@ -155,7 +157,7 @@ pub struct EthSync { | |
impl EthSync { | ||
/// Creates and register protocol with the network service | ||
pub fn new(params: Params) -> Result<Arc<EthSync>, NetworkError> { | ||
let pruning_info = params.chain.pruning_info(); | ||
let pruning_info = params.chain.pruning_info(); | ||
let light_proto = match params.config.serve_light { | ||
false => None, | ||
true => Some({ | ||
|
@@ -297,7 +299,7 @@ impl ChainNotify for EthSync { | |
Some(lp) => lp, | ||
None => return, | ||
}; | ||
|
||
let chain_info = self.sync_handler.chain.chain_info(); | ||
light_proto.make_announcement(context, Announcement { | ||
head_hash: chain_info.best_block_hash, | ||
|
@@ -323,7 +325,7 @@ impl ChainNotify for EthSync { | |
// register the warp sync subprotocol | ||
self.network.register_protocol(self.sync_handler.clone(), WARP_SYNC_PROTOCOL_ID, SNAPSHOT_SYNC_PACKET_COUNT, &[1u8]) | ||
.unwrap_or_else(|e| warn!("Error registering snapshot sync protocol: {:?}", e)); | ||
|
||
// register the light protocol. | ||
if let Some(light_proto) = self.light_proto.as_ref().map(|x| x.clone()) { | ||
self.network.register_protocol(light_proto, self.light_subprotocol_name, ::light::net::PACKET_COUNT, ::light::net::PROTOCOL_VERSIONS) | ||
|
@@ -335,6 +337,11 @@ impl ChainNotify for EthSync { | |
self.sync_handler.snapshot_service.abort_restore(); | ||
self.network.stop().unwrap_or_else(|e| warn!("Error stopping network: {:?}", e)); | ||
} | ||
|
||
fn transactions_imported(&self, hashes: Vec<H256>, peer_id: Option<H512>, block_number: u64) { | ||
let mut sync = self.sync_handler.sync.write(); | ||
sync.transactions_imported(hashes, peer_id, block_number); | ||
} | ||
} | ||
|
||
/// LES event handler. | ||
|
@@ -344,7 +351,8 @@ struct TxRelay(Arc<BlockChainClient>); | |
impl LightHandler for TxRelay { | ||
fn on_transactions(&self, ctx: &EventContext, relay: &[::ethcore::transaction::SignedTransaction]) { | ||
trace!(target: "les", "Relaying {} transactions from peer {}", relay.len(), ctx.peer()); | ||
self.0.queue_transactions(relay.iter().map(|tx| ::rlp::encode(tx).to_vec()).collect()) | ||
// TODO [ToDr] Can we get a peer enode somehow? | ||
self.0.queue_transactions(relay.iter().map(|tx| ::rlp::encode(tx).to_vec()).collect(), None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
|
@@ -547,4 +555,4 @@ pub struct ServiceConfiguration { | |
pub net: NetworkConfiguration, | ||
/// IPC path. | ||
pub io_path: String, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not it happen only after successful import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the event is misleading, even if the transaction is already in queue we want to note the the peer has propagated the transaction again, so we don't really care if it was imported or not.
Will rename to
transactions_received
.