Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy lints on merge-f2f #2626

Merged
merged 3 commits into from
Sep 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,19 +1065,20 @@ impl<'a, T: BeaconChainTypes> FullyVerifiedBlock<'a, T> {
ExecutionPayloadError::NoEth1Connection,
))?;

if !eth1_chain
.on_payload(block.message().body().execution_payload().ok_or(
let payload_valid = eth1_chain
.on_payload(block.message().body().execution_payload().ok_or_else(|| {
BlockError::InconsistentFork(InconsistentFork {
fork_at_slot: eth2::types::ForkName::Merge,
object_fork: block.message().body().fork_name(),
}),
)?)
})
})?)
.map_err(|e| {
BlockError::ExecutionPayloadError(ExecutionPayloadError::Eth1VerificationError(
e,
))
})?
{
})?;

if !payload_valid {
return Err(BlockError::ExecutionPayloadError(
ExecutionPayloadError::RejectedByExecutionEngine,
));
Expand Down Expand Up @@ -1206,17 +1207,17 @@ fn validate_execution_payload<E: EthSpec>(
.execution_payload()
// TODO: this really should never error so maybe
// we should make this simpler..
.ok_or(BlockError::InconsistentFork(InconsistentFork {
fork_at_slot: eth2::types::ForkName::Merge,
object_fork: block.body().fork_name(),
}))?;

if is_merge_complete(state) {
if *execution_payload == <ExecutionPayload<E>>::default() {
return Err(BlockError::ExecutionPayloadError(
ExecutionPayloadError::PayloadEmpty,
));
}
.ok_or_else(|| {
BlockError::InconsistentFork(InconsistentFork {
fork_at_slot: eth2::types::ForkName::Merge,
object_fork: block.body().fork_name(),
})
})?;

if is_merge_complete(state) && *execution_payload == <ExecutionPayload<E>>::default() {
return Err(BlockError::ExecutionPayloadError(
ExecutionPayloadError::PayloadEmpty,
));
}

// TODO: finish these
Expand Down
5 changes: 4 additions & 1 deletion consensus/ssz_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ fn ssz_encode_derive_enum_union(derive_input: &DeriveInput, enum_data: &DataEnum
fn ssz_bytes_len(&self) -> usize {
match self {
#(
#patterns => inner.ssz_bytes_len() + 1,
#patterns => inner
.ssz_bytes_len()
.checked_add(1)
.expect("encoded length must be less than usize::max_value"),
)*
}
}
Expand Down
26 changes: 17 additions & 9 deletions consensus/state_processing/src/per_block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,24 +288,32 @@ pub fn get_new_eth1_data<T: EthSpec>(
pub fn is_valid_gas_limit<T: EthSpec>(
payload: &ExecutionPayload<T>,
parent: &ExecutionPayloadHeader<T>,
) -> bool {
) -> Result<bool, ArithError> {
// check if payload used too much gas
if payload.gas_used > payload.gas_limit {
return false;
return Ok(false);
}
// check if payload changed the gas limit too much
if payload.gas_limit >= parent.gas_limit + parent.gas_limit / T::gas_limit_denominator() {
return false;
if payload.gas_limit
>= parent
.gas_limit
.safe_add(parent.gas_limit.safe_div(T::gas_limit_denominator())?)?
{
return Ok(false);
}
if payload.gas_limit <= parent.gas_limit - parent.gas_limit / T::gas_limit_denominator() {
return false;
if payload.gas_limit
<= parent
.gas_limit
.safe_sub(parent.gas_limit.safe_div(T::gas_limit_denominator())?)?
{
return Ok(false);
}
// check if the gas limit is at least the minimum gas limit
if payload.gas_limit < T::min_gas_limit() {
return false;
return Ok(false);
}

return true;
Ok(true)
}

/// https://github.com/ethereum/consensus-specs/blob/dev/specs/merge/beacon-chain.md#process_execution_payload
Expand Down Expand Up @@ -344,7 +352,7 @@ pub fn process_execution_payload<T: EthSpec>(
}
);
block_verify!(
is_valid_gas_limit(payload, state.latest_execution_payload_header()?),
is_valid_gas_limit(payload, state.latest_execution_payload_header()?)?,
BlockProcessingError::ExecutionInvalidGasLimit {
used: payload.gas_used,
limit: payload.gas_limit,
Expand Down