Skip to content

Commit

Permalink
Improve compile time (#1989)
Browse files Browse the repository at this point in the history
## Issue Addressed

Closes #1264

## Proposed Changes

* Milagro BLS: tweak the feature flags so that Milagro doesn't get compiled if we're using BLST. Profiling showed that it was consuming about 1 minute of CPU time out of 60 minutes of CPU time (real time ~15 mins). A 1.6% saving.
* Reduce monomorphization: compiling for 3 different `EthSpec` types causes a heck of a lot of generic functions to be instantiated (monomorphized). Removing 2 of 3 cuts the LLVM+linking step from around 250 seconds to 180 seconds, a saving of 70 seconds (real time!). This applies only to `make` and not the CI build, because we test with the minimal spec on CI.
* Update `web3` crate to v0.13. This is perhaps the most controversial change, because it requires axing some deposit contract tools from `lcli`. I suspect these tools weren't used much anyway, and could be maintained separately, but I'm also happy to revert this change. However, it does save us a lot of compile time. With #1839, we now have 3 versions of Tokio (and all of Tokio's deps). This change brings us down to 2 versions, but 1 should be achievable once web3 (and reqwest) move to Tokio 0.3.
* Remove `lcli` from the Docker image. It's a dev tool and can be built from the repo if required.
  • Loading branch information
michaelsproul committed Dec 8, 2020
1 parent 4f85371 commit 12c3480
Show file tree
Hide file tree
Showing 20 changed files with 282 additions and 1,124 deletions.
1,047 changes: 197 additions & 850 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ COPY . lighthouse
ARG PORTABLE
ENV PORTABLE $PORTABLE
RUN cd lighthouse && make
RUN cd lighthouse && make install-lcli

FROM debian:buster-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand All @@ -13,4 +12,3 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/cargo/bin/lighthouse /usr/local/bin/lighthouse
COPY --from=builder /usr/local/cargo/bin/lcli /usr/local/bin/lcli
2 changes: 1 addition & 1 deletion account_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ eth2_ssz_derive = "0.1.0"
hex = "0.4.2"
rayon = "1.4.1"
eth2_network_config = { path = "../common/eth2_network_config" }
futures = { version = "0.3.7", features = ["compat"] }
futures = "0.3.7"
clap_utils = { path = "../common/clap_utils" }
directory = { path = "../common/directory" }
eth2_wallet = { path = "../crypto/eth2_wallet" }
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/eth1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ edition = "2018"
[dev-dependencies]
eth1_test_rig = { path = "../../testing/eth1_test_rig" }
toml = "0.5.6"
web3 = "0.11.0"
web3 = "0.13.0"
sloggers = "1.0.1"
environment = { path = "../../lighthouse/environment" }
tokio-compat-02 = "0.1"

[dependencies]
reqwest = { version = "0.10.8", features = ["native-tls-vendored"] }
futures = { version = "0.3.7", features = ["compat"] }
futures = "0.3.7"
serde_json = "1.0.58"
serde = { version = "1.0.116", features = ["derive"] }
hex = "0.4.2"
Expand Down
2 changes: 0 additions & 2 deletions beacon_node/eth1/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use eth1::http::{get_deposit_count, get_deposit_logs_in_range, get_deposit_root,
use eth1::{Config, Service};
use eth1::{DepositCache, DEFAULT_CHAIN_ID, DEFAULT_NETWORK_ID};
use eth1_test_rig::GanacheEth1Instance;
use futures::compat::Future01CompatExt;
use merkle_proof::verify_merkle_proof;
use slog::Logger;
use sloggers::{null::NullLoggerBuilder, Build};
Expand Down Expand Up @@ -90,7 +89,6 @@ async fn blocking_deposit_count(eth1: &GanacheEth1Instance, block_number: u64) -
async fn get_block_number(web3: &Web3<Http>) -> u64 {
web3.eth()
.block_number()
.compat()
.await
.map(|v| v.as_u64())
.expect("should get block number")
Expand Down
2 changes: 0 additions & 2 deletions beacon_node/genesis/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use environment::{Environment, EnvironmentBuilder};
use eth1::{DEFAULT_CHAIN_ID, DEFAULT_NETWORK_ID};
use eth1_test_rig::{DelayThenDeposit, GanacheEth1Instance};
use futures::compat::Future01CompatExt;
use genesis::{Eth1Config, Eth1GenesisService};
use state_processing::is_valid_genesis_state;
use std::time::Duration;
Expand Down Expand Up @@ -40,7 +39,6 @@ fn basic() {
let now = web3
.eth()
.block_number()
.compat()
.await
.map(|v| v.as_u64())
.expect("should get block number");
Expand Down
4 changes: 2 additions & 2 deletions crypto/bls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
eth2_ssz = "0.1.2"
tree_hash = "0.1.1"
milagro_bls = { git = "https://github.com/sigp/milagro_bls", tag = "v1.4.0" }
milagro_bls = { git = "https://github.com/sigp/milagro_bls", tag = "v1.4.0", optional = true }
rand = "0.7.3"
serde = "1.0.116"
serde_derive = "1.0.116"
Expand All @@ -22,7 +22,7 @@ blst = "0.3.2"
[features]
default = ["supranational"]
fake_crypto = []
milagro = []
milagro = ["milagro_bls"]
supranational = []
supranational-portable = ["supranational", "blst/portable"]
supranational-force-adx = ["supranational", "blst/force-adx"]
1 change: 1 addition & 0 deletions crypto/bls/src/impls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod blst;
pub mod fake_crypto;
#[cfg(feature = "milagro")]
pub mod milagro;
4 changes: 4 additions & 0 deletions crypto/bls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ pub use get_withdrawal_credentials::get_withdrawal_credentials;
pub use zeroize_hash::ZeroizeHash;

use blst::BLST_ERROR as BlstError;
#[cfg(feature = "milagro")]
use milagro_bls::AmclError;

pub type Hash256 = ethereum_types::H256;

#[derive(Clone, Debug, PartialEq)]
pub enum Error {
/// An error was raised from the Milagro BLS library.
#[cfg(feature = "milagro")]
MilagroError(AmclError),
/// An error was raised from the Supranational BLST BLS library.
BlstError(BlstError),
Expand All @@ -62,6 +64,7 @@ pub enum Error {
InvalidZeroSecretKey,
}

#[cfg(feature = "milagro")]
impl From<AmclError> for Error {
fn from(e: AmclError) -> Error {
Error::MilagroError(e)
Expand Down Expand Up @@ -122,6 +125,7 @@ macro_rules! define_mod {
};
}

#[cfg(feature = "milagro")]
define_mod!(milagro_implementations, crate::impls::milagro::types);
define_mod!(blst_implementations, crate::impls::blst::types);
#[cfg(feature = "fake_crypto")]
Expand Down
2 changes: 1 addition & 1 deletion crypto/bls/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ mod blst {
test_suite!(blst_implementations);
}

#[cfg(not(debug_assertions))]
#[cfg(all(feature = "milagro", not(debug_assertions)))]
mod milagro {
test_suite!(milagro_implementations);
}
3 changes: 1 addition & 2 deletions lcli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ types = { path = "../consensus/types" }
state_processing = { path = "../consensus/state_processing" }
eth2_ssz = "0.1.2"
regex = "1.3.9"
futures = { version = "0.3.7", features = ["compat"] }
futures = "0.3.7"
environment = { path = "../lighthouse/environment" }
web3 = "0.11.0"
eth2_network_config = { path = "../common/eth2_network_config" }
dirs = "3.0.1"
genesis = { path = "../beacon_node/genesis" }
Expand Down
71 changes: 0 additions & 71 deletions lcli/src/deploy_deposit_contract.rs

This file was deleted.

Loading

0 comments on commit 12c3480

Please sign in to comment.