{
pool: Arc,
graph: Arc>,
client: Arc,
@@ -104,7 +102,6 @@ where
C: HeaderBackend + StorageProvider + 'static,
BE: Backend + 'static,
A: ChainApi,
- EC: EthConfig,
{
pub fn new(
client: Arc,
@@ -606,9 +603,9 @@ fn rich_block_build(
.enumerate()
.map(|(index, transaction)| {
transaction_build(
- transaction.clone(),
- Some(block.clone()),
- Some(statuses[index].clone().unwrap_or_default()),
+ transaction,
+ Some(&block),
+ statuses[index].as_ref(),
base_fee,
)
})
@@ -632,17 +629,30 @@ fn rich_block_build(
}
fn transaction_build(
- ethereum_transaction: EthereumTransaction,
- block: Option,
- status: Option,
+ ethereum_transaction: &EthereumTransaction,
+ block: Option<&EthereumBlock>,
+ status: Option<&TransactionStatus>,
base_fee: Option,
) -> Transaction {
- let mut transaction: Transaction = ethereum_transaction.clone().into();
+ let pubkey = match public_key(ethereum_transaction) {
+ Ok(p) => Some(p),
+ Err(_) => None,
+ };
+ let from = status.map_or(
+ {
+ match pubkey {
+ Some(pk) => H160::from(H256::from(keccak_256(&pk))),
+ _ => H160::default(),
+ }
+ },
+ |status| status.from,
+ );
+
+ let mut transaction: Transaction = Transaction::build_from(from, ethereum_transaction);
if let EthereumTransaction::EIP1559(_) = ethereum_transaction {
if block.is_none() && status.is_none() {
// If transaction is not mined yet, gas price is considered just max fee per gas.
- transaction.gas_price = transaction.max_fee_per_gas;
} else {
let base_fee = base_fee.unwrap_or_default();
let max_priority_fee_per_gas = transaction.max_priority_fee_per_gas.unwrap_or_default();
@@ -657,52 +667,18 @@ fn transaction_build(
}
}
- let pubkey = match public_key(ðereum_transaction) {
- Ok(p) => Some(p),
- Err(_e) => None,
- };
-
// Block hash.
- transaction.block_hash = block
- .as_ref()
- .map(|block| H256::from(keccak_256(&rlp::encode(&block.header))));
+ transaction.block_hash = block.map(|block| block.header.hash());
// Block number.
- transaction.block_number = block.as_ref().map(|block| block.header.number);
+ transaction.block_number = block.map(|block| block.header.number);
// Transaction index.
- transaction.transaction_index = status.as_ref().map(|status| {
+ transaction.transaction_index = status.map(|status| {
U256::from(UniqueSaturatedInto::::unique_saturated_into(
status.transaction_index,
))
});
- // From.
- transaction.from = status.as_ref().map_or(
- {
- match pubkey {
- Some(pk) => H160::from(H256::from(keccak_256(&pk))),
- _ => H160::default(),
- }
- },
- |status| status.from,
- );
- // To.
- transaction.to = status.as_ref().map_or(
- {
- let action = match ethereum_transaction {
- EthereumTransaction::Legacy(t) => t.action,
- EthereumTransaction::EIP2930(t) => t.action,
- EthereumTransaction::EIP1559(t) => t.action,
- };
- match action {
- ethereum::TransactionAction::Call(to) => Some(to),
- _ => None,
- }
- },
- |status| status.to,
- );
// Creates.
- transaction.creates = status.as_ref().and_then(|status| status.contract_address);
- // Public key.
- transaction.public_key = pubkey.as_ref().map(H512::from);
+ transaction.creates = status.and_then(|status| status.contract_address);
transaction
}
diff --git a/client/rpc/src/eth/pending.rs b/client/rpc/src/eth/pending.rs
index 822562ded0..0b951242d7 100644
--- a/client/rpc/src/eth/pending.rs
+++ b/client/rpc/src/eth/pending.rs
@@ -36,7 +36,7 @@ use sp_runtime::{
};
use sp_timestamp::TimestampInherentData;
-use crate::eth::{Eth, EthConfig};
+use crate::eth::Eth;
const LOG_TARGET: &str = "eth-pending";
@@ -64,7 +64,6 @@ where
BE: Backend,
A: ChainApi,
CIDP: CreateInherentDataProviders + Send + 'static,
- EC: EthConfig,
{
/// Creates a pending runtime API.
pub(crate) async fn pending_runtime_api(&self) -> Result<(B::Hash, ApiRef), Error> {
@@ -89,7 +88,7 @@ where
Default::default()
};
- log::info!(target: LOG_TARGET, "Pending runtime API: header digest = {digest:?}");
+ log::debug!(target: LOG_TARGET, "Pending runtime API: header digest = {digest:?}");
let pending_header = <::Header as HeaderT>::new(
best_number + One::one(),
diff --git a/client/rpc/src/eth/state.rs b/client/rpc/src/eth/state.rs
index 5301128a51..95c2c0169e 100644
--- a/client/rpc/src/eth/state.rs
+++ b/client/rpc/src/eth/state.rs
@@ -32,10 +32,7 @@ use sp_runtime::traits::Block as BlockT;
use fc_rpc_core::types::*;
use fp_rpc::EthereumRuntimeRPCApi;
-use crate::{
- eth::{Eth, EthConfig},
- frontier_backend_client, internal_err,
-};
+use crate::{eth::Eth, frontier_backend_client, internal_err};
impl Eth
where
@@ -47,7 +44,6 @@ where
P: TransactionPool + 'static,
A: ChainApi,
CIDP: CreateInherentDataProviders + Send + 'static,
- EC: EthConfig,
{
pub async fn balance(
&self,
@@ -144,7 +140,7 @@ where
for tx in self.pool.ready() {
// since transactions in `ready()` need to be ordered by nonce
// it's fine to continue with current iterator.
- if tx.provides().get(0) == Some(¤t_tag) {
+ if tx.provides().first() == Some(¤t_tag) {
current_nonce = current_nonce.saturating_add(1.into());
current_tag = (address, current_nonce).encode();
}
diff --git a/client/rpc/src/eth/submit.rs b/client/rpc/src/eth/submit.rs
index c87affd666..acc86df336 100644
--- a/client/rpc/src/eth/submit.rs
+++ b/client/rpc/src/eth/submit.rs
@@ -27,15 +27,13 @@ use sp_api::{ApiExt, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder as BlockBuilderApi;
use sp_blockchain::HeaderBackend;
use sp_inherents::CreateInherentDataProviders;
-use sp_runtime::{
- generic::BlockId, traits::Block as BlockT, transaction_validity::TransactionSource,
-};
+use sp_runtime::{traits::Block as BlockT, transaction_validity::TransactionSource};
// Frontier
use fc_rpc_core::types::*;
use fp_rpc::{ConvertTransaction, ConvertTransactionRuntimeApi, EthereumRuntimeRPCApi};
use crate::{
- eth::{format, Eth, EthConfig},
+ eth::{format, Eth},
internal_err,
};
@@ -50,7 +48,6 @@ where
CT: ConvertTransaction<::Extrinsic> + 'static,
A: ChainApi,
CIDP: CreateInherentDataProviders + Send + 'static,
- EC: EthConfig,
{
pub async fn send_transaction(&self, request: TransactionRequest) -> RpcResult {
let from = match request.from {
@@ -61,7 +58,7 @@ where
Err(e) => return Err(e),
};
- match accounts.get(0) {
+ match accounts.first() {
Some(account) => *account,
None => return Err(internal_err("no signer available")),
}
@@ -82,13 +79,13 @@ where
Err(e) => return Err(e),
};
- let hash = self.client.info().best_hash;
+ let block_hash = self.client.info().best_hash;
let gas_price = request.gas_price;
let gas_limit = match request.gas {
Some(gas_limit) => gas_limit,
None => {
- let block = self.client.runtime_api().current_block(hash);
+ let block = self.client.runtime_api().current_block(block_hash);
if let Ok(Some(block)) = block {
block.header.gas_limit
} else {
@@ -96,6 +93,7 @@ where
}
}
};
+
let max_fee_per_gas = request.max_fee_per_gas;
let message: Option = request.into();
let message = match message {
@@ -130,7 +128,6 @@ where
};
let mut transaction = None;
-
for signer in &self.signers {
if signer.accounts().contains(&from) {
match signer.sign(message, &from) {
@@ -147,99 +144,60 @@ where
};
let transaction_hash = transaction.hash();
- let block_hash = self.client.info().best_hash;
- let api_version = match self
- .client
- .runtime_api()
- .api_version::>(block_hash)
- {
- Ok(api_version) => api_version,
- _ => return Err(internal_err("cannot access runtime api")),
- };
-
- let extrinsic = match api_version {
- Some(2) => match self
- .client
- .runtime_api()
- .convert_transaction(block_hash, transaction)
- {
- Ok(extrinsic) => extrinsic,
- Err(_) => return Err(internal_err("cannot access runtime api")),
- },
- Some(1) => {
- if let ethereum::TransactionV2::Legacy(legacy_transaction) = transaction {
- // To be compatible with runtimes that do not support transactions v2
- #[allow(deprecated)]
- match self
- .client
- .runtime_api()
- .convert_transaction_before_version_2(block_hash, legacy_transaction)
- {
- Ok(extrinsic) => extrinsic,
- Err(_) => return Err(internal_err("cannot access runtime api")),
- }
- } else {
- return Err(internal_err("This runtime not support eth transactions v2"));
- }
- }
- None => {
- if let Some(ref convert_transaction) = self.convert_transaction {
- convert_transaction.convert_transaction(transaction.clone())
- } else {
- return Err(internal_err(
- "No TransactionConverter is provided and the runtime api ConvertTransactionRuntimeApi is not found"
- ));
- }
- }
- _ => {
- return Err(internal_err(
- "ConvertTransactionRuntimeApi version not supported",
- ))
- }
- };
+ let extrinsic = self.convert_transaction(block_hash, transaction)?;
self.pool
- .submit_one(
- &BlockId::Hash(block_hash),
- TransactionSource::Local,
- extrinsic,
- )
+ .submit_one(block_hash, TransactionSource::Local, extrinsic)
.map_ok(move |_| transaction_hash)
.map_err(|err| internal_err(format::Geth::pool_error(err)))
.await
}
pub async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult {
- let slice = &bytes.0[..];
- if slice.is_empty() {
+ let bytes = bytes.into_vec();
+ if bytes.is_empty() {
return Err(internal_err("transaction data is empty"));
}
- let transaction: ethereum::TransactionV2 = match ethereum::EnvelopedDecodable::decode(slice)
- {
- Ok(transaction) => transaction,
- Err(_) => return Err(internal_err("decode transaction failed")),
- };
+ let transaction: ethereum::TransactionV2 =
+ match ethereum::EnvelopedDecodable::decode(&bytes) {
+ Ok(transaction) => transaction,
+ Err(_) => return Err(internal_err("decode transaction failed")),
+ };
let transaction_hash = transaction.hash();
let block_hash = self.client.info().best_hash;
+ let extrinsic = self.convert_transaction(block_hash, transaction)?;
+
+ self.pool
+ .submit_one(block_hash, TransactionSource::Local, extrinsic)
+ .map_ok(move |_| transaction_hash)
+ .map_err(|err| internal_err(format::Geth::pool_error(err)))
+ .await
+ }
+
+ fn convert_transaction(
+ &self,
+ block_hash: B::Hash,
+ transaction: ethereum::TransactionV2,
+ ) -> RpcResult {
let api_version = match self
.client
.runtime_api()
.api_version::>(block_hash)
{
Ok(api_version) => api_version,
- _ => return Err(internal_err("cannot access runtime api")),
+ _ => return Err(internal_err("cannot access `ConvertTransactionRuntimeApi`")),
};
- let extrinsic = match api_version {
+ match api_version {
Some(2) => match self
.client
.runtime_api()
.convert_transaction(block_hash, transaction)
{
- Ok(extrinsic) => extrinsic,
- Err(_) => return Err(internal_err("cannot access runtime api")),
+ Ok(extrinsic) => Ok(extrinsic),
+ Err(_) => Err(internal_err("cannot access `ConvertTransactionRuntimeApi`")),
},
Some(1) => {
if let ethereum::TransactionV2::Legacy(legacy_transaction) = transaction {
@@ -250,39 +208,27 @@ where
.runtime_api()
.convert_transaction_before_version_2(block_hash, legacy_transaction)
{
- Ok(extrinsic) => extrinsic,
- Err(_) => {
- return Err(internal_err("cannot access runtime api"));
- }
+ Ok(extrinsic) => Ok(extrinsic),
+ Err(_) => Err(internal_err("cannot access `ConvertTransactionRuntimeApi`")),
}
} else {
- return Err(internal_err("This runtime not support eth transactions v2"));
+ Err(internal_err(
+ "Ethereum transactions v2 is not supported by the runtime",
+ ))
}
}
None => {
if let Some(ref convert_transaction) = self.convert_transaction {
- convert_transaction.convert_transaction(transaction.clone())
+ Ok(convert_transaction.convert_transaction(transaction.clone()))
} else {
- return Err(internal_err(
- "No TransactionConverter is provided and the runtime api ConvertTransactionRuntimeApi is not found"
- ));
+ Err(internal_err(
+ "`ConvertTransactionRuntimeApi` is not found and no `TransactionConverter` is provided"
+ ))
}
}
- _ => {
- return Err(internal_err(
- "ConvertTransactionRuntimeApi version not supported",
- ))
- }
- };
-
- self.pool
- .submit_one(
- &BlockId::Hash(block_hash),
- TransactionSource::Local,
- extrinsic,
- )
- .map_ok(move |_| transaction_hash)
- .map_err(|err| internal_err(format::Geth::pool_error(err)))
- .await
+ _ => Err(internal_err(
+ "`ConvertTransactionRuntimeApi` is not supported",
+ )),
+ }
}
}
diff --git a/client/rpc/src/eth/transaction.rs b/client/rpc/src/eth/transaction.rs
index cf15d394bd..2778aa6a39 100644
--- a/client/rpc/src/eth/transaction.rs
+++ b/client/rpc/src/eth/transaction.rs
@@ -34,7 +34,7 @@ use fc_rpc_core::types::*;
use fp_rpc::EthereumRuntimeRPCApi;
use crate::{
- eth::{transaction_build, BlockInfo, Eth, EthConfig},
+ eth::{transaction_build, BlockInfo, Eth},
frontier_backend_client, internal_err,
};
@@ -46,7 +46,6 @@ where
C: HeaderBackend + StorageProvider + 'static,
BE: Backend + 'static,
A: ChainApi,
- EC: EthConfig,
{
pub async fn transaction_by_hash(&self, hash: H256) -> RpcResult