Skip to content

Commit 9cafd21

Browse files
committed
Fixes
1 parent 191c1bc commit 9cafd21

File tree

7 files changed

+36
-64
lines changed

7 files changed

+36
-64
lines changed

beacon_node/beacon_chain/benches/benches.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ fn create_test_block_and_blobs<E: EthSpec>(
2626
let blobs = (0..num_of_blobs)
2727
.map(|_| Blob::<E>::default())
2828
.collect::<Vec<_>>()
29-
.into();
30-
let proofs = vec![KzgProof::empty(); num_of_blobs * E::number_of_columns()].into();
29+
.try_into()
30+
.unwrap();
31+
let proofs = vec![KzgProof::empty(); num_of_blobs * E::number_of_columns()]
32+
.try_into()
33+
.unwrap();
3134

3235
(signed_block, blobs, proofs)
3336
}

beacon_node/beacon_chain/src/attestation_verification.rs

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ use types::{
6363
Attestation, AttestationData, AttestationRef, BeaconCommittee,
6464
BeaconStateError::NoCommitteeFound, ChainSpec, CommitteeIndex, Epoch, EthSpec, Hash256,
6565
IndexedAttestation, SelectionProof, SignedAggregateAndProof, SingleAttestation, Slot, SubnetId,
66-
attestation::Error as AttestationError,
6766
};
6867

6968
pub use batch::{batch_verify_aggregated_attestations, batch_verify_unaggregated_attestations};
@@ -108,18 +107,14 @@ pub enum Error {
108107
/// ## Peer scoring
109108
///
110109
/// The peer has sent an invalid message.
111-
InvalidSelectionProof {
112-
aggregator_index: u64,
113-
},
110+
InvalidSelectionProof { aggregator_index: u64 },
114111
/// The `selection_proof` on the aggregate attestation selects it as a validator, however the
115112
/// aggregator index is not in the committee for that attestation.
116113
///
117114
/// ## Peer scoring
118115
///
119116
/// The peer has sent an invalid message.
120-
AggregatorNotInCommittee {
121-
aggregator_index: u64,
122-
},
117+
AggregatorNotInCommittee { aggregator_index: u64 },
123118
/// The `attester_index` for a `SingleAttestation` is not a member of the committee defined
124119
/// by its `beacon_block_root`, `committee_index` and `slot`.
125120
///
@@ -171,19 +166,15 @@ pub enum Error {
171166
///
172167
/// The attestation points to a block we have not yet imported. It's unclear if the attestation
173168
/// is valid or not.
174-
UnknownHeadBlock {
175-
beacon_block_root: Hash256,
176-
},
169+
UnknownHeadBlock { beacon_block_root: Hash256 },
177170
/// The `attestation.data.beacon_block_root` block is from before the finalized checkpoint.
178171
///
179172
/// ## Peer scoring
180173
///
181174
/// The attestation is not descended from the finalized checkpoint, which is a REJECT according
182175
/// to the spec. We downscore lightly because this could also happen if we are processing
183176
/// attestations extremely slowly.
184-
HeadBlockFinalized {
185-
beacon_block_root: Hash256,
186-
},
177+
HeadBlockFinalized { beacon_block_root: Hash256 },
187178
/// The `attestation.data.slot` is not from the same epoch as `data.target.epoch`.
188179
///
189180
/// ## Peer scoring
@@ -210,10 +201,7 @@ pub enum Error {
210201
/// ## Peer scoring
211202
///
212203
/// The peer has sent an invalid message.
213-
NoCommitteeForSlotAndIndex {
214-
slot: Slot,
215-
index: CommitteeIndex,
216-
},
204+
NoCommitteeForSlotAndIndex { slot: Slot, index: CommitteeIndex },
217205
/// The attestation doesn't have only one aggregation bit set.
218206
///
219207
/// ## Peer scoring
@@ -228,20 +216,14 @@ pub enum Error {
228216
/// It's unclear if this attestation is valid, however we have already observed a
229217
/// single-participant attestation from this validator for this epoch and should not observe
230218
/// another.
231-
PriorAttestationKnown {
232-
validator_index: u64,
233-
epoch: Epoch,
234-
},
219+
PriorAttestationKnown { validator_index: u64, epoch: Epoch },
235220
/// The attestation is attesting to a state that is later than itself. (Viz., attesting to the
236221
/// future).
237222
///
238223
/// ## Peer scoring
239224
///
240225
/// The peer has sent an invalid message.
241-
AttestsToFutureBlock {
242-
block: Slot,
243-
attestation: Slot,
244-
},
226+
AttestsToFutureBlock { block: Slot, attestation: Slot },
245227
/// The attestation was received on an invalid attestation subnet.
246228
///
247229
/// ## Peer scoring
@@ -268,10 +250,7 @@ pub enum Error {
268250
/// ## Peer scoring
269251
///
270252
/// The peer has sent an invalid message.
271-
InvalidTargetEpoch {
272-
slot: Slot,
273-
epoch: Epoch,
274-
},
253+
InvalidTargetEpoch { slot: Slot, epoch: Epoch },
275254
/// The attestation references an invalid target block.
276255
///
277256
/// ## Peer scoring
@@ -288,7 +267,6 @@ pub enum Error {
288267
/// We were unable to process this attestation due to an internal error. It's unclear if the
289268
/// attestation is valid.
290269
BeaconChainError(Box<BeaconChainError>),
291-
AttestationError(Box<AttestationError>),
292270
}
293271

294272
impl From<BeaconChainError> for Error {
@@ -464,10 +442,8 @@ fn process_slash_info<T: BeaconChainTypes>(
464442
.spec
465443
.fork_name_at_slot::<T::EthSpec>(attestation.data.slot);
466444

467-
match attestation.to_indexed(fork_name) {
468-
Ok(indexed_attestation) => (indexed_attestation, true, err),
469-
Err(e) => return Error::AttestationError(Box::new(e)),
470-
}
445+
let indexed_attestation = attestation.to_indexed(fork_name);
446+
(indexed_attestation, true, err)
471447
}
472448
SignatureNotCheckedIndexed(indexed, err) => (indexed, true, err),
473449
SignatureInvalid(e) => return e,
@@ -956,15 +932,7 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {
956932
.spec
957933
.fork_name_at_slot::<T::EthSpec>(attestation.data.slot);
958934

959-
let indexed_attestation = match attestation.to_indexed(fork_name) {
960-
Ok(indexed) => indexed,
961-
Err(e) => {
962-
return Err(SignatureNotCheckedSingle(
963-
attestation,
964-
Error::AttestationError(Box::new(e)),
965-
));
966-
}
967-
};
935+
let indexed_attestation = attestation.to_indexed(fork_name);
968936

969937
let validator_index = match Self::verify_middle_checks(attestation, chain) {
970938
Ok(t) => t,

beacon_node/beacon_chain/tests/block_verification.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ async fn invalid_signature_attester_slashing() {
699699

700700
let attester_slashing = if fork_name.electra_enabled() {
701701
let indexed_attestation = IndexedAttestationElectra {
702-
attesting_indices: vec![0].into(),
702+
attesting_indices: vec![0].try_into().unwrap(),
703703
data: AttestationData {
704704
slot: Slot::new(0),
705705
index: 0,
@@ -723,7 +723,7 @@ async fn invalid_signature_attester_slashing() {
723723
AttesterSlashing::Electra(attester_slashing)
724724
} else {
725725
let indexed_attestation = IndexedAttestationBase {
726-
attesting_indices: vec![0].into(),
726+
attesting_indices: vec![0].try_into().unwrap(),
727727
data: AttestationData {
728728
slot: Slot::new(0),
729729
index: 0,
@@ -890,7 +890,9 @@ async fn invalid_signature_deposit() {
890890
let harness = get_invalid_sigs_harness(&chain_segment).await;
891891
let mut snapshots = chain_segment.clone();
892892
let deposit = Deposit {
893-
proof: vec![Hash256::zero(); DEPOSIT_TREE_DEPTH + 1].into(),
893+
proof: vec![Hash256::zero(); DEPOSIT_TREE_DEPTH + 1]
894+
.try_into()
895+
.unwrap(),
894896
data: DepositData {
895897
pubkey: Keypair::random().pk.into(),
896898
withdrawal_credentials: Hash256::zero(),
@@ -1262,7 +1264,9 @@ async fn block_gossip_verification() {
12621264
as usize;
12631265

12641266
if let Ok(kzg_commitments) = block.body_mut().blob_kzg_commitments_mut() {
1265-
*kzg_commitments = vec![KzgCommitment::empty_for_testing(); kzg_commitments_len + 1].into();
1267+
*kzg_commitments = vec![KzgCommitment::empty_for_testing(); kzg_commitments_len + 1]
1268+
.try_into()
1269+
.unwrap();
12661270
assert!(
12671271
matches!(
12681272
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature))).await),

consensus/fork_choice/tests/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,10 @@ async fn invalid_attestation_empty_bitfield() {
753753
MutationDelay::NoDelay,
754754
|attestation, _| match attestation {
755755
IndexedAttestation::Base(att) => {
756-
att.attesting_indices = vec![].into();
756+
att.attesting_indices = vec![].try_into().unwrap();
757757
}
758758
IndexedAttestation::Electra(att) => {
759-
att.attesting_indices = vec![].into();
759+
att.attesting_indices = vec![].try_into().unwrap();
760760
}
761761
},
762762
|result| {

consensus/types/src/attestation.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -622,26 +622,23 @@ pub struct SingleAttestation {
622622
}
623623

624624
impl SingleAttestation {
625-
pub fn to_indexed<E: EthSpec>(
626-
&self,
627-
fork_name: ForkName,
628-
) -> Result<IndexedAttestation<E>, Error> {
625+
pub fn to_indexed<E: EthSpec>(&self, fork_name: ForkName) -> IndexedAttestation<E> {
629626
if fork_name.electra_enabled() {
630-
Ok(IndexedAttestation::Electra(IndexedAttestationElectra {
627+
IndexedAttestation::Electra(IndexedAttestationElectra {
631628
attesting_indices: vec![self.attester_index]
632629
.try_into()
633-
.map_err(Error::SszTypesError)?,
630+
.expect("Single index should not exceed MaxValidatorsPerSlot"),
634631
data: self.data.clone(),
635632
signature: self.signature.clone(),
636-
}))
633+
})
637634
} else {
638-
Ok(IndexedAttestation::Base(IndexedAttestationBase {
635+
IndexedAttestation::Base(IndexedAttestationBase {
639636
attesting_indices: vec![self.attester_index]
640637
.try_into()
641-
.map_err(Error::SszTypesError)?,
638+
.expect("Single index should not exceed MaxValidatorsPerCommittee"),
642639
data: self.data.clone(),
643640
signature: self.signature.clone(),
644-
}))
641+
})
645642
}
646643
}
647644
}

lcli/src/http_sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ async fn get_block_from_source<T: EthSpec>(
139139
let block_root = block_from_source.canonical_root();
140140
let block_contents = SignedBlockContents {
141141
signed_block: Arc::new(block_from_source),
142-
kzg_proofs: kzg_proofs.into(),
143-
blobs: blobs.into(),
142+
kzg_proofs: kzg_proofs.try_into().unwrap(),
143+
blobs: blobs.try_into().unwrap(),
144144
};
145145
let publish_block_req = PublishBlockRequest::BlockContents(block_contents);
146146

testing/ef_tests/src/cases/ssz_generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,6 @@ where
326326
N::to_usize()
327327
)))
328328
} else {
329-
Ok(decoded.into())
329+
Ok(decoded.try_into().unwrap())
330330
}
331331
}

0 commit comments

Comments
 (0)