Skip to content

Commit

Permalink
Do Moonriver and Moonbeam runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshOrndorff committed Oct 26, 2021
1 parent b24544b commit 1f9bc56
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion node/service/src/chain_spec/moonbeam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub fn testnet_genesis(
accounts: Precompiles::used_addresses()
.map(|addr| {
(
addr,
addr.into(),
GenesisAccount {
nonce: Default::default(),
balance: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion node/service/src/chain_spec/moonriver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub fn testnet_genesis(
accounts: Precompiles::used_addresses()
.map(|addr| {
(
addr,
addr.into(),
GenesisAccount {
nonce: Default::default(),
balance: Default::default(),
Expand Down
27 changes: 24 additions & 3 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use account::AccountId20;
use cumulus_pallet_parachain_system::RelaychainBlockNumberProvider;
use fp_rpc::TransactionStatus;
use frame_support::{
Expand All @@ -50,7 +51,7 @@ use pallet_ethereum::Call::transact;
use pallet_ethereum::Transaction as EthereumTransaction;
use pallet_evm::{
Account as EVMAccount, EnsureAddressNever, EnsureAddressRoot, FeeCalculator, GasWeightMapping,
IdentityAddressMapping, Runner,
Runner,
};
use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment};
pub use parachain_staking::{InflationInfo, Range};
Expand Down Expand Up @@ -369,21 +370,41 @@ impl FeeCalculator for FixedGasPrice {
pub type SlowAdjustingFeeUpdate<R> =
TargetedFeeAdjustment<R, TargetBlockFullness, AdjustmentVariable, MinimumMultiplier>;

use frame_support::traits::FindAuthor;
//TODO It feels like this shold be able to work for any T: H160, but I tried for
// embarassingly long and couldn't figure that out.

/// The author inherent provides a AccountId20, but pallet evm needs an H160.
/// This simple adapter makes the conversion.
pub struct FindAuthorAdapter<Inner>(sp_std::marker::PhantomData<Inner>);

impl<Inner> FindAuthor<H160> for FindAuthorAdapter<Inner>
where
Inner: FindAuthor<AccountId20>,
{
fn find_author<'a, I>(digests: I) -> Option<H160>
where
I: 'a + IntoIterator<Item = (sp_runtime::ConsensusEngineId, &'a [u8])>,
{
Inner::find_author(digests).map(Into::into)
}
}

impl pallet_evm::Config for Runtime {
type FeeCalculator = FixedGasPrice;
type GasWeightMapping = MoonbeamGasWeightMapping;
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;
type CallOrigin = EnsureAddressRoot<AccountId>;
type WithdrawOrigin = EnsureAddressNever<AccountId>;
type AddressMapping = IdentityAddressMapping;
type AddressMapping = runtime_common::IntoAddressMapping;
type Currency = Balances;
type Event = Event;
type Runner = pallet_evm::runner::stack::Runner<Self>;
type Precompiles = MoonbeamPrecompiles<Self>;
type ChainId = EthereumChainId;
type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees<Runtime>>;
type BlockGasLimit = BlockGasLimit;
type FindAuthor = AuthorInherent;
type FindAuthor = FindAuthorAdapter<AuthorInherent>;
}

parameter_types! {
Expand Down
27 changes: 24 additions & 3 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use account::AccountId20;
use cumulus_pallet_parachain_system::RelaychainBlockNumberProvider;
use fp_rpc::TransactionStatus;
use frame_support::{
Expand All @@ -50,7 +51,7 @@ use pallet_ethereum::Call::transact;
use pallet_ethereum::Transaction as EthereumTransaction;
use pallet_evm::{
Account as EVMAccount, EnsureAddressNever, EnsureAddressRoot, FeeCalculator, GasWeightMapping,
IdentityAddressMapping, Runner,
Runner,
};
use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment};
pub use parachain_staking::{InflationInfo, Range};
Expand Down Expand Up @@ -349,21 +350,41 @@ impl FeeCalculator for FixedGasPrice {
pub type SlowAdjustingFeeUpdate<R> =
TargetedFeeAdjustment<R, TargetBlockFullness, AdjustmentVariable, MinimumMultiplier>;

use frame_support::traits::FindAuthor;
//TODO It feels like this shold be able to work for any T: H160, but I tried for
// embarassingly long and couldn't figure that out.

/// The author inherent provides a AccountId20, but pallet evm needs an H160.
/// This simple adapter makes the conversion.
pub struct FindAuthorAdapter<Inner>(sp_std::marker::PhantomData<Inner>);

impl<Inner> FindAuthor<H160> for FindAuthorAdapter<Inner>
where
Inner: FindAuthor<AccountId20>,
{
fn find_author<'a, I>(digests: I) -> Option<H160>
where
I: 'a + IntoIterator<Item = (sp_runtime::ConsensusEngineId, &'a [u8])>,
{
Inner::find_author(digests).map(Into::into)
}
}

impl pallet_evm::Config for Runtime {
type FeeCalculator = FixedGasPrice;
type GasWeightMapping = MoonbeamGasWeightMapping;
type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping<Self>;
type CallOrigin = EnsureAddressRoot<AccountId>;
type WithdrawOrigin = EnsureAddressNever<AccountId>;
type AddressMapping = IdentityAddressMapping;
type AddressMapping = runtime_common::IntoAddressMapping;
type Currency = Balances;
type Event = Event;
type Runner = pallet_evm::runner::stack::Runner<Self>;
type Precompiles = MoonriverPrecompiles<Self>;
type ChainId = EthereumChainId;
type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, DealWithFees<Runtime>>;
type BlockGasLimit = BlockGasLimit;
type FindAuthor = AuthorInherent;
type FindAuthor = FindAuthorAdapter<AuthorInherent>;
}

parameter_types! {
Expand Down

0 comments on commit 1f9bc56

Please sign in to comment.