mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: alloy 0.4 (#11334)
This commit is contained in:
@ -56,40 +56,35 @@ impl<ChainSpec: EthChainSpec + EthereumHardforks> EthBeaconConsensus<ChainSpec>
|
||||
// Determine the parent gas limit, considering elasticity multiplier on the London fork.
|
||||
let parent_gas_limit =
|
||||
if self.chain_spec.fork(EthereumHardfork::London).transitions_at_block(header.number) {
|
||||
parent.gas_limit as u64 *
|
||||
parent.gas_limit *
|
||||
self.chain_spec
|
||||
.base_fee_params_at_timestamp(header.timestamp)
|
||||
.elasticity_multiplier as u64
|
||||
} else {
|
||||
parent.gas_limit as u64
|
||||
parent.gas_limit
|
||||
};
|
||||
|
||||
// Check for an increase in gas limit beyond the allowed threshold.
|
||||
|
||||
if header.gas_limit as u64 > parent_gas_limit {
|
||||
if header.gas_limit as u64 - parent_gas_limit >=
|
||||
parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR
|
||||
{
|
||||
if header.gas_limit > parent_gas_limit {
|
||||
if header.gas_limit - parent_gas_limit >= parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR {
|
||||
return Err(ConsensusError::GasLimitInvalidIncrease {
|
||||
parent_gas_limit,
|
||||
child_gas_limit: header.gas_limit as u64,
|
||||
child_gas_limit: header.gas_limit,
|
||||
})
|
||||
}
|
||||
}
|
||||
// Check for a decrease in gas limit beyond the allowed threshold.
|
||||
else if parent_gas_limit - header.gas_limit as u64 >=
|
||||
parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR
|
||||
else if parent_gas_limit - header.gas_limit >= parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR
|
||||
{
|
||||
return Err(ConsensusError::GasLimitInvalidDecrease {
|
||||
parent_gas_limit,
|
||||
child_gas_limit: header.gas_limit as u64,
|
||||
child_gas_limit: header.gas_limit,
|
||||
})
|
||||
}
|
||||
// Check if the self gas limit is below the minimum required limit.
|
||||
else if header.gas_limit < MINIMUM_GAS_LIMIT.into() {
|
||||
return Err(ConsensusError::GasLimitInvalidMinimum {
|
||||
child_gas_limit: header.gas_limit as u64,
|
||||
})
|
||||
else if header.gas_limit < MINIMUM_GAS_LIMIT {
|
||||
return Err(ConsensusError::GasLimitInvalidMinimum { child_gas_limit: header.gas_limit })
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -238,7 +233,7 @@ mod tests {
|
||||
use reth_primitives::proofs;
|
||||
|
||||
fn header_with_gas_limit(gas_limit: u64) -> SealedHeader {
|
||||
let header = Header { gas_limit: gas_limit.into(), ..Default::default() };
|
||||
let header = Header { gas_limit, ..Default::default() };
|
||||
SealedHeader::new(header, B256::ZERO)
|
||||
}
|
||||
|
||||
@ -270,15 +265,15 @@ mod tests {
|
||||
fn test_invalid_gas_limit_increase_exceeding_limit() {
|
||||
let parent = header_with_gas_limit(GAS_LIMIT_BOUND_DIVISOR * 10);
|
||||
let child = header_with_gas_limit(
|
||||
(parent.gas_limit + parent.gas_limit / GAS_LIMIT_BOUND_DIVISOR as u128 + 1) as u64,
|
||||
parent.gas_limit + parent.gas_limit / GAS_LIMIT_BOUND_DIVISOR + 1,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
EthBeaconConsensus::new(Arc::new(ChainSpec::default()))
|
||||
.validate_against_parent_gas_limit(&child, &parent),
|
||||
Err(ConsensusError::GasLimitInvalidIncrease {
|
||||
parent_gas_limit: parent.gas_limit as u64,
|
||||
child_gas_limit: child.gas_limit as u64,
|
||||
parent_gas_limit: parent.gas_limit,
|
||||
child_gas_limit: child.gas_limit,
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -286,7 +281,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_valid_gas_limit_decrease_within_limit() {
|
||||
let parent = header_with_gas_limit(GAS_LIMIT_BOUND_DIVISOR * 10);
|
||||
let child = header_with_gas_limit(parent.gas_limit as u64 - 5);
|
||||
let child = header_with_gas_limit(parent.gas_limit - 5);
|
||||
|
||||
assert_eq!(
|
||||
EthBeaconConsensus::new(Arc::new(ChainSpec::default()))
|
||||
@ -299,15 +294,15 @@ mod tests {
|
||||
fn test_invalid_gas_limit_decrease_exceeding_limit() {
|
||||
let parent = header_with_gas_limit(GAS_LIMIT_BOUND_DIVISOR * 10);
|
||||
let child = header_with_gas_limit(
|
||||
(parent.gas_limit - parent.gas_limit / GAS_LIMIT_BOUND_DIVISOR as u128 - 1) as u64,
|
||||
parent.gas_limit - parent.gas_limit / GAS_LIMIT_BOUND_DIVISOR - 1,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
EthBeaconConsensus::new(Arc::new(ChainSpec::default()))
|
||||
.validate_against_parent_gas_limit(&child, &parent),
|
||||
Err(ConsensusError::GasLimitInvalidDecrease {
|
||||
parent_gas_limit: parent.gas_limit as u64,
|
||||
child_gas_limit: child.gas_limit as u64,
|
||||
parent_gas_limit: parent.gas_limit,
|
||||
child_gas_limit: child.gas_limit,
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -319,7 +314,7 @@ mod tests {
|
||||
let chain_spec = Arc::new(ChainSpecBuilder::mainnet().shanghai_activated().build());
|
||||
|
||||
let sealed = Header {
|
||||
base_fee_per_gas: Some(1337u128),
|
||||
base_fee_per_gas: Some(1337),
|
||||
withdrawals_root: Some(proofs::calculate_withdrawals_root(&[])),
|
||||
..Default::default()
|
||||
}
|
||||
|
||||
@ -16,9 +16,9 @@ pub fn validate_block_post_execution<ChainSpec: EthereumHardforks>(
|
||||
// Check if gas used matches the value set in header.
|
||||
let cumulative_gas_used =
|
||||
receipts.last().map(|receipt| receipt.cumulative_gas_used).unwrap_or(0);
|
||||
if block.gas_used as u64 != cumulative_gas_used {
|
||||
if block.gas_used != cumulative_gas_used {
|
||||
return Err(ConsensusError::BlockGasUsed {
|
||||
gas: GotExpected { got: cumulative_gas_used, expected: block.gas_used as u64 },
|
||||
gas: GotExpected { got: cumulative_gas_used, expected: block.gas_used },
|
||||
gas_spent_by_tx: gas_spent_by_transactions(receipts),
|
||||
})
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ where
|
||||
for (sender, transaction) in block.transactions_with_sender() {
|
||||
// The sum of the transaction’s gas limit, Tg, and the gas utilized in this block prior,
|
||||
// must be no greater than the block’s gasLimit.
|
||||
let block_available_gas = (block.header.gas_limit - cumulative_gas_used) as u64;
|
||||
let block_available_gas = block.header.gas_limit - cumulative_gas_used;
|
||||
if transaction.gas_limit() > block_available_gas {
|
||||
return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
|
||||
transaction_gas_limit: transaction.gas_limit(),
|
||||
@ -189,7 +189,7 @@ where
|
||||
evm.db_mut().commit(state);
|
||||
|
||||
// append gas used
|
||||
cumulative_gas_used += result.gas_used() as u128;
|
||||
cumulative_gas_used += result.gas_used();
|
||||
|
||||
// Push transaction changeset and calculate header bloom filter for receipt.
|
||||
receipts.push(
|
||||
@ -199,7 +199,7 @@ where
|
||||
// Success flag was added in `EIP-658: Embedding transaction status code in
|
||||
// receipts`.
|
||||
success: result.is_success(),
|
||||
cumulative_gas_used: cumulative_gas_used as u64,
|
||||
cumulative_gas_used,
|
||||
// convert to reth log
|
||||
logs: result.into_logs(),
|
||||
..Default::default()
|
||||
@ -225,7 +225,7 @@ where
|
||||
vec![]
|
||||
};
|
||||
|
||||
Ok(EthExecuteOutput { receipts, requests, gas_used: cumulative_gas_used as u64 })
|
||||
Ok(EthExecuteOutput { receipts, requests, gas_used: cumulative_gas_used })
|
||||
}
|
||||
}
|
||||
|
||||
@ -808,7 +808,7 @@ mod tests {
|
||||
timestamp: 1,
|
||||
number: 1,
|
||||
parent_beacon_block_root: Some(B256::with_last_byte(0x69)),
|
||||
base_fee_per_gas: Some(u64::MAX.into()),
|
||||
base_fee_per_gas: Some(u64::MAX),
|
||||
excess_blob_gas: Some(0),
|
||||
..Header::default()
|
||||
};
|
||||
@ -1250,7 +1250,7 @@ mod tests {
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(chain_spec.chain.id()),
|
||||
nonce: 1,
|
||||
gas_price: header.base_fee_per_gas.unwrap(),
|
||||
gas_price: header.base_fee_per_gas.unwrap().into(),
|
||||
gas_limit: 134_807,
|
||||
to: TxKind::Call(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS),
|
||||
// `MIN_WITHDRAWAL_REQUEST_FEE`
|
||||
@ -1337,7 +1337,7 @@ mod tests {
|
||||
Transaction::Legacy(TxLegacy {
|
||||
chain_id: Some(chain_spec.chain.id()),
|
||||
nonce: 1,
|
||||
gas_price: header.base_fee_per_gas.unwrap(),
|
||||
gas_price: header.base_fee_per_gas.unwrap().into(),
|
||||
gas_limit: 2_500_000, // higher than block gas limit
|
||||
to: TxKind::Call(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS),
|
||||
value: U256::from(1),
|
||||
|
||||
@ -145,7 +145,7 @@ impl ConfigureEvmEnv for EthEvmConfig {
|
||||
None
|
||||
}
|
||||
})
|
||||
.map(|excess_blob_gas| BlobExcessGasAndPrice::new(excess_blob_gas as u64));
|
||||
.map(BlobExcessGasAndPrice::new);
|
||||
|
||||
let mut basefee = parent.next_block_base_fee(
|
||||
self.chain_spec.base_fee_params_at_timestamp(attributes.timestamp),
|
||||
@ -165,7 +165,7 @@ impl ConfigureEvmEnv for EthEvmConfig {
|
||||
gas_limit *= U256::from(elasticity_multiplier);
|
||||
|
||||
// set the base fee to the initial base fee from the EIP-1559 spec
|
||||
basefee = Some(EIP1559_INITIAL_BASE_FEE.into())
|
||||
basefee = Some(EIP1559_INITIAL_BASE_FEE)
|
||||
}
|
||||
|
||||
let block_env = BlockEnv {
|
||||
|
||||
@ -390,7 +390,7 @@ where
|
||||
excess_blob_gas = if chain_spec.is_cancun_active_at_timestamp(parent_block.timestamp) {
|
||||
let parent_excess_blob_gas = parent_block.excess_blob_gas.unwrap_or_default();
|
||||
let parent_blob_gas_used = parent_block.blob_gas_used.unwrap_or_default();
|
||||
Some(calc_excess_blob_gas(parent_excess_blob_gas as u64, parent_blob_gas_used as u64))
|
||||
Some(calc_excess_blob_gas(parent_excess_blob_gas, parent_blob_gas_used))
|
||||
} else {
|
||||
// for the first post-fork block, both parent.blob_gas_used and
|
||||
// parent.excess_blob_gas are evaluated as 0
|
||||
@ -412,11 +412,11 @@ where
|
||||
timestamp: attributes.timestamp,
|
||||
mix_hash: attributes.prev_randao,
|
||||
nonce: BEACON_NONCE.into(),
|
||||
base_fee_per_gas: Some(base_fee.into()),
|
||||
base_fee_per_gas: Some(base_fee),
|
||||
number: parent_block.number + 1,
|
||||
gas_limit: block_gas_limit.into(),
|
||||
gas_limit: block_gas_limit,
|
||||
difficulty: U256::ZERO,
|
||||
gas_used: cumulative_gas_used.into(),
|
||||
gas_used: cumulative_gas_used,
|
||||
extra_data,
|
||||
parent_beacon_block_root: attributes.parent_beacon_block_root,
|
||||
blob_gas_used: blob_gas_used.map(Into::into),
|
||||
|
||||
Reference in New Issue
Block a user