core: fix pre-check for account balance under EIP-1559 (#23244)

This commit is contained in:
Daniel Liu 2024-05-28 16:58:19 +08:00
parent 5b01b23af6
commit 43a0cdf7ce
2 changed files with 2 additions and 1 deletions

View file

@ -120,7 +120,7 @@ func TestStateProcessorErrors(t *testing.T) {
txs: []*types.Transaction{
makeTx(0, common.Address{}, big.NewInt(1000000000000000000), params.TxGas, big.NewInt(875000000), nil),
},
want: "insufficient funds for transfer: address xdc71562b71999873DB5b286dF957af199Ec94617F7",
want: "insufficient funds for gas * price + value: address xdc71562b71999873DB5b286dF957af199Ec94617F7",
},
{ // ErrInsufficientFunds
txs: []*types.Transaction{

View file

@ -186,6 +186,7 @@ func (st *StateTransition) buyGas() error {
if st.gasFeeCap != nil {
balanceCheck = new(big.Int).SetUint64(st.msg.Gas())
balanceCheck = balanceCheck.Mul(balanceCheck, st.gasFeeCap)
balanceCheck.Add(balanceCheck, st.value)
}
if have, want := st.state.GetBalance(st.msg.From()), balanceCheck; have.Cmp(want) < 0 {
return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From().Hex(), have, want)