Repository: paritytech/polkadot-sdk
Pull request #8559: [pallet-revive] rename DepositLimit::Unchecked & minor code cleanup 
Author: login: pgherveou
Labels: name: R0-no-crate-publish-required
description: The change does not require any crates to be re-published.
name: T7-smart_contracts
description: This PR/Issue is related to smart contracts.
Created: 2025-05-19T07:44:02Z | Merged: 2025-05-20T09:10:12Z

minor cleanups for pallet-revive eth-rpc
rename DepositLimit::Unchecked to DepositLimit::UnsafeOnlyForDryRun


Diff:
diff --git a/prdoc/pr_8559.prdoc b/prdoc/pr_8559.prdoc
new file mode 100644
index 0000000000000..64aea15b7e27c
--- /dev/null
+++ b/prdoc/pr_8559.prdoc
@@ -0,0 +1,11 @@
+title: '[pallet-revive] rename DepositLimit::Unchecked & minor code cleanup '
+doc:
+- audience: Runtime Dev
+  description: |-
+    minor cleanups for pallet-revive eth-rpc
+    rename DepositLimit::Unchecked to DepositLimit::UnsafeOnlyForDryRun
+crates:
+- name: pallet-revive-eth-rpc
+  bump: patch
+- name: pallet-revive
+  bump: major
diff --git a/substrate/frame/revive/rpc/src/block_info_provider.rs b/substrate/frame/revive/rpc/src/block_info_provider.rs
index 9c574add30df0..808cd8c8a16d6 100644
--- a/substrate/frame/revive/rpc/src/block_info_provider.rs
+++ b/substrate/frame/revive/rpc/src/block_info_provider.rs
@@ -106,24 +106,36 @@ impl BlockInfoProvider for SubxtBlockInfoProvider {
 		&self,
 		block_number: SubstrateBlockNumber,
 	) -> Result<Option<Arc<SubstrateBlock>>, ClientError> {
-		if block_number == self.latest_block().await.number() {
-			return Ok(Some(self.latest_block().await));
-		} else if block_number == self.latest_finalized_block().await.number() {
-			return Ok(Some(self.latest_finalized_block().await));
+		let latest = self.latest_block().await;
+		if block_number == latest.number() {
+			return Ok(Some(latest));
+		}
+
+		let latest_finalized = self.latest_finalized_block().await;
+		if block_number == latest_finalized.number() {
+			return Ok(Some(latest_finalized));
 		}
 
 		let Some(hash) = self.rpc.chain_get_block_hash(Some(block_number.into())).await? else {
 			return Ok(None);
 		};
 
-		self.block_by_hash(&hash).await
+		match self.api.blocks().at(hash).await {
+			Ok(block) => Ok(Some(Arc::new(block))),
+			Err(subxt::Error::Block(subxt::error::BlockError::NotFound(_))) => Ok(None),
+			Err(err) => Err(err.into()),
+		}
 	}
 
 	async fn block_by_hash(&self, hash: &H256) -> Result<Option<Arc<SubstrateBlock>>, ClientError> {
-		if hash == &self.latest_block().await.hash() {
-			return Ok(Some(self.latest_block().await));
-		} else if hash == &self.latest_finalized_block().await.hash() {
-			return Ok(Some(self.latest_finalized_block().await));
+		let latest = self.latest_block().await;
+		if hash == &latest.hash() {
+			return Ok(Some(latest));
+		}
+
+		let latest_finalized = self.latest_finalized_block().await;
+		if hash == &latest_finalized.hash() {
+			return Ok(Some(latest_finalized));
 		}
 
 		match self.api.blocks().at(*hash).await {
diff --git a/substrate/frame/revive/rpc/src/client.rs b/substrate/frame/revive/rpc/src/client.rs
index 2eb1fb913a327..276ed625ba7bc 100644
--- a/substrate/frame/revive/rpc/src/client.rs
+++ b/substrate/frame/revive/rpc/src/client.rs
@@ -53,7 +53,6 @@ use subxt::{
 	Config, OnlineClient,
 };
 use thiserror::Error;
-use tokio::sync::RwLock;
 
 /// The substrate block type.
 pub type SubstrateBlock = subxt::blocks::Block<SrcChainConfig, OnlineClient<SrcChainConfig>>;
@@ -67,9 +66,6 @@ pub type SubstrateBlockNumber = <SubstrateBlockHeader as Header>::Number;
 /// The substrate block hash type.
 pub type SubstrateBlockHash = <SrcChainConfig as Config>::Hash;
 
-/// Type alias for shared data.
-pub type Shared<T> = Arc<RwLock<T>>;
-
 /// The runtime balance type.
 pub type Balance = u128;
 
diff --git a/substrate/frame/revive/rpc/src/fee_history.rs b/substrate/frame/revive/rpc/src/fee_history.rs
deleted file mode 100644
index cf16213c18ce7..0000000000000
--- a/substrate/frame/revive/rpc/src/fee_history.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-// This file is part of Substrate.
-
-// Copyright (C) Parity Technologies (UK) Ltd.
-// SPDX-License-Identifier: Apache-2.0
-
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// 	http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-pub struct FeeHistoryCacheItem {
-	pub base_fee: u64,
-	pub gas_used_ratio: f64,
-	pub rewards: Vec<u64>,
-}
-
-pub struct FeeHistoryProvider {
-	pub client: Arc<dyn Client>,
-	pub fee_history_cache: RwLock<HashMap<SubstrateBlockNumbe, FeeHistoryCacheItem>>,
-}
diff --git a/substrate/frame/revive/rpc/src/lib.rs b/substrate/frame/revive/rpc/src/lib.rs
index cffdccb668f44..3f72de15a132a 100644
--- a/substrate/frame/revive/rpc/src/lib.rs
+++ b/substrate/frame/revive/rpc/src/lib.rs
@@ -322,7 +322,10 @@ impl EthRpcServer for EthRpcServerImpl {
 	) -> RpcResult<Option<TransactionInfo>> {
 		let Some(receipt) = self
 			.client
-			.receipt_by_hash_and_index(&block_hash, transaction_index.as_usize())
+			.receipt_by_hash_and_index(
+				&block_hash,
+				transaction_index.try_into().map_err(|_| EthRpcError::ConversionError)?,
+			)
 			.await
 		else {
 			return Ok(None);
diff --git a/substrate/frame/revive/src/lib.rs b/substrate/frame/revive/src/lib.rs
index c248dda126c6a..2c8a6f4766a63 100644
--- a/substrate/frame/revive/src/lib.rs
+++ b/substrate/frame/revive/src/lib.rs
@@ -1034,7 +1034,8 @@ where
 			let origin = Origin::from_runtime_origin(origin)?;
 			let mut storage_meter = match storage_deposit_limit {
 				DepositLimit::Balance(limit) => StorageMeter::new(&origin, limit, value)?,
-				DepositLimit::Unchecked => StorageMeter::new_unchecked(BalanceOf::<T>::max_value()),
+				DepositLimit::UnsafeOnlyForDryRun =>
+					StorageMeter::new_unchecked(BalanceOf::<T>::max_value()),
 			};
 			let result = ExecStack::<T, WasmBlob<T>>::run_call(
 				origin.clone(),
@@ -1080,7 +1081,7 @@ where
 		let unchecked_deposit_limit = storage_deposit_limit.is_unchecked();
 		let mut storage_deposit_limit = match storage_deposit_limit {
 			DepositLimit::Balance(limit) => limit,
-			DepositLimit::Unchecked => BalanceOf::<T>::max_value(),
+			DepositLimit::UnsafeOnlyForDryRun => BalanceOf::<T>::max_value(),
 		};
 
 		let try_instantiate = || {
@@ -1161,7 +1162,7 @@ where
 		let storage_deposit_limit = if tx.gas.is_some() {
 			DepositLimit::Balance(BalanceOf::<T>::max_value())
 		} else {
-			DepositLimit::Unchecked
+			DepositLimit::UnsafeOnlyForDryRun
 		};
 
 		if tx.nonce.is_none() {
diff --git a/substrate/frame/revive/src/primitives.rs b/substrate/frame/revive/src/primitives.rs
index e2900bd027b69..c23febb46dd0d 100644
--- a/substrate/frame/revive/src/primitives.rs
+++ b/substrate/frame/revive/src/primitives.rs
@@ -31,7 +31,7 @@ use sp_runtime::{
 #[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)]
 pub enum DepositLimit<Balance> {
 	/// Allows bypassing all balance transfer checks.
-	Unchecked,
+	UnsafeOnlyForDryRun,
 
 	/// Specifies a maximum allowable balance for a deposit.
 	Balance(Balance),
@@ -40,7 +40,7 @@ pub enum DepositLimit<Balance> {
 impl<T> DepositLimit<T> {
 	pub fn is_unchecked(&self) -> bool {
 		match self {
-			Self::Unchecked => true,
+			Self::UnsafeOnlyForDryRun => true,
 			_ => false,
 		}
 	}


Reviews:
user: login: athei
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-19T13:45:46Z
user: login: pgherveou
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-19T14:04:44Z
user: login: xermicus
state: APPROVED
author_association: MEMBER
submitted_at: 2025-05-19T14:51:33Z
user: login: athei
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-20T07:56:14Z
user: login: athei
state: APPROVED
author_association: MEMBER
submitted_at: 2025-05-20T08:00:22Z

Review comments:
path: substrate/frame/revive/rpc/src/fee_history.rs
user: login: athei
body: This file is referenced nowhere?
created_at: 2025-05-19T13:45:46Z
author_association: MEMBER
path: substrate/frame/revive/rpc/src/fee_history.rs
user: login: pgherveou
body: yes
created_at: 2025-05-19T14:04:44Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,11 @@
+title: '[pallet-revive] rename DepositLimit::Unchecked & minor code cleanup '
+doc:
+- audience: Runtime Dev
+  description: |-
+    minor cleanups for pallet-revive eth-rpc
+    rename DepositLimit::Unchecked to DepositLimit::UnsafeOnlyForDryRun
+crates:
+- name: pallet-revive-eth-rpc
+  bump: patch
+- name: pallet-revive
+  bump: patch
path: prdoc/pr_8559.prdoc
user: login: athei
body: ```suggestion
  bump: major
```
created_at: 2025-05-20T07:56:02Z
author_association: MEMBER

PR comments:
user: login: pgherveou
created_at: 2025-05-19T12:51:07Z
body: /cmd prdoc --audience runtime_dev --bump patch
author_association: CONTRIBUTOR
user: login: athei
created_at: 2025-05-19T13:45:30Z
body: What are we fixing here?
author_association: MEMBER
user: login: pgherveou
created_at: 2025-05-19T14:05:14Z
body: > What are we fixing here?

yeah will rephrase, just nit improvments
author_association: CONTRIBUTOR
user: login: pgherveou
created_at: 2025-05-19T14:18:59Z
body: /cmd prdoc --audience runtime_dev --bump patch --force
author_association: CONTRIBUTOR
user: login: castillax
created_at: 2025-05-19T14:36:36Z
body: nit: might want to change the is_unchecked() too for uniformity.
author_association: NONE
user: login: paritytech-workflow-stopper[bot]
created_at: 2025-05-19T15:17:34Z
body: 
All GitHub workflows were cancelled due to failure one of the required jobs.
**Failed workflow url**: https://github.com/paritytech/polkadot-sdk/actions/runs/15115555903
**Failed job name**: test-linux-stable-no-try-runtime

author_association: NONE