mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 13:28:33 +00:00
Squashed reset to unstable
This commit is contained in:
committed by
Daniel Knopik
parent
b71b5f2231
commit
f61f0b654c
@@ -1,65 +1,33 @@
|
||||
//! This build script downloads the latest Web3Signer release and places it in the `OUT_DIR` so it
|
||||
//! can be used for integration testing.
|
||||
|
||||
use reqwest::{
|
||||
header::{self, HeaderValue},
|
||||
Client,
|
||||
};
|
||||
use serde_json::Value;
|
||||
use reqwest::Client;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use zip::ZipArchive;
|
||||
|
||||
/// Use `None` to download the latest Github release.
|
||||
/// Use `Some("21.8.1")` to download a specific version.
|
||||
const FIXED_VERSION_STRING: Option<&str> = None;
|
||||
|
||||
pub async fn download_binary(dest_dir: PathBuf, github_token: &str) {
|
||||
let version_file = dest_dir.join("version");
|
||||
|
||||
let client = Client::builder()
|
||||
// Github gives a 403 without a user agent.
|
||||
.user_agent("web3signer_tests")
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
// This function no longer makes any attempt to avoid downloads, because in practice we use it
|
||||
// with a fresh temp directory every time we run the tests. We might want to change this in future
|
||||
// to enable reproducible/offline testing.
|
||||
pub async fn download_binary(dest_dir: PathBuf) {
|
||||
let version = if let Some(version) = FIXED_VERSION_STRING {
|
||||
version.to_string()
|
||||
} else if let Ok(env_version) = env::var("LIGHTHOUSE_WEB3SIGNER_VERSION") {
|
||||
env_version
|
||||
} else {
|
||||
// Get the latest release of the web3 signer repo.
|
||||
let mut token_header_value = HeaderValue::from_str(github_token).unwrap();
|
||||
token_header_value.set_sensitive(true);
|
||||
let latest_response: Value = client
|
||||
.get("https://api.github.com/repos/ConsenSys/web3signer/releases/latest")
|
||||
.header(header::AUTHORIZATION, token_header_value)
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.error_for_status()
|
||||
.unwrap()
|
||||
.json()
|
||||
.await
|
||||
.unwrap();
|
||||
latest_response
|
||||
.get("tag_name")
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
// The Consenys artifact server resolves `latest` to the latest release. We previously hit
|
||||
// the Github API to establish the version, but that is no longer necessary.
|
||||
"latest".to_string()
|
||||
};
|
||||
eprintln!("Downloading web3signer version: {version}");
|
||||
|
||||
if version_file.exists() && fs::read(&version_file).unwrap() == version.as_bytes() {
|
||||
// The latest version is already downloaded, do nothing.
|
||||
return;
|
||||
} else {
|
||||
// Ignore the result since we don't care if the version file already exists.
|
||||
let _ = fs::remove_file(&version_file);
|
||||
}
|
||||
|
||||
// Download the latest release zip.
|
||||
// Download the release zip.
|
||||
let client = Client::builder().build().unwrap();
|
||||
let zip_url = format!("https://artifacts.consensys.net/public/web3signer/raw/names/web3signer.zip/versions/{}/web3signer-{}.zip", version, version);
|
||||
let zip_response = client
|
||||
.get(zip_url)
|
||||
@@ -73,8 +41,9 @@ pub async fn download_binary(dest_dir: PathBuf, github_token: &str) {
|
||||
.unwrap();
|
||||
|
||||
// Write the zip to a file.
|
||||
let zip_path = dest_dir.join(format!("{}.zip", version));
|
||||
let zip_path = dest_dir.join(format!("web3signer-{version}.zip"));
|
||||
fs::write(&zip_path, zip_response).unwrap();
|
||||
|
||||
// Unzip the zip.
|
||||
let mut zip_file = fs::File::open(&zip_path).unwrap();
|
||||
ZipArchive::new(&mut zip_file)
|
||||
@@ -88,15 +57,33 @@ pub async fn download_binary(dest_dir: PathBuf, github_token: &str) {
|
||||
if web3signer_dir.exists() {
|
||||
fs::remove_dir_all(&web3signer_dir).unwrap();
|
||||
}
|
||||
fs::rename(
|
||||
dest_dir.join(format!("web3signer-{}", version)),
|
||||
web3signer_dir,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Delete zip and unzipped dir.
|
||||
let versioned_web3signer_dir = find_versioned_web3signer_dir(&dest_dir);
|
||||
eprintln!(
|
||||
"Renaming versioned web3signer dir at: {}",
|
||||
versioned_web3signer_dir.display()
|
||||
);
|
||||
|
||||
fs::rename(versioned_web3signer_dir, web3signer_dir).unwrap();
|
||||
|
||||
// Delete zip.
|
||||
fs::remove_file(&zip_path).unwrap();
|
||||
|
||||
// Update the version file to avoid duplicate downloads.
|
||||
fs::write(&version_file, version).unwrap();
|
||||
}
|
||||
|
||||
fn find_versioned_web3signer_dir(dest_dir: &Path) -> PathBuf {
|
||||
for entry in fs::read_dir(dest_dir).unwrap() {
|
||||
let entry = entry.unwrap();
|
||||
let path = entry.path();
|
||||
|
||||
if path
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.map(|s| s.starts_with("web3signer-"))
|
||||
.unwrap_or(false)
|
||||
&& entry.file_type().unwrap().is_dir()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
panic!("no directory named web3signer-* found after ZIP extraction")
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ mod tests {
|
||||
use initialized_validators::{
|
||||
load_pem_certificate, load_pkcs12_identity, InitializedValidators,
|
||||
};
|
||||
use lighthouse_validator_store::LighthouseValidatorStore;
|
||||
use logging::test_logger;
|
||||
use parking_lot::Mutex;
|
||||
use reqwest::Client;
|
||||
use serde::Serialize;
|
||||
@@ -46,7 +44,7 @@ mod tests {
|
||||
use tokio::time::sleep;
|
||||
use types::{attestation::AttestationBase, *};
|
||||
use url::Url;
|
||||
use validator_store::{Error as ValidatorStoreError, SignedBlock, ValidatorStore};
|
||||
use validator_store::{Error as ValidatorStoreError, ValidatorStore};
|
||||
|
||||
/// If the we are unable to reach the Web3Signer HTTP API within this time out then we will
|
||||
/// assume it failed to start.
|
||||
@@ -75,7 +73,6 @@ mod tests {
|
||||
impl SignedObject for Signature {}
|
||||
impl SignedObject for Attestation<E> {}
|
||||
impl SignedObject for SignedBeaconBlock<E> {}
|
||||
impl SignedObject for SignedBlock<E> {}
|
||||
impl SignedObject for SignedAggregateAndProof<E> {}
|
||||
impl SignedObject for SelectionProof {}
|
||||
impl SignedObject for SyncSelectionProof {}
|
||||
@@ -180,14 +177,7 @@ mod tests {
|
||||
pub async fn new(network: &str, listen_address: &str, listen_port: u16) -> Self {
|
||||
GET_WEB3SIGNER_BIN
|
||||
.get_or_init(|| async {
|
||||
// Read a Github API token from the environment. This is intended to prevent rate-limits on CI.
|
||||
// We use a name that is unlikely to accidentally collide with anything the user has configured.
|
||||
let github_token = env::var("LIGHTHOUSE_GITHUB_TOKEN");
|
||||
download_binary(
|
||||
TEMP_DIR.lock().path().to_path_buf(),
|
||||
github_token.as_deref().unwrap_or(""),
|
||||
)
|
||||
.await;
|
||||
download_binary(TEMP_DIR.lock().path().to_path_buf()).await;
|
||||
})
|
||||
.await;
|
||||
|
||||
@@ -311,7 +301,7 @@ mod tests {
|
||||
|
||||
/// A testing rig which holds a `ValidatorStore`.
|
||||
struct ValidatorStoreRig {
|
||||
validator_store: Arc<LighthouseValidatorStore<TestingSlotClock, E>>,
|
||||
validator_store: Arc<ValidatorStore<TestingSlotClock, E>>,
|
||||
_validator_dir: TempDir,
|
||||
runtime: Arc<tokio::runtime::Runtime>,
|
||||
_runtime_shutdown: async_channel::Sender<()>,
|
||||
@@ -325,7 +315,6 @@ mod tests {
|
||||
using_web3signer: bool,
|
||||
spec: Arc<ChainSpec>,
|
||||
) -> Self {
|
||||
let log = test_logger();
|
||||
let validator_dir = TempDir::new().unwrap();
|
||||
|
||||
let config = initialized_validators::Config::default();
|
||||
@@ -334,7 +323,6 @@ mod tests {
|
||||
validator_definitions,
|
||||
validator_dir.path().into(),
|
||||
config.clone(),
|
||||
log.clone(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -349,8 +337,12 @@ mod tests {
|
||||
);
|
||||
let (runtime_shutdown, exit) = async_channel::bounded(1);
|
||||
let (shutdown_tx, _) = futures::channel::mpsc::channel(1);
|
||||
let executor =
|
||||
TaskExecutor::new(Arc::downgrade(&runtime), exit, log.clone(), shutdown_tx);
|
||||
let executor = TaskExecutor::new(
|
||||
Arc::downgrade(&runtime),
|
||||
exit,
|
||||
shutdown_tx,
|
||||
"test".to_string(),
|
||||
);
|
||||
|
||||
let slashing_db_path = validator_dir.path().join(SLASHING_PROTECTION_FILENAME);
|
||||
let slashing_protection = SlashingDatabase::open_or_create(&slashing_db_path).unwrap();
|
||||
@@ -360,12 +352,12 @@ mod tests {
|
||||
|
||||
let slot_clock =
|
||||
TestingSlotClock::new(Slot::new(0), Duration::from_secs(0), Duration::from_secs(1));
|
||||
let config = lighthouse_validator_store::Config {
|
||||
let config = validator_store::Config {
|
||||
enable_web3signer_slashing_protection: slashing_protection_config.local,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let validator_store = LighthouseValidatorStore::new(
|
||||
let validator_store = ValidatorStore::<_, E>::new(
|
||||
initialized_validators,
|
||||
slashing_protection,
|
||||
Hash256::repeat_byte(42),
|
||||
@@ -374,7 +366,6 @@ mod tests {
|
||||
slot_clock,
|
||||
&config,
|
||||
executor,
|
||||
log.clone(),
|
||||
);
|
||||
|
||||
Self {
|
||||
@@ -490,7 +481,7 @@ mod tests {
|
||||
generate_sig: F,
|
||||
) -> Self
|
||||
where
|
||||
F: Fn(PublicKeyBytes, Arc<LighthouseValidatorStore<TestingSlotClock, E>>) -> R,
|
||||
F: Fn(PublicKeyBytes, Arc<ValidatorStore<TestingSlotClock, E>>) -> R,
|
||||
R: Future<Output = S>,
|
||||
// We use the `SignedObject` trait to white-list objects for comparison. This avoids
|
||||
// accidentally comparing something meaningless like a `()`.
|
||||
@@ -525,8 +516,8 @@ mod tests {
|
||||
web3signer_should_sign: bool,
|
||||
) -> Self
|
||||
where
|
||||
F: Fn(PublicKeyBytes, Arc<LighthouseValidatorStore<TestingSlotClock, E>>) -> R,
|
||||
R: Future<Output = Result<(), lighthouse_validator_store::Error>>,
|
||||
F: Fn(PublicKeyBytes, Arc<ValidatorStore<TestingSlotClock, E>>) -> R,
|
||||
R: Future<Output = Result<(), ValidatorStoreError>>,
|
||||
{
|
||||
for validator_rig in &self.validator_rigs {
|
||||
let result =
|
||||
@@ -600,10 +591,10 @@ mod tests {
|
||||
.assert_signatures_match("beacon_block_base", |pubkey, validator_store| {
|
||||
let spec = spec.clone();
|
||||
async move {
|
||||
let block = BeaconBlock::<E>::Base(BeaconBlockBase::empty(&spec));
|
||||
let block = BeaconBlock::Base(BeaconBlockBase::empty(&spec));
|
||||
let block_slot = block.slot();
|
||||
validator_store
|
||||
.sign_block(pubkey, block.into(), block_slot)
|
||||
.sign_block(pubkey, block, block_slot)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
@@ -670,14 +661,10 @@ mod tests {
|
||||
.assert_signatures_match("beacon_block_altair", |pubkey, validator_store| {
|
||||
let spec = spec.clone();
|
||||
async move {
|
||||
let mut altair_block = BeaconBlockAltair::<E>::empty(&spec);
|
||||
let mut altair_block = BeaconBlockAltair::empty(&spec);
|
||||
altair_block.slot = altair_fork_slot;
|
||||
validator_store
|
||||
.sign_block(
|
||||
pubkey,
|
||||
BeaconBlock::Altair(altair_block).into(),
|
||||
altair_fork_slot,
|
||||
)
|
||||
.sign_block(pubkey, BeaconBlock::Altair(altair_block), altair_fork_slot)
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
@@ -757,12 +744,12 @@ mod tests {
|
||||
.assert_signatures_match("beacon_block_bellatrix", |pubkey, validator_store| {
|
||||
let spec = spec.clone();
|
||||
async move {
|
||||
let mut bellatrix_block = BeaconBlockBellatrix::<E>::empty(&spec);
|
||||
let mut bellatrix_block = BeaconBlockBellatrix::empty(&spec);
|
||||
bellatrix_block.slot = bellatrix_fork_slot;
|
||||
validator_store
|
||||
.sign_block(
|
||||
pubkey,
|
||||
BeaconBlock::Bellatrix(bellatrix_block).into(),
|
||||
BeaconBlock::Bellatrix(bellatrix_block),
|
||||
bellatrix_fork_slot,
|
||||
)
|
||||
.await
|
||||
@@ -818,7 +805,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let first_block = || {
|
||||
let mut bellatrix_block = BeaconBlockBellatrix::<E>::empty(&spec);
|
||||
let mut bellatrix_block = BeaconBlockBellatrix::empty(&spec);
|
||||
bellatrix_block.slot = bellatrix_fork_slot;
|
||||
BeaconBlock::Bellatrix(bellatrix_block)
|
||||
};
|
||||
@@ -884,7 +871,7 @@ mod tests {
|
||||
let block = first_block();
|
||||
let slot = block.slot();
|
||||
validator_store
|
||||
.sign_block(pubkey, block.into(), slot)
|
||||
.sign_block(pubkey, block, slot)
|
||||
.await
|
||||
.unwrap()
|
||||
})
|
||||
@@ -895,7 +882,7 @@ mod tests {
|
||||
let block = double_vote_block();
|
||||
let slot = block.slot();
|
||||
validator_store
|
||||
.sign_block(pubkey, block.into(), slot)
|
||||
.sign_block(pubkey, block, slot)
|
||||
.await
|
||||
.map(|_| ())
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user