From fb76cd09c7b2fb59fd7bc0cd567de66839283305 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 15 Jan 2021 06:21:16 -0500 Subject: [PATCH] Abstract block gas limit (#265) * Update pallet * wire it back to the runtime. * Use U256 max * Fix mock * Keep the value small enough for Polkadot JS --- frame/ethereum/src/lib.rs | 4 +++- frame/ethereum/src/mock.rs | 5 +++++ template/runtime/src/lib.rs | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/frame/ethereum/src/lib.rs b/frame/ethereum/src/lib.rs index 486b25212..0bc0f766b 100644 --- a/frame/ethereum/src/lib.rs +++ b/frame/ethereum/src/lib.rs @@ -79,6 +79,8 @@ pub trait Config: frame_system::Config + pallet_balances::Config + pa type FindAuthor: FindAuthor; /// How Ethereum state root is calculated. type StateRoot: Get; + /// The block gas limit. Can be a simple constant, or an adjustment algorithm in another pallet. + type BlockGasLimit: Get; } decl_storage! { @@ -309,7 +311,7 @@ impl Module { frame_system::Module::::block_number() ) ), - gas_limit: U256::from(u32::max_value()), // TODO: set this using Ethereum's gas limit change algorithm. + gas_limit: T::BlockGasLimit::get(), gas_used: receipts.clone().into_iter().fold(U256::zero(), |acc, r| acc + r.used_gas), timestamp: UniqueSaturatedInto::::unique_saturated_into( pallet_timestamp::Module::::get() diff --git a/frame/ethereum/src/mock.rs b/frame/ethereum/src/mock.rs index 1cb16cd54..edb595151 100644 --- a/frame/ethereum/src/mock.rs +++ b/frame/ethereum/src/mock.rs @@ -149,10 +149,15 @@ impl pallet_evm::Config for Test { type ChainId = ChainId; } +parameter_types! { + pub const BlockGasLimit: U256 = U256::MAX; +} + impl Config for Test { type Event = (); type FindAuthor = EthereumFindAuthor; type StateRoot = IntermediateStateRoot; + type BlockGasLimit = BlockGasLimit; } pub type System = frame_system::Module; diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index fa243554c..0f4ea7383 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -316,10 +316,15 @@ impl> FindAuthor for EthereumFindAuthor } } +parameter_types! { + pub BlockGasLimit: U256 = U256::from(u32::max_value()); +} + impl pallet_ethereum::Config for Runtime { type Event = Event; type FindAuthor = EthereumFindAuthor; type StateRoot = pallet_ethereum::IntermediateStateRoot; + type BlockGasLimit = BlockGasLimit; } // Create the runtime by composing the FRAME pallets that were previously configured.