Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions pm/recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions pm/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down