mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
Merge remote-tracking branch 'origin/unstable' into tree-states
This commit is contained in:
@@ -41,5 +41,8 @@ tokio-postgres = "0.7.5"
|
||||
http_api = { path = "../beacon_node/http_api" }
|
||||
beacon_chain = { path = "../beacon_node/beacon_chain" }
|
||||
network = { path = "../beacon_node/network" }
|
||||
testcontainers = "0.14.0"
|
||||
# TODO: update to 0.15 when released: https://github.com/testcontainers/testcontainers-rs/issues/497
|
||||
testcontainers = { git = "https://github.com/testcontainers/testcontainers-rs/", rev = "0f2c9851" }
|
||||
unused_port = { path = "../common/unused_port" }
|
||||
task_executor = { path = "../common/task_executor" }
|
||||
logging = { path = "../common/logging" }
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
#![recursion_limit = "256"]
|
||||
#![cfg(unix)]
|
||||
|
||||
use beacon_chain::test_utils::{
|
||||
AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType,
|
||||
use beacon_chain::{
|
||||
test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType},
|
||||
ChainConfig,
|
||||
};
|
||||
use eth2::{types::BlockId, BeaconNodeHttpClient, SensitiveUrl, Timeouts};
|
||||
use http_api::test_utils::{create_api_server, ApiServer};
|
||||
use log::error;
|
||||
use logging::test_logger;
|
||||
use network::NetworkReceivers;
|
||||
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::{thread_rng, Rng};
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::net::SocketAddr;
|
||||
use std::time::Duration;
|
||||
use testcontainers::{clients::Cli, core::WaitFor, Image, RunnableImage};
|
||||
use tokio::sync::oneshot;
|
||||
use tokio::{runtime, task::JoinHandle};
|
||||
use tokio_postgres::{config::Config as PostgresConfig, Client, NoTls};
|
||||
use types::{Hash256, MainnetEthSpec, Slot};
|
||||
use unused_port::unused_tcp4_port;
|
||||
use url::Url;
|
||||
use watch::{
|
||||
client::WatchHttpClient,
|
||||
@@ -21,14 +31,40 @@ use watch::{
|
||||
updater::{handler::*, run_updater, Config as UpdaterConfig, WatchSpec},
|
||||
};
|
||||
|
||||
use log::error;
|
||||
use std::net::SocketAddr;
|
||||
use std::time::Duration;
|
||||
use tokio::{runtime, task::JoinHandle};
|
||||
use tokio_postgres::{config::Config as PostgresConfig, Client, NoTls};
|
||||
use unused_port::unused_tcp4_port;
|
||||
#[derive(Debug)]
|
||||
pub struct Postgres(HashMap<String, String>);
|
||||
|
||||
use testcontainers::{clients::Cli, images::postgres::Postgres, RunnableImage};
|
||||
impl Default for Postgres {
|
||||
fn default() -> Self {
|
||||
let mut env_vars = HashMap::new();
|
||||
env_vars.insert("POSTGRES_DB".to_owned(), "postgres".to_owned());
|
||||
env_vars.insert("POSTGRES_HOST_AUTH_METHOD".into(), "trust".into());
|
||||
|
||||
Self(env_vars)
|
||||
}
|
||||
}
|
||||
|
||||
impl Image for Postgres {
|
||||
type Args = ();
|
||||
|
||||
fn name(&self) -> String {
|
||||
"postgres".to_owned()
|
||||
}
|
||||
|
||||
fn tag(&self) -> String {
|
||||
"11-alpine".to_owned()
|
||||
}
|
||||
|
||||
fn ready_conditions(&self) -> Vec<WaitFor> {
|
||||
vec![WaitFor::message_on_stderr(
|
||||
"database system is ready to accept connections",
|
||||
)]
|
||||
}
|
||||
|
||||
fn env_vars(&self) -> Box<dyn Iterator<Item = (&String, &String)> + '_> {
|
||||
Box::new(self.0.iter())
|
||||
}
|
||||
}
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
|
||||
@@ -36,6 +72,11 @@ const VALIDATOR_COUNT: usize = 32;
|
||||
const SLOTS_PER_EPOCH: u64 = 32;
|
||||
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5);
|
||||
|
||||
/// Set this environment variable to use a different hostname for connecting to
|
||||
/// the database. Can be set to `host.docker.internal` for docker-in-docker
|
||||
/// setups.
|
||||
const WATCH_HOST_ENV_VARIABLE: &str = "WATCH_HOST";
|
||||
|
||||
fn build_test_config(config: &DatabaseConfig) -> PostgresConfig {
|
||||
let mut postgres_config = PostgresConfig::new();
|
||||
postgres_config
|
||||
@@ -71,17 +112,25 @@ pub async fn create_test_database(config: &DatabaseConfig) {
|
||||
.expect("Database creation failed");
|
||||
}
|
||||
|
||||
pub fn get_host_from_env() -> String {
|
||||
env::var(WATCH_HOST_ENV_VARIABLE).unwrap_or_else(|_| "localhost".to_string())
|
||||
}
|
||||
|
||||
struct TesterBuilder {
|
||||
pub harness: BeaconChainHarness<EphemeralHarnessType<E>>,
|
||||
pub config: Config,
|
||||
_bn_network_rx: NetworkReceivers<E>,
|
||||
_bn_api_shutdown_tx: oneshot::Sender<()>,
|
||||
}
|
||||
|
||||
impl TesterBuilder {
|
||||
pub async fn new() -> TesterBuilder {
|
||||
let harness = BeaconChainHarness::builder(E::default())
|
||||
.default_spec()
|
||||
.chain_config(ChainConfig {
|
||||
reconstruct_historic_states: true,
|
||||
..ChainConfig::default()
|
||||
})
|
||||
.logger(test_logger())
|
||||
.deterministic_keypairs(VALIDATOR_COUNT)
|
||||
.fresh_ephemeral_store()
|
||||
.build();
|
||||
@@ -92,10 +141,14 @@ impl TesterBuilder {
|
||||
let ApiServer {
|
||||
server,
|
||||
listening_socket: bn_api_listening_socket,
|
||||
shutdown_tx: _bn_api_shutdown_tx,
|
||||
network_rx: _bn_network_rx,
|
||||
..
|
||||
} = create_api_server(harness.chain.clone(), harness.logger().clone()).await;
|
||||
} = create_api_server(
|
||||
harness.chain.clone(),
|
||||
&harness.runtime,
|
||||
harness.logger().clone(),
|
||||
)
|
||||
.await;
|
||||
tokio::spawn(server);
|
||||
|
||||
/*
|
||||
@@ -107,6 +160,7 @@ impl TesterBuilder {
|
||||
database: DatabaseConfig {
|
||||
dbname: random_dbname(),
|
||||
port: database_port,
|
||||
host: get_host_from_env(),
|
||||
..Default::default()
|
||||
},
|
||||
server: ServerConfig {
|
||||
@@ -128,7 +182,6 @@ impl TesterBuilder {
|
||||
harness,
|
||||
config,
|
||||
_bn_network_rx,
|
||||
_bn_api_shutdown_tx,
|
||||
}
|
||||
}
|
||||
pub async fn build(self, pool: PgPool) -> Tester {
|
||||
@@ -175,7 +228,6 @@ impl TesterBuilder {
|
||||
config: self.config,
|
||||
updater,
|
||||
_bn_network_rx: self._bn_network_rx,
|
||||
_bn_api_shutdown_tx: self._bn_api_shutdown_tx,
|
||||
_watch_shutdown_tx,
|
||||
}
|
||||
}
|
||||
@@ -193,7 +245,6 @@ struct Tester {
|
||||
pub config: Config,
|
||||
pub updater: UpdateHandler<E>,
|
||||
_bn_network_rx: NetworkReceivers<E>,
|
||||
_bn_api_shutdown_tx: oneshot::Sender<()>,
|
||||
_watch_shutdown_tx: oneshot::Sender<()>,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user