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

Commit

Permalink
Merge remote-tracking branch 'origin/master' into refactor/hashdb-gen…
Browse files Browse the repository at this point in the history
…eric

* origin/master:
  Fix local transactions policy. (#8691)
  Shutdown the Snapshot Service early (#8658)
  network-devp2p: handle UselessPeer disconnect (#8686)
  Fix compilation error on nightly rust (#8707)
  Add a test for decoding corrupt data (#8713)
  Update dev chain (#8717)
  Remove unused imports (#8722)
  • Loading branch information
dvdplm committed May 30, 2018
2 parents 013666f + 1620eab commit aabe7dd
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 62 deletions.
65 changes: 44 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ members = [
"transaction-pool",
"whisper",
"whisper/cli",
"util/learn-generics",
]

[patch.crates-io]
Expand Down
12 changes: 11 additions & 1 deletion ethcore/res/instant_seal.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@
"minGasLimit": "0x1388",
"networkID" : "0x11",
"registrar" : "0x0000000000000000000000000000000000001337",
"eip150Transition": "0x0",
"eip160Transition": "0x0",
"eip161abcTransition": "0x0",
"eip161dTransition": "0x0",
"eip155Transition": "0x0",
"eip98Transition": "0x7fffffffffffff",
"eip86Transition": "0x7fffffffffffff",
"maxCodeSize": 24576,
"maxCodeSizeTransition": "0x0",
"eip140Transition": "0x0",
"eip211Transition": "0x0",
"eip214Transition": "0x0",
"eip658Transition": "0x0"
"eip658Transition": "0x0",
"wasmActivationTransition": "0x0"
},
"genesis": {
"seal": {
Expand Down
7 changes: 6 additions & 1 deletion ethcore/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use sync::PrivateTxHandler;
use ethcore::client::{Client, ClientConfig, ChainNotify, ClientIoMessage};
use ethcore::miner::Miner;
use ethcore::snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
use ethcore::snapshot::{RestorationStatus};
use ethcore::snapshot::{SnapshotService as _SnapshotService, RestorationStatus};
use ethcore::spec::Spec;
use ethcore::account_provider::AccountProvider;

Expand Down Expand Up @@ -168,6 +168,11 @@ impl ClientService {

/// Get a handle to the database.
pub fn db(&self) -> Arc<KeyValueDB> { self.database.clone() }

/// Shutdown the Client Service
pub fn shutdown(&self) {
self.snapshot.shutdown();
}
}

/// IO interface for the Client handler
Expand Down
4 changes: 4 additions & 0 deletions ethcore/src/snapshot/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@ impl SnapshotService for Service {
trace!("Error sending snapshot service message: {:?}", e);
}
}

fn shutdown(&self) {
self.abort_restore();
}
}

impl Drop for Service {
Expand Down
3 changes: 3 additions & 0 deletions ethcore/src/snapshot/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ pub trait SnapshotService : Sync + Send {
/// Feed a raw block chunk to the service to be processed asynchronously.
/// no-op if currently restoring.
fn restore_block_chunk(&self, hash: H256, chunk: Bytes);

/// Shutdown the Snapshot Service by aborting any ongoing restore
fn shutdown(&self);
}
4 changes: 4 additions & 0 deletions ethcore/sync/src/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ impl SnapshotService for TestSnapshotService {
self.block_restoration_chunks.lock().insert(hash, chunk);
}
}

fn shutdown(&self) {
self.abort_restore();
}
}

#[test]
Expand Down
33 changes: 33 additions & 0 deletions miner/src/pool/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ impl txpool::Scoring<VerifiedTransaction> for NonceAndGasPrice {
}
}

// Always kick out non-local transactions in favour of local ones.
if new.priority().is_local() && !old.priority().is_local() {
return true;
}
// And never kick out local transactions in favour of external ones.
if !new.priority().is_local() && old.priority.is_local() {
return false;
}

self.choose(old, new) == txpool::scoring::Choice::ReplaceOld
}
}
Expand All @@ -119,6 +128,30 @@ mod tests {
use pool::tests::tx::{Tx, TxExt};
use txpool::Scoring;

#[test]
fn should_replace_non_local_transaction_with_local_one() {
// given
let scoring = NonceAndGasPrice(PrioritizationStrategy::GasPriceOnly);
let tx1 = {
let tx = Tx::default().signed().verified();
txpool::Transaction {
insertion_id: 0,
transaction: Arc::new(tx),
}
};
let tx2 = {
let mut tx = Tx::default().signed().verified();
tx.priority = ::pool::Priority::Local;
txpool::Transaction {
insertion_id: 0,
transaction: Arc::new(tx),
}
};

assert!(scoring.should_replace(&tx1, &tx2));
assert!(!scoring.should_replace(&tx2, &tx1));
}

#[test]
fn should_calculate_score_correctly() {
// given
Expand Down
33 changes: 32 additions & 1 deletion miner/src/pool/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,4 +766,35 @@ fn should_reject_big_transaction() {
verifier::Transaction::Local(PendingTransaction::new(big_tx, transaction::Condition::Timestamp(1000).into()))
]);
assert_eq!(res, vec![Err(transaction::Error::TooBig)]);
}
}

#[test]
fn should_include_local_transaction_to_a_full_pool() {
// given
let txq = TransactionQueue::new(
txpool::Options {
max_count: 1,
max_per_sender: 2,
max_mem_usage: 50
},
verifier::Options {
minimal_gas_price: 1.into(),
block_gas_limit: 1_000_000.into(),
tx_gas_limit: 1_000_000.into(),
},
PrioritizationStrategy::GasPriceOnly,
);
let tx1 = Tx::gas_price(10_000).signed().unverified();
let tx2 = Tx::gas_price(1).signed().local();

let res = txq.import(TestClient::new().with_balance(1_000_000_000), vec![tx1]);
assert_eq!(res, vec![Ok(())]);
assert_eq!(txq.status().status.transaction_count, 1);

// when
let res = txq.import(TestClient::new(), vec![tx2]);
assert_eq!(res, vec![Ok(())]);

// then
assert_eq!(txq.status().status.transaction_count, 1);
}
9 changes: 7 additions & 2 deletions parity/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,8 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
rpc: rpc_direct,
informant,
client,
keep_alive: Box::new((watcher, service, updater, ws_server, http_server, ipc_server, ui_server, secretstore_key_server, ipfs_server, event_loop)),
client_service: Arc::new(service),
keep_alive: Box::new((watcher, updater, ws_server, http_server, ipc_server, ui_server, secretstore_key_server, ipfs_server, event_loop)),
}
})
}
Expand All @@ -909,6 +910,7 @@ enum RunningClientInner {
rpc: jsonrpc_core::MetaIoHandler<Metadata, informant::Middleware<informant::ClientNotifier>>,
informant: Arc<Informant<FullNodeInformantData>>,
client: Arc<Client>,
client_service: Arc<ClientService>,
keep_alive: Box<Any>,
},
}
Expand Down Expand Up @@ -946,11 +948,14 @@ impl RunningClient {
drop(client);
wait_for_drop(weak_client);
},
RunningClientInner::Full { rpc, informant, client, keep_alive } => {
RunningClientInner::Full { rpc, informant, client, client_service, keep_alive } => {
info!("Finishing work, please wait...");
// Create a weak reference to the client so that we can wait on shutdown
// until it is dropped
let weak_client = Arc::downgrade(&client);
// Shutdown and drop the ServiceClient
client_service.shutdown();
drop(client_service);
// drop this stuff as soon as exit detected.
drop(rpc);
drop(keep_alive);
Expand Down
Loading

0 comments on commit aabe7dd

Please sign in to comment.