feat: improve balance check (#607)

* feat: improve balance check

* clean up
This commit is contained in:
HAOYUatHZ 2023-12-26 00:09:41 +08:00 committed by GitHub
parent b235afbccf
commit 833f9041bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions

View file

@ -1233,6 +1233,10 @@ loop:
w.checkCurrentTxNumWithCCC(w.current.tcount)
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:
// Strange error, discard the transaction and get the next in line (note, the
// nonce-too-high clause will prevent us from executing in vain).

View file

@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major 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
)

View file

@ -202,18 +202,19 @@ func VerifyFee(signer types.Signer, tx *types.Transaction, state StateDB) error
}
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()
l2Fee := calculateL2Fee(tx)
cost = cost.Add(cost, l2Fee)
if balance.Cmp(cost) < 0 {
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)
if balance.Cmp(cost) < 0 {
return errors.New("invalid transaction: insufficient funds for l1fee + gas * price + value")