Beta backports (#4067)

* Improving logs for transaction propagation

Conflicts:
	sync/src/chain.rs

* Propagate only on timer

Conflicts:
	sync/src/chain.rs

* Maintaining a list of transactions propagated from other peers

Conflicts:
	ethcore/src/client/client.rs
	ethcore/src/client/traits.rs
	js/src/dapps/localtx/Transaction/transaction.js
	js/src/dapps/localtx/Transaction/transaction.spec.js
	rpc/src/v1/tests/helpers/sync_provider.rs
	rpc/src/v1/types/sync.rs
	sync/src/api.rs
	sync/src/chain.rs
	sync/src/transactions_stats.rs

* fixing test

Conflicts:
	rpc/src/v1/tests/mocked/parity.rs

* Returning persistent node id

Conflicts:
	ethcore/light/src/net/context.rs
	ethcore/light/src/net/tests/mod.rs
	sync/src/api.rs

* Prevent broadcasting transactions to peer that send them.

Conflicts:
	js/src/dapps/localtx/Transaction/transaction.js
	rpc/src/v1/tests/helpers/sync_provider.rs
	rpc/src/v1/tests/mocked/parity.rs
	rpc/src/v1/types/sync.rs
	sync/src/api.rs
	sync/src/chain.rs
	sync/src/transactions_stats.rs

* Bumping versions

* Fixing broken classic.json

Former-commit-id: 2cadea67a0a2f60dd11e0fb943bb0c79b42ab4eb
This commit is contained in:
Tomasz Drwięga
2017-01-06 16:05:35 +01:00
committed by Gav Wood
parent a6204ab7bf
commit 091a59ef0b
15 changed files with 82 additions and 47 deletions

View File

@@ -18,7 +18,7 @@
"ecip1010ContinueTransition": 5000000,
"eip161abcTransition": "0x7fffffffffffffff",
"eip161dTransition": "0x7fffffffffffffff",
"eip161dTransition": "0x7fffffffffffffff"
}
}
},

View File

@@ -40,6 +40,14 @@ pub trait ChainNotify : Send + Sync {
fn stop(&self) {
// does nothing by default
}
/// fires when new transactions are received from a peer
fn transactions_received(&self,
_hashes: Vec<H256>,
_peer_id: usize,
) {
// does nothing by default
}
}
impl IpcConfig for ChainNotify { }

View File

@@ -554,10 +554,15 @@ impl Client {
}
/// Import transactions from the IO queue
pub fn import_queued_transactions(&self, transactions: &[Bytes]) -> usize {
pub fn import_queued_transactions(&self, transactions: &[Bytes], peer_id: usize) -> usize {
trace!(target: "external_tx", "Importing queued");
let _timer = PerfTimer::new("import_queued_transactions");
self.queue_transactions.fetch_sub(transactions.len(), AtomicOrdering::SeqCst);
let txs = transactions.iter().filter_map(|bytes| UntrustedRlp::new(bytes).as_val().ok()).collect();
let txs: Vec<SignedTransaction> = transactions.iter().filter_map(|bytes| UntrustedRlp::new(bytes).as_val().ok()).collect();
let hashes: Vec<_> = txs.iter().map(|tx| tx.hash()).collect();
self.notify(|notify| {
notify.transactions_received(hashes.clone(), peer_id);
});
let results = self.miner.import_external_transactions(self, txs);
results.len()
}
@@ -1164,12 +1169,14 @@ impl BlockChainClient for Client {
(*self.build_last_hashes(self.chain.read().best_block_hash())).clone()
}
fn queue_transactions(&self, transactions: Vec<Bytes>) {
if self.queue_transactions.load(AtomicOrdering::Relaxed) > MAX_TX_QUEUE_SIZE {
fn queue_transactions(&self, transactions: Vec<Bytes>, peer_id: usize) {
let queue_size = self.queue_transactions.load(AtomicOrdering::Relaxed);
trace!(target: "external_tx", "Queue size: {}", queue_size);
if queue_size > MAX_TX_QUEUE_SIZE {
debug!("Ignoring {} transactions: queue is full", transactions.len());
} else {
let len = transactions.len();
match self.io_channel.lock().send(ClientIoMessage::NewTransactions(transactions)) {
match self.io_channel.lock().send(ClientIoMessage::NewTransactions(transactions, peer_id)) {
Ok(_) => {
self.queue_transactions.fetch_add(len, AtomicOrdering::SeqCst);
}

View File

@@ -644,7 +644,7 @@ impl BlockChainClient for TestBlockChainClient {
unimplemented!();
}
fn queue_transactions(&self, transactions: Vec<Bytes>) {
fn queue_transactions(&self, transactions: Vec<Bytes>, _peer_id: usize) {
// import right here
let txs = transactions.into_iter().filter_map(|bytes| UntrustedRlp::new(&bytes).as_val().ok()).collect();
self.miner.import_external_transactions(self, txs);

View File

@@ -188,7 +188,7 @@ pub trait BlockChainClient : Sync + Send {
fn last_hashes(&self) -> LastHashes;
/// Queue transactions for importing.
fn queue_transactions(&self, transactions: Vec<Bytes>);
fn queue_transactions(&self, transactions: Vec<Bytes>, peer_id: usize);
/// list all transactions
fn pending_transactions(&self) -> Vec<SignedTransaction>;
@@ -267,3 +267,4 @@ pub trait MiningBlockChainClient : BlockChainClient {
}
impl IpcConfig for BlockChainClient { }

View File

@@ -39,7 +39,7 @@ pub enum ClientIoMessage {
/// A block is ready
BlockVerified,
/// New transaction RLPs are ready to be imported
NewTransactions(Vec<Bytes>),
NewTransactions(Vec<Bytes>, usize),
/// Begin snapshot restoration
BeginRestoration(ManifestData),
/// Feed a state chunk to the snapshot service
@@ -192,7 +192,9 @@ impl IoHandler<ClientIoMessage> for ClientIoHandler {
match *net_message {
ClientIoMessage::BlockVerified => { self.client.import_verified_blocks(); }
ClientIoMessage::NewTransactions(ref transactions) => { self.client.import_queued_transactions(transactions); }
ClientIoMessage::NewTransactions(ref transactions, peer_id) => {
self.client.import_queued_transactions(transactions, peer_id);
}
ClientIoMessage::BeginRestoration(ref manifest) => {
if let Err(e) = self.snapshot.init_restore(manifest.clone(), true) {
warn!("Failed to initialize snapshot restoration: {}", e);