diff --git a/Cargo.lock b/Cargo.lock index 210f6bc942..ae1ad35ee2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12158,4 +12158,4 @@ dependencies = [ "cc", "libc", "pkg-config", -] +] \ No newline at end of file diff --git a/client/rpc-core/src/eth.rs b/client/rpc-core/src/eth.rs index 8a18c33086..e93977760b 100644 --- a/client/rpc-core/src/eth.rs +++ b/client/rpc-core/src/eth.rs @@ -202,6 +202,10 @@ pub trait EthApi { number_or_hash: Option, ) -> RpcResult; + /// Returns all pending transactions. + #[method(name = "eth_pendingTransactions")] + async fn pending_transactions(&self) -> RpcResult>; + // ######################################################################## // Fee // ######################################################################## diff --git a/client/rpc/src/eth/mod.rs b/client/rpc/src/eth/mod.rs index d7d3e14fba..88680e1a1b 100644 --- a/client/rpc/src/eth/mod.rs +++ b/client/rpc/src/eth/mod.rs @@ -455,6 +455,10 @@ where self.transaction_count(address, number_or_hash).await } + async fn pending_transactions(&self) -> RpcResult> { + self.pending_transactions().await + } + async fn code_at( &self, address: H160, diff --git a/client/rpc/src/eth/submit.rs b/client/rpc/src/eth/submit.rs index 1a4f9556ac..ebea5f7937 100644 --- a/client/rpc/src/eth/submit.rs +++ b/client/rpc/src/eth/submit.rs @@ -178,6 +178,51 @@ where .await } + pub async fn pending_transactions(&self) -> RpcResult> { + let ready = self + .graph + .validated_pool() + .ready() + .map(|in_pool_tx| in_pool_tx.clone()) + .collect(); + + let future = self + .graph + .validated_pool() + .futures() + .iter() + .map(|(_, extrinsic)| extrinsic.clone()) + .collect(); + + let mut all_extrinsics = Vec::new(); + all_extrinsics.extend(ready); + all_extrinsics.extend(future); + + let best_block = self.client.info().best_hash; + let api = self.client.runtime_api(); + + let api_version = api + .api_version::>(best_block) + .map_err(|err| internal_err(format!("Failed to get API version: {}", err)))? + .ok_or_else(|| internal_err("Failed to get API version"))?; + + let ethereum_txs = if api_version > 1 { + api.extrinsic_filter(best_block, all_extrinsics) + .map_err(|err| internal_err(format!("Runtime call failed: {}", err)))? + } else { + #[allow(deprecated)] + let legacy = api + .extrinsic_filter_before_version_2(best_block, all_extrinsics) + .map_err(|err| internal_err(format!("Runtime call failed: {}", err)))?; + legacy.into_iter().map(|tx| tx.into()).collect() + }; + + Ok(ethereum_txs + .into_iter() + .map(|tx| Transaction::build_from(tx.recover_from().unwrap_or_default(), &tx)) + .collect()) + } + fn convert_transaction( &self, block_hash: B::Hash, diff --git a/client/rpc/src/eth_pubsub.rs b/client/rpc/src/eth_pubsub.rs index c8fdf022d6..05627afcc9 100644 --- a/client/rpc/src/eth_pubsub.rs +++ b/client/rpc/src/eth_pubsub.rs @@ -151,7 +151,7 @@ where future::ready(res.map(|(block, receipts)| PubSubResult::logs(block, receipts, params))) } - fn pending_transaction(&self, hash: &TxHash

) -> future::Ready> { + fn pending_transactions(&self, hash: &TxHash

) -> future::Ready> { let res = if let Some(xt) = self.pool.ready_transaction(hash) { let best_block = self.client.info().best_hash; @@ -263,7 +263,7 @@ where let pool = pubsub.pool.clone(); let stream = pool .import_notification_stream() - .filter_map(move |hash| pubsub.pending_transaction(&hash)); + .filter_map(move |hash| pubsub.pending_transactions(&hash)); PendingSubscription::from(pending) .pipe_from_stream(stream, BoundedVecDeque::new(16)) .await; diff --git a/frame/evm/src/tests.rs b/frame/evm/src/tests.rs index 8bef720c77..5e17cdb1ab 100644 --- a/frame/evm/src/tests.rs +++ b/frame/evm/src/tests.rs @@ -238,7 +238,8 @@ mod proof_size_test { let expected_proof_size = ((read_account_metadata * 2) + reading_contract_len + reading_main_contract_len - + is_empty_check + increase_nonce) as u64; + + is_empty_check + + increase_nonce) as u64; let actual_proof_size = result .weight_info @@ -295,7 +296,8 @@ mod proof_size_test { let expected_proof_size = (basic_account_size + read_account_metadata + reading_main_contract_len - + is_empty_check + increase_nonce) as u64; + + is_empty_check + + increase_nonce) as u64; let actual_proof_size = result .weight_info @@ -520,7 +522,8 @@ mod proof_size_test { let expected_proof_size = ((read_account_metadata * 2) + reading_callee_contract_len + reading_main_contract_len - + is_empty_check + increase_nonce) as u64; + + is_empty_check + + increase_nonce) as u64; let actual_proof_size = result .weight_info