-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Evm part 2 #1349
Merged
Merged
Evm part 2 #1349
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
05e8ba7
Cleanup un-addressed feedback from initial EVM PR
23c25d3
Split some EVM parts out to common
3805d6c
Add EVM to Altair and Centrifuge runtime
93598c2
Add EVM node support to altair & centrifuge
95c6c71
Remove non-evm service fns
084861b
Remove unused dynamic_fee data provider
77d2475
fix lints
092f96c
Subalfred
cb14406
Filter EVM create at transaction check time
fbee4e7
Update runtime/altair/src/evm.rs
c95f77a
Add EVM configuration to CLI
8438027
Move WEIGHT_PER_GAS constant to common
c4bbe7a
Merge remote-tracking branch 'origin/main' into evm-part-2
6296d3a
Merge remote-tracking branch 'origin/evm-part-2' into evm-part-2
82cc485
Add EVM Chain ID migration to Centrifuge and Altair
a2ea6bb
Allow clippy lint in code from Frontier template
8dfece4
Unify account conversion for EVM and Connectors
2dfcb78
Add a few more comments
e00fdc7
Add tests for account conversion
9b861ea
Update endowed EVM accounts to account for new conversion
3e3146f
taplo fmt
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2023 Centrifuge Foundation (centrifuge.io). | ||
// | ||
// This file is part of the Centrifuge chain project. | ||
// Centrifuge is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version (see http://www.gnu.org/licenses). | ||
// Centrifuge is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
use cfg_primitives::{MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO}; | ||
use frame_support::{parameter_types, traits::FindAuthor, weights::Weight, ConsensusEngineId}; | ||
use pallet_evm::{EnsureAddressRoot, EnsureAddressTruncated}; | ||
use runtime_common::evm::{ | ||
precompile::CentrifugePrecompiles, BaseFeeThreshold, ExpandedAddressMapping, WEIGHT_PER_GAS, | ||
}; | ||
use sp_core::{crypto::ByteArray, H160, U256}; | ||
use sp_runtime::Permill; | ||
use sp_std::marker::PhantomData; | ||
|
||
use crate::Aura; | ||
|
||
/// To create valid Ethereum-compatible blocks, we need a 20-byte | ||
/// "author" for the block. Since that author is purely informational, | ||
/// we do a simple truncation of the 32-byte Substrate author | ||
pub struct FindAuthorTruncated<F>(PhantomData<F>); | ||
impl<F: FindAuthor<u32>> FindAuthor<H160> for FindAuthorTruncated<F> { | ||
fn find_author<'a, I>(digests: I) -> Option<H160> | ||
where | ||
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>, | ||
{ | ||
if let Some(author_index) = F::find_author(digests) { | ||
let authority_id = Aura::authorities()[author_index as usize].clone(); | ||
return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24])); | ||
} | ||
None | ||
} | ||
} | ||
|
||
parameter_types! { | ||
pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS); | ||
pub PrecompilesValue: CentrifugePrecompiles<crate::Runtime> = CentrifugePrecompiles::<_>::new(); | ||
pub WeightPerGas: Weight = Weight::from_ref_time(WEIGHT_PER_GAS); | ||
} | ||
|
||
impl pallet_evm::Config for crate::Runtime { | ||
type AddressMapping = ExpandedAddressMapping; | ||
type BlockGasLimit = BlockGasLimit; | ||
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>; | ||
type CallOrigin = EnsureAddressRoot<crate::AccountId>; | ||
type ChainId = crate::EVMChainId; | ||
type Currency = crate::Balances; | ||
type FeeCalculator = crate::BaseFee; | ||
type FindAuthor = FindAuthorTruncated<Aura>; | ||
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>; | ||
type OnChargeTransaction = (); | ||
type PrecompilesType = CentrifugePrecompiles<Self>; | ||
type PrecompilesValue = PrecompilesValue; | ||
type Runner = pallet_evm::runner::stack::Runner<Self>; | ||
type RuntimeEvent = crate::RuntimeEvent; | ||
type WeightPerGas = WeightPerGas; | ||
type WithdrawOrigin = EnsureAddressTruncated; | ||
} | ||
|
||
impl pallet_evm_chain_id::Config for crate::Runtime {} | ||
|
||
parameter_types! { | ||
pub DefaultBaseFeePerGas: U256 = U256::from(1_000_000_000); | ||
pub DefaultElasticity: Permill = Permill::from_parts(125_000); | ||
} | ||
|
||
impl pallet_base_fee::Config for crate::Runtime { | ||
type DefaultBaseFeePerGas = DefaultBaseFeePerGas; | ||
type DefaultElasticity = DefaultElasticity; | ||
type RuntimeEvent = crate::RuntimeEvent; | ||
type Threshold = BaseFeeThreshold; | ||
} | ||
|
||
impl pallet_ethereum::Config for crate::Runtime { | ||
type RuntimeEvent = crate::RuntimeEvent; | ||
type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of runtime-agnostic trait impl could to to
runtime-commons
and just be referenced in the different runtimes instead of duplicated in all of them 🧹There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it needs to be made generic over the Runtime (that
Aura
in there is reallypallet_aura::Pallet::<Runtime>
), but indeed could be made properly runtime agnostic. Worth doing for sureThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, my bad, I didn't spot the
Aura
bit 🙃 I don't know how to make stuff generic over a runtime when referencing a specific pallet from that runtime tho.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add a
Get<Vec<Authorities>>
and impl that for Aura in the actual runtime. But feel like this makes it more opaque than actually easier to understand.