mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 06:44:35 +00:00
Improve single-node testnet support and Arc NetworkConfig/ChainSpec (#6396)
* Arc ChainSpec and NetworkConfig * Fix release tests * Fix lint * Merge remote-tracking branch 'origin/unstable' into single-node-testnet
This commit is contained in:
@@ -9,6 +9,7 @@ use parking_lot::RwLock;
|
||||
use ssz::four_byte_option_impl;
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::sync::Arc;
|
||||
use superstruct::superstruct;
|
||||
use types::{ChainSpec, DepositTreeSnapshot, Eth1Data};
|
||||
|
||||
@@ -51,7 +52,7 @@ pub struct Inner {
|
||||
pub to_finalize: RwLock<Option<Eth1Data>>,
|
||||
pub config: RwLock<Config>,
|
||||
pub remote_head_block: RwLock<Option<Eth1Block>>,
|
||||
pub spec: ChainSpec,
|
||||
pub spec: Arc<ChainSpec>,
|
||||
}
|
||||
|
||||
impl Inner {
|
||||
@@ -71,7 +72,7 @@ impl Inner {
|
||||
}
|
||||
|
||||
/// Recover `Inner` given byte representation of eth1 deposit and block caches.
|
||||
pub fn from_bytes(bytes: &[u8], config: Config, spec: ChainSpec) -> Result<Self, String> {
|
||||
pub fn from_bytes(bytes: &[u8], config: Config, spec: Arc<ChainSpec>) -> Result<Self, String> {
|
||||
SszEth1Cache::from_ssz_bytes(bytes)
|
||||
.map_err(|e| format!("Ssz decoding error: {:?}", e))?
|
||||
.to_inner(config, spec)
|
||||
@@ -109,7 +110,7 @@ impl SszEth1Cache {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_inner(&self, config: Config, spec: ChainSpec) -> Result<Inner, String> {
|
||||
pub fn to_inner(&self, config: Config, spec: Arc<ChainSpec>) -> Result<Inner, String> {
|
||||
Ok(Inner {
|
||||
block_cache: RwLock::new(self.block_cache.clone()),
|
||||
deposit_cache: RwLock::new(DepositUpdater {
|
||||
|
||||
@@ -397,7 +397,7 @@ pub struct Service {
|
||||
|
||||
impl Service {
|
||||
/// Creates a new service. Does not attempt to connect to the eth1 node.
|
||||
pub fn new(config: Config, log: Logger, spec: ChainSpec) -> Result<Self, String> {
|
||||
pub fn new(config: Config, log: Logger, spec: Arc<ChainSpec>) -> Result<Self, String> {
|
||||
Ok(Self {
|
||||
inner: Arc::new(Inner {
|
||||
block_cache: <_>::default(),
|
||||
@@ -414,6 +414,10 @@ impl Service {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn chain_spec(&self) -> &Arc<ChainSpec> {
|
||||
&self.inner.spec
|
||||
}
|
||||
|
||||
pub fn client(&self) -> &HttpJsonRpc {
|
||||
&self.inner.endpoint
|
||||
}
|
||||
@@ -422,7 +426,7 @@ impl Service {
|
||||
pub fn from_deposit_snapshot(
|
||||
config: Config,
|
||||
log: Logger,
|
||||
spec: ChainSpec,
|
||||
spec: Arc<ChainSpec>,
|
||||
deposit_snapshot: &DepositTreeSnapshot,
|
||||
) -> Result<Self, Error> {
|
||||
let deposit_cache =
|
||||
@@ -464,7 +468,7 @@ impl Service {
|
||||
bytes: &[u8],
|
||||
config: Config,
|
||||
log: Logger,
|
||||
spec: ChainSpec,
|
||||
spec: Arc<ChainSpec>,
|
||||
) -> Result<Self, String> {
|
||||
let inner = Inner::from_bytes(bytes, config, spec)?;
|
||||
Ok(Self {
|
||||
|
||||
@@ -8,6 +8,7 @@ use logging::test_logger;
|
||||
use merkle_proof::verify_merkle_proof;
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tree_hash::TreeHash;
|
||||
use types::{
|
||||
@@ -122,8 +123,12 @@ mod eth1_cache {
|
||||
};
|
||||
let cache_follow_distance = config.cache_follow_distance();
|
||||
|
||||
let service =
|
||||
Service::new(config, log.clone(), MainnetEthSpec::default_spec()).unwrap();
|
||||
let service = Service::new(
|
||||
config,
|
||||
log.clone(),
|
||||
Arc::new(MainnetEthSpec::default_spec()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Create some blocks and then consume them, performing the test `rounds` times.
|
||||
for round in 0..2 {
|
||||
@@ -204,7 +209,7 @@ mod eth1_cache {
|
||||
..Config::default()
|
||||
},
|
||||
log,
|
||||
MainnetEthSpec::default_spec(),
|
||||
Arc::new(MainnetEthSpec::default_spec()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -259,7 +264,7 @@ mod eth1_cache {
|
||||
..Config::default()
|
||||
},
|
||||
log,
|
||||
MainnetEthSpec::default_spec(),
|
||||
Arc::new(MainnetEthSpec::default_spec()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -310,7 +315,7 @@ mod eth1_cache {
|
||||
..Config::default()
|
||||
},
|
||||
log,
|
||||
MainnetEthSpec::default_spec(),
|
||||
Arc::new(MainnetEthSpec::default_spec()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -365,7 +370,7 @@ mod deposit_tree {
|
||||
..Config::default()
|
||||
},
|
||||
log,
|
||||
MainnetEthSpec::default_spec(),
|
||||
Arc::new(MainnetEthSpec::default_spec()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -447,7 +452,7 @@ mod deposit_tree {
|
||||
..Config::default()
|
||||
},
|
||||
log,
|
||||
MainnetEthSpec::default_spec(),
|
||||
Arc::new(MainnetEthSpec::default_spec()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -694,7 +699,7 @@ mod fast {
|
||||
let anvil_client = eth1.json_rpc_client();
|
||||
|
||||
let now = get_block_number(&anvil_client).await;
|
||||
let spec = MainnetEthSpec::default_spec();
|
||||
let spec = Arc::new(MainnetEthSpec::default_spec());
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoint: Eth1Endpoint::NoAuth(
|
||||
@@ -788,8 +793,12 @@ mod persist {
|
||||
block_cache_truncation: None,
|
||||
..Config::default()
|
||||
};
|
||||
let service =
|
||||
Service::new(config.clone(), log.clone(), MainnetEthSpec::default_spec()).unwrap();
|
||||
let service = Service::new(
|
||||
config.clone(),
|
||||
log.clone(),
|
||||
Arc::new(MainnetEthSpec::default_spec()),
|
||||
)
|
||||
.unwrap();
|
||||
let n = 10;
|
||||
let deposits: Vec<_> = (0..n).map(|_| random_deposit_data()).collect();
|
||||
for deposit in &deposits {
|
||||
@@ -828,9 +837,13 @@ mod persist {
|
||||
// Drop service and recover from bytes
|
||||
drop(service);
|
||||
|
||||
let recovered_service =
|
||||
Service::from_bytes(ð1_bytes, config, log, MainnetEthSpec::default_spec())
|
||||
.unwrap();
|
||||
let recovered_service = Service::from_bytes(
|
||||
ð1_bytes,
|
||||
config,
|
||||
log,
|
||||
Arc::new(MainnetEthSpec::default_spec()),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
recovered_service.block_cache_len(),
|
||||
block_count,
|
||||
|
||||
Reference in New Issue
Block a user