Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modles.go evm prefix cleanup #9654

Merged
merged 8 commits into from
Jun 22, 2023
6 changes: 3 additions & 3 deletions core/chains/evm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Chain interface {
Config() evmconfig.ChainScopedConfig
LogBroadcaster() log.Broadcaster
HeadBroadcaster() httypes.HeadBroadcaster
TxManager() txmgr.EvmTxManager
TxManager() txmgr.TxManager
HeadTracker() httypes.HeadTracker
Logger() logger.Logger
BalanceMonitor() monitor.BalanceMonitor
Expand All @@ -56,7 +56,7 @@ type chain struct {
id *big.Int
cfg evmconfig.ChainScopedConfig
client evmclient.Client
txm txmgr.EvmTxManager
txm txmgr.TxManager
logger logger.Logger
headBroadcaster httypes.HeadBroadcaster
headTracker httypes.HeadTracker
Expand Down Expand Up @@ -273,7 +273,7 @@ func (c *chain) Config() evmconfig.ChainScopedConfig { return c.cfg }
func (c *chain) LogBroadcaster() log.Broadcaster { return c.logBroadcaster }
func (c *chain) LogPoller() logpoller.LogPoller { return c.logPoller }
func (c *chain) HeadBroadcaster() httypes.HeadBroadcaster { return c.headBroadcaster }
func (c *chain) TxManager() txmgr.EvmTxManager { return c.txm }
func (c *chain) TxManager() txmgr.TxManager { return c.txm }
func (c *chain) HeadTracker() httypes.HeadTracker { return c.headTracker }
func (c *chain) Logger() logger.Logger { return c.logger }
func (c *chain) BalanceMonitor() monitor.BalanceMonitor { return c.balanceMonitor }
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/chain_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ type ChainSetOpts struct {
GenLogBroadcaster func(*big.Int) log.Broadcaster
GenLogPoller func(*big.Int) logpoller.LogPoller
GenHeadTracker func(*big.Int, httypes.HeadBroadcaster) httypes.HeadTracker
GenTxManager func(*big.Int) txmgr.EvmTxManager
GenTxManager func(*big.Int) txmgr.TxManager
GenGasEstimator func(*big.Int) gas.EvmFeeEstimator
}

Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/evm_txm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func newEvmTxm(
lggr logger.Logger,
logPoller logpoller.LogPoller,
opts ChainSetOpts,
) (txm txmgr.EvmTxManager,
) (txm txmgr.TxManager,
estimator gas.EvmFeeEstimator,
err error,
) {
chainID := cfg.ChainID()
if !evmRPCEnabled {
txm = &txmgr.NullEvmTxManager{ErrMsg: fmt.Sprintf("Ethereum is disabled for chain %d", chainID)}
txm = &txmgr.NullTxManager{ErrMsg: fmt.Sprintf("Ethereum is disabled for chain %d", chainID)}
return txm, nil, nil
}

Expand Down
24 changes: 12 additions & 12 deletions core/chains/evm/txmgr/attempts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type TxAttemptSigner[ADDR commontypes.Hashable] interface {
SignTx(fromAddress ADDR, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)
}

var _ EvmTxAttemptBuilder = (*evmTxAttemptBuilder)(nil)
var _ TxAttemptBuilder = (*evmTxAttemptBuilder)(nil)

type evmTxAttemptBuilder struct {
chainID big.Int
Expand All @@ -48,7 +48,7 @@ func NewEvmTxAttemptBuilder(chainID big.Int, config evmTxAttemptBuilderConfig, f

// NewTxAttempt builds an new attempt using the configured fee estimator + using the EIP1559 config to determine tx type
// used for when a brand new transaction is being created in the txm
func (c *evmTxAttemptBuilder) NewTxAttempt(ctx context.Context, etx EvmTx, lggr logger.Logger, opts ...feetypes.Opt) (attempt EvmTxAttempt, fee gas.EvmFee, feeLimit uint32, retryable bool, err error) {
func (c *evmTxAttemptBuilder) NewTxAttempt(ctx context.Context, etx Tx, lggr logger.Logger, opts ...feetypes.Opt) (attempt TxAttempt, fee gas.EvmFee, feeLimit uint32, retryable bool, err error) {
txType := 0x0
if c.feeConfig.EIP1559DynamicFees() {
txType = 0x2
Expand All @@ -58,7 +58,7 @@ func (c *evmTxAttemptBuilder) NewTxAttempt(ctx context.Context, etx EvmTx, lggr

// 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 EvmTx, lggr logger.Logger, txType int, opts ...feetypes.Opt) (attempt EvmTxAttempt, fee gas.EvmFee, feeLimit uint32, retryable bool, err error) {
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.config.KeySpecificMaxGasPriceWei(etx.FromAddress)
fee, feeLimit, err = c.EvmFeeEstimator.GetFee(ctx, etx.EncodedPayload, etx.FeeLimit, keySpecificMaxGasPriceWei, opts...)
if err != nil {
Expand All @@ -71,7 +71,7 @@ func (c *evmTxAttemptBuilder) NewTxAttemptWithType(ctx context.Context, etx EvmT

// 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 EvmTx, previousAttempt EvmTxAttempt, priorAttempts []EvmTxAttempt, lggr logger.Logger) (attempt EvmTxAttempt, bumpedFee gas.EvmFee, bumpedFeeLimit uint32, retryable bool, err error) {
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.config.KeySpecificMaxGasPriceWei(etx.FromAddress)

bumpedFee, bumpedFeeLimit, err = c.EvmFeeEstimator.BumpFee(ctx, previousAttempt.TxFee, etx.FeeLimit, keySpecificMaxGasPriceWei, newEvmPriorAttempts(priorAttempts))
Expand All @@ -85,7 +85,7 @@ func (c *evmTxAttemptBuilder) NewBumpTxAttempt(ctx context.Context, etx EvmTx, p

// NewCustomTxAttempt is the lowest level func where the fee parameters + tx type must be passed in
// used in the txm for force rebroadcast where fees and tx type are pre-determined without an estimator
func (c *evmTxAttemptBuilder) NewCustomTxAttempt(etx EvmTx, fee gas.EvmFee, gasLimit uint32, txType int, lggr logger.Logger) (attempt EvmTxAttempt, retryable bool, err error) {
func (c *evmTxAttemptBuilder) NewCustomTxAttempt(etx Tx, fee gas.EvmFee, gasLimit uint32, txType int, lggr logger.Logger) (attempt TxAttempt, retryable bool, err error) {
switch txType {
case 0x0: // legacy
if fee.Legacy == nil {
Expand Down Expand Up @@ -115,7 +115,7 @@ func (c *evmTxAttemptBuilder) NewCustomTxAttempt(etx EvmTx, fee gas.EvmFee, gasL
}

// NewEmptyTxAttempt is used in ForceRebroadcast to create a signed tx with zero value sent to the zero address
func (c *evmTxAttemptBuilder) NewEmptyTxAttempt(nonce evmtypes.Nonce, feeLimit uint32, fee gas.EvmFee, fromAddress common.Address) (attempt EvmTxAttempt, err error) {
func (c *evmTxAttemptBuilder) NewEmptyTxAttempt(nonce evmtypes.Nonce, feeLimit uint32, fee gas.EvmFee, fromAddress common.Address) (attempt TxAttempt, err error) {
value := big.NewInt(0)
payload := []byte{}

Expand All @@ -136,7 +136,7 @@ func (c *evmTxAttemptBuilder) NewEmptyTxAttempt(nonce evmtypes.Nonce, feeLimit u

}

func (c *evmTxAttemptBuilder) newDynamicFeeAttempt(etx EvmTx, fee gas.DynamicFee, gasLimit uint32) (attempt EvmTxAttempt, err error) {
func (c *evmTxAttemptBuilder) newDynamicFeeAttempt(etx Tx, fee gas.DynamicFee, gasLimit uint32) (attempt TxAttempt, err error) {
if err = validateDynamicFeeGas(c.config, c.feeConfig.TipCapMin(), fee, gasLimit, etx); err != nil {
return attempt, errors.Wrap(err, "error validating gas")
}
Expand Down Expand Up @@ -169,7 +169,7 @@ var Max256BitUInt = big.NewInt(0).Exp(big.NewInt(2), big.NewInt(256), nil)

// validateDynamicFeeGas is a sanity check - we have other checks elsewhere, but this
// makes sure we _never_ create an invalid attempt
func validateDynamicFeeGas(cfg evmTxAttemptBuilderConfig, tipCapMinimum *assets.Wei, fee gas.DynamicFee, gasLimit uint32, etx EvmTx) error {
func validateDynamicFeeGas(cfg evmTxAttemptBuilderConfig, tipCapMinimum *assets.Wei, fee gas.DynamicFee, gasLimit uint32, etx Tx) error {
gasTipCap, gasFeeCap := fee.TipCap, fee.FeeCap

if gasTipCap == nil {
Expand Down Expand Up @@ -217,7 +217,7 @@ func newDynamicFeeTransaction(nonce uint64, to common.Address, value *big.Int, g
}
}

func (c *evmTxAttemptBuilder) newLegacyAttempt(etx EvmTx, gasPrice *assets.Wei, gasLimit uint32) (attempt EvmTxAttempt, err error) {
func (c *evmTxAttemptBuilder) newLegacyAttempt(etx Tx, gasPrice *assets.Wei, gasLimit uint32) (attempt TxAttempt, err error) {
if err = validateLegacyGas(c.config, c.feeConfig.PriceMin(), gasPrice, gasLimit, etx); err != nil {
return attempt, errors.Wrap(err, "error validating gas")
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (c *evmTxAttemptBuilder) newLegacyAttempt(etx EvmTx, gasPrice *assets.Wei,

// validateLegacyGas is a sanity check - we have other checks elsewhere, but this
// makes sure we _never_ create an invalid attempt
func validateLegacyGas(cfg evmTxAttemptBuilderConfig, minGasPriceWei, gasPrice *assets.Wei, gasLimit uint32, etx EvmTx) error {
func validateLegacyGas(cfg evmTxAttemptBuilderConfig, minGasPriceWei, gasPrice *assets.Wei, gasLimit uint32, etx Tx) error {
if gasPrice == nil {
panic("gas price missing")
}
Expand All @@ -266,7 +266,7 @@ func validateLegacyGas(cfg evmTxAttemptBuilderConfig, minGasPriceWei, gasPrice *
return nil
}

func (c *evmTxAttemptBuilder) newSignedAttempt(etx EvmTx, tx *types.Transaction) (attempt EvmTxAttempt, err error) {
func (c *evmTxAttemptBuilder) newSignedAttempt(etx Tx, tx *types.Transaction) (attempt TxAttempt, err error) {
hash, signedTxBytes, err := c.SignTx(etx.FromAddress, tx)
if err != nil {
return attempt, errors.Wrapf(err, "error using account %s to sign transaction %v", etx.FromAddress.String(), etx.ID)
Expand Down Expand Up @@ -305,7 +305,7 @@ func (c *evmTxAttemptBuilder) SignTx(address common.Address, tx *types.Transacti
return txHash, rlp.Bytes(), nil
}

func newEvmPriorAttempts(attempts []EvmTxAttempt) (prior []gas.EvmPriorAttempt) {
func newEvmPriorAttempts(attempts []TxAttempt) (prior []gas.EvmPriorAttempt) {
for i := range attempts {
priorAttempt := gas.EvmPriorAttempt{
ChainSpecificFeeLimit: attempts[i].ChainSpecificFeeLimit,
Expand Down
20 changes: 10 additions & 10 deletions core/chains/evm/txmgr/attempts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestTxm_NewDynamicFeeTx(t *testing.T) {
cfg := evmtest.NewChainScopedConfig(t, gcfg)
cks := txmgr.NewEvmTxAttemptBuilder(*big.NewInt(1), cfg.EVM(), newFeeConfig(), kst, nil)
dynamicFee := gas.DynamicFee{TipCap: assets.GWei(100), FeeCap: assets.GWei(200)}
a, _, err := cks.NewCustomTxAttempt(txmgr.EvmTx{Sequence: &n, FromAddress: addr}, gas.EvmFee{
a, _, err := cks.NewCustomTxAttempt(txmgr.Tx{Sequence: &n, FromAddress: addr}, gas.EvmFee{
DynamicTipCap: dynamicFee.TipCap,
DynamicFeeCap: dynamicFee.FeeCap,
}, 100, 0x2, lggr)
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestTxm_NewDynamicFeeTx(t *testing.T) {
cfg := evmtest.NewChainScopedConfig(t, gcfg)
cks := txmgr.NewEvmTxAttemptBuilder(*big.NewInt(1), cfg.EVM(), cfg.EVM().GasEstimator(), kst, nil)
dynamicFee := gas.DynamicFee{TipCap: test.tipcap, FeeCap: test.feecap}
_, _, err := cks.NewCustomTxAttempt(txmgr.EvmTx{Sequence: &n, FromAddress: addr}, gas.EvmFee{
_, _, err := cks.NewCustomTxAttempt(txmgr.Tx{Sequence: &n, FromAddress: addr}, gas.EvmFee{
DynamicTipCap: dynamicFee.TipCap,
DynamicFeeCap: dynamicFee.FeeCap,
}, 100, 0x2, lggr)
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestTxm_NewLegacyAttempt(t *testing.T) {

t.Run("creates attempt with fields", func(t *testing.T) {
var n evmtypes.Nonce
a, _, err := cks.NewCustomTxAttempt(txmgr.EvmTx{Sequence: &n, FromAddress: addr}, gas.EvmFee{Legacy: assets.NewWeiI(25)}, 100, 0x0, lggr)
a, _, err := cks.NewCustomTxAttempt(txmgr.Tx{Sequence: &n, FromAddress: addr}, gas.EvmFee{Legacy: assets.NewWeiI(25)}, 100, 0x0, lggr)
require.NoError(t, err)
assert.Equal(t, 100, int(a.ChainSpecificFeeLimit))
assert.NotNil(t, a.TxFee.Legacy)
Expand All @@ -182,7 +182,7 @@ func TestTxm_NewLegacyAttempt(t *testing.T) {
})

t.Run("verifies max gas price", func(t *testing.T) {
_, _, err := cks.NewCustomTxAttempt(txmgr.EvmTx{FromAddress: addr}, gas.EvmFee{Legacy: assets.NewWeiI(100)}, 100, 0x0, lggr)
_, _, err := cks.NewCustomTxAttempt(txmgr.Tx{FromAddress: addr}, gas.EvmFee{Legacy: assets.NewWeiI(100)}, 100, 0x0, lggr)
require.Error(t, err)
assert.Contains(t, err.Error(), fmt.Sprintf("specified gas price of 100 wei would exceed max configured gas price of 50 wei for key %s", addr.String()))
})
Expand All @@ -200,21 +200,21 @@ func TestTxm_NewCustomTxAttempt_NonRetryableErrors(t *testing.T) {
legacyFee := assets.NewWeiI(100)

t.Run("dynamic fee with legacy tx type", func(t *testing.T) {
_, retryable, err := cks.NewCustomTxAttempt(txmgr.EvmTx{}, gas.EvmFee{
_, retryable, err := cks.NewCustomTxAttempt(txmgr.Tx{}, gas.EvmFee{
DynamicTipCap: dynamicFee.TipCap,
DynamicFeeCap: dynamicFee.FeeCap,
}, 100, 0x0, lggr)
require.Error(t, err)
assert.False(t, retryable)
})
t.Run("legacy fee with dynamic tx type", func(t *testing.T) {
_, retryable, err := cks.NewCustomTxAttempt(txmgr.EvmTx{}, gas.EvmFee{Legacy: legacyFee}, 100, 0x2, lggr)
_, retryable, err := cks.NewCustomTxAttempt(txmgr.Tx{}, gas.EvmFee{Legacy: legacyFee}, 100, 0x2, lggr)
require.Error(t, err)
assert.False(t, retryable)
})

t.Run("invalid type", func(t *testing.T) {
_, retryable, err := cks.NewCustomTxAttempt(txmgr.EvmTx{}, gas.EvmFee{}, 100, 0xA, lggr)
_, retryable, err := cks.NewCustomTxAttempt(txmgr.Tx{}, gas.EvmFee{}, 100, 0xA, lggr)
require.Error(t, err)
assert.False(t, retryable)
})
Expand All @@ -234,19 +234,19 @@ func TestTxm_EvmTxAttemptBuilder_RetryableEstimatorError(t *testing.T) {
cks := txmgr.NewEvmTxAttemptBuilder(*big.NewInt(1), cfg, &feeConfig{eip1559DynamicFees: true}, kst, est)

t.Run("NewAttempt", func(t *testing.T) {
_, _, _, retryable, err := cks.NewTxAttempt(ctx, txmgr.EvmTx{}, lggr)
_, _, _, retryable, err := cks.NewTxAttempt(ctx, txmgr.Tx{}, lggr)
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to get fee")
assert.True(t, retryable)
})
t.Run("NewAttemptWithType", func(t *testing.T) {
_, _, _, retryable, err := cks.NewTxAttemptWithType(ctx, txmgr.EvmTx{}, lggr, 0x0)
_, _, _, retryable, err := cks.NewTxAttemptWithType(ctx, txmgr.Tx{}, lggr, 0x0)
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to get fee")
assert.True(t, retryable)
})
t.Run("NewBumpAttempt", func(t *testing.T) {
_, _, _, retryable, err := cks.NewBumpTxAttempt(ctx, txmgr.EvmTx{}, txmgr.EvmTxAttempt{}, nil, lggr)
_, _, _, retryable, err := cks.NewBumpTxAttempt(ctx, txmgr.Tx{}, txmgr.TxAttempt{}, nil, lggr)
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to bump fee")
assert.True(t, retryable)
Expand Down
Loading