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

Delta #83

Draft
wants to merge 1 commit into
base: polkadot-v0.9.37
Choose a base branch
from
Draft
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
1,554 changes: 810 additions & 744 deletions Cargo.lock

Large diffs are not rendered by default.

122 changes: 61 additions & 61 deletions Cargo.toml

Large diffs are not rendered by default.

72 changes: 13 additions & 59 deletions client/rpc/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use jsonrpsee::core::RpcResult as Result;
use sc_client_api::backend::{Backend, StateBackend, StorageProvider};
use sc_network_common::ExHashT;
use sc_transaction_pool::ChainApi;
use sp_api::{BlockId, HeaderT, ProvideRuntimeApi};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_core::hashing::keccak_256;
use sp_runtime::traits::{BlakeTwo256, Block as BlockT};
Expand Down Expand Up @@ -73,40 +73,16 @@ where
.current_transaction_statuses(schema, substrate_hash)
.await;

let base_fee = client.runtime_api().gas_price(&id).ok();
let base_fee = client.runtime_api().gas_price(&id).unwrap_or_default();

match (block, statuses) {
(Some(block), Some(statuses)) => {
let mut rich_block = rich_block_build(
block,
statuses.into_iter().map(Option::Some).collect(),
Some(hash),
full,
base_fee,
);
// Indexers heavily rely on the parent hash.
// Moonbase client-level patch for inconsistent runtime 1200 state.
let number = rich_block.inner.header.number.unwrap_or_default();
if rich_block.inner.header.parent_hash == H256::default() && number > U256::zero() {
if let Ok(Some(header)) = client.header(substrate_hash) {
let parent_hash = *header.parent_hash();

let parent_id = BlockId::Hash(parent_hash);
let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
client.as_ref(),
parent_id,
);
if let Some(block) =
block_data_cache.current_block(schema, parent_hash).await
{
rich_block.inner.header.parent_hash = H256::from_slice(
keccak_256(&rlp::encode(&block.header)).as_slice(),
);
}
}
}
Ok(Some(rich_block))
}
(Some(block), Some(statuses)) => Ok(Some(rich_block_build(
block,
statuses.into_iter().map(Option::Some).collect(),
Some(hash),
full,
Some(base_fee),
))),
_ => Ok(None),
}
}
Expand Down Expand Up @@ -140,41 +116,19 @@ where
.current_transaction_statuses(schema, substrate_hash)
.await;

let base_fee = client.runtime_api().gas_price(&id).ok();
let base_fee = client.runtime_api().gas_price(&id).unwrap_or_default();

match (block, statuses) {
(Some(block), Some(statuses)) => {
let hash = H256::from(keccak_256(&rlp::encode(&block.header)));

let mut rich_block = rich_block_build(
Ok(Some(rich_block_build(
block,
statuses.into_iter().map(Option::Some).collect(),
Some(hash),
full,
base_fee,
);
// Indexers heavily rely on the parent hash.
// Moonbase client-level patch for inconsistent runtime 1200 state.
let number = rich_block.inner.header.number.unwrap_or_default();
if rich_block.inner.header.parent_hash == H256::default() && number > U256::zero() {
if let Ok(Some(header)) = client.header(substrate_hash) {
let parent_hash = *header.parent_hash();

let parent_id = BlockId::Hash(parent_hash);
let schema = frontier_backend_client::onchain_storage_schema::<B, C, BE>(
client.as_ref(),
parent_id,
);
if let Some(block) =
block_data_cache.current_block(schema, parent_hash).await
{
rich_block.inner.header.parent_hash = H256::from_slice(
keccak_256(&rlp::encode(&block.header)).as_slice(),
);
}
}
}
Ok(Some(rich_block))
Some(base_fee),
)))
}
_ => Ok(None),
}
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/src/eth/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ where
let base_fee = client.runtime_api().gas_price(&id).unwrap_or_default();
let receipts = handler.current_receipts(&id);
let mut result = FeeHistoryCacheItem {
base_fee: base_fee.as_u64(),
base_fee: if base_fee > U256::from(u64::MAX) { u64::MAX } else { base_fee.low_u64() },
gas_used_ratio: 0f64,
rewards: Vec::new(),
};
Expand Down
6 changes: 2 additions & 4 deletions client/rpc/src/eth/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ where
}
};

if let Err(sp_blockchain::Error::UnknownBlock(_)) =
self.client.expect_block_hash_from_id(&id)
{
let Ok(_hash) = self.client.expect_block_hash_from_id(&id) else {
return Err(crate::err(JSON_RPC_ERROR_DEFAULT, "header not found", None));
}
};

let api_version =
if let Ok(Some(api_version)) = api.api_version::<dyn EthereumRuntimeRPCApi<B>>(&id) {
Expand Down
22 changes: 19 additions & 3 deletions client/rpc/src/eth/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_runtime::{
generic::BlockId,
traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto},
traits::{BlakeTwo256, Block as BlockT, Header as HeaderT, UniqueSaturatedInto},
};
// Frontier
use fc_rpc_core::types::*;
Expand Down Expand Up @@ -71,8 +71,24 @@ where
self.backend.as_ref(),
Some(newest_block),
) {
let Ok(number) = self.client.expect_block_number_from_id(&id) else {
return Err(internal_err(format!("Failed to retrieve block number at {id}")));
let Ok(hash) = self.client.expect_block_hash_from_id(&id) else {
return Err(internal_err(format!("Failed to retrieve block hash at {id}")));
};
let header = match self.client.header(hash) {
Ok(Some(h)) => h,
_ => {
return Err(internal_err(format!("Failed to retrieve header at {}", id)));
}
};
// Canonical chain block number.
let number = match self.client.number(header.hash()) {
Ok(Some(n)) => n,
_ => {
return Err(internal_err(format!(
"Failed to retrieve block number at {}",
id
)));
}
};
// Highest and lowest block number within the requested range.
let highest = UniqueSaturatedInto::<u64>::unique_saturated_into(number);
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ where
// In case of Pending, we need an overlayed state to query over.
let api = client.runtime_api();
let best_hash = client.info().best_hash;
let best = BlockId::Hash(client.info().best_hash);
let best = BlockId::Hash(best_hash);
// Get all transactions in the ready queue.
let xts: Vec<<B as BlockT>::Extrinsic> = graph
.validated_pool()
Expand Down
9 changes: 6 additions & 3 deletions client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub mod frontier_backend_client {
use sp_blockchain::HeaderBackend;
use sp_runtime::{
generic::BlockId,
traits::{BlakeTwo256, Block as BlockT, UniqueSaturatedInto, Zero},
traits::{BlakeTwo256, Block as BlockT, Header as HeaderT, UniqueSaturatedInto, Zero},
};
use sp_storage::StorageKey;
// Frontier
Expand Down Expand Up @@ -151,8 +151,11 @@ pub mod frontier_backend_client {
BE: Backend<B> + 'static,
BE::State: StateBackend<BlakeTwo256>,
{
if let Ok(Some(hash)) = client.block_hash_from_id(&at) {
match client.storage(hash, &StorageKey(PALLET_ETHEREUM_SCHEMA.to_vec())) {
let Ok(at) = client.expect_block_hash_from_id(&at) else {
return EthereumStorageSchema::Undefined
};
if let Ok(Some(header)) = client.header(at) {
match client.storage(header.hash(), &StorageKey(PALLET_ETHEREUM_SCHEMA.to_vec())) {
Ok(Some(bytes)) => Decode::decode(&mut &bytes.0[..])
.ok()
.unwrap_or(EthereumStorageSchema::Undefined),
Expand Down
6 changes: 3 additions & 3 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4238,9 +4238,9 @@ htmlparser2@^3.3.0:
readable-stream "^3.1.1"

http-cache-semantics@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz#49e91c5cbf36c9b94bcfcd71c23d5249ec74e390"
integrity sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==
version "4.1.1"
resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a"
integrity sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==

http-deceiver@^1.2.7:
version "1.2.7"
Expand Down
2 changes: 0 additions & 2 deletions frame/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ repository = { workspace = true }
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
environmental = { workspace = true }
ethereum = { workspace = true, features = ["with-codec"] }
ethereum-types = { workspace = true }
evm = { workspace = true, features = ["with-codec"] }
Expand Down Expand Up @@ -46,7 +45,6 @@ sp-core = { workspace = true }
[features]
default = ["std"]
std = [
"environmental/std",
"ethereum/std",
"evm/std",
"ethereum-types/std",
Expand Down
32 changes: 0 additions & 32 deletions frame/ethereum/src/catch_exec_info.rs

This file was deleted.

5 changes: 0 additions & 5 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::comparison_chain, clippy::large_enum_variant)]

mod catch_exec_info;
#[cfg(all(feature = "std", test))]
mod mock;
#[cfg(all(feature = "std", test))]
mod tests;

pub use catch_exec_info::catch_exec_info;

use ethereum_types::{Bloom, BloomInput, H160, H256, H64, U256};
use evm::ExitReason;
use fp_consensus::{PostLog, PreLog, FRONTIER_ENGINE_ID};
Expand Down Expand Up @@ -520,8 +517,6 @@ impl<T: Config> Pallet<T> {
) -> DispatchResultWithPostInfo {
let (to, _, info) = Self::execute(source, &transaction, None)?;

catch_exec_info::fill_exec_info(&info);

let pending = Pending::<T>::get();
let transaction_hash = transaction.hash();
let transaction_index = pending.len() as u32;
Expand Down
1 change: 1 addition & 0 deletions frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl pallet_evm::Config for Test {
type BlockGasLimit = BlockGasLimit;
type Runner = pallet_evm::runner::stack::Runner<Self>;
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
}

Expand Down
1 change: 1 addition & 0 deletions frame/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
environmental = { workspace = true, optional = true }
evm = { workspace = true, features = ["with-codec"] }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
impl-trait-for-tuples = "0.2.2"
log = { version = "0.4.17", default-features = false }
rlp = { workspace = true }
scale-codec = { package = "parity-scale-codec", workspace = true }
Expand Down
1 change: 1 addition & 0 deletions frame/evm/precompile/dispatch/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl pallet_evm::Config for Test {
type BlockGasLimit = BlockGasLimit;
type Runner = pallet_evm::runner::stack::Runner<Self>;
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
}

Expand Down
21 changes: 21 additions & 0 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ use frame_support::{
weights::Weight,
};
use frame_system::RawOrigin;
use impl_trait_for_tuples::impl_for_tuples;
use sp_core::{Hasher, H160, H256, U256};
use sp_runtime::{
traits::{BadOrigin, Saturating, UniqueSaturatedInto, Zero},
Expand Down Expand Up @@ -148,6 +149,9 @@ pub mod pallet {
/// Similar to `OnChargeTransaction` of `pallet_transaction_payment`
type OnChargeTransaction: OnChargeEVMTransaction<Self>;

/// Called on create calls, used to record owner
type OnCreate: OnCreate<Self>;

/// Find author for the current block.
type FindAuthor: FindAuthor<H160>;

Expand Down Expand Up @@ -892,3 +896,20 @@ U256: UniqueSaturatedInto<BalanceOf<T>>,
<EVMCurrencyAdapter::<<T as Config>::Currency, ()> as OnChargeEVMTransaction<T>>::pay_priority_fee(tip);
}
}

pub trait OnCreate<T> {
fn on_create(owner: H160, contract: H160);
}

impl<T> OnCreate<T> for () {
fn on_create(_owner: H160, _contract: H160) {}
}

#[impl_for_tuples(1, 12)]
impl<T> OnCreate<T> for Tuple {
fn on_create(owner: H160, contract: H160) {
for_tuples!(#(
Tuple::on_create(owner, contract);
)*)
}
}
1 change: 1 addition & 0 deletions frame/evm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl crate::Config for Test {
type BlockGasLimit = BlockGasLimit;
type Runner = crate::runner::stack::Runner<Self>;
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
}

Expand Down
6 changes: 4 additions & 2 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

use crate::{
runner::Runner as RunnerT, AccountCodes, AccountStorages, AddressMapping, BalanceOf,
BlockHashMapping, Config, Error, Event, FeeCalculator, OnChargeEVMTransaction, Pallet,
RunnerError,
BlockHashMapping, Config, Error, Event, FeeCalculator, OnChargeEVMTransaction, OnCreate,
Pallet, RunnerError,
};
use evm::{
backend::Backend as BackendT,
Expand Down Expand Up @@ -417,6 +417,7 @@ where
is_transactional,
|executor| {
let address = executor.create_address(evm::CreateScheme::Legacy { caller: source });
T::OnCreate::on_create(source, address);
let (reason, _) =
executor.transact_create(source, value, init, gas_limit, access_list);
(reason, address)
Expand Down Expand Up @@ -470,6 +471,7 @@ where
code_hash,
salt,
});
T::OnCreate::on_create(source, address);
let (reason, _) =
executor.transact_create2(source, value, init, salt, gas_limit, access_list);
(reason, address)
Expand Down
6 changes: 3 additions & 3 deletions template/examples/contract-erc20/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading