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

Introduce more optional features in ethcore #9020

Merged
merged 5 commits into from
Jul 5, 2018

Conversation

udoprog
Copy link
Contributor

@udoprog udoprog commented Jun 30, 2018

This introduces optional features to ethcore. If they are not enabled, they leave out the entire hyper/tokio ecosystem which is a lot of dependencies which are not needed when doing things like smart contract testing (e.g. parables).

This is cargo tree --verbose in ./ethcore before and after the change.

Before:

cargo tree --verbose | wc -l
691

After:

cargo tree --verbose | wc -l
493

@parity-cla-bot
Copy link

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

Many thanks,

Parity Technologies CLA Bot

@5chdn 5chdn added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. M0-build 🏗 Building and build system. M5-dependencies 🖇 Dependencies. labels Jun 30, 2018
@5chdn 5chdn added this to the 1.12 milestone Jun 30, 2018
@5chdn
Copy link
Contributor

5chdn commented Jun 30, 2018

error: Could not compile parity.

@udoprog
Copy link
Contributor Author

udoprog commented Jun 30, 2018

@5chdn Ah, tests are run with --no-default-features. So all the things provided by dependencies through features have to be conditionally supported as well?

@tomaka
Copy link
Contributor

tomaka commented Jun 30, 2018

So all the things provided by dependencies through features have to be conditionally supported as well?

I'm not sure if I understand your comment correctly.
If compilation fails when you disable a feature, then it shouldn't be a feature in the first place.

@udoprog
Copy link
Contributor Author

udoprog commented Jun 30, 2018

@tomaka well... yeah :). That made it click. They should be part of the dependency, not the local [features] for the parity app.

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.

While I totally understand the ambition to reduce ethcore compile times and complexity, I am not sure I agree that this is the right approach. It seems to add a lot of visual clutter and adding a barrier to reason about the code – "is this code compiled for the binary used?" is not something I'd like to ponder while fixing user bugs.
At the very least, the various features need good docs that explain when/why they're used.

@tomaka
Copy link
Contributor

tomaka commented Jul 2, 2018

For what it's worth, this feature is desirable for #7915 because hyper and tokio don't work when inside a browser.

@udoprog
Copy link
Contributor Author

udoprog commented Jul 2, 2018

@dvdplm Hey!

I am not sure I agree that this is the right approach

Increasing modularization seems to be the right long term approach. Features are more like a way to get it done right now, and they can be removed as things are broken up into more composable traits, types, and crates. But apart from not being as visible as a dependency, a missing feature causes a compile-time error similar to a missing dependency.

"is this code compiled for the binary used?"`

Note that the features introduced here are not gated in the binary (thanks due to the comment by @tomaka). You would get a compile time error if you try to use a type or function that is feature-gated in ethcore. It's similar to if you were trying to use serde for a dependency without enabling the feature.

Copy link
Contributor

@tomaka tomaka left a comment

Choose a reason for hiding this comment

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

The intent is good, just some minor issues.

@@ -211,6 +213,7 @@ pub struct Miner {
}

impl Miner {
#[cfg(feature = "work-notify")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this line should be under the /// comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

{
let _stratum = stratum;
}

Ok(())
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, an error should be returned if work-notify is disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case, maybe we should just gate the pub fn register function for a compile-time error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Since the stratum feature is mandatory in the Parity client, I guess it's indeed better to disable the function entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks!


/// Struct to look after updating the acceptable gas price of a miner.
#[derive(Debug, PartialEq)]
pub enum GasPricer {
/// A fixed gas price in terms of Wei - always the argument given.
Fixed(U256),
#[cfg(feature = "price-info")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should be under the ///.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

/// Gas price is calibrated according to a fixed amount of USD.
Calibrated(GasPriceCalibrator),
}

impl GasPricer {
#[cfg(feature = "price-info")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should be under the ///.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed! ... Thanks!

@5chdn 5chdn added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jul 3, 2018
@dvdplm
Copy link
Collaborator

dvdplm commented Jul 3, 2018

@udoprog Ok, I rest my case! :)

@5chdn 5chdn added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Jul 5, 2018
@5chdn 5chdn merged commit 71bbcd5 into openethereum:master Jul 5, 2018
@udoprog udoprog deleted the more-optional-features branch July 5, 2018 14:38
ordian added a commit to ordian/parity that referenced this pull request Jul 9, 2018
…rp_sync_on_light_client

* 'master' of https://github.com/paritytech/parity:
  Fixes for misbehavior reporting in AuthorityRound (openethereum#8998)
  A last bunch of txqueue performance optimizations (openethereum#9024)
  reduce number of constraints for triedb types (openethereum#9043)
  bump fs-swap to 0.2.3 so it is compatible with osx 10.11 again (openethereum#9050)
  Recursive test (openethereum#9042)
  Introduce more optional features in ethcore (openethereum#9020)
  Update ETSC bootnodes (openethereum#9038)
  Optimize pending transactions filter (openethereum#9026)
  eip160/eip161 spec: u64 -> BlockNumber (openethereum#9044)
WorkPoster::new(&cmd.miner_extras.work_notify, fetch.clone(), event_loop.remote())
));

#[cfg(feature = "work-notify")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's never enabled. main Cargo.toml doesn't have that feature.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. M0-build 🏗 Building and build system. M4-core ⛓ Core client code / Rust. M5-dependencies 🖇 Dependencies.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants