mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
feat: improve balance check (#607)
* feat: improve balance check * clean up
This commit is contained in:
parent
b235afbccf
commit
833f9041bb
3 changed files with 12 additions and 7 deletions
|
|
@ -1233,6 +1233,10 @@ loop:
|
||||||
w.checkCurrentTxNumWithCCC(w.current.tcount)
|
w.checkCurrentTxNumWithCCC(w.current.tcount)
|
||||||
break loop
|
break loop
|
||||||
|
|
||||||
|
case (errors.Is(err, core.ErrInsufficientFunds) || errors.Is(errors.Unwrap(err), core.ErrInsufficientFunds)):
|
||||||
|
log.Trace("Skipping account with insufficient funds", "sender", from)
|
||||||
|
txs.Pop()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Strange error, discard the transaction and get the next in line (note, the
|
// Strange error, discard the transaction and get the next in line (note, the
|
||||||
// nonce-too-high clause will prevent us from executing in vain).
|
// nonce-too-high clause will prevent us from executing in vain).
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 1 // Minor version component of the current release
|
VersionMinor = 1 // Minor version component of the current release
|
||||||
VersionPatch = 7 // Patch version component of the current release
|
VersionPatch = 8 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -202,18 +202,19 @@ func VerifyFee(signer types.Signer, tx *types.Transaction, state StateDB) error
|
||||||
}
|
}
|
||||||
|
|
||||||
balance := state.GetBalance(from)
|
balance := state.GetBalance(from)
|
||||||
l2Fee := calculateL2Fee(tx)
|
|
||||||
l1DataFee, err := CalculateL1DataFee(tx, state)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("invalid transaction: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cost := tx.Value()
|
cost := tx.Value()
|
||||||
|
|
||||||
|
l2Fee := calculateL2Fee(tx)
|
||||||
cost = cost.Add(cost, l2Fee)
|
cost = cost.Add(cost, l2Fee)
|
||||||
if balance.Cmp(cost) < 0 {
|
if balance.Cmp(cost) < 0 {
|
||||||
return errors.New("invalid transaction: insufficient funds for gas * price + value")
|
return errors.New("invalid transaction: insufficient funds for gas * price + value")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l1DataFee, err := CalculateL1DataFee(tx, state)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid transaction: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
cost = cost.Add(cost, l1DataFee)
|
cost = cost.Add(cost, l1DataFee)
|
||||||
if balance.Cmp(cost) < 0 {
|
if balance.Cmp(cost) < 0 {
|
||||||
return errors.New("invalid transaction: insufficient funds for l1fee + gas * price + value")
|
return errors.New("invalid transaction: insufficient funds for l1fee + gas * price + value")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue