mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 13:28:33 +00:00
Remove fallback support from eth1 service (#3594)
## Issue Addressed N/A ## Proposed Changes With https://github.com/sigp/lighthouse/pull/3214 we made it such that you can either have 1 auth endpoint or multiple non auth endpoints. Now that we are post merge on all networks (testnets and mainnet), we cannot progress a chain without a dedicated auth execution layer connection so there is no point in having a non-auth eth1-endpoint for syncing deposit cache. This code removes all fallback related code in the eth1 service. We still keep the single non-auth endpoint since it's useful for testing. ## Additional Info This removes all eth1 fallback related metrics that were relevant for the monitoring service, so we might need to change the api upstream.
This commit is contained in:
@@ -117,10 +117,9 @@ mod eth1_cache {
|
||||
let initial_block_number = get_block_number(&web3).await;
|
||||
|
||||
let config = Config {
|
||||
endpoints: Eth1Endpoint::NoAuth(vec![SensitiveUrl::parse(
|
||||
eth1.endpoint().as_str(),
|
||||
)
|
||||
.unwrap()]),
|
||||
endpoint: Eth1Endpoint::NoAuth(
|
||||
SensitiveUrl::parse(eth1.endpoint().as_str()).unwrap(),
|
||||
),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
lowest_cached_block_number: initial_block_number,
|
||||
follow_distance,
|
||||
@@ -128,7 +127,8 @@ mod eth1_cache {
|
||||
};
|
||||
let cache_follow_distance = config.cache_follow_distance();
|
||||
|
||||
let service = Service::new(config, log.clone(), MainnetEthSpec::default_spec());
|
||||
let service =
|
||||
Service::new(config, log.clone(), MainnetEthSpec::default_spec()).unwrap();
|
||||
|
||||
// Create some blocks and then consume them, performing the test `rounds` times.
|
||||
for round in 0..2 {
|
||||
@@ -149,19 +149,17 @@ mod eth1_cache {
|
||||
eth1.ganache.evm_mine().await.expect("should mine block");
|
||||
}
|
||||
|
||||
let endpoints = service.init_endpoints().unwrap();
|
||||
|
||||
service
|
||||
.update_deposit_cache(None, &endpoints)
|
||||
.update_deposit_cache(None)
|
||||
.await
|
||||
.expect("should update deposit cache");
|
||||
service
|
||||
.update_block_cache(None, &endpoints)
|
||||
.update_block_cache(None)
|
||||
.await
|
||||
.expect("should update block cache");
|
||||
|
||||
service
|
||||
.update_block_cache(None, &endpoints)
|
||||
.update_block_cache(None)
|
||||
.await
|
||||
.expect("should update cache when nothing has changed");
|
||||
|
||||
@@ -201,10 +199,9 @@ mod eth1_cache {
|
||||
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoints: Eth1Endpoint::NoAuth(vec![SensitiveUrl::parse(
|
||||
eth1.endpoint().as_str(),
|
||||
)
|
||||
.unwrap()]),
|
||||
endpoint: Eth1Endpoint::NoAuth(
|
||||
SensitiveUrl::parse(eth1.endpoint().as_str()).unwrap(),
|
||||
),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
lowest_cached_block_number: get_block_number(&web3).await,
|
||||
follow_distance: 0,
|
||||
@@ -213,7 +210,8 @@ mod eth1_cache {
|
||||
},
|
||||
log,
|
||||
MainnetEthSpec::default_spec(),
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let blocks = cache_len * 2;
|
||||
|
||||
@@ -221,14 +219,12 @@ mod eth1_cache {
|
||||
eth1.ganache.evm_mine().await.expect("should mine block")
|
||||
}
|
||||
|
||||
let endpoints = service.init_endpoints().unwrap();
|
||||
|
||||
service
|
||||
.update_deposit_cache(None, &endpoints)
|
||||
.update_deposit_cache(None)
|
||||
.await
|
||||
.expect("should update deposit cache");
|
||||
service
|
||||
.update_block_cache(None, &endpoints)
|
||||
.update_block_cache(None)
|
||||
.await
|
||||
.expect("should update block cache");
|
||||
|
||||
@@ -258,10 +254,9 @@ mod eth1_cache {
|
||||
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoints: Eth1Endpoint::NoAuth(vec![SensitiveUrl::parse(
|
||||
eth1.endpoint().as_str(),
|
||||
)
|
||||
.unwrap()]),
|
||||
endpoint: Eth1Endpoint::NoAuth(
|
||||
SensitiveUrl::parse(eth1.endpoint().as_str()).unwrap(),
|
||||
),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
lowest_cached_block_number: get_block_number(&web3).await,
|
||||
follow_distance: 0,
|
||||
@@ -270,19 +265,19 @@ mod eth1_cache {
|
||||
},
|
||||
log,
|
||||
MainnetEthSpec::default_spec(),
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for _ in 0..4u8 {
|
||||
for _ in 0..cache_len / 2 {
|
||||
eth1.ganache.evm_mine().await.expect("should mine block")
|
||||
}
|
||||
let endpoints = service.init_endpoints().unwrap();
|
||||
service
|
||||
.update_deposit_cache(None, &endpoints)
|
||||
.update_deposit_cache(None)
|
||||
.await
|
||||
.expect("should update deposit cache");
|
||||
service
|
||||
.update_block_cache(None, &endpoints)
|
||||
.update_block_cache(None)
|
||||
.await
|
||||
.expect("should update block cache");
|
||||
}
|
||||
@@ -311,10 +306,9 @@ mod eth1_cache {
|
||||
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoints: Eth1Endpoint::NoAuth(vec![SensitiveUrl::parse(
|
||||
eth1.endpoint().as_str(),
|
||||
)
|
||||
.unwrap()]),
|
||||
endpoint: Eth1Endpoint::NoAuth(
|
||||
SensitiveUrl::parse(eth1.endpoint().as_str()).unwrap(),
|
||||
),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
lowest_cached_block_number: get_block_number(&web3).await,
|
||||
follow_distance: 0,
|
||||
@@ -322,21 +316,21 @@ mod eth1_cache {
|
||||
},
|
||||
log,
|
||||
MainnetEthSpec::default_spec(),
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for _ in 0..n {
|
||||
eth1.ganache.evm_mine().await.expect("should mine block")
|
||||
}
|
||||
|
||||
let endpoints = service.init_endpoints().unwrap();
|
||||
futures::try_join!(
|
||||
service.update_deposit_cache(None, &endpoints),
|
||||
service.update_deposit_cache(None, &endpoints)
|
||||
service.update_deposit_cache(None),
|
||||
service.update_deposit_cache(None)
|
||||
)
|
||||
.expect("should perform two simultaneous updates of deposit cache");
|
||||
futures::try_join!(
|
||||
service.update_block_cache(None, &endpoints),
|
||||
service.update_block_cache(None, &endpoints)
|
||||
service.update_block_cache(None),
|
||||
service.update_block_cache(None)
|
||||
)
|
||||
.expect("should perform two simultaneous updates of block cache");
|
||||
|
||||
@@ -366,10 +360,9 @@ mod deposit_tree {
|
||||
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoints: Eth1Endpoint::NoAuth(vec![SensitiveUrl::parse(
|
||||
eth1.endpoint().as_str(),
|
||||
)
|
||||
.unwrap()]),
|
||||
endpoint: Eth1Endpoint::NoAuth(
|
||||
SensitiveUrl::parse(eth1.endpoint().as_str()).unwrap(),
|
||||
),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
deposit_contract_deploy_block: start_block,
|
||||
follow_distance: 0,
|
||||
@@ -377,7 +370,8 @@ mod deposit_tree {
|
||||
},
|
||||
log,
|
||||
MainnetEthSpec::default_spec(),
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for round in 0..3 {
|
||||
let deposits: Vec<_> = (0..n).map(|_| random_deposit_data()).collect();
|
||||
@@ -389,15 +383,13 @@ mod deposit_tree {
|
||||
.expect("should perform a deposit");
|
||||
}
|
||||
|
||||
let endpoints = service.init_endpoints().unwrap();
|
||||
|
||||
service
|
||||
.update_deposit_cache(None, &endpoints)
|
||||
.update_deposit_cache(None)
|
||||
.await
|
||||
.expect("should perform update");
|
||||
|
||||
service
|
||||
.update_deposit_cache(None, &endpoints)
|
||||
.update_deposit_cache(None)
|
||||
.await
|
||||
.expect("should perform update when nothing has changed");
|
||||
|
||||
@@ -449,10 +441,9 @@ mod deposit_tree {
|
||||
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoints: Eth1Endpoint::NoAuth(vec![SensitiveUrl::parse(
|
||||
eth1.endpoint().as_str(),
|
||||
)
|
||||
.unwrap()]),
|
||||
endpoint: Eth1Endpoint::NoAuth(
|
||||
SensitiveUrl::parse(eth1.endpoint().as_str()).unwrap(),
|
||||
),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
deposit_contract_deploy_block: start_block,
|
||||
lowest_cached_block_number: start_block,
|
||||
@@ -461,7 +452,8 @@ mod deposit_tree {
|
||||
},
|
||||
log,
|
||||
MainnetEthSpec::default_spec(),
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let deposits: Vec<_> = (0..n).map(|_| random_deposit_data()).collect();
|
||||
|
||||
@@ -472,10 +464,9 @@ mod deposit_tree {
|
||||
.expect("should perform a deposit");
|
||||
}
|
||||
|
||||
let endpoints = service.init_endpoints().unwrap();
|
||||
futures::try_join!(
|
||||
service.update_deposit_cache(None, &endpoints),
|
||||
service.update_deposit_cache(None, &endpoints)
|
||||
service.update_deposit_cache(None),
|
||||
service.update_deposit_cache(None)
|
||||
)
|
||||
.expect("should perform two updates concurrently");
|
||||
|
||||
@@ -706,10 +697,9 @@ mod fast {
|
||||
let now = get_block_number(&web3).await;
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoints: Eth1Endpoint::NoAuth(vec![SensitiveUrl::parse(
|
||||
eth1.endpoint().as_str(),
|
||||
)
|
||||
.unwrap()]),
|
||||
endpoint: Eth1Endpoint::NoAuth(
|
||||
SensitiveUrl::parse(eth1.endpoint().as_str()).unwrap(),
|
||||
),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
deposit_contract_deploy_block: now,
|
||||
lowest_cached_block_number: now,
|
||||
@@ -719,7 +709,8 @@ mod fast {
|
||||
},
|
||||
log,
|
||||
MainnetEthSpec::default_spec(),
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
let client = HttpJsonRpc::new(SensitiveUrl::parse(ð1.endpoint()).unwrap()).unwrap();
|
||||
let n = 10;
|
||||
let deposits: Vec<_> = (0..n).map(|_| random_deposit_data()).collect();
|
||||
@@ -732,9 +723,8 @@ mod fast {
|
||||
eth1.ganache.evm_mine().await.expect("should mine block");
|
||||
}
|
||||
|
||||
let endpoints = service.init_endpoints().unwrap();
|
||||
service
|
||||
.update_deposit_cache(None, &endpoints)
|
||||
.update_deposit_cache(None)
|
||||
.await
|
||||
.expect("should perform update");
|
||||
|
||||
@@ -787,10 +777,9 @@ mod persist {
|
||||
|
||||
let now = get_block_number(&web3).await;
|
||||
let config = Config {
|
||||
endpoints: Eth1Endpoint::NoAuth(vec![SensitiveUrl::parse(
|
||||
eth1.endpoint().as_str(),
|
||||
)
|
||||
.unwrap()]),
|
||||
endpoint: Eth1Endpoint::NoAuth(
|
||||
SensitiveUrl::parse(eth1.endpoint().as_str()).unwrap(),
|
||||
),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
deposit_contract_deploy_block: now,
|
||||
lowest_cached_block_number: now,
|
||||
@@ -798,7 +787,8 @@ mod persist {
|
||||
block_cache_truncation: None,
|
||||
..Config::default()
|
||||
};
|
||||
let service = Service::new(config.clone(), log.clone(), MainnetEthSpec::default_spec());
|
||||
let service =
|
||||
Service::new(config.clone(), log.clone(), MainnetEthSpec::default_spec()).unwrap();
|
||||
let n = 10;
|
||||
let deposits: Vec<_> = (0..n).map(|_| random_deposit_data()).collect();
|
||||
for deposit in &deposits {
|
||||
@@ -808,9 +798,8 @@ mod persist {
|
||||
.expect("should perform a deposit");
|
||||
}
|
||||
|
||||
let endpoints = service.init_endpoints().unwrap();
|
||||
service
|
||||
.update_deposit_cache(None, &endpoints)
|
||||
.update_deposit_cache(None)
|
||||
.await
|
||||
.expect("should perform update");
|
||||
|
||||
@@ -822,7 +811,7 @@ mod persist {
|
||||
let deposit_count = service.deposit_cache_len();
|
||||
|
||||
service
|
||||
.update_block_cache(None, &endpoints)
|
||||
.update_block_cache(None)
|
||||
.await
|
||||
.expect("should perform update");
|
||||
|
||||
@@ -855,228 +844,3 @@ mod persist {
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
/// Tests for eth1 fallback
|
||||
mod fallbacks {
|
||||
use super::*;
|
||||
use tokio::time::sleep;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_fallback_when_offline() {
|
||||
async {
|
||||
let log = null_logger();
|
||||
let endpoint2 = new_ganache_instance()
|
||||
.await
|
||||
.expect("should start eth1 environment");
|
||||
let deposit_contract = &endpoint2.deposit_contract;
|
||||
|
||||
let initial_block_number = get_block_number(&endpoint2.web3()).await;
|
||||
|
||||
// Create some blocks and then consume them, performing the test `rounds` times.
|
||||
let new_blocks = 4;
|
||||
|
||||
for _ in 0..new_blocks {
|
||||
endpoint2
|
||||
.ganache
|
||||
.evm_mine()
|
||||
.await
|
||||
.expect("should mine block");
|
||||
}
|
||||
|
||||
let endpoint1 = endpoint2
|
||||
.ganache
|
||||
.fork()
|
||||
.expect("should start eth1 environment");
|
||||
|
||||
//mine additional blocks on top of the original endpoint
|
||||
for _ in 0..new_blocks {
|
||||
endpoint2
|
||||
.ganache
|
||||
.evm_mine()
|
||||
.await
|
||||
.expect("should mine block");
|
||||
}
|
||||
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoints: Eth1Endpoint::NoAuth(vec![
|
||||
SensitiveUrl::parse(endpoint1.endpoint().as_str()).unwrap(),
|
||||
SensitiveUrl::parse(endpoint2.endpoint().as_str()).unwrap(),
|
||||
]),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
lowest_cached_block_number: initial_block_number,
|
||||
follow_distance: 0,
|
||||
..Config::default()
|
||||
},
|
||||
log.clone(),
|
||||
MainnetEthSpec::default_spec(),
|
||||
);
|
||||
|
||||
let endpoint1_block_number = get_block_number(&endpoint1.web3).await;
|
||||
//the first call will only query endpoint1
|
||||
service.update().await.expect("should update deposit cache");
|
||||
assert_eq!(
|
||||
service.deposits().read().last_processed_block.unwrap(),
|
||||
endpoint1_block_number
|
||||
);
|
||||
|
||||
drop(endpoint1);
|
||||
|
||||
let endpoint2_block_number = get_block_number(&endpoint2.web3()).await;
|
||||
assert!(endpoint1_block_number < endpoint2_block_number);
|
||||
//endpoint1 is offline => query will import blocks from endpoint2
|
||||
service.update().await.expect("should update deposit cache");
|
||||
assert_eq!(
|
||||
service.deposits().read().last_processed_block.unwrap(),
|
||||
endpoint2_block_number
|
||||
);
|
||||
}
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_fallback_when_wrong_chain_id() {
|
||||
async {
|
||||
let log = null_logger();
|
||||
let correct_chain_id: u64 = DEFAULT_CHAIN_ID.into();
|
||||
let wrong_chain_id = correct_chain_id + 1;
|
||||
let endpoint1 = GanacheEth1Instance::new(wrong_chain_id)
|
||||
.await
|
||||
.expect("should start eth1 environment");
|
||||
let endpoint2 = new_ganache_instance()
|
||||
.await
|
||||
.expect("should start eth1 environment");
|
||||
let deposit_contract = &endpoint2.deposit_contract;
|
||||
|
||||
let initial_block_number = get_block_number(&endpoint2.web3()).await;
|
||||
|
||||
// Create some blocks and then consume them, performing the test `rounds` times.
|
||||
let new_blocks = 4;
|
||||
|
||||
for _ in 0..new_blocks {
|
||||
endpoint1
|
||||
.ganache
|
||||
.evm_mine()
|
||||
.await
|
||||
.expect("should mine block");
|
||||
endpoint2
|
||||
.ganache
|
||||
.evm_mine()
|
||||
.await
|
||||
.expect("should mine block");
|
||||
}
|
||||
|
||||
//additional blocks for endpoint1 to be able to distinguish
|
||||
for _ in 0..new_blocks {
|
||||
endpoint1
|
||||
.ganache
|
||||
.evm_mine()
|
||||
.await
|
||||
.expect("should mine block");
|
||||
}
|
||||
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoints: Eth1Endpoint::NoAuth(vec![
|
||||
SensitiveUrl::parse(endpoint2.endpoint().as_str()).unwrap(),
|
||||
SensitiveUrl::parse(endpoint1.endpoint().as_str()).unwrap(),
|
||||
]),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
lowest_cached_block_number: initial_block_number,
|
||||
follow_distance: 0,
|
||||
..Config::default()
|
||||
},
|
||||
log.clone(),
|
||||
MainnetEthSpec::default_spec(),
|
||||
);
|
||||
|
||||
let endpoint1_block_number = get_block_number(&endpoint1.web3()).await;
|
||||
let endpoint2_block_number = get_block_number(&endpoint2.web3()).await;
|
||||
assert!(endpoint2_block_number < endpoint1_block_number);
|
||||
//the call will fallback to endpoint2
|
||||
service.update().await.expect("should update deposit cache");
|
||||
assert_eq!(
|
||||
service.deposits().read().last_processed_block.unwrap(),
|
||||
endpoint2_block_number
|
||||
);
|
||||
}
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_fallback_when_node_far_behind() {
|
||||
async {
|
||||
let log = null_logger();
|
||||
let endpoint2 = new_ganache_instance()
|
||||
.await
|
||||
.expect("should start eth1 environment");
|
||||
let deposit_contract = &endpoint2.deposit_contract;
|
||||
|
||||
let initial_block_number = get_block_number(&endpoint2.web3()).await;
|
||||
|
||||
// Create some blocks and then consume them, performing the test `rounds` times.
|
||||
let new_blocks = 4;
|
||||
|
||||
for _ in 0..new_blocks {
|
||||
endpoint2
|
||||
.ganache
|
||||
.evm_mine()
|
||||
.await
|
||||
.expect("should mine block");
|
||||
}
|
||||
|
||||
let endpoint1 = endpoint2
|
||||
.ganache
|
||||
.fork()
|
||||
.expect("should start eth1 environment");
|
||||
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoints: Eth1Endpoint::NoAuth(vec![
|
||||
SensitiveUrl::parse(endpoint1.endpoint().as_str()).unwrap(),
|
||||
SensitiveUrl::parse(endpoint2.endpoint().as_str()).unwrap(),
|
||||
]),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
lowest_cached_block_number: initial_block_number,
|
||||
follow_distance: 0,
|
||||
node_far_behind_seconds: 5,
|
||||
..Config::default()
|
||||
},
|
||||
log.clone(),
|
||||
MainnetEthSpec::default_spec(),
|
||||
);
|
||||
|
||||
let endpoint1_block_number = get_block_number(&endpoint1.web3).await;
|
||||
//the first call will only query endpoint1
|
||||
service.update().await.expect("should update deposit cache");
|
||||
assert_eq!(
|
||||
service.deposits().read().last_processed_block.unwrap(),
|
||||
endpoint1_block_number
|
||||
);
|
||||
|
||||
sleep(Duration::from_secs(7)).await;
|
||||
|
||||
//both endpoints don't have recent blocks => should return error
|
||||
assert!(service.update().await.is_err());
|
||||
|
||||
//produce some new blocks on endpoint2
|
||||
for _ in 0..new_blocks {
|
||||
endpoint2
|
||||
.ganache
|
||||
.evm_mine()
|
||||
.await
|
||||
.expect("should mine block");
|
||||
}
|
||||
|
||||
let endpoint2_block_number = get_block_number(&endpoint2.web3()).await;
|
||||
|
||||
//endpoint1 is far behind + endpoint2 not => update will import blocks from endpoint2
|
||||
service.update().await.expect("should update deposit cache");
|
||||
assert_eq!(
|
||||
service.deposits().read().last_processed_block.unwrap(),
|
||||
endpoint2_block_number
|
||||
);
|
||||
}
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user