mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
Fix clippy lints on merge-f2f (#2626)
* Remove unchecked arith from ssz_derive * Address clippy lints in block_verfication * Use safe math for is_valid_gas_limit
This commit is contained in:
@@ -296,24 +296,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
|
||||
@@ -352,7 +360,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,
|
||||
|
||||
Reference in New Issue
Block a user