Skip to content
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

Release branch polkadot-v1.0.0 #1123

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
683 changes: 381 additions & 302 deletions Cargo.lock

Large diffs are not rendered by default.

131 changes: 66 additions & 65 deletions Cargo.toml

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions client/rpc/src/eth/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ use scale_codec::{Decode, Encode};
// Substrate
use sc_client_api::backend::{Backend, StorageProvider};
use sc_transaction_pool::ChainApi;
use sp_api::{ApiExt, CallApiAt, CallApiAtParams, ProvideRuntimeApi, StorageTransactionCache};
use sp_api::{
ApiExt, CallApiAt, CallApiAtParams, CallContext, Extensions, ProvideRuntimeApi,
StorageTransactionCache,
};
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::HeaderBackend;
use sp_core::ExecutionContext;
use sp_io::hashing::{blake2_128, twox_128};
use sp_runtime::{traits::Block as BlockT, DispatchError, SaturatedConversion};
use sp_state_machine::OverlayedChanges;
Expand Down Expand Up @@ -243,8 +245,9 @@ where
arguments: encoded_params,
overlayed_changes: &RefCell::new(overlayed_changes),
storage_transaction_cache: &storage_transaction_cache,
context: ExecutionContext::OffchainCall(None),
call_context: CallContext::Offchain,
recorder: &None,
extensions: &RefCell::new(Extensions::new()),
};

let value = if api_version == 4 {
Expand Down
11 changes: 6 additions & 5 deletions frame/base-fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::comparison_chain)]
#![deny(unused_crate_dependencies)]
#![warn(unused_crate_dependencies)]

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -56,7 +56,8 @@ pub mod pallet {
pub struct GenesisConfig<T: Config> {
pub base_fee_per_gas: U256,
pub elasticity: Permill,
_marker: PhantomData<T>,
#[serde(skip)]
pub _marker: PhantomData<T>,
}

impl<T: Config> GenesisConfig<T> {
Expand All @@ -80,7 +81,7 @@ pub mod pallet {
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
<BaseFeePerGas<T>>::put(self.base_fee_per_gas);
<Elasticity<T>>::put(self.elasticity);
Expand Down Expand Up @@ -113,7 +114,7 @@ pub mod pallet {

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: T::BlockNumber) -> Weight {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
// Register the Weight used on_finalize.
// - One storage read to get the block_weight.
// - One storage read to get the Elasticity.
Expand All @@ -122,7 +123,7 @@ pub mod pallet {
db_weight.reads_writes(2, 1)
}

fn on_finalize(_n: <T as frame_system::Config>::BlockNumber) {
fn on_finalize(_n: BlockNumberFor<T>) {
if <Elasticity<T>>::get().is_zero() {
// Zero elasticity means constant BaseFeePerGas.
return;
Expand Down
24 changes: 7 additions & 17 deletions frame/base-fee/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,21 @@
use frame_support::{
assert_ok,
dispatch::DispatchClass,
pallet_prelude::GenesisBuild,
parameter_types,
traits::{ConstU32, OnFinalize},
weights::Weight,
};
use sp_core::{H256, U256};
use sp_io::TestExternalities;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
Permill,
BuildStorage, Permill,
};

use super::*;
use crate as pallet_base_fee;
use crate::BaseFeeThreshold as BaseFeeThresholdT;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
Expand All @@ -50,13 +45,12 @@ impl frame_system::Config for Test {
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = frame_system::mocking::MockBlock<Self>;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
type Version = ();
Expand Down Expand Up @@ -96,19 +90,15 @@ impl Config for Test {
}

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
pub enum Test {
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
BaseFee: pallet_base_fee::{Pallet, Call, Storage, Event},
}
);

pub fn new_test_ext(base_fee: Option<U256>, elasticity: Option<Permill>) -> TestExternalities {
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();

match (base_fee, elasticity) {
Expand Down
2 changes: 2 additions & 0 deletions frame/dynamic-fee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
sp-core = { workspace = true }
sp-inherents = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
# Frontier
fp-dynamic-fee = { workspace = true }
Expand All @@ -37,6 +38,7 @@ std = [
# Substrate
"sp-core/std",
"sp-inherents/std",
"sp-runtime/std",
"sp-std/std",
# Substrate
"frame-system/std",
Expand Down
10 changes: 6 additions & 4 deletions frame/dynamic-fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(unused_crate_dependencies)]
#![warn(unused_crate_dependencies)]

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -85,13 +85,15 @@ pub mod pallet {
}

#[pallet::genesis_config]
#[derive(Default)]
pub struct GenesisConfig {
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T> {
pub min_gas_price: U256,
#[serde(skip)]
pub _marker: PhantomData<T>,
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
MinGasPrice::<T>::put(self.min_gas_price);
}
Expand Down
22 changes: 7 additions & 15 deletions frame/dynamic-fee/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,17 @@ use frame_support::{
use sp_core::{H256, U256};
use sp_io::TestExternalities;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};

pub fn new_test_ext() -> TestExternalities {
let t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();
TestExternalities::new(t)
}

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
Expand All @@ -52,13 +49,12 @@ impl frame_system::Config for Test {
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = frame_system::mocking::MockBlock<Self>;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
type Version = ();
Expand Down Expand Up @@ -90,12 +86,8 @@ impl Config for Test {
}

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
pub enum Test {
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage},
DynamicFee: pallet_dynamic_fee::{Pallet, Call, Storage, Inherent},
}
Expand Down
15 changes: 9 additions & 6 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::comparison_chain, clippy::large_enum_variant)]
#![deny(unused_crate_dependencies)]
#![warn(unused_crate_dependencies)]

#[cfg(all(feature = "std", test))]
mod mock;
Expand Down Expand Up @@ -201,7 +201,7 @@ pub mod pallet {

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_finalize(n: T::BlockNumber) {
fn on_finalize(n: BlockNumberFor<T>) {
<Pallet<T>>::store_block(
match fp_consensus::find_pre_log(&frame_system::Pallet::<T>::digest()) {
Ok(_) => None,
Expand All @@ -225,7 +225,7 @@ pub mod pallet {
Pending::<T>::kill();
}

fn on_initialize(_: T::BlockNumber) -> Weight {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
let mut weight = T::SystemWeightInfo::kill_storage(1);

// If the digest contain an existing ethereum block(encoded as PreLog), If contains,
Expand Down Expand Up @@ -337,11 +337,14 @@ pub mod pallet {
pub type BlockHash<T: Config> = StorageMap<_, Twox64Concat, U256, H256, ValueQuery>;

#[pallet::genesis_config]
#[derive(Default)]
pub struct GenesisConfig {}
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T> {
#[serde(skip)]
pub _marker: PhantomData<T>,
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
<Pallet<T>>::store_block(None, U256::zero());
frame_support::storage::unhashed::put::<EthereumStorageSchema>(
Expand Down
29 changes: 10 additions & 19 deletions frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,21 @@ use pallet_evm::{AddressMapping, EnsureAddressTruncated, FeeCalculator};
use rlp::RlpStream;
use sp_core::{hashing::keccak_256, H160, H256, U256};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
AccountId32,
AccountId32, BuildStorage,
};

use super::*;
use crate::IntermediateStateRoot;

pub type SignedExtra = (frame_system::CheckSpecVersion<Test>,);

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test, (), SignedExtra>;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime! {
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
pub enum Test {
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage},
EVM: pallet_evm::{Pallet, Call, Storage, Config, Event<T>},
EVM: pallet_evm::{Pallet, Call, Storage, Config<T>, Event<T>},
Ethereum: crate::{Pallet, Call, Storage, Event, Origin},
}
}
Expand All @@ -67,13 +59,12 @@ impl frame_system::Config for Test {
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId32;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = frame_system::mocking::MockBlock<Self>;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
type Version = ();
Expand Down Expand Up @@ -275,8 +266,8 @@ fn address_build(seed: u8) -> AccountInfo {
// our desired mockup.
pub fn new_test_ext(accounts_len: usize) -> (Vec<AccountInfo>, sp_io::TestExternalities) {
// sc_cli::init_logger("");
let mut ext = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let mut ext = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();

let pairs = (0..accounts_len)
Expand All @@ -301,8 +292,8 @@ pub fn new_test_ext_with_initial_balance(
initial_balance: u64,
) -> (Vec<AccountInfo>, sp_io::TestExternalities) {
// sc_cli::init_logger("");
let mut ext = frame_system::GenesisConfig::default()
.build_storage::<Test>()
let mut ext = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.unwrap();

let pairs = (0..accounts_len)
Expand Down
2 changes: 2 additions & 0 deletions frame/evm-chain-id/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ scale-info = { workspace = true }
# Substrate
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-runtime = { workspace = true }

[features]
default = ["std"]
Expand All @@ -25,6 +26,7 @@ std = [
# Substrate
"frame-support/std",
"frame-system/std",
"sp-runtime/std",
]
try-runtime = [
"frame-support/try-runtime",
Expand Down
10 changes: 6 additions & 4 deletions frame/evm-chain-id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

// Ensure we're `no_std` when compiling for Wasm.
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(unused_crate_dependencies)]
#![warn(unused_crate_dependencies)]

pub use pallet::*;

Expand Down Expand Up @@ -54,13 +54,15 @@ pub mod pallet {
pub type ChainId<T> = StorageValue<_, u64, ValueQuery>;

#[pallet::genesis_config]
#[derive(Default)]
pub struct GenesisConfig {
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T> {
pub chain_id: u64,
#[serde(skip)]
pub _marker: PhantomData<T>,
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
ChainId::<T>::put(self.chain_id);
}
Expand Down
Loading
Loading