File tree Expand file tree Collapse file tree
pkg/chain/ethereum/ethutil Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -82,6 +82,16 @@ func (mw MiningWaiter) ForceMining(
8282 originalTransaction * types.Transaction ,
8383 resubmitFn ResubmitTransactionFn ,
8484) {
85+ // if the original transaction's gas price was higher or equal the max
86+ // allowed we do nothing; we need to wait for it to be mined
87+ if originalTransaction .GasPrice ().Cmp (mw .maxGasPrice ) >= 0 {
88+ logger .Infof (
89+ "original transaction gas price is higher than the max allowed; " +
90+ "skipping resubmissions" ,
91+ )
92+ return
93+ }
94+
8595 transaction := originalTransaction
8696 for {
8797 receipt , err := mw .WaitMined (mw .checkInterval , transaction )
Original file line number Diff line number Diff line change @@ -168,6 +168,33 @@ func TestForceMining_MaxAllowedPriceReached(t *testing.T) {
168168 }
169169}
170170
171+ func TestForceMining_OriginalPriceHigherThanMaxAllowed (t * testing.T ) {
172+ // original transaction was priced at 46 Gwei, the maximum allowed gas price
173+ // is 45 Gwei
174+ originalTransaction := createTransaction (big .NewInt (46000000000 ))
175+
176+ mockBackend := & mockDeployBackend {}
177+
178+ var resubmissionGasPrices []* big.Int
179+
180+ resubmitFn := func (gasPrice * big.Int ) (* types.Transaction , error ) {
181+ resubmissionGasPrices = append (resubmissionGasPrices , gasPrice )
182+ // not setting mockBackend.receipt, mining takes a very long time
183+ return createTransaction (gasPrice ), nil
184+ }
185+
186+ waiter := NewMiningWaiter (mockBackend , checkInterval , maxGasPrice )
187+ waiter .ForceMining (
188+ originalTransaction ,
189+ resubmitFn ,
190+ )
191+
192+ resubmissionCount := len (resubmissionGasPrices )
193+ if resubmissionCount != 0 {
194+ t .Fatalf ("expected no resubmissions; has: [%v]" , resubmissionCount )
195+ }
196+ }
197+
171198func createTransaction (gasPrice * big.Int ) * types.Transaction {
172199 return types .NewTransaction (
173200 10 , // nonce
You can’t perform that action at this time.
0 commit comments