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

Replace tokio_core with tokio (ring -> 0.13) #9657

Merged
merged 2 commits into from
Oct 23, 2018

Conversation

c0gent
Copy link
Contributor

@c0gent c0gent commented Sep 26, 2018

Changes

Replace tokio_core with tokio.

  • Remove tokio-core and replace with tokio in

    • ethcore/stratum

    • secret_store

    • util/fetch

    • util/reactor

  • Bump hyper to 0.12 in

    • miner

    • util/fake-fetch

    • util/fetch

    • secret_store

  • Bump jsonrpc-*** to 0.9 in

    • parity

    • ethcore/stratum

    • ipfs

    • rpc

    • rpc_client

    • whisper

  • Bump ring to 0.13

  • Use a more graceful shutdown process in secret_store tests.

  • Convert some mutexes to rwlocks in secret_store.

Consolidate Tokio Runtime use, remove CpuPool.

  • Rename and move the tokio_reactor crate (util/reactor) to
    tokio_runtime (util/runtime).

  • Rename EventLoop to Runtime.

    • Rename EventLoop::spawn to Runtime::with_default_thread_count.

    • Add the Runtime::with_thread_count method.

    • Rename Remote to Executor.

  • Remove uses of CpuPool and spawn all tasks via the Runtime executor
    instead.

  • Other changes related to CpuPool removal:

    • Remove Reservations::with_pool. ::new now takes an Executor as an argument.

    • Remove SenderReservations::with_pool. ::new now takes an Executor as an argument.

Still Incomplete

  • Troubleshoot the following failing tests:
    • json_tests::state::state_tests::GeneralStateTest_stCallCreateCallCodeTest
    • json_tests::state::state_tests::GeneralStateTest_stDelegatecallTestHomestead
    • json_tests::state::state_tests::GeneralStateTest_stInitCodeTest
    • json_tests::state::state_tests::GeneralStateTest_stRandom
    • json_tests::state::state_tests::GeneralStateTest_stRevertTest
    • json_tests::state::state_tests::GeneralStateTest_stSpecialTest
    • json_tests::state::state_tests::GeneralStateTest_stSystemOperationsTest
    • json_tests::state::state_tests::GeneralStateTest_stTransactionTest
    • json_tests::state::state_tests::GeneralStateTest_stTransitionTest
    • json_tests::state::state_tests::GeneralStateTest_stZeroCallsRevert
  • Replace/Update dependency sources:
  • Determine what to do with the it_should_not_read_too_much_data_sync
    test (util/fetch/src/client.rs:807). This can be left alone and deferred to a future PR.
  • Address intermittent stalling/timeouts in secret_store tests.
  • Address issues with fetch client.

Related Upcoming TODOs (separate PR)

  • Convert many boxed future return types to impl Future and clean up extra types.
  • Ensure no errors are discarded in secret_store/src/key_server_cluster/cluster.rs (and elsewhere).
  • Remove or modify the it_should_not_read_too_much_data_sync test (util/fetch/src/client.rs).

Closes #9533
Closes #9722

@parity-cla-bot
Copy link

It looks like @c0gent signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

Cargo.toml Outdated
ring = { git = "https://github.com/paritytech/ring" }
# ring = { git = "https://github.com/paritytech/ring" }
ring = { git = "https://github.com/briansmith/ring" }
parity-crypto = { git = "https://github.com/c0gent/parity-common", branch = "ring-0.13" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

parity-crypto = "0.2"

Cargo.toml Outdated
@@ -140,4 +140,7 @@ members = [
]

[patch.crates-io]
ring = { git = "https://github.com/paritytech/ring" }
# ring = { git = "https://github.com/paritytech/ring" }
ring = { git = "https://github.com/briansmith/ring" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

we don't need this

@5chdn 5chdn added this to the 2.2 milestone Sep 27, 2018
@5chdn 5chdn added A0-pleasereview 🤓 Pull request needs code review. A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. M5-dependencies 🖇 Dependencies. labels Sep 27, 2018
Cargo.toml Outdated
# ring = { git = "https://github.com/paritytech/ring" }
ring = { git = "https://github.com/briansmith/ring" }
parity-crypto = { git = "https://github.com/c0gent/parity-common", branch = "ring-0.13" }
cid = { git = "https://github.com/c0gent/rust-cid", branch = "bump-multihash" }
Copy link
Contributor

Choose a reason for hiding this comment

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

I pinged the slack of Protocol Labs about multiformats/rust-cid#11

tomaka
tomaka previously requested changes Sep 27, 2018
}

impl ::std::error::Error for ServerError {
fn description(&self) -> &str { "ServerError" }
Copy link
Contributor

Choose a reason for hiding this comment

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

The methods of the Error trait are deprecated. Instead, it's the implementation of Display that should write ServerError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, (and I'm inclined to move errors towards failure depending on what happens with the new std error trait) but std::error::Error is required when building a hyper server.

Copy link
Contributor

Choose a reason for hiding this comment

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

Error itself is not deprecated, just implementing the methods on it.
You still should write impl Error for ServerError {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, my mistake. It's been a while since I've manually implemented it at all. :)

I thought maybe you were referring to potential future deprecation: rust-lang/rfcs#2504.

@@ -59,7 +59,7 @@ const KEEP_ALIVE_SEND_INTERVAL: Duration = Duration::from_secs(30);
const KEEP_ALIVE_DISCONNECT_INTERVAL: Duration = Duration::from_secs(60);

/// Empty future.
pub type BoxedEmptyFuture = Box<Future<Item = (), Error = ()> + Send>;
pub type BoxedEmptyFuture = Box<Future<Item = (), Error = ()> + Send + 'static>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: change shouldn't be needed.


Ok(Arc::new(ClusterCore {
handle: handle,
// executor: executor,
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented out code.

}
}
let check_predicate = future::loop_fn((), move|_| {
if predicate() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong indentation.

@@ -1119,7 +1117,15 @@ pub mod tests {
use std::time::{Duration, Instant};
use std::collections::{BTreeSet, VecDeque};
use parking_lot::Mutex;
use tokio_core::reactor::Core;
use tokio::{
// reactor::Reactor,
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented out code.

pub fn deadline<F, T>(duration: Duration, future: F) -> Result<Deadline<F>, io::Error>
where F: Future<Item = T, Error = io::Error> + Send + 'static, T: Send + 'static
{
// let timeout: DeadlineBox<F> = Box::new(Timeout::new((), duration)?.map(|_| DeadlineStatus::Timeout));
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented out code.

@c0gent c0gent force-pushed the c0gent-tokio branch 2 times, most recently from b4e8e4d to bd7d453 Compare September 27, 2018 20:31
@5chdn 5chdn removed the A0-pleasereview 🤓 Pull request needs code review. label Sep 27, 2018
@c0gent c0gent force-pushed the c0gent-tokio branch 2 times, most recently from 2fe3c98 to 4a49a06 Compare September 28, 2018 16:39
Copy link
Collaborator

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

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

Good stuff here, I like it! :)

Cargo.toml Outdated
@@ -31,7 +31,7 @@ futures = "0.1"
futures-cpupool = "0.1"
fdlimit = "0.1"
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
jsonrpc-core = { git = "https://github.com/c0gent/jsonrpc.git", branch = "c0gent-hyper" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will change back to "https://github.com/paritytech/jsonrpc.git" at some point before the PR lands right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely. Currently just waiting on a specific release/branch/tag etc. to depend on (It's probably wise to hold off on that until this PR is confirmed to work properly).

jsonrpc-tcp-server = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
jsonrpc-core = { git = "https://github.com/c0gent/jsonrpc.git", branch = "c0gent-hyper" }
jsonrpc-macros = { git = "https://github.com/c0gent/jsonrpc.git", branch = "c0gent-hyper" }
jsonrpc-tcp-server = { git = "https://github.com/c0gent/jsonrpc.git", branch = "c0gent-hyper" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

These will change back to "https://github.com/paritytech/jsonrpc.git" at some point before the PR lands right?

@@ -34,10 +34,9 @@ pub fn serve() -> (Server<ws::Server>, usize, GuardedAuthCodes) {
let authcodes = GuardedAuthCodes::new();
let stats = Arc::new(informant::RpcStats::default());

let res = Server::new(|remote| ::start_ws(
let res = Server::new(|_remote| ::start_ws(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just Server::new(|_| …?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No reason really. I like to label those unused variables just to make it easy to know what's there but I'm happy to change it.

X: core::futures::Future<Item=Option<core::Response>, Error=()> + Send + 'static,
fn on_request<F, X>(&self, request: core::Request, meta: Metadata, process: F)
-> Either<Self::Future, X>
where F: FnOnce(core::Request, Metadata) -> X,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Funny indentation here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a funny guy!

@@ -137,7 +137,7 @@ pub struct ClusterConfiguration {
/// Administrator public key.
pub admin_public: Option<Public>,
/// Should key servers set change session should be started when servers set changes.
/// This will only work when servers set is configured using KeyServerSet contract.
/// This will only work when servers set is configured using KeyServerSet contract.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Double spaces here. Also: s/when servers set is/when the server set is/

/// Handle to the event loop.
handle: Handle,
// /// Handle to the event loop.
// executor: TaskExecutor,
Copy link
Collaborator

Choose a reason for hiding this comment

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

commented out lines

}

/// Start listening for incoming connections.
fn listen(handle: &Handle, data: Arc<ClusterData>, listen_address: SocketAddr) -> Result<BoxedEmptyFuture, Error> {
Ok(Box::new(TcpListener::bind(&listen_address, &handle)?
fn listen(data: Arc<ClusterData>, listen_address: SocketAddr) -> Result<BoxedEmptyFuture, Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't traced through all the calls but aren't we dropping a few possible errors in this method? Perhaps out of scope for this PR though...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the errors are not handled the way I would do it. I've tried not to change too much functionality from the original in this PR in order to keep things as straightforward as possible. I'll make a note to have a look at that in an upcoming PR :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@dvdplm Not sure I got it - all connection-establish (both for incoming && outcoming) related errors are processed in process_connection_result by tracing? Probably some other errors are dropped? Or do you have idea how to handle these errors in other way? Could you please, elaborate?

util/fetch/Cargo.toml Show resolved Hide resolved
@c0gent
Copy link
Contributor Author

c0gent commented Oct 3, 2018

I haven't been able to spend time on it but I could still use help from someone more familiar with json_tests to give me some idea of where I might start looking for the reason why those are failing.

@c0gent c0gent force-pushed the c0gent-tokio branch 3 times, most recently from 0c9c31a to 8f087b6 Compare October 8, 2018 22:42
@dvdplm
Copy link
Collaborator

dvdplm commented Oct 9, 2018

re-json_tests: @sorpaas are you able to provide a few pointers here? :)

@sorpaas
Copy link
Collaborator

sorpaas commented Oct 9, 2018

@c0gent The issue looks like that you updated ethereum/tests submodule in this PR. Revert back that part should fix jsontests.

@c0gent
Copy link
Contributor Author

c0gent commented Oct 9, 2018

I'm re-running the tests and I have to leave for an appointment. I'll push the changes this afternoon (PST).

It will leave two items remaining (see OP), 1.) A jsonrpc tag/branch/release to depend on, 2.) Decide what to do about that test -- this can be deferred to a future PR.

@cheme
Copy link
Contributor

cheme commented Oct 9, 2018

About the json_tests, as @sorpaas point out, it is a submodule issue (I just run them successfully with your PR).
About jsonrpc, I ran the test with latest master dependencies, and got some failures, mainly related to secret_store keyserver:

failures:
    key_server_cluster::client_sessions::generation_session::tests::encryption_session_works_over_network
    key_server_cluster::cluster::tests::error_in_generation_session_broadcasted_to_all_other_nodes
    key_server_cluster::cluster::tests::generation_session_completion_signalled_if_failed_on_master
    key_server_cluster::cluster::tests::generation_session_is_removed_when_succeeded
    key_server_cluster::cluster::tests::sessions_are_removed_when_initialization_fails

Plus stratum 'can_push_work' also seem to fail, but mainly when running with other tests (randomly).
But others than those 6 tests all seems to pass :)

@c0gent
Copy link
Contributor Author

c0gent commented Oct 9, 2018

Yup thanks. I'll fix all of that when I get back in a few hrs (hopefully).

@c0gent
Copy link
Contributor Author

c0gent commented Oct 10, 2018

I can't reproduce those CI test failures locally but I'll see if I can get to the bottom of it. It's undoubtedly related to the ungraceful shutdown issue noted above.

@5chdn 5chdn added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Oct 19, 2018
@5chdn
Copy link
Contributor

5chdn commented Oct 19, 2018

Will merge once last grumbles are addressed

Cargo.toml Outdated
fdlimit = "0.1"
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.11" }
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", rev = "7a59776" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I branched out jsonrpc now, can you update this to use parity-2.2 branch?

@@ -672,7 +675,7 @@ impl ClusterConnections {
Ok(ClusterConnections {
self_node_id: config.self_key_pair.public().clone(),
key_server_set: config.key_server_set.clone(),
trigger: Mutex::new(trigger),
trigger: RwLock::new(trigger),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems we never do self.trigger.read() anyway, what's the purpose of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, changed back.

panic!("no result in {:?}", timeout);
}
}
runtime.block_on(Interval::new_interval(Duration::new(0, 1_000_000))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you just use Duration::from_millis(1) instaed of specifying nanoseconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why I did that, I usually do use from_millis.

* Rename and move the `tokio_reactor` crate (`util/reactor`) to
  `tokio_runtime` (`util/runtime`).

* Rename `EventLoop` to `Runtime`.

    - Rename `EventLoop::spawn` to `Runtime::with_default_thread_count`.

    - Add the `Runtime::with_thread_count` method.

    - Rename `Remote` to `Executor`.

* Remove uses of `CpuPool` and spawn all tasks via the `Runtime` executor
  instead.

* Other changes related to `CpuPool` removal:

    - Remove `Reservations::with_pool`. `::new` now takes an `Executor` as an argument.

    - Remove `SenderReservations::with_pool`. `::new` now takes an `Executor` as an argument.
@c0gent
Copy link
Contributor Author

c0gent commented Oct 19, 2018

Should be all addressed.

@svyatonik svyatonik added A0-pleasereview 🤓 Pull request needs code review. and removed A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. labels Oct 19, 2018
@ordian ordian removed the A0-pleasereview 🤓 Pull request needs code review. label Oct 19, 2018
@niklasad1
Copy link
Collaborator

@tomusdrw are you ok with this now? if that's the case let's merge it

@tomusdrw tomusdrw added the A7-looksgoodtestsfail 🤖 Pull request is reviewed well, but cannot be merged due to tests failing. label Oct 20, 2018
@tomusdrw
Copy link
Collaborator

Looks good but the tests are failing and some of the failures seems legit. @5chdn is it a known issue or something specific to this PR?

@5chdn
Copy link
Contributor

5chdn commented Oct 22, 2018

Failures are unrelated. Thanks, everyone.

1 similar comment
@5chdn
Copy link
Contributor

5chdn commented Oct 22, 2018

Failures are unrelated. Thanks, everyone.

@5chdn 5chdn merged commit 15d71a0 into openethereum:master Oct 23, 2018
@5chdn
Copy link
Contributor

5chdn commented Oct 23, 2018

Merged 4x 🤦‍♂️

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. A9-buythatmanabeer 🍻 Pull request is reviewed well and worth buying the author a beer. M4-core ⛓ Core client code / Rust. M5-dependencies 🖇 Dependencies.
Projects
None yet
Development

Successfully merging this pull request may close these issues.