Skip to content

Commit be959ab

Browse files
committed
fix linter complaints
1 parent d3ea16c commit be959ab

File tree

3 files changed

+56
-61
lines changed

3 files changed

+56
-61
lines changed

beacon_node/beacon_chain/src/envelope_verification.rs

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -159,50 +159,46 @@ fn load_snapshot<T: BeaconChainTypes>(
159159

160160
// TODO(EIP-7732): add metrics here
161161

162-
let result = {
163-
// Load the parent block's state from the database, returning an error if it is not found.
164-
// It is an error because if we know the parent block we should also know the parent state.
165-
// Retrieve any state that is advanced through to at most `block.slot()`: this is
166-
// particularly important if `block` descends from the finalized/split block, but at a slot
167-
// prior to the finalized slot (which is invalid and inaccessible in our DB schema).
168-
let (parent_state_root, state) = chain
169-
.store
170-
// TODO(EIP-7732): the state doesn't need to be advanced here because we're applying an envelope
171-
// but this function does use a lot of caches that could be more efficient. Is there
172-
// a better way to do this?
173-
.get_advanced_hot_state(
174-
beacon_block_root,
175-
proto_beacon_block.slot,
162+
// Load the parent block's state from the database, returning an error if it is not found.
163+
// It is an error because if we know the parent block we should also know the parent state.
164+
// Retrieve any state that is advanced through to at most `block.slot()`: this is
165+
// particularly important if `block` descends from the finalized/split block, but at a slot
166+
// prior to the finalized slot (which is invalid and inaccessible in our DB schema).
167+
let (parent_state_root, state) = chain
168+
.store
169+
// TODO(EIP-7732): the state doesn't need to be advanced here because we're applying an envelope
170+
// but this function does use a lot of caches that could be more efficient. Is there
171+
// a better way to do this?
172+
.get_advanced_hot_state(
173+
beacon_block_root,
174+
proto_beacon_block.slot,
175+
proto_beacon_block.state_root,
176+
)
177+
.map_err(|e| EnvelopeError::BeaconChainError(Arc::new(e.into())))?
178+
.ok_or_else(|| {
179+
BeaconChainError::DBInconsistent(format!(
180+
"Missing state for parent block {beacon_block_root:?}",
181+
))
182+
})?;
183+
184+
if state.slot() == proto_beacon_block.slot {
185+
// Sanity check.
186+
if parent_state_root != proto_beacon_block.state_root {
187+
return Err(BeaconChainError::DBInconsistent(format!(
188+
"Parent state at slot {} has the wrong state root: {:?} != {:?}",
189+
state.slot(),
190+
parent_state_root,
176191
proto_beacon_block.state_root,
177-
)
178-
.map_err(|e| EnvelopeError::BeaconChainError(Arc::new(e.into())))?
179-
.ok_or_else(|| {
180-
BeaconChainError::DBInconsistent(format!(
181-
"Missing state for parent block {beacon_block_root:?}",
182-
))
183-
})?;
184-
185-
if state.slot() == proto_beacon_block.slot {
186-
// Sanity check.
187-
if parent_state_root != proto_beacon_block.state_root {
188-
return Err(BeaconChainError::DBInconsistent(format!(
189-
"Parent state at slot {} has the wrong state root: {:?} != {:?}",
190-
state.slot(),
191-
parent_state_root,
192-
proto_beacon_block.state_root,
193-
))
194-
.into());
195-
}
192+
))
193+
.into());
196194
}
195+
}
197196

198-
Ok(EnvelopeProcessingSnapshot {
199-
pre_state: state,
200-
state_root: parent_state_root,
201-
beacon_block_root,
202-
})
203-
};
204-
205-
result
197+
Ok(EnvelopeProcessingSnapshot {
198+
pre_state: state,
199+
state_root: parent_state_root,
200+
beacon_block_root,
201+
})
206202
}
207203

208204
/// A wrapper around a `SignedExecutionPayloadEnvelope` that indicates it has been approved for re-gossiping on
@@ -320,7 +316,7 @@ impl<T: BeaconChainTypes> GossipVerifiedEnvelope<T> {
320316
builder_index: envelope.builder_index(),
321317
})?;
322318
signed_envelope.verify_signature(
323-
&builder_pubkey,
319+
builder_pubkey,
324320
&fork,
325321
chain.genesis_validators_root,
326322
&chain.spec,

consensus/state_processing/src/envelope_processing.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn envelope_processing<E: EthSpec>(
119119
if verify_signatures.is_true() {
120120
// Verify Signed Envelope Signature
121121
// TODO(EIP-7732): there is probably a more efficient way to do this..
122-
if !signed_envelope.verify_signature_with_state(&state, spec)? {
122+
if !signed_envelope.verify_signature_with_state(state, spec)? {
123123
return Err(EnvelopeProcessingError::BadSignature);
124124
}
125125
}
@@ -205,18 +205,16 @@ pub fn envelope_processing<E: EthSpec>(
205205
state: *state.get_randao_mix(state.current_epoch())?,
206206
envelope: payload.prev_randao(),
207207
}
208-
.into()
209208
);
210209

211210
// Verify the timestamp
212-
let state_timestamp = compute_timestamp_at_slot(&state, state.slot(), spec)?;
211+
let state_timestamp = compute_timestamp_at_slot(state, state.slot(), spec)?;
213212
envelope_verify!(
214213
payload.timestamp() == state_timestamp,
215214
EnvelopeProcessingError::TimestampMismatch {
216215
state: state_timestamp,
217216
envelope: payload.timestamp(),
218217
}
219-
.into()
220218
);
221219

222220
// Verify the commitments are under limit
@@ -227,7 +225,6 @@ pub fn envelope_processing<E: EthSpec>(
227225
max: max_blobs,
228226
envelope: envelope.blob_kzg_commitments().len(),
229227
}
230-
.into()
231228
);
232229

233230
// process electra operations
@@ -242,7 +239,9 @@ pub fn envelope_processing<E: EthSpec>(
242239
let mut payment = state
243240
.builder_pending_payments()?
244241
.get(payment_index)
245-
.ok_or_else(|| EnvelopeProcessingError::BuilderPaymentIndexOutOfBounds(payment_index))?
242+
.ok_or(EnvelopeProcessingError::BuilderPaymentIndexOutOfBounds(
243+
payment_index,
244+
))?
246245
.clone();
247246
let amount = payment.withdrawal.amount;
248247
if amount > 0 {
@@ -257,8 +256,9 @@ pub fn envelope_processing<E: EthSpec>(
257256
*state
258257
.builder_pending_payments_mut()?
259258
.get_mut(payment_index)
260-
.ok_or_else(|| EnvelopeProcessingError::BuilderPaymentIndexOutOfBounds(payment_index))? =
261-
BuilderPendingPayment::default();
259+
.ok_or(EnvelopeProcessingError::BuilderPaymentIndexOutOfBounds(
260+
payment_index,
261+
))? = BuilderPendingPayment::default();
262262

263263
// cache the execution payload hash
264264
let availability_index = state
@@ -268,7 +268,7 @@ pub fn envelope_processing<E: EthSpec>(
268268
state
269269
.execution_payload_availability_mut()?
270270
.set(availability_index, true)
271-
.map_err(|e| EnvelopeProcessingError::BitFieldError(e))?;
271+
.map_err(EnvelopeProcessingError::BitFieldError)?;
272272
*state.latest_block_hash_mut()? = payload.block_hash();
273273

274274
// verify the state root

consensus/types/src/beacon_state/tests.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,15 @@ async fn build_state<E: EthSpec>(validator_count: usize) -> BeaconState<E> {
5353
.head_beacon_state_cloned()
5454
}
5555

56-
/// TODO(EIP-7732): Add tests for PTC (Payload Timeliness Committee) functions:
57-
/// - get_ptc: Test committee selection, size, balance-weighted selection
58-
/// - get_ptc_attester_seed: Test seed generation and determinism
59-
/// - compute_balance_weighted_selection: Test selection algorithm with various balances
60-
/// - compute_balance_weighted_acceptance: Test acceptance probability
61-
/// These tests require being able to build Gloas states with initialized committee caches,
62-
/// which currently fails due to incomplete Gloas block structure as mentioned here:
63-
/// https://github.com/sigp/lighthouse/pull/8273
64-
/// Similar to existing committee_consistency_test suite for get_beacon_committee.
65-
56+
// TODO(EIP-7732): Add tests for PTC (Payload Timeliness Committee) functions:
57+
// - get_ptc: Test committee selection, size, balance-weighted selection
58+
// - get_ptc_attester_seed: Test seed generation and determinism
59+
// - compute_balance_weighted_selection: Test selection algorithm with various balances
60+
// - compute_balance_weighted_acceptance: Test acceptance probability
61+
// These tests require being able to build Gloas states with initialized committee caches,
62+
// which currently fails due to incomplete Gloas block structure as mentioned here:
63+
// https://github.com/sigp/lighthouse/pull/8273
64+
// Similar to existing committee_consistency_test suite for get_beacon_committee.
6665
async fn test_beacon_proposer_index<E: EthSpec>() {
6766
let spec = E::default_spec();
6867

0 commit comments

Comments
 (0)