Skip to content

Commit 6b92fa2

Browse files
committed
The last resubmission should be with the maximum allowed gas cost
We were never hitting the maximum, stopping before the maximum was reached.
1 parent 49ad28c commit 6b92fa2

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

pkg/chain/ethereum/ethutil/mine_waiter.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,22 @@ func (mw MiningWaiter) ForceMining(
104104
return
105105
}
106106

107-
// transaction not yet mined, add 20% to the previous gas price
107+
// transaction not yet mined, if the previous gas price was the maximum
108+
// one, we no longer resubmit
108109
gasPrice := transaction.GasPrice()
110+
if gasPrice.Cmp(mw.maxGasPrice) == 0 {
111+
logger.Infof("reached the maximum allowed gas price; stopping resubmissions")
112+
return
113+
}
114+
115+
// if we still have some margin, add 20% to the previous gas price
109116
twentyPercent := new(big.Int).Div(gasPrice, big.NewInt(5))
110117
gasPrice = new(big.Int).Add(gasPrice, twentyPercent)
111118

112-
// transaction not yet mined but we reached the maximum allowed gas
113-
// price; giving up, we need to wait for the last submitted TX to be
114-
// mined
119+
// if we reached the maximum allowed gas price, submit one more time
120+
// with the maximum
115121
if gasPrice.Cmp(mw.maxGasPrice) > 0 {
116-
logger.Infof("reached the maximum allowed gas price; stopping resubmissions")
117-
return
122+
gasPrice = mw.maxGasPrice
118123
}
119124

120125
// transaction not yet mined and we are still under the maximum allowed

pkg/chain/ethereum/ethutil/mine_waiter_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,13 @@ func TestForceMining_MaxAllowedPriceReached(t *testing.T) {
126126

127127
var resubmissionGasPrices []*big.Int
128128

129-
expectedAttempts := 4
129+
expectedAttempts := 5
130130
expectedResubmissionGasPrices := []*big.Int{
131131
big.NewInt(24000000000), // + 20%
132132
big.NewInt(28800000000), // + 20%
133133
big.NewInt(34560000000), // + 20%
134134
big.NewInt(41472000000), // + 20%
135-
// the next one would be 49766400000 but since maxGasPrice = 45 Gwei
136-
// resubmissions should stop here
135+
big.NewInt(45000000000), // max allowed
137136
}
138137

139138
resubmitFn := func(gasPrice *big.Int) (*types.Transaction, error) {

0 commit comments

Comments
 (0)