Bump ssz_types to v0.12.2 (#8032)

https://github.com/sigp/lighthouse/issues/8012


  Replace all instances of `VariableList::from` and `FixedVector::from` to their `try_from` variants.

While I tried to use proper error handling in most cases, there were certain situations where adding an `expect` for situations where `try_from` can trivially never fail avoided adding a lot of extra complexity.


Co-Authored-By: Mac L <mjladson@pm.me>

Co-Authored-By: Michael Sproul <michaelsproul@users.noreply.github.com>

Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
Mac L
2025-10-28 08:01:09 +04:00
committed by GitHub
parent 5840004c36
commit f5809aff87
39 changed files with 758 additions and 465 deletions

View File

@@ -622,19 +622,22 @@ pub struct SingleAttestation {
}
impl SingleAttestation {
pub fn to_indexed<E: EthSpec>(&self, fork_name: ForkName) -> IndexedAttestation<E> {
pub fn to_indexed<E: EthSpec>(
&self,
fork_name: ForkName,
) -> Result<IndexedAttestation<E>, ssz_types::Error> {
if fork_name.electra_enabled() {
IndexedAttestation::Electra(IndexedAttestationElectra {
attesting_indices: vec![self.attester_index].into(),
Ok(IndexedAttestation::Electra(IndexedAttestationElectra {
attesting_indices: vec![self.attester_index].try_into()?,
data: self.data.clone(),
signature: self.signature.clone(),
})
}))
} else {
IndexedAttestation::Base(IndexedAttestationBase {
attesting_indices: vec![self.attester_index].into(),
Ok(IndexedAttestation::Base(IndexedAttestationBase {
attesting_indices: vec![self.attester_index].try_into()?,
data: self.data.clone(),
signature: self.signature.clone(),
})
}))
}
}
}

View File

@@ -2067,7 +2067,7 @@ fn max_data_columns_by_root_request_common<E: EthSpec>(max_request_blocks: u64)
let empty_data_columns_by_root_id = DataColumnsByRootIdentifier {
block_root: Hash256::zero(),
columns: VariableList::from(vec![0; E::number_of_columns()]),
columns: VariableList::repeat_full(0),
};
RuntimeVariableList::<DataColumnsByRootIdentifier<E>>::new(

View File

@@ -310,6 +310,11 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq +
Self::BytesPerBlob::to_usize()
}
/// Returns the `BYTES_PER_CELL` constant for this specification.
fn bytes_per_cell() -> usize {
Self::BytesPerCell::to_usize()
}
/// Returns the `KZG_COMMITMENT_INCLUSION_PROOF_DEPTH` preset for this specification.
fn kzg_proof_inclusion_proof_depth() -> usize {
Self::KzgCommitmentInclusionProofDepth::to_usize()

View File

@@ -151,32 +151,44 @@ impl<E: EthSpec> LightClientBootstrap<E> {
ForkName::Altair | ForkName::Bellatrix => Self::Altair(LightClientBootstrapAltair {
header: LightClientHeaderAltair::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
ForkName::Capella => Self::Capella(LightClientBootstrapCapella {
header: LightClientHeaderCapella::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
ForkName::Deneb => Self::Deneb(LightClientBootstrapDeneb {
header: LightClientHeaderDeneb::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
ForkName::Electra => Self::Electra(LightClientBootstrapElectra {
header: LightClientHeaderElectra::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
ForkName::Fulu => Self::Fulu(LightClientBootstrapFulu {
header: LightClientHeaderFulu::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
ForkName::Gloas => Self::Gloas(LightClientBootstrapGloas {
header: LightClientHeaderGloas::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
};
@@ -201,32 +213,44 @@ impl<E: EthSpec> LightClientBootstrap<E> {
ForkName::Altair | ForkName::Bellatrix => Self::Altair(LightClientBootstrapAltair {
header: LightClientHeaderAltair::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
ForkName::Capella => Self::Capella(LightClientBootstrapCapella {
header: LightClientHeaderCapella::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
ForkName::Deneb => Self::Deneb(LightClientBootstrapDeneb {
header: LightClientHeaderDeneb::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
ForkName::Electra => Self::Electra(LightClientBootstrapElectra {
header: LightClientHeaderElectra::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
ForkName::Fulu => Self::Fulu(LightClientBootstrapFulu {
header: LightClientHeaderFulu::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
ForkName::Gloas => Self::Gloas(LightClientBootstrapGloas {
header: LightClientHeaderGloas::block_to_light_client_header(block)?,
current_sync_committee,
current_sync_committee_branch: current_sync_committee_branch.into(),
current_sync_committee_branch: current_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
}),
};

View File

@@ -116,7 +116,7 @@ impl<E: EthSpec> LightClientFinalityUpdate<E> {
finalized_header: LightClientHeaderAltair::block_to_light_client_header(
finalized_block,
)?,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate,
signature_slot,
})
@@ -128,7 +128,7 @@ impl<E: EthSpec> LightClientFinalityUpdate<E> {
finalized_header: LightClientHeaderCapella::block_to_light_client_header(
finalized_block,
)?,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate,
signature_slot,
}),
@@ -139,7 +139,7 @@ impl<E: EthSpec> LightClientFinalityUpdate<E> {
finalized_header: LightClientHeaderDeneb::block_to_light_client_header(
finalized_block,
)?,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate,
signature_slot,
}),
@@ -150,7 +150,7 @@ impl<E: EthSpec> LightClientFinalityUpdate<E> {
finalized_header: LightClientHeaderElectra::block_to_light_client_header(
finalized_block,
)?,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate,
signature_slot,
}),
@@ -161,7 +161,7 @@ impl<E: EthSpec> LightClientFinalityUpdate<E> {
finalized_header: LightClientHeaderFulu::block_to_light_client_header(
finalized_block,
)?,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate,
signature_slot,
}),
@@ -172,7 +172,7 @@ impl<E: EthSpec> LightClientFinalityUpdate<E> {
finalized_header: LightClientHeaderGloas::block_to_light_client_header(
finalized_block,
)?,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate,
signature_slot,
}),

View File

@@ -261,9 +261,11 @@ impl<E: EthSpec> LightClientUpdate<E> {
Self::Altair(LightClientUpdateAltair {
attested_header,
next_sync_committee,
next_sync_committee_branch: next_sync_committee_branch.into(),
next_sync_committee_branch: next_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
finalized_header,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate: sync_aggregate.clone(),
signature_slot: block_slot,
})
@@ -285,9 +287,11 @@ impl<E: EthSpec> LightClientUpdate<E> {
Self::Capella(LightClientUpdateCapella {
attested_header,
next_sync_committee,
next_sync_committee_branch: next_sync_committee_branch.into(),
next_sync_committee_branch: next_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
finalized_header,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate: sync_aggregate.clone(),
signature_slot: block_slot,
})
@@ -309,9 +313,11 @@ impl<E: EthSpec> LightClientUpdate<E> {
Self::Deneb(LightClientUpdateDeneb {
attested_header,
next_sync_committee,
next_sync_committee_branch: next_sync_committee_branch.into(),
next_sync_committee_branch: next_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
finalized_header,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate: sync_aggregate.clone(),
signature_slot: block_slot,
})
@@ -333,9 +339,11 @@ impl<E: EthSpec> LightClientUpdate<E> {
Self::Electra(LightClientUpdateElectra {
attested_header,
next_sync_committee,
next_sync_committee_branch: next_sync_committee_branch.into(),
next_sync_committee_branch: next_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
finalized_header,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate: sync_aggregate.clone(),
signature_slot: block_slot,
})
@@ -357,9 +365,11 @@ impl<E: EthSpec> LightClientUpdate<E> {
Self::Fulu(LightClientUpdateFulu {
attested_header,
next_sync_committee,
next_sync_committee_branch: next_sync_committee_branch.into(),
next_sync_committee_branch: next_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
finalized_header,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate: sync_aggregate.clone(),
signature_slot: block_slot,
})
@@ -381,9 +391,11 @@ impl<E: EthSpec> LightClientUpdate<E> {
Self::Gloas(LightClientUpdateGloas {
attested_header,
next_sync_committee,
next_sync_committee_branch: next_sync_committee_branch.into(),
next_sync_committee_branch: next_sync_committee_branch
.try_into()
.map_err(Error::SszTypesError)?,
finalized_header,
finality_branch: finality_branch.into(),
finality_branch: finality_branch.try_into().map_err(Error::SszTypesError)?,
sync_aggregate: sync_aggregate.clone(),
signature_slot: block_slot,
})

View File

@@ -115,7 +115,7 @@ where
}
}
output.into()
output.try_into().unwrap()
}
}