mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(no-std): add no_std support for reth-optimism-consensus (#13692)
This commit is contained in:
@ -38,4 +38,19 @@ op-alloy-consensus.workspace = true
|
|||||||
reth-optimism-chainspec.workspace = true
|
reth-optimism-chainspec.workspace = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
default = ["std"]
|
||||||
|
std = [
|
||||||
|
"reth-chainspec/std",
|
||||||
|
"reth-consensus/std",
|
||||||
|
"reth-consensus-common/std",
|
||||||
|
"reth-primitives/std",
|
||||||
|
"reth-optimism-forks/std",
|
||||||
|
"reth-optimism-chainspec/std",
|
||||||
|
"reth-optimism-primitives/std",
|
||||||
|
"alloy-eips/std",
|
||||||
|
"alloy-primitives/std",
|
||||||
|
"alloy-consensus/std",
|
||||||
|
"alloy-trie/std",
|
||||||
|
"op-alloy-consensus/std",
|
||||||
|
]
|
||||||
optimism = ["reth-primitives/optimism", "reth-optimism-primitives/optimism"]
|
optimism = ["reth-primitives/optimism", "reth-optimism-primitives/optimism"]
|
||||||
|
|||||||
@ -6,9 +6,13 @@
|
|||||||
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
|
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
|
||||||
)]
|
)]
|
||||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||||
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
// The `optimism` feature must be enabled to use this crate.
|
// The `optimism` feature must be enabled to use this crate.
|
||||||
#![cfg(feature = "optimism")]
|
#![cfg(feature = "optimism")]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
use alloc::sync::Arc;
|
||||||
use alloy_consensus::{BlockHeader, Header, EMPTY_OMMER_ROOT_HASH};
|
use alloy_consensus::{BlockHeader, Header, EMPTY_OMMER_ROOT_HASH};
|
||||||
use alloy_eips::eip7840::BlobParams;
|
use alloy_eips::eip7840::BlobParams;
|
||||||
use alloy_primitives::{B64, U256};
|
use alloy_primitives::{B64, U256};
|
||||||
@ -26,7 +30,6 @@ use reth_optimism_chainspec::OpChainSpec;
|
|||||||
use reth_optimism_forks::OpHardforks;
|
use reth_optimism_forks::OpHardforks;
|
||||||
use reth_optimism_primitives::{OpBlock, OpBlockBody, OpPrimitives, OpReceipt};
|
use reth_optimism_primitives::{OpBlock, OpBlockBody, OpPrimitives, OpReceipt};
|
||||||
use reth_primitives::{BlockWithSenders, GotExpected, SealedBlockFor, SealedHeader};
|
use reth_primitives::{BlockWithSenders, GotExpected, SealedBlockFor, SealedHeader};
|
||||||
use std::{sync::Arc, time::SystemTime};
|
|
||||||
|
|
||||||
mod proof;
|
mod proof;
|
||||||
pub use proof::calculate_receipt_root_no_memo_optimism;
|
pub use proof::calculate_receipt_root_no_memo_optimism;
|
||||||
@ -157,43 +160,33 @@ impl HeaderValidator for OpBeaconConsensus {
|
|||||||
_total_difficulty: U256,
|
_total_difficulty: U256,
|
||||||
) -> Result<(), ConsensusError> {
|
) -> Result<(), ConsensusError> {
|
||||||
// with OP-stack Bedrock activation number determines when TTD (eth Merge) has been reached.
|
// with OP-stack Bedrock activation number determines when TTD (eth Merge) has been reached.
|
||||||
let is_post_merge = self.chain_spec.is_bedrock_active_at_block(header.number);
|
debug_assert!(
|
||||||
|
self.chain_spec.is_bedrock_active_at_block(header.number),
|
||||||
|
"manually import OVM blocks"
|
||||||
|
);
|
||||||
|
|
||||||
if is_post_merge {
|
if header.nonce != B64::ZERO {
|
||||||
if header.nonce != B64::ZERO {
|
return Err(ConsensusError::TheMergeNonceIsNotZero)
|
||||||
return Err(ConsensusError::TheMergeNonceIsNotZero)
|
|
||||||
}
|
|
||||||
|
|
||||||
if header.ommers_hash != EMPTY_OMMER_ROOT_HASH {
|
|
||||||
return Err(ConsensusError::TheMergeOmmerRootIsNotEmpty)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Post-merge, the consensus layer is expected to perform checks such that the block
|
|
||||||
// timestamp is a function of the slot. This is different from pre-merge, where blocks
|
|
||||||
// are only allowed to be in the future (compared to the system's clock) by a certain
|
|
||||||
// threshold.
|
|
||||||
//
|
|
||||||
// Block validation with respect to the parent should ensure that the block timestamp
|
|
||||||
// is greater than its parent timestamp.
|
|
||||||
|
|
||||||
// validate header extra data for all networks post merge
|
|
||||||
validate_header_extra_data(header)?;
|
|
||||||
|
|
||||||
// mixHash is used instead of difficulty inside EVM
|
|
||||||
// https://eips.ethereum.org/EIPS/eip-4399#using-mixhash-field-instead-of-difficulty
|
|
||||||
} else {
|
|
||||||
// Check if timestamp is in the future. Clock can drift but this can be consensus issue.
|
|
||||||
let present_timestamp =
|
|
||||||
SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
|
|
||||||
|
|
||||||
if header.exceeds_allowed_future_timestamp(present_timestamp) {
|
|
||||||
return Err(ConsensusError::TimestampIsInFuture {
|
|
||||||
timestamp: header.timestamp,
|
|
||||||
present_timestamp,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if header.ommers_hash != EMPTY_OMMER_ROOT_HASH {
|
||||||
|
return Err(ConsensusError::TheMergeOmmerRootIsNotEmpty)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Post-merge, the consensus layer is expected to perform checks such that the block
|
||||||
|
// timestamp is a function of the slot. This is different from pre-merge, where blocks
|
||||||
|
// are only allowed to be in the future (compared to the system's clock) by a certain
|
||||||
|
// threshold.
|
||||||
|
//
|
||||||
|
// Block validation with respect to the parent should ensure that the block timestamp
|
||||||
|
// is greater than its parent timestamp.
|
||||||
|
|
||||||
|
// validate header extra data for all networks post merge
|
||||||
|
validate_header_extra_data(header)?;
|
||||||
|
|
||||||
|
// mixHash is used instead of difficulty inside EVM
|
||||||
|
// https://eips.ethereum.org/EIPS/eip-4399#using-mixhash-field-instead-of-difficulty
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
//! Helper function for Receipt root calculation for Optimism hardforks.
|
//! Helper function for Receipt root calculation for Optimism hardforks.
|
||||||
|
|
||||||
|
use alloc::vec::Vec;
|
||||||
use alloy_consensus::TxReceipt;
|
use alloy_consensus::TxReceipt;
|
||||||
use alloy_eips::eip2718::Encodable2718;
|
use alloy_eips::eip2718::Encodable2718;
|
||||||
use alloy_primitives::B256;
|
use alloy_primitives::B256;
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use crate::proof::calculate_receipt_root_optimism;
|
use crate::proof::calculate_receipt_root_optimism;
|
||||||
|
use alloc::vec::Vec;
|
||||||
use alloy_consensus::TxReceipt;
|
use alloy_consensus::TxReceipt;
|
||||||
use alloy_primitives::{Bloom, B256};
|
use alloy_primitives::{Bloom, B256};
|
||||||
use reth_chainspec::{ChainSpec, EthereumHardforks};
|
use reth_chainspec::{ChainSpec, EthereumHardforks};
|
||||||
|
|||||||
@ -74,7 +74,8 @@ std = [
|
|||||||
"thiserror/std",
|
"thiserror/std",
|
||||||
"op-alloy-consensus/std",
|
"op-alloy-consensus/std",
|
||||||
"reth-chainspec/std",
|
"reth-chainspec/std",
|
||||||
"reth-consensus-common/std"
|
"reth-optimism-consensus/std",
|
||||||
|
"reth-consensus-common/std",
|
||||||
]
|
]
|
||||||
optimism = [
|
optimism = [
|
||||||
"reth-primitives/optimism",
|
"reth-primitives/optimism",
|
||||||
|
|||||||
Reference in New Issue
Block a user