-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gregory Hill <[email protected]>
- Loading branch information
Showing
30 changed files
with
3,364 additions
and
494 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,71 @@ | ||
use frame_support::{ | ||
traits::OnRuntimeUpgrade, | ||
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, | ||
}; | ||
use pallet_ethereum::{Transaction, TransactionAction}; | ||
use sp_core::Get; | ||
use sp_runtime::Permill; | ||
use sp_std::marker::PhantomData; | ||
|
||
pub mod precompiles; | ||
|
||
/// Current approximation of the gas/s consumption (Moonbeam) | ||
pub const GAS_PER_SECOND: u64 = 40_000_000; | ||
/// Approximate ratio of the amount of Weight per Gas (Moonbeam) | ||
pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND; | ||
|
||
/// Sets the ideal block fullness to 50%. | ||
/// If the block weight is between: | ||
/// - 0-50% the gas fee will decrease | ||
/// - 50-100% the gas fee will increase | ||
pub struct BaseFeeThreshold; | ||
impl pallet_base_fee::BaseFeeThreshold for BaseFeeThreshold { | ||
fn lower() -> Permill { | ||
Permill::zero() | ||
} | ||
fn ideal() -> Permill { | ||
Permill::from_parts(500_000) | ||
} | ||
fn upper() -> Permill { | ||
Permill::from_parts(1_000_000) | ||
} | ||
} | ||
|
||
/// Get the "action" (call or create) of an Ethereum transaction | ||
pub trait GetTransactionAction { | ||
fn action(&self) -> TransactionAction; | ||
} | ||
|
||
impl GetTransactionAction for Transaction { | ||
fn action(&self) -> TransactionAction { | ||
match self { | ||
Transaction::Legacy(transaction) => transaction.action, | ||
Transaction::EIP2930(transaction) => transaction.action, | ||
Transaction::EIP1559(transaction) => transaction.action, | ||
} | ||
} | ||
} | ||
|
||
/// Set the EVM chain ID based on the parachain ID | ||
pub struct SetEvmChainId<T>(PhantomData<T>); | ||
impl<T> OnRuntimeUpgrade for SetEvmChainId<T> | ||
where | ||
T: frame_system::Config + parachain_info::Config + pallet_evm_chain_id::Config, | ||
{ | ||
fn on_runtime_upgrade() -> Weight { | ||
let para_id: u32 = parachain_info::Pallet::<T>::parachain_id().into(); | ||
let evm_id: u64 = para_id.into(); | ||
pallet_evm_chain_id::ChainId::<T>::put(evm_id); | ||
<T as frame_system::Config>::DbWeight::get().reads_writes(1, 1) | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, &'static str> { | ||
Ok(Default::default()) | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn post_upgrade(_: sp_std::vec::Vec<u8>) -> Result<(), &'static str> { | ||
Ok(()) | ||
} | ||
} |
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,45 @@ | ||
use pallet_evm::{IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet}; | ||
use sp_core::H160; | ||
use sp_std::marker::PhantomData; | ||
|
||
use pallet_evm_precompile_modexp::Modexp; | ||
use pallet_evm_precompile_simple::{ECRecover, Identity, Ripemd160, Sha256}; | ||
|
||
pub struct InterBtcPrecompiles<R>(PhantomData<R>); | ||
|
||
impl<R> InterBtcPrecompiles<R> { | ||
pub fn new() -> Self { | ||
Self(Default::default()) | ||
} | ||
pub fn used_addresses() -> [H160; 5] { | ||
[hash(1), hash(2), hash(3), hash(4), hash(5)] | ||
} | ||
} | ||
|
||
impl<R> PrecompileSet for InterBtcPrecompiles<R> | ||
where | ||
R: pallet_evm::Config, | ||
{ | ||
fn execute(&self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> { | ||
match handle.code_address() { | ||
// Ethereum precompiles: | ||
a if a == hash(1) => Some(ECRecover::execute(handle)), | ||
a if a == hash(2) => Some(Sha256::execute(handle)), | ||
a if a == hash(3) => Some(Ripemd160::execute(handle)), | ||
a if a == hash(4) => Some(Identity::execute(handle)), | ||
a if a == hash(5) => Some(Modexp::execute(handle)), | ||
_ => None, | ||
} | ||
} | ||
|
||
fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult { | ||
IsPrecompileResult::Answer { | ||
is_precompile: Self::used_addresses().contains(&address), | ||
extra_cost: 0, | ||
} | ||
} | ||
} | ||
|
||
fn hash(a: u64) -> H160 { | ||
H160::from_low_u64_be(a) | ||
} |
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
Oops, something went wrong.