Skip to content

Commit

Permalink
Change MaxPriceKey to PriceMaxKey
Browse files Browse the repository at this point in the history
  • Loading branch information
george-dorin committed Jul 10, 2023
1 parent b6cfd04 commit 934bbe1
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type GasEstimator interface {
PriceMax() *assets.Wei
PriceMin() *assets.Wei
Mode() string
MaxPriceKey(gethcommon.Address) *assets.Wei
PriceMaxKey(gethcommon.Address) *assets.Wei
}

type LimitJobType interface {
Expand Down
18 changes: 9 additions & 9 deletions core/chains/evm/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestChainScopedConfig(t *testing.T) {
})
})

t.Run("MaxPriceKey", func(t *testing.T) {
t.Run("PriceMaxKey", func(t *testing.T) {
addr := testutils.NewAddress()
randomOtherAddr := testutils.NewAddress()
gcfg2 := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
Expand All @@ -97,7 +97,7 @@ func TestChainScopedConfig(t *testing.T) {
cfg2 := evmtest.NewChainScopedConfig(t, gcfg2)

t.Run("uses chain-specific default value when nothing is set", func(t *testing.T) {
assert.Equal(t, assets.NewWeiI(100000000000000), cfg2.EVM().GasEstimator().MaxPriceKey(addr))
assert.Equal(t, assets.NewWeiI(100000000000000), cfg2.EVM().GasEstimator().PriceMaxKey(addr))
})

t.Run("uses chain-specific override value when that is set", func(t *testing.T) {
Expand All @@ -107,7 +107,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, val.String(), cfg3.EVM().GasEstimator().MaxPriceKey(addr).String())
assert.Equal(t, val.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses key-specific override value when set", func(t *testing.T) {
val := assets.GWei(250)
Expand All @@ -122,7 +122,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, val.String(), cfg3.EVM().GasEstimator().MaxPriceKey(addr).String())
assert.Equal(t, val.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses key-specific override value when set and lower than chain specific config", func(t *testing.T) {
keySpecificPrice := assets.GWei(900)
Expand All @@ -139,7 +139,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, keySpecificPrice.String(), cfg3.EVM().GasEstimator().MaxPriceKey(addr).String())
assert.Equal(t, keySpecificPrice.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses chain-specific value when higher than key-specific value", func(t *testing.T) {
keySpecificPrice := assets.GWei(1400)
Expand All @@ -156,7 +156,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, chainSpecificPrice.String(), cfg3.EVM().GasEstimator().MaxPriceKey(addr).String())
assert.Equal(t, chainSpecificPrice.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses key-specific override value when set and lower than global config", func(t *testing.T) {
keySpecificPrice := assets.GWei(900)
Expand All @@ -171,7 +171,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, keySpecificPrice.String(), cfg3.EVM().GasEstimator().MaxPriceKey(addr).String())
assert.Equal(t, keySpecificPrice.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses global value when higher than key-specific value", func(t *testing.T) {
keySpecificPrice := assets.GWei(1400)
Expand All @@ -188,7 +188,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, chainSpecificPrice.String(), cfg3.EVM().GasEstimator().MaxPriceKey(addr).String())
assert.Equal(t, chainSpecificPrice.String(), cfg3.EVM().GasEstimator().PriceMaxKey(addr).String())
})
t.Run("uses global value when there is no key-specific price", func(t *testing.T) {
val := assets.NewWeiI(rand.Int63())
Expand All @@ -198,7 +198,7 @@ func TestChainScopedConfig(t *testing.T) {
})
cfg3 := evmtest.NewChainScopedConfig(t, gcfg3)

assert.Equal(t, val.String(), cfg3.EVM().GasEstimator().MaxPriceKey(unsetAddr).String())
assert.Equal(t, val.String(), cfg3.EVM().GasEstimator().PriceMaxKey(unsetAddr).String())
})
})

Expand Down
32 changes: 16 additions & 16 deletions core/chains/evm/config/mocks/gas_estimator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/chains/evm/config/v2/chain_scoped_gas_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type gasEstimatorConfig struct {
transactionsMaxInFlight *uint32
}

func (g *gasEstimatorConfig) MaxPriceKey(addr gethcommon.Address) *assets.Wei {
func (g *gasEstimatorConfig) PriceMaxKey(addr gethcommon.Address) *assets.Wei {
var keySpecific *assets.Wei
for i := range g.k {
ks := g.k[i]
Expand Down
12 changes: 6 additions & 6 deletions core/chains/evm/txmgr/attempts.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type evmTxAttemptBuilderFeeConfig interface {
EIP1559DynamicFees() bool
TipCapMin() *assets.Wei
PriceMin() *assets.Wei
MaxPriceKey(common.Address) *assets.Wei
PriceMaxKey(common.Address) *assets.Wei
}

func NewEvmTxAttemptBuilder(chainID big.Int, feeConfig evmTxAttemptBuilderFeeConfig, keystore TxAttemptSigner[common.Address], estimator gas.EvmFeeEstimator) *evmTxAttemptBuilder {
Expand All @@ -55,7 +55,7 @@ func (c *evmTxAttemptBuilder) NewTxAttempt(ctx context.Context, etx Tx, lggr log
// NewTxAttemptWithType builds a new attempt with a new fee estimation where the txType can be specified by the caller
// used for L2 re-estimation on broadcasting (note EIP1559 must be disabled otherwise this will fail with mismatched fees + tx type)
func (c *evmTxAttemptBuilder) NewTxAttemptWithType(ctx context.Context, etx Tx, lggr logger.Logger, txType int, opts ...feetypes.Opt) (attempt TxAttempt, fee gas.EvmFee, feeLimit uint32, retryable bool, err error) {
keySpecificMaxGasPriceWei := c.feeConfig.MaxPriceKey(etx.FromAddress)
keySpecificMaxGasPriceWei := c.feeConfig.PriceMaxKey(etx.FromAddress)
fee, feeLimit, err = c.EvmFeeEstimator.GetFee(ctx, etx.EncodedPayload, etx.FeeLimit, keySpecificMaxGasPriceWei, opts...)
if err != nil {
return attempt, fee, feeLimit, true, errors.Wrap(err, "failed to get fee") // estimator errors are retryable
Expand All @@ -68,7 +68,7 @@ func (c *evmTxAttemptBuilder) NewTxAttemptWithType(ctx context.Context, etx Tx,
// NewBumpTxAttempt builds a new attempt with a bumped fee - based on the previous attempt tx type
// used in the txm broadcaster + confirmer when tx ix rejected for too low fee or is not included in a timely manner
func (c *evmTxAttemptBuilder) NewBumpTxAttempt(ctx context.Context, etx Tx, previousAttempt TxAttempt, priorAttempts []TxAttempt, lggr logger.Logger) (attempt TxAttempt, bumpedFee gas.EvmFee, bumpedFeeLimit uint32, retryable bool, err error) {
keySpecificMaxGasPriceWei := c.feeConfig.MaxPriceKey(etx.FromAddress)
keySpecificMaxGasPriceWei := c.feeConfig.PriceMaxKey(etx.FromAddress)

bumpedFee, bumpedFeeLimit, err = c.EvmFeeEstimator.BumpFee(ctx, previousAttempt.TxFee, etx.FeeLimit, keySpecificMaxGasPriceWei, newEvmPriorAttempts(priorAttempts))
if err != nil {
Expand Down Expand Up @@ -164,7 +164,7 @@ func (c *evmTxAttemptBuilder) newDynamicFeeAttempt(etx Tx, fee gas.DynamicFee, g
var Max256BitUInt = big.NewInt(0).Exp(big.NewInt(2), big.NewInt(256), nil)

type keySpecificEstimator interface {
MaxPriceKey(addr common.Address) *assets.Wei
PriceMaxKey(addr common.Address) *assets.Wei
}

// validateDynamicFeeGas is a sanity check - we have other checks elsewhere, but this
Expand Down Expand Up @@ -192,7 +192,7 @@ func validateDynamicFeeGas(kse keySpecificEstimator, tipCapMinimum *assets.Wei,
}

// Configuration sanity-check
max := kse.MaxPriceKey(etx.FromAddress)
max := kse.PriceMaxKey(etx.FromAddress)
if gasFeeCap.Cmp(max) > 0 {
return errors.Errorf("cannot create tx attempt: specified gas fee cap of %s would exceed max configured gas price of %s for key %s", gasFeeCap.String(), max.String(), etx.FromAddress.String())
}
Expand Down Expand Up @@ -255,7 +255,7 @@ func validateLegacyGas(kse keySpecificEstimator, minGasPriceWei, gasPrice *asset
if gasPrice == nil {
panic("gas price missing")
}
max := kse.MaxPriceKey(etx.FromAddress)
max := kse.PriceMaxKey(etx.FromAddress)
if gasPrice.Cmp(max) > 0 {
return errors.Errorf("cannot create tx attempt: specified gas price of %s would exceed max configured gas price of %s for key %s", gasPrice.String(), max.String(), etx.FromAddress.String())
}
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/attempts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func newFeeConfig() *feeConfig {
func (g *feeConfig) EIP1559DynamicFees() bool { return g.eip1559DynamicFees }
func (g *feeConfig) TipCapMin() *assets.Wei { return g.tipCapMin }
func (g *feeConfig) PriceMin() *assets.Wei { return g.priceMin }
func (g *feeConfig) MaxPriceKey(addr gethcommon.Address) *assets.Wei { return g.priceMax }
func (g *feeConfig) PriceMaxKey(addr gethcommon.Address) *assets.Wei { return g.priceMax }

func TestTxm_SignTx(t *testing.T) {
t.Parallel()
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_OptimisticLockingOnEthTx(t *testi
chStartEstimate := make(chan struct{})
chBlock := make(chan struct{})

estimator.On("GetFee", mock.Anything, mock.Anything, mock.Anything, ccfg.EVM().GasEstimator().MaxPriceKey(fromAddress)).Return(gas.EvmFee{Legacy: assets.GWei(32)}, uint32(500), nil).Run(func(_ mock.Arguments) {
estimator.On("GetFee", mock.Anything, mock.Anything, mock.Anything, ccfg.EVM().GasEstimator().PriceMaxKey(fromAddress)).Return(gas.EvmFee{Legacy: assets.GWei(32)}, uint32(500), nil).Run(func(_ mock.Arguments) {
close(chStartEstimate)
<-chBlock
})
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type FeeConfig interface {
TipCapMin() *assets.Wei
PriceMax() *assets.Wei
PriceMin() *assets.Wei
MaxPriceKey(gethcommon.Address) *assets.Wei
PriceMaxKey(gethcommon.Address) *assets.Wei
}

type DatabaseConfig interface {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/txmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func (g *gasEstimatorConfig) PriceMax() *assets.Wei { return asse
func (g *gasEstimatorConfig) PriceMin() *assets.Wei { return assets.NewWeiI(42) }
func (g *gasEstimatorConfig) Mode() string { return "FixedPrice" }
func (g *gasEstimatorConfig) LimitJobType() evmconfig.LimitJobType { return &limitJobTypeConfig{} }
func (e *gasEstimatorConfig) MaxPriceKey(addr common.Address) *assets.Wei {
func (e *gasEstimatorConfig) PriceMaxKey(addr common.Address) *assets.Wei {
return assets.NewWeiI(42)
}

Expand Down
6 changes: 3 additions & 3 deletions core/services/vrf/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Config interface {
type FeeConfig interface {
LimitDefault() uint32
LimitJobType() config.LimitJobType
MaxPriceKey(common.Address) *assets.Wei
PriceMaxKey(common.Address) *assets.Wei
}

func NewDelegate(
Expand Down Expand Up @@ -146,11 +146,11 @@ func (d *Delegate) ServicesForSpec(jb job.Job) ([]job.ServiceCtx, error) {
return nil, err
}

if !FromAddressMaxGasPricesAllEqual(jb, chain.Config().EVM().GasEstimator().MaxPriceKey) {
if !FromAddressMaxGasPricesAllEqual(jb, chain.Config().EVM().GasEstimator().PriceMaxKey) {
return nil, errors.New("key-specific max gas prices of all fromAddresses are not equal, please set them to equal values")
}

if err := CheckFromAddressMaxGasPrices(jb, chain.Config().EVM().GasEstimator().MaxPriceKey); err != nil {
if err := CheckFromAddressMaxGasPrices(jb, chain.Config().EVM().GasEstimator().PriceMaxKey); err != nil {
return nil, err
}

Expand Down
24 changes: 12 additions & 12 deletions core/services/vrf/delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ decode_log->vrf->encode_tx->submit_tx
require.NoError(tt, err)

gasEstimator := mocks.NewGasEstimator(t)
require.NoError(tt, vrf.CheckFromAddressMaxGasPrices(jb, gasEstimator.MaxPriceKey))
require.NoError(tt, vrf.CheckFromAddressMaxGasPrices(jb, gasEstimator.PriceMaxKey))
})

t.Run("returns nil error on valid gas lane <=> key specific gas price setting", func(tt *testing.T) {
Expand All @@ -506,7 +506,7 @@ decode_log->vrf->encode_tx->submit_tx

gasEstimator := mocks.NewGasEstimator(t)
for _, a := range fromAddresses {
gasEstimator.On("MaxPriceKey", common.HexToAddress(a)).Return(assets.GWei(100)).Once()
gasEstimator.On("PriceMaxKey", common.HexToAddress(a)).Return(assets.GWei(100)).Once()
}
defer gasEstimator.AssertExpectations(tt)

Expand All @@ -522,7 +522,7 @@ decode_log->vrf->encode_tx->submit_tx
Toml())
require.NoError(t, err)

require.NoError(tt, vrf.CheckFromAddressMaxGasPrices(jb, gasEstimator.MaxPriceKey))
require.NoError(tt, vrf.CheckFromAddressMaxGasPrices(jb, gasEstimator.PriceMaxKey))
})

t.Run("returns error on invalid setting", func(tt *testing.T) {
Expand All @@ -532,10 +532,10 @@ decode_log->vrf->encode_tx->submit_tx
}

gasEstimator := mocks.NewGasEstimator(t)
gasEstimator.On("MaxPriceKey", common.HexToAddress(fromAddresses[0])).Return(assets.GWei(100)).Once()
gasEstimator.On("MaxPriceKey", common.HexToAddress(fromAddresses[1])).Return(assets.GWei(100)).Once()
gasEstimator.On("PriceMaxKey", common.HexToAddress(fromAddresses[0])).Return(assets.GWei(100)).Once()
gasEstimator.On("PriceMaxKey", common.HexToAddress(fromAddresses[1])).Return(assets.GWei(100)).Once()
// last from address has wrong key-specific max gas price
gasEstimator.On("MaxPriceKey", common.HexToAddress(fromAddresses[2])).Return(assets.GWei(50)).Once()
gasEstimator.On("PriceMaxKey", common.HexToAddress(fromAddresses[2])).Return(assets.GWei(50)).Once()
defer gasEstimator.AssertExpectations(tt)

jb, err := vrf.ValidatedVRFSpec(testspecs.GenerateVRFSpec(
Expand All @@ -550,7 +550,7 @@ decode_log->vrf->encode_tx->submit_tx
Toml())
require.NoError(t, err)

require.Error(tt, vrf.CheckFromAddressMaxGasPrices(jb, gasEstimator.MaxPriceKey))
require.Error(tt, vrf.CheckFromAddressMaxGasPrices(jb, gasEstimator.PriceMaxKey))
})
}

Expand Down Expand Up @@ -634,11 +634,11 @@ func Test_FromAddressMaxGasPricesAllEqual(t *testing.T) {

gasEstimator := mocks.NewGasEstimator(t)
for _, a := range fromAddresses {
gasEstimator.On("MaxPriceKey", common.HexToAddress(a)).Return(assets.GWei(100))
gasEstimator.On("PriceMaxKey", common.HexToAddress(a)).Return(assets.GWei(100))
}
defer gasEstimator.AssertExpectations(tt)

assert.True(tt, vrf.FromAddressMaxGasPricesAllEqual(jb, gasEstimator.MaxPriceKey))
assert.True(tt, vrf.FromAddressMaxGasPricesAllEqual(jb, gasEstimator.PriceMaxKey))
})

t.Run("one max gas price not equal to others", func(tt *testing.T) {
Expand All @@ -661,12 +661,12 @@ func Test_FromAddressMaxGasPricesAllEqual(t *testing.T) {

gasEstimator := mocks.NewGasEstimator(t)
for _, a := range fromAddresses[:3] {
gasEstimator.On("MaxPriceKey", common.HexToAddress(a)).Return(assets.GWei(100))
gasEstimator.On("PriceMaxKey", common.HexToAddress(a)).Return(assets.GWei(100))
}
gasEstimator.On("MaxPriceKey", common.HexToAddress(fromAddresses[len(fromAddresses)-1])).
gasEstimator.On("PriceMaxKey", common.HexToAddress(fromAddresses[len(fromAddresses)-1])).
Return(assets.GWei(200)) // doesn't match the rest
defer gasEstimator.AssertExpectations(tt)

assert.False(tt, vrf.FromAddressMaxGasPricesAllEqual(jb, gasEstimator.MaxPriceKey))
assert.False(tt, vrf.FromAddressMaxGasPricesAllEqual(jb, gasEstimator.PriceMaxKey))
})
}
4 changes: 2 additions & 2 deletions core/services/vrf/listener_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func (lsn *listenerV2) processRequestsPerSubBatch(

// All fromAddresses passed to the VRFv2 job have the same KeySpecific-MaxPrice value.
fromAddresses := lsn.fromAddresses()
maxGasPriceWei := lsn.feeCfg.MaxPriceKey(fromAddresses[0])
maxGasPriceWei := lsn.feeCfg.PriceMaxKey(fromAddresses[0])

// Cases:
// 1. Never simulated: in this case, we want to observe the time until simulated
Expand Down Expand Up @@ -881,7 +881,7 @@ func (lsn *listenerV2) processRequestsPerSub(

// All fromAddresses passed to the VRFv2 job have the same KeySpecific-MaxPrice value.
fromAddresses := lsn.fromAddresses()
maxGasPriceWei := lsn.feeCfg.MaxPriceKey(fromAddresses[0])
maxGasPriceWei := lsn.feeCfg.PriceMaxKey(fromAddresses[0])
observeRequestSimDuration(lsn.job.Name.ValueOrZero(), lsn.job.ExternalJobID, v2, unfulfilled)
pipelines := lsn.runPipelines(ctx, l, maxGasPriceWei, unfulfilled)
for _, p := range pipelines {
Expand Down
2 changes: 1 addition & 1 deletion core/web/eth_keys_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (ekc *ETHKeysController) setKeyMaxGasPriceWei(state ethkey.State, keyAddres
ekc.lggr.Errorw("Failed to get EVM Chain", "chainID", chainID, "err", err)
}
} else {
price = chain.Config().EVM().GasEstimator().MaxPriceKey(keyAddress)
price = chain.Config().EVM().GasEstimator().PriceMaxKey(keyAddress)
}
return presenters.SetETHKeyMaxGasPriceWei(utils.NewBig(price.ToInt()))
}
Expand Down
2 changes: 1 addition & 1 deletion core/web/evm_transfer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func ValidateEthBalanceForTransfer(c *gin.Context, chain evm.Chain, fromAddr com
gasLimit := chain.Config().EVM().GasEstimator().LimitTransfer()
estimator := chain.GasEstimator()

fees, gasLimit, err = estimator.GetFee(c, nil, gasLimit, chain.Config().EVM().GasEstimator().MaxPriceKey(fromAddr))
fees, gasLimit, err = estimator.GetFee(c, nil, gasLimit, chain.Config().EVM().GasEstimator().PriceMaxKey(fromAddr))
if err != nil {
return errors.Wrap(err, "failed to estimate gas")
}
Expand Down
2 changes: 1 addition & 1 deletion core/web/resolver/eth_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (r *ETHKeyResolver) MaxGasPriceWei() *string {
return nil
}

gasPrice := r.key.chain.Config().EVM().GasEstimator().MaxPriceKey(r.key.addr.Address())
gasPrice := r.key.chain.Config().EVM().GasEstimator().PriceMaxKey(r.key.addr.Address())

if gasPrice != nil {
val := gasPrice.ToInt().String()
Expand Down
2 changes: 1 addition & 1 deletion core/web/resolver/eth_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestResolver_ETHKeys(t *testing.T) {
statesError := fmt.Errorf("error getting key states: %v", gError)

evmMockConfig := mockEvmConfig{linkAddr: "0x5431F5F973781809D18643b87B44921b11355d81", gasEstimatorMock: mocks2.NewGasEstimator(t)}
evmMockConfig.gasEstimatorMock.On("MaxPriceKey", mock.Anything).Return(assets.NewWeiI(1))
evmMockConfig.gasEstimatorMock.On("PriceMaxKey", mock.Anything).Return(assets.NewWeiI(1))

testCases := []GQLTestCase{
unauthorizedTestCase(GQLTestCase{query: query}, "ethKeys"),
Expand Down

0 comments on commit 934bbe1

Please sign in to comment.