Upgrade to tokio 0.3 (#1839)

## Description

This PR updates Lighthouse to tokio 0.3. It includes a number of dependency updates and some structural changes as to how we create and spawn tasks.

This also brings with it a number of various improvements:

- Discv5 update
- Libp2p update
- Fix for recompilation issues
- Improved UPnP port mapping handling
- Futures dependency update
- Log downgrade to traces for rejecting peers when we've reached our max



Co-authored-by: blacktemplar <blacktemplar@a1.net>
This commit is contained in:
Age Manning
2020-11-28 05:30:57 +00:00
parent 5a3b94cbb4
commit a567f788bd
81 changed files with 3666 additions and 2762 deletions

View File

@@ -20,7 +20,7 @@ types = { path = "../consensus/types" }
state_processing = { path = "../consensus/state_processing" }
eth2_ssz = "0.1.2"
regex = "1.3.9"
futures = { version = "0.3.5", features = ["compat"] }
futures = { version = "0.3.7", features = ["compat"] }
environment = { path = "../lighthouse/environment" }
web3 = "0.11.0"
eth2_testnet_config = { path = "../common/eth2_testnet_config" }
@@ -28,7 +28,7 @@ dirs = "3.0.1"
genesis = { path = "../beacon_node/genesis" }
deposit_contract = { path = "../common/deposit_contract" }
tree_hash = "0.1.1"
tokio = { version = "0.2.22", features = ["full"] }
tokio = { version = "0.3.2", features = ["full"] }
clap_utils = { path = "../common/clap_utils" }
eth2_libp2p = { path = "../beacon_node/eth2_libp2p" }
validator_dir = { path = "../common/validator_dir", features = ["insecure_keys"] }
@@ -36,3 +36,4 @@ rand = "0.7.3"
eth2_keystore = { path = "../crypto/eth2_keystore" }
lighthouse_version = { path = "../common/lighthouse_version" }
directory = { path = "../common/directory" }
tokio-compat-02 = "0.1"

View File

@@ -6,6 +6,7 @@ use deposit_contract::{
use environment::Environment;
use futures::compat::Future01CompatExt;
use std::path::PathBuf;
use tokio_compat_02::FutureExt;
use types::EthSpec;
use web3::{
contract::{Contract, Options},
@@ -14,7 +15,7 @@ use web3::{
Web3,
};
pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches<'_>) -> Result<(), String> {
pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches<'_>) -> Result<(), String> {
let eth1_ipc_path: PathBuf = clap_utils::parse_required(matches, "eth1-ipc")?;
let from_address: Address = clap_utils::parse_required(matches, "from-address")?;
let confirmations: usize = clap_utils::parse_required(matches, "confirmations")?;
@@ -30,38 +31,41 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches<'_>) -> Res
)
})?;
env.runtime().block_on(async {
// It's unlikely that this will be the _actual_ deployment block, however it'll be close
// enough to serve our purposes.
//
// We only need the deposit block to put a lower bound on the block number we need to search
// for deposit logs.
let deploy_block = web3
.eth()
.block_number()
.compat()
.await
.map_err(|e| format!("Failed to get block number: {}", e))?;
env.runtime().block_on(
async {
// It's unlikely that this will be the _actual_ deployment block, however it'll be close
// enough to serve our purposes.
//
// We only need the deposit block to put a lower bound on the block number we need to search
// for deposit logs.
let deploy_block = web3
.eth()
.block_number()
.compat()
.await
.map_err(|e| format!("Failed to get block number: {}", e))?;
let pending_contract = Contract::deploy(web3.eth(), &ABI)
.map_err(|e| format!("Unable to build contract deployer: {:?}", e))?
.confirmations(confirmations)
.options(Options {
gas: Some(U256::from(CONTRACT_DEPLOY_GAS)),
..Options::default()
})
.execute(bytecode, (), from_address)
.map_err(|e| format!("Unable to execute deployment: {:?}", e))?;
let pending_contract = Contract::deploy(web3.eth(), &ABI)
.map_err(|e| format!("Unable to build contract deployer: {:?}", e))?
.confirmations(confirmations)
.options(Options {
gas: Some(U256::from(CONTRACT_DEPLOY_GAS)),
..Options::default()
})
.execute(bytecode, (), from_address)
.map_err(|e| format!("Unable to execute deployment: {:?}", e))?;
let address = pending_contract
.compat()
.await
.map_err(|e| format!("Unable to await pending contract: {:?}", e))?
.address();
let address = pending_contract
.compat()
.await
.map_err(|e| format!("Unable to await pending contract: {:?}", e))?
.address();
println!("deposit_contract_address: {:?}", address);
println!("deposit_contract_deploy_block: {}", deploy_block);
println!("deposit_contract_address: {:?}", address);
println!("deposit_contract_deploy_block: {}", deploy_block);
Ok(())
})
Ok(())
}
.compat(),
)
}

View File

@@ -6,6 +6,7 @@ use ssz::Encode;
use std::cmp::max;
use std::path::PathBuf;
use std::time::Duration;
use tokio_compat_02::FutureExt;
use types::EthSpec;
/// Interval between polling the eth1 node for genesis information.
@@ -58,19 +59,22 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches<'_>) -> Res
let genesis_service =
Eth1GenesisService::new(config, env.core_context().log().clone(), spec.clone());
env.runtime().block_on(async {
let _ = genesis_service
.wait_for_genesis_state::<T>(ETH1_GENESIS_UPDATE_INTERVAL, spec)
.await
.map(move |genesis_state| {
eth2_testnet_config.genesis_state_bytes = Some(genesis_state.as_ssz_bytes());
eth2_testnet_config.force_write_to_file(testnet_dir)
})
.map_err(|e| format!("Failed to find genesis: {}", e))?;
env.runtime().block_on(
async {
let _ = genesis_service
.wait_for_genesis_state::<T>(ETH1_GENESIS_UPDATE_INTERVAL, spec)
.await
.map(move |genesis_state| {
eth2_testnet_config.genesis_state_bytes = Some(genesis_state.as_ssz_bytes());
eth2_testnet_config.force_write_to_file(testnet_dir)
})
.map_err(|e| format!("Failed to find genesis: {}", e))?;
info!("Starting service to produce genesis BeaconState from eth1");
info!("Connecting to eth1 http endpoints: {:?}", endpoints);
info!("Starting service to produce genesis BeaconState from eth1");
info!("Connecting to eth1 http endpoints: {:?}", endpoints);
Ok(())
})
Ok(())
}
.compat(),
)
}

View File

@@ -2,6 +2,7 @@ use clap::ArgMatches;
use environment::Environment;
use futures::compat::Future01CompatExt;
use std::path::PathBuf;
use tokio_compat_02::FutureExt;
use types::EthSpec;
use web3::{
transports::Ipc,
@@ -12,7 +13,7 @@ use web3::{
/// `keccak("steal()")[0..4]`
pub const STEAL_FN_SIGNATURE: &[u8] = &[0xcf, 0x7a, 0x89, 0x65];
pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches<'_>) -> Result<(), String> {
pub fn run<T: EthSpec>(env: Environment<T>, matches: &ArgMatches<'_>) -> Result<(), String> {
let eth1_ipc_path: PathBuf = clap_utils::parse_required(matches, "eth1-ipc")?;
let from: Address = clap_utils::parse_required(matches, "from-address")?;
let contract_address: Address = clap_utils::parse_required(matches, "contract-address")?;
@@ -21,23 +22,26 @@ pub fn run<T: EthSpec>(mut env: Environment<T>, matches: &ArgMatches<'_>) -> Res
Ipc::new(eth1_ipc_path).map_err(|e| format!("Unable to connect to eth1 IPC: {:?}", e))?;
let web3 = Web3::new(transport);
env.runtime().block_on(async {
let _ = web3
.eth()
.send_transaction(TransactionRequest {
from,
to: Some(contract_address),
gas: Some(U256::from(400_000)),
gas_price: None,
value: Some(U256::zero()),
data: Some(STEAL_FN_SIGNATURE.into()),
nonce: None,
condition: None,
})
.compat()
.await
.map_err(|e| format!("Failed to call steal fn: {:?}", e))?;
env.runtime().block_on(
async {
let _ = web3
.eth()
.send_transaction(TransactionRequest {
from,
to: Some(contract_address),
gas: Some(U256::from(400_000)),
gas_price: None,
value: Some(U256::zero()),
data: Some(STEAL_FN_SIGNATURE.into()),
nonce: None,
condition: None,
})
.compat()
.await
.map_err(|e| format!("Failed to call steal fn: {:?}", e))?;
Ok(())
})
Ok(())
}
.compat(),
)
}