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

Avoid broadcasting transactions to peers that send them #3796

Merged
merged 9 commits into from
Dec 12, 2016
Merged

Conversation

tomusdrw
Copy link
Collaborator

Closes #3757

It's looks a bit ugly to propagate the peer_id to the client and then back to sync, @arkpar any ideas how to improve this?

@rphmeier in light client implementation we cannot easily get network.peer_session_info(peer_id) any ideas how to solve this?

@tomusdrw tomusdrw added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Dec 10, 2016
@rphmeier
Copy link
Contributor

rphmeier commented Dec 10, 2016

@tomusdrw Most likely can be done with an extension to the EventContext trait, although I'd prefer something like persistent_id(&PeerId) -> Option<H512> as opposed to exposing the full p2p session info at such a high level. Then edit the TxRelay handler within sync/api.rs to use it.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx.persistent_peer_id(&ctx.peer()) once the method I mentioned has been added.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 85.593% when pulling e66157f on tx-broadcast into 60ea787 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 85.581% when pulling aaf6da4 on tx-broadcast into 60ea787 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 85.578% when pulling aaf6da4 on tx-broadcast into 60ea787 on master.

@@ -75,6 +82,9 @@ pub trait EventContext {
/// disconnected/connected peer.
fn peer(&self) -> PeerId;

/// Returns the relevant's peer persistent Id (aka NodeId).
fn persistent_peer_id(&self) -> Option<NodeId>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer for this to take arbitrary &PeerId ideally.

let hashes: Vec<_> = txs.iter().map(|tx| tx.hash()).collect();
let block_number = self.chain_info().best_block_number;
self.notify(|notify| {
notify.transactions_imported(hashes.clone(), peer_id.clone(), block_number);
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.


fn persistent_peer_id(&self) -> Option<NodeId> {
self.io.persistent_peer_id(self.peer)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation looks strange around this block. Does the file use spaces?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, this is my mistake from earlier. Fixed in #3801

@tomusdrw tomusdrw added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels Dec 10, 2016
@tomusdrw tomusdrw changed the title Maintaining a list of transactions propagated from other peers Avoid broadcasting transactions to peers that send them Dec 10, 2016
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 85.586% when pulling 1e86386 on tx-broadcast into 60ea787 on master.

Conflicts:
	ethcore/light/src/net/context.rs
	ethcore/light/src/net/tests/mod.rs
@tomusdrw tomusdrw added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Dec 11, 2016
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 83d9bc1 on tx-broadcast into ** on master**.

@arkpar arkpar added A8-looksgood 🦄 Pull request is reviewed well. A7-looksgoodcantmerge 🙄 Pull request is reviewed well, but cannot be merged due to conflicts. and removed A0-pleasereview 🤓 Pull request needs code review. A8-looksgood 🦄 Pull request is reviewed well. labels Dec 11, 2016
@arkpar arkpar added A7-looksgoodtestsfail 🤖 Pull request is reviewed well, but cannot be merged due to tests failing. and removed A7-looksgoodcantmerge 🙄 Pull request is reviewed well, but cannot be merged due to conflicts. labels Dec 11, 2016
@gavofyork gavofyork merged commit c0a2d5c into master Dec 12, 2016
@gavofyork gavofyork deleted the tx-broadcast branch December 12, 2016 03:13
@tomusdrw tomusdrw mentioned this pull request Jan 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A7-looksgoodtestsfail 🤖 Pull request is reviewed well, but cannot be merged due to tests failing. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants