Skip to content

Commit 648cc16

Browse files
pallet-revive: Fix dry run balance check logic (#9942)
Fix fault balance check logic during dry-run: We should not enforce that the sender has enough balance for the fees in case no `gas` is supplied. cc @TorstenStueber --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 0028bec commit 648cc16

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

prdoc/pr_9942.prdoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
title: 'pallet-revive: Fix dry run balance check logic'
2+
doc:
3+
- audience: Runtime User
4+
description: |-
5+
Fix fault balance check logic during dry-run:
6+
7+
We should not enforce that the sender has enough balance for the fees in case no `gas` is supplied.
8+
9+
cc @TorstenStueber
10+
crates:
11+
- name: pallet-revive
12+
bump: major

substrate/frame/revive/src/lib.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,20 +1460,22 @@ impl<T: Config> Pallet<T> {
14601460
let mut call_info = create_call::<T>(tx, None)
14611461
.map_err(|err| EthTransactError::Message(format!("Invalid call: {err:?}")))?;
14621462

1463-
// emulate transaction behavior
1463+
// the dry-run might leave out certain fields
1464+
// in those cases we skip the check that the caller has enough balance
1465+
// to pay for the fees
14641466
let fees = call_info.tx_fee.saturating_add(call_info.storage_deposit);
1465-
match (gas, from, value.is_zero()) {
1466-
(Some(_), Some(from), _) | (_, Some(from), false) => {
1467-
let balance = Self::evm_balance(&from).saturating_add(value);
1468-
if balance < Pallet::<T>::convert_native_to_evm(fees) {
1469-
return Err(EthTransactError::Message(format!(
1470-
"insufficient funds for gas * price + value: address {from:?} have {balance:?} (supplied gas {gas:?})",
1471-
)));
1472-
}
1473-
},
1474-
_ => {},
1467+
if let Some(from) = &from {
1468+
let fees = if gas.is_some() { fees } else { Zero::zero() };
1469+
let balance = Self::evm_balance(from);
1470+
if balance < Pallet::<T>::convert_native_to_evm(fees).saturating_add(value) {
1471+
return Err(EthTransactError::Message(format!(
1472+
"insufficient funds for gas * price + value ({fees:?}): address {from:?} have {balance:?} (supplied gas {gas:?})",
1473+
)));
1474+
}
14751475
}
14761476

1477+
// the deposit is done when the transaction is transformed from an `eth_transact`
1478+
// we emulate this behavior for the dry-run her
14771479
T::FeeInfo::deposit_txfee(T::Currency::issue(fees));
14781480

14791481
let extract_error = |err| {
@@ -1599,6 +1601,7 @@ impl<T: Config> Pallet<T> {
15991601
)))?;
16001602
}
16011603

1604+
// not enough gas supplied to pay for both the tx fees and the storage deposit
16021605
let transaction_fee = T::FeeInfo::tx_fee(call_info.encoded_len, &call_info.call);
16031606
let available_fee = T::FeeInfo::remaining_txfee();
16041607
if transaction_fee > available_fee {

0 commit comments

Comments
 (0)