Merge branch 'unstable' into validator-manager

This commit is contained in:
Paul Hauner
2023-02-24 09:25:45 +11:00
286 changed files with 13296 additions and 2554 deletions

View File

@@ -21,7 +21,7 @@ bytes = "1.0.1"
account_utils = { path = "../../common/account_utils" }
sensitive_url = { path = "../../common/sensitive_url" }
eth2_ssz = "0.4.1"
eth2_ssz_derive = "0.3.0"
eth2_ssz_derive = "0.3.1"
futures-util = "0.3.8"
futures = "0.3.8"
store = { path = "../../beacon_node/store", optional = true }

View File

@@ -14,9 +14,8 @@ pub mod lighthouse_vc;
pub mod mixin;
pub mod types;
use self::mixin::{RequestAccept, ResponseForkName, ResponseOptional};
use self::mixin::{RequestAccept, ResponseOptional};
use self::types::{Error as ResponseError, *};
use ::types::map_fork_name_with;
use futures::Stream;
use futures_util::StreamExt;
use lighthouse_network::PeerId;
@@ -611,7 +610,7 @@ impl BeaconNodeHttpClient {
/// `POST beacon/blocks`
///
/// Returns `Ok(None)` on a 404 error.
pub async fn post_beacon_blocks<T: EthSpec, Payload: ExecPayload<T>>(
pub async fn post_beacon_blocks<T: EthSpec, Payload: AbstractExecPayload<T>>(
&self,
block: &SignedBeaconBlock<T, Payload>,
) -> Result<(), Error> {
@@ -631,7 +630,7 @@ impl BeaconNodeHttpClient {
/// `POST beacon/blinded_blocks`
///
/// Returns `Ok(None)` on a 404 error.
pub async fn post_beacon_blinded_blocks<T: EthSpec, Payload: ExecPayload<T>>(
pub async fn post_beacon_blinded_blocks<T: EthSpec, Payload: AbstractExecPayload<T>>(
&self,
block: &SignedBeaconBlock<T, Payload>,
) -> Result<(), Error> {
@@ -683,35 +682,7 @@ impl BeaconNodeHttpClient {
None => return Ok(None),
};
// If present, use the fork provided in the headers to decode the block. Gracefully handle
// missing and malformed fork names by falling back to regular deserialisation.
let (block, version, execution_optimistic) = match response.fork_name_from_header() {
Ok(Some(fork_name)) => {
let (data, (version, execution_optimistic)) =
map_fork_name_with!(fork_name, SignedBeaconBlock, {
let ExecutionOptimisticForkVersionedResponse {
version,
execution_optimistic,
data,
} = response.json().await?;
(data, (version, execution_optimistic))
});
(data, version, execution_optimistic)
}
Ok(None) | Err(_) => {
let ExecutionOptimisticForkVersionedResponse {
version,
execution_optimistic,
data,
} = response.json().await?;
(data, version, execution_optimistic)
}
};
Ok(Some(ExecutionOptimisticForkVersionedResponse {
version,
execution_optimistic,
data: block,
}))
Ok(Some(response.json().await?))
}
/// `GET v1/beacon/blinded_blocks/{block_id}`
@@ -728,35 +699,7 @@ impl BeaconNodeHttpClient {
None => return Ok(None),
};
// If present, use the fork provided in the headers to decode the block. Gracefully handle
// missing and malformed fork names by falling back to regular deserialisation.
let (block, version, execution_optimistic) = match response.fork_name_from_header() {
Ok(Some(fork_name)) => {
let (data, (version, execution_optimistic)) =
map_fork_name_with!(fork_name, SignedBlindedBeaconBlock, {
let ExecutionOptimisticForkVersionedResponse {
version,
execution_optimistic,
data,
} = response.json().await?;
(data, (version, execution_optimistic))
});
(data, version, execution_optimistic)
}
Ok(None) | Err(_) => {
let ExecutionOptimisticForkVersionedResponse {
version,
execution_optimistic,
data,
} = response.json().await?;
(data, version, execution_optimistic)
}
};
Ok(Some(ExecutionOptimisticForkVersionedResponse {
version,
execution_optimistic,
data: block,
}))
Ok(Some(response.json().await?))
}
/// `GET v1/beacon/blocks` (LEGACY)
@@ -1012,6 +955,24 @@ impl BeaconNodeHttpClient {
Ok(())
}
/// `POST beacon/pool/bls_to_execution_changes`
pub async fn post_beacon_pool_bls_to_execution_changes(
&self,
address_changes: &[SignedBlsToExecutionChange],
) -> Result<(), Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
.push("beacon")
.push("pool")
.push("bls_to_execution_changes");
self.post(path, &address_changes).await?;
Ok(())
}
/// `GET beacon/deposit_snapshot`
pub async fn get_deposit_snapshot(&self) -> Result<Option<types::DepositTreeSnapshot>, Error> {
use ssz::Decode;
@@ -1392,7 +1353,7 @@ impl BeaconNodeHttpClient {
}
/// `GET v2/validator/blocks/{slot}`
pub async fn get_validator_blocks<T: EthSpec, Payload: ExecPayload<T>>(
pub async fn get_validator_blocks<T: EthSpec, Payload: AbstractExecPayload<T>>(
&self,
slot: Slot,
randao_reveal: &SignatureBytes,
@@ -1403,7 +1364,7 @@ impl BeaconNodeHttpClient {
}
/// `GET v2/validator/blocks/{slot}`
pub async fn get_validator_blocks_modular<T: EthSpec, Payload: ExecPayload<T>>(
pub async fn get_validator_blocks_modular<T: EthSpec, Payload: AbstractExecPayload<T>>(
&self,
slot: Slot,
randao_reveal: &SignatureBytes,
@@ -1434,8 +1395,34 @@ impl BeaconNodeHttpClient {
self.get(path).await
}
/// `GET v1/validator/blocks_and_blobs/{slot}`
pub async fn get_validator_blocks_and_blobs<T: EthSpec, Payload: AbstractExecPayload<T>>(
&self,
slot: Slot,
randao_reveal: &SignatureBytes,
graffiti: Option<&Graffiti>,
) -> Result<ForkVersionedResponse<BlocksAndBlobs<T, Payload>>, Error> {
let mut path = self.eth_path(V1)?;
path.path_segments_mut()
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
.push("validator")
.push("blocks_and_blobs")
.push(&slot.to_string());
path.query_pairs_mut()
.append_pair("randao_reveal", &randao_reveal.to_string());
if let Some(graffiti) = graffiti {
path.query_pairs_mut()
.append_pair("graffiti", &graffiti.to_string());
}
self.get(path).await
}
/// `GET v2/validator/blinded_blocks/{slot}`
pub async fn get_validator_blinded_blocks<T: EthSpec, Payload: ExecPayload<T>>(
pub async fn get_validator_blinded_blocks<T: EthSpec, Payload: AbstractExecPayload<T>>(
&self,
slot: Slot,
randao_reveal: &SignatureBytes,
@@ -1451,7 +1438,10 @@ impl BeaconNodeHttpClient {
}
/// `GET v1/validator/blinded_blocks/{slot}`
pub async fn get_validator_blinded_blocks_modular<T: EthSpec, Payload: ExecPayload<T>>(
pub async fn get_validator_blinded_blocks_modular<
T: EthSpec,
Payload: AbstractExecPayload<T>,
>(
&self,
slot: Slot,
randao_reveal: &SignatureBytes,

View File

@@ -236,21 +236,6 @@ impl<'a, T: Serialize> From<&'a T> for GenericResponseRef<'a, T> {
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct ExecutionOptimisticForkVersionedResponse<T> {
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<ForkName>,
pub execution_optimistic: Option<bool>,
pub data: T,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct ForkVersionedResponse<T> {
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<ForkName>,
pub data: T,
}
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct RootData {
pub root: Hash256,
@@ -1129,6 +1114,38 @@ pub struct LivenessResponseData {
pub is_live: bool,
}
#[derive(PartialEq, Debug, Serialize, Deserialize)]
#[serde(bound = "T: EthSpec, Payload: AbstractExecPayload<T>")]
pub struct BlocksAndBlobs<T: EthSpec, Payload: AbstractExecPayload<T>> {
pub block: BeaconBlock<T, Payload>,
pub blobs: Vec<Blob<T>>,
pub kzg_aggregate_proof: KzgProof,
}
impl<T: EthSpec, Payload: AbstractExecPayload<T>> ForkVersionDeserialize
for BlocksAndBlobs<T, Payload>
{
fn deserialize_by_fork<'de, D: serde::Deserializer<'de>>(
value: serde_json::value::Value,
fork_name: ForkName,
) -> Result<Self, D::Error> {
#[derive(Deserialize)]
#[serde(bound = "T: EthSpec")]
struct Helper<T: EthSpec> {
block: serde_json::Value,
blobs: Vec<Blob<T>>,
kzg_aggregate_proof: KzgProof,
}
let helper: Helper<T> = serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(Self {
block: BeaconBlock::deserialize_by_fork::<'de, D>(helper.block, fork_name)?,
blobs: helper.blobs,
kzg_aggregate_proof: helper.kzg_aggregate_proof,
})
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -36,6 +36,12 @@ ALTAIR_FORK_EPOCH: 512
# Merge
BELLATRIX_FORK_VERSION: 0x02000064
BELLATRIX_FORK_EPOCH: 385536
# Capella
CAPELLA_FORK_VERSION: 0x03000064
CAPELLA_FORK_EPOCH: 18446744073709551615
# Eip4844
EIP4844_FORK_VERSION: 0x04000064
EIP4844_FORK_EPOCH: 18446744073709551615
# Sharding
SHARDING_FORK_VERSION: 0x03000064
SHARDING_FORK_EPOCH: 18446744073709551615

View File

@@ -36,6 +36,12 @@ ALTAIR_FORK_EPOCH: 74240
# Merge
BELLATRIX_FORK_VERSION: 0x02000000
BELLATRIX_FORK_EPOCH: 144896 # Sept 6, 2022, 11:34:47am UTC
# Capella
CAPELLA_FORK_VERSION: 0x03000000
CAPELLA_FORK_EPOCH: 18446744073709551615
# Eip4844
EIP4844_FORK_VERSION: 0x04000000
EIP4844_FORK_EPOCH: 18446744073709551615
# Sharding
SHARDING_FORK_VERSION: 0x03000000
SHARDING_FORK_EPOCH: 18446744073709551615

View File

@@ -29,8 +29,12 @@ TERMINAL_BLOCK_HASH: 0x000000000000000000000000000000000000000000000000000000000
TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615
# Capella
CAPELLA_FORK_VERSION: 0x03001020
CAPELLA_FORK_EPOCH: 18446744073709551615
CAPELLA_FORK_VERSION: 0x90000072
CAPELLA_FORK_EPOCH: 56832
# Eip4844
EIP4844_FORK_VERSION: 0x03001020
EIP4844_FORK_EPOCH: 18446744073709551615
# Sharding
SHARDING_FORK_VERSION: 0x04001020

View File

@@ -17,8 +17,8 @@ pub const VERSION: &str = git_version!(
// NOTE: using --match instead of --exclude for compatibility with old Git
"--match=thiswillnevermatchlol"
],
prefix = "Lighthouse/v3.4.0-",
fallback = "Lighthouse/v3.4.0"
prefix = "Lighthouse/v3.5.0-",
fallback = "Lighthouse/v3.5.0"
);
/// Returns `VERSION`, but with platform information appended to the end.

View File

@@ -31,6 +31,77 @@ where
}
}
/// Inserts a key without removal of potentially expired elements.
/// Returns true if the key does not already exist.
pub fn raw_insert(&mut self, key: Key) -> bool {
// check the cache before removing elements
let is_new = self.map.insert(key.clone());
// add the new key to the list, if it doesn't already exist.
if is_new {
self.list.push_back(Element {
key,
inserted: Instant::now(),
});
} else {
let position = self
.list
.iter()
.position(|e| e.key == key)
.expect("Key is not new");
let mut element = self
.list
.remove(position)
.expect("Position is not occupied");
element.inserted = Instant::now();
self.list.push_back(element);
}
#[cfg(test)]
self.check_invariant();
is_new
}
/// Removes a key from the cache without purging expired elements. Returns true if the key
/// existed.
pub fn raw_remove(&mut self, key: &Key) -> bool {
if self.map.remove(key) {
let position = self
.list
.iter()
.position(|e| &e.key == key)
.expect("Key must exist");
self.list
.remove(position)
.expect("Position is not occupied");
true
} else {
false
}
}
/// Removes all expired elements and returns them
pub fn remove_expired(&mut self) -> Vec<Key> {
if self.list.is_empty() {
return Vec::new();
}
let mut removed_elements = Vec::new();
let now = Instant::now();
// remove any expired results
while let Some(element) = self.list.pop_front() {
if element.inserted + self.ttl > now {
self.list.push_front(element);
break;
}
self.map.remove(&element.key);
removed_elements.push(element.key);
}
#[cfg(test)]
self.check_invariant();
removed_elements
}
// Inserts a new key. It first purges expired elements to do so.
//
// If the key was not present this returns `true`. If the value was already present this

View File

@@ -1,6 +1,7 @@
use super::SlotClock;
use parking_lot::RwLock;
use std::convert::TryInto;
use std::sync::Arc;
use std::time::Duration;
use types::Slot;
@@ -10,7 +11,7 @@ pub struct ManualSlotClock {
/// Duration from UNIX epoch to genesis.
genesis_duration: Duration,
/// Duration from UNIX epoch to right now.
current_time: RwLock<Duration>,
current_time: Arc<RwLock<Duration>>,
/// The length of each slot.
slot_duration: Duration,
}
@@ -20,7 +21,7 @@ impl Clone for ManualSlotClock {
ManualSlotClock {
genesis_slot: self.genesis_slot,
genesis_duration: self.genesis_duration,
current_time: RwLock::new(*self.current_time.read()),
current_time: Arc::clone(&self.current_time),
slot_duration: self.slot_duration,
}
}
@@ -90,7 +91,7 @@ impl SlotClock for ManualSlotClock {
Self {
genesis_slot,
current_time: RwLock::new(genesis_duration),
current_time: Arc::new(RwLock::new(genesis_duration)),
genesis_duration,
slot_duration,
}