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

Bump actions/checkout from 3 to 4 #88

Open
wants to merge 3 commits into
base: polkadot-v0.9.43
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Expand Up @@ -11,7 +11,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Rust Setup
uses: actions-rs/toolchain@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/editorconfig.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
name: 'Check editorconfig'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Submodules
run: git submodule update --init --recursive
- name: Init
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
name: 'Run Rust tests'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Rust Setup
uses: actions-rs/toolchain@v1
with:
Expand All @@ -34,7 +34,7 @@ jobs:
name: 'Run integration tests'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Rust Setup
uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
name: 'Run lints'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Rust Setup
uses: actions-rs/toolchain@v1
with:
Expand Down
20 changes: 18 additions & 2 deletions client/rpc/src/eth/block.rs
Expand Up @@ -33,7 +33,7 @@ use fc_rpc_core::types::*;
use fp_rpc::EthereumRuntimeRPCApi;

use crate::{
eth::{rich_block_build, Eth, EthConfig},
eth::{empty_block_from, rich_block_build, Eth, EthConfig},
frontier_backend_client, internal_err,
};

Expand Down Expand Up @@ -198,7 +198,23 @@ where
_ => Ok(None),
}
}
None => Ok(None),
None => {
if let BlockNumber::Num(block_number) = number {
let eth_block = empty_block_from(block_number.into());
let eth_hash =
H256::from_slice(keccak_256(&rlp::encode(&eth_block.header)).as_slice());
Ok(Some(rich_block_build(
eth_block,
Default::default(),
Some(eth_hash),
full,
None,
false,
)))
} else {
Ok(None)
}
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions client/rpc/src/eth/mod.rs
Expand Up @@ -473,6 +473,31 @@ fn rich_block_build(
}
}

fn empty_block_from(number: U256) -> ethereum::BlockV2 {
let ommers = Vec::<ethereum::Header>::new();
let receipts = Vec::<ethereum::ReceiptV2>::new();
let receipts_root = ethereum::util::ordered_trie_root(
receipts.iter().map(ethereum::EnvelopedEncodable::encode),
);
let logs_bloom = ethereum_types::Bloom::default();
let partial_header = ethereum::PartialHeader {
parent_hash: H256::default(),
beneficiary: Default::default(),
state_root: Default::default(),
receipts_root,
logs_bloom,
difficulty: U256::zero(),
number,
gas_limit: U256::from(4_000_000),
gas_used: U256::zero(),
timestamp: Default::default(),
extra_data: Vec::new(),
mix_hash: H256::default(),
nonce: H64::default(),
};
ethereum::Block::new(partial_header, Default::default(), ommers)
}

fn transaction_build(
ethereum_transaction: EthereumTransaction,
block: Option<EthereumBlock>,
Expand Down
57 changes: 31 additions & 26 deletions frame/ethereum/src/lib.rs
Expand Up @@ -42,7 +42,9 @@ use fp_evm::{
use fp_storage::{EthereumStorageSchema, PALLET_ETHEREUM_SCHEMA};
use frame_support::{
codec::{Decode, Encode, MaxEncodedLen},
dispatch::{DispatchInfo, DispatchResultWithPostInfo, Pays, PostDispatchInfo},
dispatch::{
DispatchErrorWithPostInfo, DispatchInfo, DispatchResultWithPostInfo, Pays, PostDispatchInfo,
},
scale_info::TypeInfo,
traits::{EnsureOrigin, Get, PalletInfoAccess, Time},
weights::Weight,
Expand All @@ -55,7 +57,7 @@ use sp_runtime::{
transaction_validity::{
InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransactionBuilder,
},
DispatchErrorWithPostInfo, RuntimeDebug, SaturatedConversion,
RuntimeDebug, SaturatedConversion,
};
use sp_std::{marker::PhantomData, prelude::*};

Expand Down Expand Up @@ -241,7 +243,7 @@ pub mod pallet {
Self::validate_transaction_in_block(source, &transaction).expect(
"pre-block transaction verification failed; the block cannot be built",
);
let r = Self::apply_validated_transaction(source, transaction)
let (r, _) = Self::apply_validated_transaction(source, transaction)
.expect("pre-block apply transaction failed; the block cannot be built");

weight = weight.saturating_add(r.actual_weight.unwrap_or_default());
Expand Down Expand Up @@ -290,7 +292,7 @@ pub mod pallet {
"pre log already exists; block is invalid",
);

Self::apply_validated_transaction(source, transaction)
Self::apply_validated_transaction(source, transaction).map(|(post_info, _)| post_info)
}
}

Expand All @@ -317,7 +319,7 @@ pub mod pallet {

/// Current building block's transactions and receipts.
#[pallet::storage]
pub(super) type Pending<T: Config> =
pub type Pending<T: Config> =
StorageValue<_, Vec<(Transaction, TransactionStatus, Receipt)>, ValueQuery>;

/// The current Ethereum block.
Expand Down Expand Up @@ -558,14 +560,14 @@ impl<T: Config> Pallet<T> {
fn apply_validated_transaction(
source: H160,
transaction: Transaction,
) -> DispatchResultWithPostInfo {
) -> Result<(PostDispatchInfo, CallOrCreateInfo), DispatchErrorWithPostInfo> {
let (to, _, info) = Self::execute(source, &transaction, None)?;

let pending = Pending::<T>::get();
let transaction_hash = transaction.hash();
let transaction_index = pending.len() as u32;

let (reason, status, weight_info, used_gas, dest, extra_data) = match info {
let (reason, status, weight_info, used_gas, dest, extra_data) = match info.clone() {
CallOrCreateInfo::Call(info) => (
info.exit_reason.clone(),
TransactionStatus {
Expand Down Expand Up @@ -680,21 +682,24 @@ impl<T: Config> Pallet<T> {
extra_data,
});

Ok(PostDispatchInfo {
actual_weight: {
let mut gas_to_weight = T::GasWeightMapping::gas_to_weight(
used_gas.standard.unique_saturated_into(),
true,
);
if let Some(weight_info) = weight_info {
if let Some(proof_size_usage) = weight_info.proof_size_usage {
*gas_to_weight.proof_size_mut() = proof_size_usage;
Ok((
(PostDispatchInfo {
actual_weight: {
let mut gas_to_weight = T::GasWeightMapping::gas_to_weight(
used_gas.standard.unique_saturated_into(),
true,
);
if let Some(weight_info) = weight_info {
if let Some(proof_size_usage) = weight_info.proof_size_usage {
*gas_to_weight.proof_size_mut() = proof_size_usage;
}
}
}
Some(gas_to_weight)
},
pays_fee: Pays::No,
})
Some(gas_to_weight)
},
pays_fee: Pays::No,
}),
info,
))
}

/// Get current block hash
Expand All @@ -707,10 +712,7 @@ impl<T: Config> Pallet<T> {
from: H160,
transaction: &Transaction,
config: Option<evm::Config>,
) -> Result<
(Option<H160>, Option<H160>, CallOrCreateInfo),
DispatchErrorWithPostInfo<PostDispatchInfo>,
> {
) -> Result<(Option<H160>, Option<H160>, CallOrCreateInfo), DispatchErrorWithPostInfo> {
let (
input,
value,
Expand Down Expand Up @@ -963,7 +965,10 @@ impl<T: Config> Pallet<T> {

pub struct ValidatedTransaction<T>(PhantomData<T>);
impl<T: Config> ValidatedTransactionT for ValidatedTransaction<T> {
fn apply(source: H160, transaction: Transaction) -> DispatchResultWithPostInfo {
fn apply(
source: H160,
transaction: Transaction,
) -> Result<(PostDispatchInfo, CallOrCreateInfo), DispatchErrorWithPostInfo> {
Pallet::<T>::apply_validated_transaction(source, transaction)
}
}
Expand Down
5 changes: 4 additions & 1 deletion primitives/consensus/src/lib.rs
Expand Up @@ -130,5 +130,8 @@ pub fn find_log(digest: &Digest) -> Result<Log, FindLogError> {
}

pub fn ensure_log(digest: &Digest) -> Result<(), FindLogError> {
find_log(digest).map(|_log| ())
match find_log(digest) {
Err(FindLogError::MultipleLogs) => Err(FindLogError::MultipleLogs),
_ => Ok(()),
}
}
7 changes: 4 additions & 3 deletions primitives/ethereum/src/lib.rs
Expand Up @@ -23,9 +23,10 @@ pub use ethereum::{
TransactionAction, TransactionV2 as Transaction,
};
use ethereum_types::{H160, H256, U256};
use fp_evm::CheckEvmTransactionInput;
use fp_evm::{CallOrCreateInfo, CheckEvmTransactionInput};
use frame_support::dispatch::{DispatchErrorWithPostInfo, PostDispatchInfo};
use scale_codec::{Decode, Encode};
use sp_std::vec::Vec;
use sp_std::prelude::*;

#[repr(u8)]
#[derive(num_enum::FromPrimitive, num_enum::IntoPrimitive)]
Expand All @@ -44,7 +45,7 @@ pub trait ValidatedTransaction {
fn apply(
source: H160,
transaction: Transaction,
) -> frame_support::dispatch::DispatchResultWithPostInfo;
) -> Result<(PostDispatchInfo, CallOrCreateInfo), DispatchErrorWithPostInfo>;
}

#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode)]
Expand Down