Skip to content

Commit

Permalink
l2geth: fix for gas-oracle race condition
Browse files Browse the repository at this point in the history
Prevent the error being returned in consensus for when
the user does not have enough balance. The policy level
check *must* filter out transactions that do not have
enough gas to pay for their execution. The policy
level check happens in the `SyncService`. This change
gracefully handles the race condition where a user transaction
passes the policy level check as a `gas-oracle` transaction
is executing and updating the gas prices. If the gas price
goes up and the user transaction no longer can afford execution,
then it will return an error from consensus.
  • Loading branch information
tynes committed Oct 27, 2021
1 parent 0b89338 commit 54ba81b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilly-wasps-divide.md
@@ -0,0 +1,5 @@
---
'@eth-optimism/l2geth': patch
---

Handle policy/consensus race condition for balance check
10 changes: 9 additions & 1 deletion l2geth/core/state_transition.go
Expand Up @@ -185,7 +185,15 @@ func (st *StateTransition) buyGas() error {
}
}
if st.state.GetBalance(st.msg.From()).Cmp(mgval) < 0 {
return errInsufficientBalanceForGas
if rcfg.UsingOVM {
// Hack to prevent race conditions with the `gas-oracle`
// where policy level balance checks pass and then fail
// during consensus. The user gets some free gas
// in this case.
mgval = st.state.GetBalance(st.msg.From())
} else {
return errInsufficientBalanceForGas
}
}
if err := st.gp.SubGas(st.msg.Gas()); err != nil {
return err
Expand Down

0 comments on commit 54ba81b

Please sign in to comment.