diff --git a/pm/recipient.go b/pm/recipient.go index 2199842489..3d40778430 100644 --- a/pm/recipient.go +++ b/pm/recipient.go @@ -30,9 +30,9 @@ var paramsExpiryBuffer = int64(1) var evMultiplier = big.NewInt(100) -// Hardcode to 3 gwei +// Hardcode to 10 gwei for Arbitrum Nitro // TODO: Replace this hardcoded value by dynamically determining the average gas price during a period of time -var avgGasPrice = new(big.Int).Mul(big.NewInt(3), new(big.Int).Exp(big.NewInt(10), big.NewInt(9), nil)) +var avgGasPrice = new(big.Int).Mul(big.NewInt(10), new(big.Int).Exp(big.NewInt(10), big.NewInt(9), nil)) // Recipient is an interface which describes an object capable // of receiving tickets @@ -74,6 +74,7 @@ type TicketParamsConfig struct { // GasPriceMonitor defines methods for monitoring gas prices type GasPriceMonitor interface { GasPrice() *big.Int + MaxGasPrice() *big.Int } // recipient is an implementation of the Recipient interface that @@ -254,6 +255,12 @@ func (r *recipient) txCost() *big.Int { if gp := r.gpm.GasPrice(); gp != nil { gasPrice = gp } + + // Cap gasPrice at MaxGasPrice if MaxGasPrice is set, is non-zero, and current gas price exceeds it + if maxGP := r.gpm.MaxGasPrice(); maxGP != nil && maxGP.Sign() > 0 && gasPrice.Cmp(maxGP) > 0 { + gasPrice = maxGP + } + return r.txCostWithGasPrice(gasPrice) } diff --git a/pm/stub.go b/pm/stub.go index a1424bd743..1c08510621 100644 --- a/pm/stub.go +++ b/pm/stub.go @@ -379,6 +379,10 @@ func (s *stubGasPriceMonitor) GasPrice() *big.Int { return s.gasPrice } +func (s *stubGasPriceMonitor) MaxGasPrice() *big.Int { + return nil +} + type stubSenderMonitor struct { maxFloat *big.Int redeemable chan *redemption