diff --git a/frame/ethereum/src/lib.rs b/frame/ethereum/src/lib.rs index f351101510..3a474bfdf5 100644 --- a/frame/ethereum/src/lib.rs +++ b/frame/ethereum/src/lib.rs @@ -163,6 +163,13 @@ where } } +#[derive(Copy, Clone, Eq, PartialEq, Default)] +pub enum PostLogContent { + #[default] + BlockAndTxnHashes, + OnlyBlockHash, +} + pub use self::pallet::*; #[frame_support::pallet] @@ -185,13 +192,18 @@ pub mod pallet { type RuntimeEvent: From + IsType<::RuntimeEvent>; /// How Ethereum state root is calculated. type StateRoot: Get; + /// What's included in the PostLog. + type PostLogContent: Get; } #[pallet::hooks] impl Hooks> for Pallet { fn on_finalize(n: T::BlockNumber) { >::store_block( - fp_consensus::find_pre_log(&frame_system::Pallet::::digest()).is_err(), + match fp_consensus::find_pre_log(&frame_system::Pallet::::digest()) { + Ok(_) => None, + Err(_) => Some(T::PostLogContent::get()), + }, U256::from(UniqueSaturatedInto::::unique_saturated_into( frame_system::Pallet::::block_number(), )), @@ -332,7 +344,7 @@ pub mod pallet { #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { - >::store_block(false, U256::zero()); + >::store_block(None, U256::zero()); frame_support::storage::unhashed::put::( PALLET_ETHEREUM_SCHEMA, &EthereumStorageSchema::V3, @@ -375,7 +387,7 @@ impl Pallet { Some(H160::from(H256::from(sp_io::hashing::keccak_256(&pubkey)))) } - fn store_block(post_log: bool, block_number: U256) { + fn store_block(post_log: Option, block_number: U256) { let mut transactions = Vec::new(); let mut statuses = Vec::new(); let mut receipts = Vec::new(); @@ -426,12 +438,22 @@ impl Pallet { CurrentTransactionStatuses::::put(statuses.clone()); BlockHash::::insert(block_number, block.header.hash()); - if post_log { - let digest = DigestItem::Consensus( - FRONTIER_ENGINE_ID, - PostLog::Hashes(fp_consensus::Hashes::from_block(block)).encode(), - ); - frame_system::Pallet::::deposit_log(digest); + match post_log { + Some(PostLogContent::BlockAndTxnHashes) => { + let digest = DigestItem::Consensus( + FRONTIER_ENGINE_ID, + PostLog::Hashes(fp_consensus::Hashes::from_block(block)).encode(), + ); + frame_system::Pallet::::deposit_log(digest); + } + Some(PostLogContent::OnlyBlockHash) => { + let digest = DigestItem::Consensus( + FRONTIER_ENGINE_ID, + PostLog::BlockHash(block.header.hash()).encode(), + ); + frame_system::Pallet::::deposit_log(digest); + } + None => { /* do nothing*/ } } } diff --git a/frame/ethereum/src/mock.rs b/frame/ethereum/src/mock.rs index 4928dca369..5e41224e9d 100644 --- a/frame/ethereum/src/mock.rs +++ b/frame/ethereum/src/mock.rs @@ -143,7 +143,6 @@ parameter_types! { } pub struct HashedAddressMapping; - impl AddressMapping for HashedAddressMapping { fn into_account_id(address: H160) -> AccountId32 { let mut data = [0u8; 32]; @@ -172,9 +171,14 @@ impl pallet_evm::Config for Test { type FindAuthor = FindAuthorTruncated; } +parameter_types! { + pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes; +} + impl Config for Test { type RuntimeEvent = RuntimeEvent; type StateRoot = IntermediateStateRoot; + type PostLogContent = PostBlockAndTxnHashes; } impl fp_self_contained::SelfContainedCall for RuntimeCall { diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index 2fbea2d6e0..4b0aec6759 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -44,7 +44,7 @@ use pallet_transaction_payment::CurrencyAdapter; // Frontier use fp_evm::weight_per_gas; use fp_rpc::TransactionStatus; -use pallet_ethereum::{Call::transact, Transaction as EthereumTransaction}; +use pallet_ethereum::{Call::transact, PostLogContent, Transaction as EthereumTransaction}; use pallet_evm::{ Account as EVMAccount, EnsureAddressTruncated, FeeCalculator, HashedAddressMapping, Runner, }; @@ -345,9 +345,14 @@ impl pallet_evm::Config for Runtime { type FindAuthor = FindAuthorTruncated; } +parameter_types! { + pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes; +} + impl pallet_ethereum::Config for Runtime { type RuntimeEvent = RuntimeEvent; type StateRoot = pallet_ethereum::IntermediateStateRoot; + type PostLogContent = PostBlockAndTxnHashes; } parameter_types! {