Skip to content

Commit

Permalink
Merge pull request #63 from EspressoSystems/ma/replace-tx-min-gas-price
Browse files Browse the repository at this point in the history
Increment gas price with at least 10%
  • Loading branch information
jbearer authored Aug 5, 2023
2 parents 61e05f4 + 6d7fb8a commit fd07d4d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ethtxmanager/ethtxmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,17 @@ func (c *Client) ReviewMonitoredTx(ctx context.Context, mTx *monitoredTx) error
return err
}

// check gas price
if gasPrice.Cmp(mTx.gasPrice) == 1 {
// The gas price of a replacement transaction needs to be at least 10%
// higher. The computation adds 1 Wei to offset rounding errors from
// truncation.
minReplace := new(big.Int).Set(mTx.gasPrice)
minReplace.Mul(minReplace, big.NewInt(11))
minReplace.Div(minReplace, big.NewInt(10))
minReplace.Add(minReplace, big.NewInt(1))

// If the current suggested gas price is higher than the minimum replacement
// gas price update the gas price for re-submission.
if gasPrice.Cmp(minReplace) == 1 {
mTxLog.Infof("monitored tx gas price updated from %v to %v", mTx.gasPrice.String(), gasPrice.String())
mTx.gasPrice = gasPrice
}
Expand Down

0 comments on commit fd07d4d

Please sign in to comment.