Skip to content

Commit

Permalink
Abstract block gas limit (#265)
Browse files Browse the repository at this point in the history
* Update pallet

* wire it back to the runtime.

* Use U256 max

* Fix mock

* Keep the value small enough for Polkadot JS
  • Loading branch information
JoshOrndorff authored Jan 15, 2021
1 parent c8cbd55 commit fb76cd0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub trait Config: frame_system::Config<Hash=H256> + pallet_balances::Config + pa
type FindAuthor: FindAuthor<H160>;
/// How Ethereum state root is calculated.
type StateRoot: Get<H256>;
/// The block gas limit. Can be a simple constant, or an adjustment algorithm in another pallet.
type BlockGasLimit: Get<U256>;
}

decl_storage! {
Expand Down Expand Up @@ -309,7 +311,7 @@ impl<T: Config> Module<T> {
frame_system::Module::<T>::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::<u64>::unique_saturated_into(
pallet_timestamp::Module::<T>::get()
Expand Down
5 changes: 5 additions & 0 deletions frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test>;
Expand Down
5 changes: 5 additions & 0 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,15 @@ impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F>
}
}

parameter_types! {
pub BlockGasLimit: U256 = U256::from(u32::max_value());
}

impl pallet_ethereum::Config for Runtime {
type Event = Event;
type FindAuthor = EthereumFindAuthor<Aura>;
type StateRoot = pallet_ethereum::IntermediateStateRoot;
type BlockGasLimit = BlockGasLimit;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
Expand Down

0 comments on commit fb76cd0

Please sign in to comment.