mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Merge branch 'eip4844' into deneb-free-blobs
This commit is contained in:
@@ -1,215 +0,0 @@
|
||||
use beacon_chain::{
|
||||
test_utils::{BeaconChainHarness, BoxedMutator, Builder, EphemeralHarnessType},
|
||||
BeaconChain, BeaconChainTypes,
|
||||
};
|
||||
use directory::DEFAULT_ROOT_DIR;
|
||||
use eth2::{BeaconNodeHttpClient, Timeouts};
|
||||
use http_api::{Config, Context};
|
||||
use lighthouse_network::{
|
||||
discv5::enr::{CombinedKey, EnrBuilder},
|
||||
libp2p::{
|
||||
core::connection::ConnectionId,
|
||||
swarm::{
|
||||
behaviour::{ConnectionEstablished, FromSwarm},
|
||||
NetworkBehaviour,
|
||||
},
|
||||
},
|
||||
rpc::methods::{MetaData, MetaDataV2},
|
||||
types::{EnrAttestationBitfield, EnrSyncCommitteeBitfield, SyncState},
|
||||
ConnectedPoint, Enr, NetworkGlobals, PeerId, PeerManager,
|
||||
};
|
||||
use logging::test_logger;
|
||||
use network::{NetworkReceivers, NetworkSenders};
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use slog::Logger;
|
||||
use std::future::Future;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use store::MemoryStore;
|
||||
use tokio::sync::oneshot;
|
||||
use types::{ChainSpec, EthSpec};
|
||||
|
||||
pub const TCP_PORT: u16 = 42;
|
||||
pub const UDP_PORT: u16 = 42;
|
||||
pub const SEQ_NUMBER: u64 = 0;
|
||||
pub const EXTERNAL_ADDR: &str = "/ip4/0.0.0.0/tcp/9000";
|
||||
|
||||
/// HTTP API tester that allows interaction with the underlying beacon chain harness.
|
||||
pub struct InteractiveTester<E: EthSpec> {
|
||||
pub harness: BeaconChainHarness<EphemeralHarnessType<E>>,
|
||||
pub client: BeaconNodeHttpClient,
|
||||
pub network_rx: NetworkReceivers<E>,
|
||||
_server_shutdown: oneshot::Sender<()>,
|
||||
}
|
||||
|
||||
/// The result of calling `create_api_server`.
|
||||
///
|
||||
/// Glue-type between `tests::ApiTester` and `InteractiveTester`.
|
||||
pub struct ApiServer<E: EthSpec, SFut: Future<Output = ()>> {
|
||||
pub server: SFut,
|
||||
pub listening_socket: SocketAddr,
|
||||
pub shutdown_tx: oneshot::Sender<()>,
|
||||
pub network_rx: NetworkReceivers<E>,
|
||||
pub local_enr: Enr,
|
||||
pub external_peer_id: PeerId,
|
||||
}
|
||||
|
||||
type HarnessBuilder<E> = Builder<EphemeralHarnessType<E>>;
|
||||
type Initializer<E> = Box<dyn FnOnce(HarnessBuilder<E>) -> HarnessBuilder<E>>;
|
||||
type Mutator<E> = BoxedMutator<E, MemoryStore<E>, MemoryStore<E>>;
|
||||
|
||||
impl<E: EthSpec> InteractiveTester<E> {
|
||||
pub async fn new(spec: Option<ChainSpec>, validator_count: usize) -> Self {
|
||||
Self::new_with_initializer_and_mutator(spec, validator_count, None, None).await
|
||||
}
|
||||
|
||||
pub async fn new_with_initializer_and_mutator(
|
||||
spec: Option<ChainSpec>,
|
||||
validator_count: usize,
|
||||
initializer: Option<Initializer<E>>,
|
||||
mutator: Option<Mutator<E>>,
|
||||
) -> Self {
|
||||
let mut harness_builder = BeaconChainHarness::builder(E::default())
|
||||
.spec_or_default(spec)
|
||||
.logger(test_logger())
|
||||
.mock_execution_layer();
|
||||
|
||||
harness_builder = if let Some(initializer) = initializer {
|
||||
// Apply custom initialization provided by the caller.
|
||||
initializer(harness_builder)
|
||||
} else {
|
||||
// Apply default initial configuration.
|
||||
harness_builder
|
||||
.deterministic_keypairs(validator_count)
|
||||
.fresh_ephemeral_store()
|
||||
};
|
||||
|
||||
// Add a mutator for the beacon chain builder which will be called in
|
||||
// `HarnessBuilder::build`.
|
||||
if let Some(mutator) = mutator {
|
||||
harness_builder = harness_builder.initial_mutator(mutator);
|
||||
}
|
||||
|
||||
let harness = harness_builder.build();
|
||||
|
||||
let ApiServer {
|
||||
server,
|
||||
listening_socket,
|
||||
shutdown_tx: _server_shutdown,
|
||||
network_rx,
|
||||
..
|
||||
} = create_api_server(harness.chain.clone(), harness.logger().clone()).await;
|
||||
|
||||
tokio::spawn(server);
|
||||
|
||||
let client = BeaconNodeHttpClient::new(
|
||||
SensitiveUrl::parse(&format!(
|
||||
"http://{}:{}",
|
||||
listening_socket.ip(),
|
||||
listening_socket.port()
|
||||
))
|
||||
.unwrap(),
|
||||
Timeouts::set_all(Duration::from_secs(1)),
|
||||
);
|
||||
|
||||
Self {
|
||||
harness,
|
||||
client,
|
||||
network_rx,
|
||||
_server_shutdown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_api_server<T: BeaconChainTypes>(
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
log: Logger,
|
||||
) -> ApiServer<T::EthSpec, impl Future<Output = ()>> {
|
||||
// Get a random unused port.
|
||||
let port = unused_port::unused_tcp4_port().unwrap();
|
||||
create_api_server_on_port(chain, log, port).await
|
||||
}
|
||||
|
||||
pub async fn create_api_server_on_port<T: BeaconChainTypes>(
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
log: Logger,
|
||||
port: u16,
|
||||
) -> ApiServer<T::EthSpec, impl Future<Output = ()>> {
|
||||
let (network_senders, network_receivers) = NetworkSenders::new();
|
||||
|
||||
// Default metadata
|
||||
let meta_data = MetaData::V2(MetaDataV2 {
|
||||
seq_number: SEQ_NUMBER,
|
||||
attnets: EnrAttestationBitfield::<T::EthSpec>::default(),
|
||||
syncnets: EnrSyncCommitteeBitfield::<T::EthSpec>::default(),
|
||||
});
|
||||
let enr_key = CombinedKey::generate_secp256k1();
|
||||
let enr = EnrBuilder::new("v4").build(&enr_key).unwrap();
|
||||
let network_globals = Arc::new(NetworkGlobals::new(
|
||||
enr.clone(),
|
||||
Some(TCP_PORT),
|
||||
None,
|
||||
meta_data,
|
||||
vec![],
|
||||
&log,
|
||||
));
|
||||
|
||||
// Only a peer manager can add peers, so we create a dummy manager.
|
||||
let config = lighthouse_network::peer_manager::config::Config::default();
|
||||
let mut pm = PeerManager::new(config, network_globals.clone(), &log).unwrap();
|
||||
|
||||
// add a peer
|
||||
let peer_id = PeerId::random();
|
||||
|
||||
let endpoint = &ConnectedPoint::Listener {
|
||||
local_addr: EXTERNAL_ADDR.parse().unwrap(),
|
||||
send_back_addr: EXTERNAL_ADDR.parse().unwrap(),
|
||||
};
|
||||
let connection_id = ConnectionId::new(1);
|
||||
pm.on_swarm_event(FromSwarm::ConnectionEstablished(ConnectionEstablished {
|
||||
peer_id,
|
||||
connection_id,
|
||||
endpoint,
|
||||
failed_addresses: &[],
|
||||
other_established: 0,
|
||||
}));
|
||||
*network_globals.sync_state.write() = SyncState::Synced;
|
||||
|
||||
let eth1_service =
|
||||
eth1::Service::new(eth1::Config::default(), log.clone(), chain.spec.clone()).unwrap();
|
||||
|
||||
let context = Arc::new(Context {
|
||||
config: Config {
|
||||
enabled: true,
|
||||
listen_addr: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
listen_port: port,
|
||||
allow_origin: None,
|
||||
tls_config: None,
|
||||
allow_sync_stalled: false,
|
||||
data_dir: std::path::PathBuf::from(DEFAULT_ROOT_DIR),
|
||||
spec_fork_name: None,
|
||||
},
|
||||
chain: Some(chain.clone()),
|
||||
network_senders: Some(network_senders),
|
||||
network_globals: Some(network_globals),
|
||||
eth1_service: Some(eth1_service),
|
||||
log,
|
||||
});
|
||||
let ctx = context.clone();
|
||||
let (shutdown_tx, shutdown_rx) = oneshot::channel();
|
||||
let server_shutdown = async {
|
||||
// It's not really interesting why this triggered, just that it happened.
|
||||
let _ = shutdown_rx.await;
|
||||
};
|
||||
let (listening_socket, server) = http_api::serve(ctx, server_shutdown).unwrap();
|
||||
|
||||
ApiServer {
|
||||
server,
|
||||
listening_socket,
|
||||
shutdown_tx,
|
||||
network_rx: network_receivers,
|
||||
local_enr: enr,
|
||||
external_peer_id: peer_id,
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
//! Tests for API behaviour across fork boundaries.
|
||||
use crate::common::*;
|
||||
use beacon_chain::{
|
||||
test_utils::{RelativeSyncCommittee, DEFAULT_ETH1_BLOCK_HASH, HARNESS_GENESIS_TIME},
|
||||
StateSkipConfig,
|
||||
};
|
||||
use eth2::types::{IndexedErrorMessage, StateId, SyncSubcommittee};
|
||||
use genesis::{bls_withdrawal_credentials, interop_genesis_state_with_withdrawal_credentials};
|
||||
use http_api::test_utils::*;
|
||||
use std::collections::HashSet;
|
||||
use types::{
|
||||
test_utils::{generate_deterministic_keypair, generate_deterministic_keypairs},
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//! Generic tests that make use of the (newer) `InteractiveApiTester`
|
||||
use crate::common::*;
|
||||
use beacon_chain::{
|
||||
chain_config::ReOrgThreshold,
|
||||
test_utils::{AttestationStrategy, BlockStrategy, SyncCommitteeStrategy},
|
||||
};
|
||||
use eth2::types::DepositContractData;
|
||||
use execution_layer::{ForkchoiceState, PayloadAttributes};
|
||||
use http_api::test_utils::InteractiveTester;
|
||||
use parking_lot::Mutex;
|
||||
use slot_clock::SlotClock;
|
||||
use state_processing::{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#![cfg(not(debug_assertions))] // Tests are too slow in debug.
|
||||
|
||||
pub mod common;
|
||||
pub mod fork_tests;
|
||||
pub mod interactive_tests;
|
||||
pub mod tests;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::common::{create_api_server, create_api_server_on_port, ApiServer};
|
||||
use beacon_chain::test_utils::RelativeSyncCommittee;
|
||||
use beacon_chain::{
|
||||
test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType},
|
||||
@@ -8,7 +7,7 @@ use environment::null_logger;
|
||||
use eth2::{
|
||||
mixin::{RequestAccept, ResponseForkName, ResponseOptional},
|
||||
reqwest::RequestBuilder,
|
||||
types::{BlockId as CoreBlockId, StateId as CoreStateId, *},
|
||||
types::{BlockId as CoreBlockId, ForkChoiceNode, StateId as CoreStateId, *},
|
||||
BeaconNodeHttpClient, Error, StatusCode, Timeouts,
|
||||
};
|
||||
use execution_layer::test_utils::TestingBuilder;
|
||||
@@ -18,7 +17,10 @@ use execution_layer::test_utils::{
|
||||
};
|
||||
use futures::stream::{Stream, StreamExt};
|
||||
use futures::FutureExt;
|
||||
use http_api::{BlockId, StateId};
|
||||
use http_api::{
|
||||
test_utils::{create_api_server, create_api_server_on_port, ApiServer},
|
||||
BlockId, StateId,
|
||||
};
|
||||
use lighthouse_network::{Enr, EnrExt, PeerId};
|
||||
use network::NetworkReceivers;
|
||||
use proto_array::ExecutionStatus;
|
||||
@@ -466,6 +468,264 @@ impl ApiTester {
|
||||
self
|
||||
}
|
||||
|
||||
// finalization tests
|
||||
pub async fn test_beacon_states_root_finalized(self) -> Self {
|
||||
for state_id in self.interesting_state_ids() {
|
||||
let state_root = state_id.root(&self.chain);
|
||||
let state = state_id.state(&self.chain);
|
||||
|
||||
// if .root or .state fail, skip the test. those would be errors outside the scope
|
||||
// of this test, here we're testing the finalized field assuming the call to .is_finalized_state
|
||||
// occurs after the state_root and state calls, and that the state_root and state calls
|
||||
// were correct.
|
||||
if state_root.is_err() || state.is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// now that we know the state is valid, we can unwrap() everything we need
|
||||
let result = self
|
||||
.client
|
||||
.get_beacon_states_root(state_id.0)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.finalized
|
||||
.unwrap();
|
||||
|
||||
let (state_root, _, _) = state_root.unwrap();
|
||||
let (state, _, _) = state.unwrap();
|
||||
let state_slot = state.slot();
|
||||
let expected = self
|
||||
.chain
|
||||
.is_finalized_state(&state_root, state_slot)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, expected, "{:?}", state_id);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_beacon_states_fork_finalized(self) -> Self {
|
||||
for state_id in self.interesting_state_ids() {
|
||||
let state_root = state_id.root(&self.chain);
|
||||
let state = state_id.state(&self.chain);
|
||||
|
||||
// if .root or .state fail, skip the test. those would be errors outside the scope
|
||||
// of this test, here we're testing the finalized field assuming the call to .is_finalized_state
|
||||
// occurs after the state_root and state calls, and that the state_root and state calls
|
||||
// were correct.
|
||||
if state_root.is_err() || state.is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// now that we know the state is valid, we can unwrap() everything we need
|
||||
let result = self
|
||||
.client
|
||||
.get_beacon_states_fork(state_id.0)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.finalized
|
||||
.unwrap();
|
||||
|
||||
let (state_root, _, _) = state_root.unwrap();
|
||||
let (state, _, _) = state.unwrap();
|
||||
let state_slot = state.slot();
|
||||
let expected = self
|
||||
.chain
|
||||
.is_finalized_state(&state_root, state_slot)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, expected, "{:?}", state_id);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_beacon_states_finality_checkpoints_finalized(self) -> Self {
|
||||
for state_id in self.interesting_state_ids() {
|
||||
let state_root = state_id.root(&self.chain);
|
||||
let state = state_id.state(&self.chain);
|
||||
|
||||
// if .root or .state fail, skip the test. those would be errors outside the scope
|
||||
// of this test, here we're testing the finalized field assuming the call to .is_finalized_state
|
||||
// occurs after the state_root and state calls, and that the state_root and state calls
|
||||
// were correct.
|
||||
if state_root.is_err() || state.is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// now that we know the state is valid, we can unwrap() everything we need
|
||||
let result = self
|
||||
.client
|
||||
.get_beacon_states_finality_checkpoints(state_id.0)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.finalized
|
||||
.unwrap();
|
||||
|
||||
let (state_root, _, _) = state_root.unwrap();
|
||||
let (state, _, _) = state.unwrap();
|
||||
let state_slot = state.slot();
|
||||
let expected = self
|
||||
.chain
|
||||
.is_finalized_state(&state_root, state_slot)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, expected, "{:?}", state_id);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_beacon_headers_block_id_finalized(self) -> Self {
|
||||
for block_id in self.interesting_block_ids() {
|
||||
let block_root = block_id.root(&self.chain);
|
||||
let block = block_id.full_block(&self.chain).await;
|
||||
|
||||
// if .root or .state fail, skip the test. those would be errors outside the scope
|
||||
// of this test, here we're testing the finalized field assuming the call to .is_finalized_state
|
||||
// occurs after the state_root and state calls, and that the state_root and state calls
|
||||
// were correct.
|
||||
if block_root.is_err() || block.is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// now that we know the block is valid, we can unwrap() everything we need
|
||||
let result = self
|
||||
.client
|
||||
.get_beacon_headers_block_id(block_id.0)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.finalized
|
||||
.unwrap();
|
||||
|
||||
let (block_root, _, _) = block_root.unwrap();
|
||||
let (block, _, _) = block.unwrap();
|
||||
let block_slot = block.slot();
|
||||
let expected = self
|
||||
.chain
|
||||
.is_finalized_block(&block_root, block_slot)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, expected, "{:?}", block_id);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_beacon_blocks_finalized<T: EthSpec>(self) -> Self {
|
||||
for block_id in self.interesting_block_ids() {
|
||||
let block_root = block_id.root(&self.chain);
|
||||
let block = block_id.full_block(&self.chain).await;
|
||||
|
||||
// if .root or .full_block fail, skip the test. those would be errors outside the scope
|
||||
// of this test, here we're testing the finalized field assuming the call to .is_finalized_block
|
||||
// occurs after those calls, and that they were correct.
|
||||
if block_root.is_err() || block.is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// now that we know the block is valid, we can unwrap() everything we need
|
||||
let result = self
|
||||
.client
|
||||
.get_beacon_blocks::<MainnetEthSpec>(block_id.0)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.finalized
|
||||
.unwrap();
|
||||
|
||||
let (block_root, _, _) = block_root.unwrap();
|
||||
let (block, _, _) = block.unwrap();
|
||||
let block_slot = block.slot();
|
||||
let expected = self
|
||||
.chain
|
||||
.is_finalized_block(&block_root, block_slot)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, expected, "{:?}", block_id);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_beacon_blinded_blocks_finalized<T: EthSpec>(self) -> Self {
|
||||
for block_id in self.interesting_block_ids() {
|
||||
let block_root = block_id.root(&self.chain);
|
||||
let block = block_id.full_block(&self.chain).await;
|
||||
|
||||
// if .root or .full_block fail, skip the test. those would be errors outside the scope
|
||||
// of this test, here we're testing the finalized field assuming the call to .is_finalized_block
|
||||
// occurs after those calls, and that they were correct.
|
||||
if block_root.is_err() || block.is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// now that we know the block is valid, we can unwrap() everything we need
|
||||
let result = self
|
||||
.client
|
||||
.get_beacon_blinded_blocks::<MainnetEthSpec>(block_id.0)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.finalized
|
||||
.unwrap();
|
||||
|
||||
let (block_root, _, _) = block_root.unwrap();
|
||||
let (block, _, _) = block.unwrap();
|
||||
let block_slot = block.slot();
|
||||
let expected = self
|
||||
.chain
|
||||
.is_finalized_block(&block_root, block_slot)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, expected, "{:?}", block_id);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_debug_beacon_states_finalized(self) -> Self {
|
||||
for state_id in self.interesting_state_ids() {
|
||||
let state_root = state_id.root(&self.chain);
|
||||
let state = state_id.state(&self.chain);
|
||||
|
||||
// if .root or .state fail, skip the test. those would be errors outside the scope
|
||||
// of this test, here we're testing the finalized field assuming the call to .is_finalized_state
|
||||
// occurs after the state_root and state calls, and that the state_root and state calls
|
||||
// were correct.
|
||||
if state_root.is_err() || state.is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// now that we know the state is valid, we can unwrap() everything we need
|
||||
let result = self
|
||||
.client
|
||||
.get_debug_beacon_states::<MainnetEthSpec>(state_id.0)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.finalized
|
||||
.unwrap();
|
||||
|
||||
let (state_root, _, _) = state_root.unwrap();
|
||||
let (state, _, _) = state.unwrap();
|
||||
let state_slot = state.slot();
|
||||
let expected = self
|
||||
.chain
|
||||
.is_finalized_state(&state_root, state_slot)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(result, expected, "{:?}", state_id);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_beacon_states_root(self) -> Self {
|
||||
for state_id in self.interesting_state_ids() {
|
||||
let result = self
|
||||
@@ -478,7 +738,7 @@ impl ApiTester {
|
||||
let expected = state_id
|
||||
.root(&self.chain)
|
||||
.ok()
|
||||
.map(|(root, _execution_optimistic)| root);
|
||||
.map(|(root, _execution_optimistic, _finalized)| root);
|
||||
|
||||
assert_eq!(result, expected, "{:?}", state_id);
|
||||
}
|
||||
@@ -512,15 +772,13 @@ impl ApiTester {
|
||||
.unwrap()
|
||||
.map(|res| res.data);
|
||||
|
||||
let expected =
|
||||
state_id
|
||||
.state(&self.chain)
|
||||
.ok()
|
||||
.map(|(state, _execution_optimistic)| FinalityCheckpointsData {
|
||||
previous_justified: state.previous_justified_checkpoint(),
|
||||
current_justified: state.current_justified_checkpoint(),
|
||||
finalized: state.finalized_checkpoint(),
|
||||
});
|
||||
let expected = state_id.state(&self.chain).ok().map(
|
||||
|(state, _execution_optimistic, _finalized)| FinalityCheckpointsData {
|
||||
previous_justified: state.previous_justified_checkpoint(),
|
||||
current_justified: state.current_justified_checkpoint(),
|
||||
finalized: state.finalized_checkpoint(),
|
||||
},
|
||||
);
|
||||
|
||||
assert_eq!(result, expected, "{:?}", state_id);
|
||||
}
|
||||
@@ -533,7 +791,9 @@ impl ApiTester {
|
||||
for validator_indices in self.interesting_validator_indices() {
|
||||
let state_opt = state_id.state(&self.chain).ok();
|
||||
let validators: Vec<Validator> = match state_opt.as_ref() {
|
||||
Some((state, _execution_optimistic)) => state.validators().clone().into(),
|
||||
Some((state, _execution_optimistic, _finalized)) => {
|
||||
state.validators().clone().into()
|
||||
}
|
||||
None => vec![],
|
||||
};
|
||||
let validator_index_ids = validator_indices
|
||||
@@ -572,7 +832,7 @@ impl ApiTester {
|
||||
.unwrap()
|
||||
.map(|res| res.data);
|
||||
|
||||
let expected = state_opt.map(|(state, _execution_optimistic)| {
|
||||
let expected = state_opt.map(|(state, _execution_optimistic, _finalized)| {
|
||||
let mut validators = Vec::with_capacity(validator_indices.len());
|
||||
|
||||
for i in validator_indices {
|
||||
@@ -602,7 +862,7 @@ impl ApiTester {
|
||||
let state_opt = state_id
|
||||
.state(&self.chain)
|
||||
.ok()
|
||||
.map(|(state, _execution_optimistic)| state);
|
||||
.map(|(state, _execution_optimistic, _finalized)| state);
|
||||
let validators: Vec<Validator> = match state_opt.as_ref() {
|
||||
Some(state) => state.validators().clone().into(),
|
||||
None => vec![],
|
||||
@@ -692,7 +952,7 @@ impl ApiTester {
|
||||
let state_opt = state_id
|
||||
.state(&self.chain)
|
||||
.ok()
|
||||
.map(|(state, _execution_optimistic)| state);
|
||||
.map(|(state, _execution_optimistic, _finalized)| state);
|
||||
let validators = match state_opt.as_ref() {
|
||||
Some(state) => state.validators().clone().into(),
|
||||
None => vec![],
|
||||
@@ -747,7 +1007,7 @@ impl ApiTester {
|
||||
let mut state_opt = state_id
|
||||
.state(&self.chain)
|
||||
.ok()
|
||||
.map(|(state, _execution_optimistic)| state);
|
||||
.map(|(state, _execution_optimistic, _finalized)| state);
|
||||
|
||||
let epoch_opt = state_opt.as_ref().map(|state| state.current_epoch());
|
||||
let results = self
|
||||
@@ -794,7 +1054,7 @@ impl ApiTester {
|
||||
let mut state_opt = state_id
|
||||
.state(&self.chain)
|
||||
.ok()
|
||||
.map(|(state, _execution_optimistic)| state);
|
||||
.map(|(state, _execution_optimistic, _finalized)| state);
|
||||
|
||||
let epoch_opt = state_opt.as_ref().map(|state| state.current_epoch());
|
||||
let result = self
|
||||
@@ -904,7 +1164,7 @@ impl ApiTester {
|
||||
let block_root_opt = block_id
|
||||
.root(&self.chain)
|
||||
.ok()
|
||||
.map(|(root, _execution_optimistic)| root);
|
||||
.map(|(root, _execution_optimistic, _finalized)| root);
|
||||
|
||||
if let CoreBlockId::Slot(slot) = block_id.0 {
|
||||
if block_root_opt.is_none() {
|
||||
@@ -918,7 +1178,7 @@ impl ApiTester {
|
||||
.full_block(&self.chain)
|
||||
.await
|
||||
.ok()
|
||||
.map(|(block, _execution_optimistic)| block);
|
||||
.map(|(block, _execution_optimistic, _finalized)| block);
|
||||
|
||||
if block_opt.is_none() && result.is_none() {
|
||||
continue;
|
||||
@@ -964,7 +1224,7 @@ impl ApiTester {
|
||||
let expected = block_id
|
||||
.root(&self.chain)
|
||||
.ok()
|
||||
.map(|(root, _execution_optimistic)| root);
|
||||
.map(|(root, _execution_optimistic, _finalized)| root);
|
||||
if let CoreBlockId::Slot(slot) = block_id.0 {
|
||||
if expected.is_none() {
|
||||
assert!(SKIPPED_SLOTS.contains(&slot.as_u64()));
|
||||
@@ -1015,7 +1275,7 @@ impl ApiTester {
|
||||
.full_block(&self.chain)
|
||||
.await
|
||||
.ok()
|
||||
.map(|(block, _execution_optimistic)| block);
|
||||
.map(|(block, _execution_optimistic, _finalized)| block);
|
||||
|
||||
if let CoreBlockId::Slot(slot) = block_id.0 {
|
||||
if expected.is_none() {
|
||||
@@ -1099,7 +1359,7 @@ impl ApiTester {
|
||||
let expected = block_id
|
||||
.blinded_block(&self.chain)
|
||||
.ok()
|
||||
.map(|(block, _execution_optimistic)| block);
|
||||
.map(|(block, _execution_optimistic, _finalized)| block);
|
||||
|
||||
if let CoreBlockId::Slot(slot) = block_id.0 {
|
||||
if expected.is_none() {
|
||||
@@ -1180,7 +1440,7 @@ impl ApiTester {
|
||||
.map(|res| res.data);
|
||||
|
||||
let expected = block_id.full_block(&self.chain).await.ok().map(
|
||||
|(block, _execution_optimistic)| {
|
||||
|(block, _execution_optimistic, _finalized)| {
|
||||
block.message().body().attestations().clone().into()
|
||||
},
|
||||
);
|
||||
@@ -1601,7 +1861,7 @@ impl ApiTester {
|
||||
let mut expected = state_id
|
||||
.state(&self.chain)
|
||||
.ok()
|
||||
.map(|(state, _execution_optimistic)| state);
|
||||
.map(|(state, _execution_optimistic, _finalized)| state);
|
||||
expected.as_mut().map(|state| state.drop_all_caches());
|
||||
|
||||
if let (Some(json), Some(expected)) = (&result_json, &expected) {
|
||||
@@ -1687,6 +1947,59 @@ impl ApiTester {
|
||||
self
|
||||
}
|
||||
|
||||
pub async fn test_get_debug_fork_choice(self) -> Self {
|
||||
let result = self.client.get_debug_fork_choice().await.unwrap();
|
||||
|
||||
let beacon_fork_choice = self.chain.canonical_head.fork_choice_read_lock();
|
||||
|
||||
let expected_proto_array = beacon_fork_choice.proto_array().core_proto_array();
|
||||
|
||||
assert_eq!(
|
||||
result.justified_checkpoint,
|
||||
expected_proto_array.justified_checkpoint
|
||||
);
|
||||
assert_eq!(
|
||||
result.finalized_checkpoint,
|
||||
expected_proto_array.finalized_checkpoint
|
||||
);
|
||||
|
||||
let expected_fork_choice_nodes: Vec<ForkChoiceNode> = expected_proto_array
|
||||
.nodes
|
||||
.iter()
|
||||
.map(|node| {
|
||||
let execution_status = if node.execution_status.is_execution_enabled() {
|
||||
Some(node.execution_status.to_string())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
ForkChoiceNode {
|
||||
slot: node.slot,
|
||||
block_root: node.root,
|
||||
parent_root: node
|
||||
.parent
|
||||
.and_then(|index| expected_proto_array.nodes.get(index))
|
||||
.map(|parent| parent.root),
|
||||
justified_epoch: node.justified_checkpoint.map(|checkpoint| checkpoint.epoch),
|
||||
finalized_epoch: node.finalized_checkpoint.map(|checkpoint| checkpoint.epoch),
|
||||
weight: node.weight,
|
||||
validity: execution_status,
|
||||
execution_block_hash: node
|
||||
.execution_status
|
||||
.block_hash()
|
||||
.map(|block_hash| block_hash.into_root()),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
assert_eq!(result.fork_choice_nodes, expected_fork_choice_nodes);
|
||||
|
||||
// need to drop beacon_fork_choice here, else borrow checker will complain
|
||||
// that self cannot be moved out since beacon_fork_choice borrowed self.chain
|
||||
// and might still live after self is moved out
|
||||
drop(beacon_fork_choice);
|
||||
self
|
||||
}
|
||||
|
||||
fn validator_count(&self) -> usize {
|
||||
self.chain.head_snapshot().beacon_state.validators().len()
|
||||
}
|
||||
@@ -3620,7 +3933,7 @@ impl ApiTester {
|
||||
let mut expected = state_id
|
||||
.state(&self.chain)
|
||||
.ok()
|
||||
.map(|(state, _execution_optimistic)| state);
|
||||
.map(|(state, _execution_optimistic, _finalized)| state);
|
||||
expected.as_mut().map(|state| state.drop_all_caches());
|
||||
|
||||
assert_eq!(result, expected, "{:?}", state_id);
|
||||
@@ -4032,6 +4345,20 @@ async fn beacon_get() {
|
||||
.await
|
||||
.test_beacon_genesis()
|
||||
.await
|
||||
.test_beacon_states_root_finalized()
|
||||
.await
|
||||
.test_beacon_states_fork_finalized()
|
||||
.await
|
||||
.test_beacon_states_finality_checkpoints_finalized()
|
||||
.await
|
||||
.test_beacon_headers_block_id_finalized()
|
||||
.await
|
||||
.test_beacon_blocks_finalized::<MainnetEthSpec>()
|
||||
.await
|
||||
.test_beacon_blinded_blocks_finalized::<MainnetEthSpec>()
|
||||
.await
|
||||
.test_debug_beacon_states_finalized()
|
||||
.await
|
||||
.test_beacon_states_root()
|
||||
.await
|
||||
.test_beacon_states_fork()
|
||||
@@ -4168,6 +4495,8 @@ async fn debug_get() {
|
||||
.test_get_debug_beacon_states()
|
||||
.await
|
||||
.test_get_debug_beacon_heads()
|
||||
.await
|
||||
.test_get_debug_fork_choice()
|
||||
.await;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user