mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-03 12:54:27 +00:00
Merge remote-tracking branch 'sigp/unstable' into validator-custody-cgc-mutex
This commit is contained in:
@@ -54,7 +54,7 @@ use eth2::types::{
|
||||
use eth2::{CONSENSUS_VERSION_HEADER, CONTENT_TYPE_HEADER, SSZ_CONTENT_TYPE_HEADER};
|
||||
use health_metrics::observe::Observe;
|
||||
use lighthouse_network::rpc::methods::MetaData;
|
||||
use lighthouse_network::{types::SyncState, EnrExt, NetworkGlobals, PeerId, PubsubMessage};
|
||||
use lighthouse_network::{types::SyncState, Enr, EnrExt, NetworkGlobals, PeerId, PubsubMessage};
|
||||
use lighthouse_version::version_with_platform;
|
||||
use logging::{crit, SSELoggingComponents};
|
||||
use network::{NetworkMessage, NetworkSenders, ValidatorSubscriptionMessage};
|
||||
@@ -68,10 +68,12 @@ use serde_json::Value;
|
||||
use slot_clock::SlotClock;
|
||||
use ssz::Encode;
|
||||
pub use state_id::StateId;
|
||||
use std::collections::HashSet;
|
||||
use std::future::Future;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::path::PathBuf;
|
||||
use std::pin::Pin;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use sysinfo::{System, SystemExt};
|
||||
use system_health::{observe_nat, observe_system_health_bn};
|
||||
@@ -1144,6 +1146,39 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
},
|
||||
);
|
||||
|
||||
// GET beacon/states/{state_id}/pending_consolidations
|
||||
let get_beacon_state_pending_consolidations = beacon_states_path
|
||||
.clone()
|
||||
.and(warp::path("pending_consolidations"))
|
||||
.and(warp::path::end())
|
||||
.then(
|
||||
|state_id: StateId,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>| {
|
||||
task_spawner.blocking_json_task(Priority::P1, move || {
|
||||
let (data, execution_optimistic, finalized) = state_id
|
||||
.map_state_and_execution_optimistic_and_finalized(
|
||||
&chain,
|
||||
|state, execution_optimistic, finalized| {
|
||||
let Ok(consolidations) = state.pending_consolidations() else {
|
||||
return Err(warp_utils::reject::custom_bad_request(
|
||||
"Pending consolidations not found".to_string(),
|
||||
));
|
||||
};
|
||||
|
||||
Ok((consolidations.clone(), execution_optimistic, finalized))
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(api_types::ExecutionOptimisticFinalizedResponse {
|
||||
data,
|
||||
execution_optimistic: Some(execution_optimistic),
|
||||
finalized: Some(finalized),
|
||||
})
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
// GET beacon/headers
|
||||
//
|
||||
// Note: this endpoint only returns information about blocks in the canonical chain. Given that
|
||||
@@ -1926,11 +1961,11 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
query: api_types::AttestationPoolQuery| {
|
||||
task_spawner.blocking_response_task(Priority::P1, move || {
|
||||
let query_filter = |data: &AttestationData| {
|
||||
let query_filter = |data: &AttestationData, committee_indices: HashSet<u64>| {
|
||||
query.slot.is_none_or(|slot| slot == data.slot)
|
||||
&& query
|
||||
.committee_index
|
||||
.is_none_or(|index| index == data.index)
|
||||
.is_none_or(|index| committee_indices.contains(&index))
|
||||
};
|
||||
|
||||
let mut attestations = chain.op_pool.get_filtered_attestations(query_filter);
|
||||
@@ -1939,7 +1974,9 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.naive_aggregation_pool
|
||||
.read()
|
||||
.iter()
|
||||
.filter(|&att| query_filter(att.data()))
|
||||
.filter(|&att| {
|
||||
query_filter(att.data(), att.get_committee_indices_map())
|
||||
})
|
||||
.cloned(),
|
||||
);
|
||||
// Use the current slot to find the fork version, and convert all messages to the
|
||||
@@ -3581,7 +3618,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.and(task_spawner_filter.clone())
|
||||
.and(chain_filter.clone())
|
||||
.and(warp_utils::json::json())
|
||||
.and(network_tx_filter)
|
||||
.and(network_tx_filter.clone())
|
||||
.then(
|
||||
|not_synced_filter: Result<(), Rejection>,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
@@ -4009,6 +4046,71 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
},
|
||||
);
|
||||
|
||||
// POST lighthouse/add_peer
|
||||
let post_lighthouse_add_peer = warp::path("lighthouse")
|
||||
.and(warp::path("add_peer"))
|
||||
.and(warp::path::end())
|
||||
.and(warp_utils::json::json())
|
||||
.and(task_spawner_filter.clone())
|
||||
.and(network_globals.clone())
|
||||
.and(network_tx_filter.clone())
|
||||
.then(
|
||||
|request_data: api_types::AdminPeer,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
network_globals: Arc<NetworkGlobals<T::EthSpec>>,
|
||||
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>| {
|
||||
task_spawner.blocking_json_task(Priority::P0, move || {
|
||||
let enr = Enr::from_str(&request_data.enr).map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!("invalid enr error {}", e))
|
||||
})?;
|
||||
info!(
|
||||
peer_id = %enr.peer_id(),
|
||||
multiaddr = ?enr.multiaddr(),
|
||||
"Adding trusted peer"
|
||||
);
|
||||
network_globals.add_trusted_peer(enr.clone());
|
||||
|
||||
publish_network_message(&network_tx, NetworkMessage::ConnectTrustedPeer(enr))?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
// POST lighthouse/remove_peer
|
||||
let post_lighthouse_remove_peer = warp::path("lighthouse")
|
||||
.and(warp::path("remove_peer"))
|
||||
.and(warp::path::end())
|
||||
.and(warp_utils::json::json())
|
||||
.and(task_spawner_filter.clone())
|
||||
.and(network_globals.clone())
|
||||
.and(network_tx_filter.clone())
|
||||
.then(
|
||||
|request_data: api_types::AdminPeer,
|
||||
task_spawner: TaskSpawner<T::EthSpec>,
|
||||
network_globals: Arc<NetworkGlobals<T::EthSpec>>,
|
||||
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>| {
|
||||
task_spawner.blocking_json_task(Priority::P0, move || {
|
||||
let enr = Enr::from_str(&request_data.enr).map_err(|e| {
|
||||
warp_utils::reject::custom_bad_request(format!("invalid enr error {}", e))
|
||||
})?;
|
||||
info!(
|
||||
peer_id = %enr.peer_id(),
|
||||
multiaddr = ?enr.multiaddr(),
|
||||
"Removing trusted peer"
|
||||
);
|
||||
network_globals.remove_trusted_peer(enr.clone());
|
||||
|
||||
publish_network_message(
|
||||
&network_tx,
|
||||
NetworkMessage::DisconnectTrustedPeer(enr),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
// POST lighthouse/liveness
|
||||
let post_lighthouse_liveness = warp::path("lighthouse")
|
||||
.and(warp::path("liveness"))
|
||||
@@ -4665,6 +4767,7 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.uor(get_beacon_state_randao)
|
||||
.uor(get_beacon_state_pending_deposits)
|
||||
.uor(get_beacon_state_pending_partial_withdrawals)
|
||||
.uor(get_beacon_state_pending_consolidations)
|
||||
.uor(get_beacon_headers)
|
||||
.uor(get_beacon_headers_block_id)
|
||||
.uor(get_beacon_block)
|
||||
@@ -4768,6 +4871,8 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.uor(post_lighthouse_ui_validator_info)
|
||||
.uor(post_lighthouse_finalize)
|
||||
.uor(post_lighthouse_compaction)
|
||||
.uor(post_lighthouse_add_peer)
|
||||
.uor(post_lighthouse_remove_peer)
|
||||
.recover(warp_utils::reject::handle_rejection),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::version::{
|
||||
use beacon_chain::{BeaconChain, BeaconChainError, BeaconChainTypes};
|
||||
use eth2::types::{
|
||||
self as api_types, ChainSpec, ForkVersionedResponse, LightClientUpdate,
|
||||
LightClientUpdateResponseChunk, LightClientUpdateSszResponse, LightClientUpdatesQuery,
|
||||
LightClientUpdateResponseChunk, LightClientUpdateResponseChunkInner, LightClientUpdatesQuery,
|
||||
};
|
||||
use ssz::Encode;
|
||||
use std::sync::Arc;
|
||||
@@ -37,15 +37,9 @@ pub fn get_light_client_updates<T: BeaconChainTypes>(
|
||||
.map(|update| map_light_client_update_to_ssz_chunk::<T>(&chain, update))
|
||||
.collect::<Vec<LightClientUpdateResponseChunk>>();
|
||||
|
||||
let ssz_response = LightClientUpdateSszResponse {
|
||||
response_chunk_len: (light_client_updates.len() as u64).to_le_bytes().to_vec(),
|
||||
response_chunk: response_chunks.as_ssz_bytes(),
|
||||
}
|
||||
.as_ssz_bytes();
|
||||
|
||||
Response::builder()
|
||||
.status(200)
|
||||
.body(ssz_response)
|
||||
.body(response_chunks.as_ssz_bytes())
|
||||
.map(|res: Response<Vec<u8>>| add_ssz_content_type_header(res))
|
||||
.map_err(|e| {
|
||||
warp_utils::reject::custom_server_error(format!(
|
||||
@@ -159,16 +153,24 @@ fn map_light_client_update_to_ssz_chunk<T: BeaconChainTypes>(
|
||||
) -> LightClientUpdateResponseChunk {
|
||||
let fork_name = chain
|
||||
.spec
|
||||
.fork_name_at_slot::<T::EthSpec>(*light_client_update.signature_slot());
|
||||
.fork_name_at_slot::<T::EthSpec>(light_client_update.attested_header_slot());
|
||||
|
||||
let fork_digest = ChainSpec::compute_fork_digest(
|
||||
chain.spec.fork_version_for_name(fork_name),
|
||||
chain.genesis_validators_root,
|
||||
);
|
||||
|
||||
LightClientUpdateResponseChunk {
|
||||
let payload = light_client_update.as_ssz_bytes();
|
||||
let response_chunk_len = fork_digest.len() + payload.len();
|
||||
|
||||
let response_chunk = LightClientUpdateResponseChunkInner {
|
||||
context: fork_digest,
|
||||
payload: light_client_update.as_ssz_bytes(),
|
||||
payload,
|
||||
};
|
||||
|
||||
LightClientUpdateResponseChunk {
|
||||
response_chunk_len: response_chunk_len as u64,
|
||||
response_chunk,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -366,7 +366,7 @@ fn spawn_build_data_sidecar_task<T: BeaconChainTypes>(
|
||||
} else {
|
||||
// Post PeerDAS: construct data columns.
|
||||
let gossip_verified_data_columns =
|
||||
build_gossip_verified_data_columns(&chain, &block, blobs)?;
|
||||
build_gossip_verified_data_columns(&chain, &block, blobs, kzg_proofs)?;
|
||||
Ok((vec![], gossip_verified_data_columns))
|
||||
}
|
||||
},
|
||||
@@ -385,10 +385,11 @@ fn build_gossip_verified_data_columns<T: BeaconChainTypes>(
|
||||
chain: &BeaconChain<T>,
|
||||
block: &SignedBeaconBlock<T::EthSpec, FullPayload<T::EthSpec>>,
|
||||
blobs: BlobsList<T::EthSpec>,
|
||||
kzg_cell_proofs: KzgProofs<T::EthSpec>,
|
||||
) -> Result<Vec<Option<GossipVerifiedDataColumn<T>>>, Rejection> {
|
||||
let slot = block.slot();
|
||||
let data_column_sidecars =
|
||||
build_blob_data_column_sidecars(chain, block, blobs).map_err(|e| {
|
||||
build_blob_data_column_sidecars(chain, block, blobs, kzg_cell_proofs).map_err(|e| {
|
||||
error!(
|
||||
error = ?e,
|
||||
%slot,
|
||||
@@ -522,7 +523,7 @@ fn publish_column_sidecars<T: BeaconChainTypes>(
|
||||
.len()
|
||||
.saturating_sub(malicious_withhold_count);
|
||||
// Randomize columns before dropping the last malicious_withhold_count items
|
||||
data_column_sidecars.shuffle(&mut rand::thread_rng());
|
||||
data_column_sidecars.shuffle(&mut **chain.rng.lock());
|
||||
data_column_sidecars.truncate(columns_to_keep);
|
||||
}
|
||||
let pubsub_messages = data_column_sidecars
|
||||
|
||||
Reference in New Issue
Block a user