Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment gas price with at least 10% #2378

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions ethtxmanager/ethtxmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ import (
const (
failureIntervalInSeconds = 5
// maxHistorySize = 10

// The minimum factor by which we must increase gas price in a replacement transaction.
minGasPriceIncreaseNumerator = 11
minGasPriceIncreaseDenominator = 10
// A small buffer, in WEI, added to the gas price after increasing by minGasPriceIncrease, to
// offset rounding errors.
minGasPriceIncreaseBuffer = 1
)

var (
Expand Down Expand Up @@ -526,8 +533,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 a small buffer to offset rounding errors from
// truncation.
minReplace := new(big.Int).Set(mTx.gasPrice)
minReplace.Mul(minReplace, big.NewInt(minGasPriceIncreaseNumerator))
minReplace.Div(minReplace, big.NewInt(minGasPriceIncreaseDenominator))
minReplace.Add(minReplace, big.NewInt(minGasPriceIncreaseBuffer))

// 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