mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Altair consensus changes and refactors (#2279)
## Proposed Changes Implement the consensus changes necessary for the upcoming Altair hard fork. ## Additional Info This is quite a heavy refactor, with pivotal types like the `BeaconState` and `BeaconBlock` changing from structs to enums. This ripples through the whole codebase with field accesses changing to methods, e.g. `state.slot` => `state.slot()`. Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
@@ -145,6 +145,31 @@ impl<'a> SszDecoderBuilder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers a variable-length object as the next item in `bytes`, without specifying the
|
||||
/// actual type.
|
||||
///
|
||||
/// ## Notes
|
||||
///
|
||||
/// Use of this function is generally discouraged since it cannot detect if some type changes
|
||||
/// from variable to fixed length.
|
||||
///
|
||||
/// Use `Self::register_type` wherever possible.
|
||||
pub fn register_anonymous_variable_length_item(&mut self) -> Result<(), DecodeError> {
|
||||
struct Anonymous;
|
||||
|
||||
impl Decode for Anonymous {
|
||||
fn is_ssz_fixed_len() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn from_ssz_bytes(_bytes: &[u8]) -> Result<Self, DecodeError> {
|
||||
unreachable!("Anonymous should never be decoded")
|
||||
}
|
||||
}
|
||||
|
||||
self.register_type::<Anonymous>()
|
||||
}
|
||||
|
||||
/// Declares that some type `T` is the next item in `bytes`.
|
||||
pub fn register_type<T: Decode>(&mut self) -> Result<(), DecodeError> {
|
||||
if T::is_ssz_fixed_len() {
|
||||
@@ -277,6 +302,14 @@ impl<'a> SszDecoder<'a> {
|
||||
pub fn decode_next<T: Decode>(&mut self) -> Result<T, DecodeError> {
|
||||
T::from_ssz_bytes(self.items.remove(0))
|
||||
}
|
||||
|
||||
/// Decodes the next item using the provided function.
|
||||
pub fn decode_next_with<T, F>(&mut self, f: F) -> Result<T, DecodeError>
|
||||
where
|
||||
F: FnOnce(&'a [u8]) -> Result<T, DecodeError>,
|
||||
{
|
||||
f(self.items.remove(0))
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads a `BYTES_PER_LENGTH_OFFSET`-byte union index from `bytes`, where `bytes.len() >=
|
||||
|
||||
Reference in New Issue
Block a user