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

Update jsonrpc dependencies and rewrite dapps to futures. #6522

Merged
merged 25 commits into from
Oct 5, 2017

Conversation

tomusdrw
Copy link
Collaborator

@tomusdrw tomusdrw commented Sep 15, 2017

  • The HTTP (RPC/Dapps & UI) servers are now based on latest version of hyper (which also makes them way more performant).
  • minihttp is not needed any more, http supports multiple server threads as well.
  • Updates futures to latest version and removes all .boxed() and BoxFuture occurrences (deprecated).

Awaiting for paritytech/jsonrpc#199 to be reviewed and merged first (so that we can branch out as parity-1.8)

Closes #6261, #6476

@tomusdrw tomusdrw added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 15, 2017
@tomusdrw tomusdrw added A0-pleasereview 🤓 Pull request needs code review. and removed A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. labels Sep 15, 2017
@gavofyork
Copy link
Contributor

doesn't build..

Copy link
Collaborator

@debris debris left a comment

Choose a reason for hiding this comment

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

overall, looks fine, but the pr of that size is simply unreviewable

Cargo.toml Outdated
@@ -117,4 +117,5 @@ lto = false
panic = "abort"

[workspace]
members = ["ethstore/cli", "ethkey/cli", "evmbin", "whisper", "chainspec", "dapps/node-health"]
members = ["ethstore/cli", "ethkey/cli", "evmbin", "whisper", "chainspec"]
exclude = ["dapps/js-glue"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is it excluded?

FetchState::Done(_, ref mut response) => {
return response.poll()
},
_ => unreachable!(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's reachable by FetchState::Empty

FetchState::Streaming(response) => {
return Ok(futures::Async::Ready(response));
},
any => any,
Copy link
Collaborator

Choose a reason for hiding this comment

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

imo, it's better to write:

if let FetchState::Error(ref mut error) = self.status {
  // here do mem::replace on error
  // and return Ok(..)
}

if let FetchState::Streaming(ref mut response) = self.response {
  // here do mem::replace on response
  // and return Ok(..)
}

Copy link
Collaborator Author

@tomusdrw tomusdrw Sep 30, 2017

Choose a reason for hiding this comment

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

That doesn't give you the ownership of error required for return.


const MAX_CHUNK_SIZE: usize = 32 * 1024;

pub struct Reader<R: io::Read> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This structure requires very descriptive documentation. I've spent over 10 minutes looking at it to understand why it's done like that.

And if I understand correctly, sending is a sink, which sends data directly to a server client. Is that right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, I can see that hyper::Response is generic over Body, so maybe there is a way to use it with every structure which implements stream of Chunks? Or anything that implements AsRef<u8>. Anyway, even if this is not possible now, maybe we should just open an issue in hyper repo. Just to avoid unnecessary allocation, when read value is moved to a heap when creating a `Chunk.

@abitrolly
Copy link

abitrolly commented Oct 1, 2017

There are a lot of warnings about .boxed() and BoxFuture in current builds. Making their removal a separate PR, like paritytech/jsonrpc#196 can speed up review.

@tomusdrw
Copy link
Collaborator Author

tomusdrw commented Oct 1, 2017

The warnings are most likely coming from jsonrpc libraries, that need to be bumped as well - and this refactoring is required for that.
I can split the PR, but I think there is not so many instances of .boxed() and BoxFuture in current codebase and it wouldn't really make this PR much smaller.

@abitrolly
Copy link

abitrolly commented Oct 2, 2017

@tomusdrw exact list of libs with warnings, mined from this log - https://travis-ci.org/cyberFund/cybernode/builds/281880085#L1321

✗ ./warncounter.py
('hash', 1)
('node-health', 8)
('fetch', 5)
('patricia_trie', 169)
('parity-hash-fetch', 6)
('vm', 5)
('parity-whisper', 4)
('parity-local-store', 3)
('parity-rpc', 368)
('parity-rpc-client', 10)
('rpc-cli', 17)

warncounter.py

@abitrolly
Copy link

With versions:

✗ ./warncounter.py
    1  hash v0.1.0
    8  node-health v0.1.0
    5  fetch v0.1.0
  169  patricia_trie v0.1.0
    6  parity-hash-fetch v1.8.0
    5  vm v0.1.0
    4  parity-whisper v0.1.0
    3  parity-local-store v0.1.0
  368  parity-rpc v1.8.0
   10  parity-rpc-client v1.4.0
   17  rpc-cli v1.4.0

@tomusdrw
Copy link
Collaborator Author

tomusdrw commented Oct 2, 2017

So because most of the lines are in parity-rpc the PR wouldn't be smaller at all. Removing .boxed() from that part of code was done more elegantly because of the changes in jsonrpc-core (allowing to return T: IntoFuture instead of BoxFuture everywhere) that is being updated in this PR. So we can fix .boxed(), but this PR will change exactly the same lines to further remove it.

That said, I'm fine with doing that if @paritytech/core-devs believe it will help with getting this PR through.

}

fn block_by_number(&self, num: BlockNumber, include_txs: bool) -> BoxFuture<Option<RichBlock>, Error> {
future::done(self.block(num.into(), include_txs)).boxed()
Copy link
Contributor

Choose a reason for hiding this comment

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

why the change from .boxed() to Box::new?

Copy link
Collaborator

Choose a reason for hiding this comment

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

boxed() has been deprecated. rust-lang/futures-rs#228

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 motivation is that .boxed() requires Future + Send + 'static and sometimes it's not needed. Wrapping with Box::new covers both cases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And usage of boxed causes warning during the compilation. It litters the build log significantly

@@ -274,10 +274,6 @@ impl ClusterCore {
Box::new(net_connect(&node_address, handle, data.self_key_pair.clone(), disconnected_nodes)
.then(move |result| ClusterCore::process_connection_result(data, Some(node_address), result))
.then(|_| finished(())))
<<<<<<< HEAD
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, thanks!

@abitrolly
Copy link

overall, looks fine, but the pr of that size is simply unreviewable

It is still +2,065 −2,881 with non-trivial changes mixed in.

@arkpar arkpar added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Oct 5, 2017
@arkpar arkpar merged commit e8b418c into master Oct 5, 2017
@arkpar arkpar deleted the td-update-jsonrpc branch October 5, 2017 10:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants