Skip to content

Commit

Permalink
Nonevm 825/remove evm config dependency from plugin (#15126)
Browse files Browse the repository at this point in the history
* remove dependency of evmConfig in plugin oracle creator function

* fix make

* add changeset

* update test
  • Loading branch information
huangzhen1997 authored Nov 6, 2024
1 parent 039777f commit bf9b08c
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-frogs-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

update plugin and evm chainwriter to remove evmConfig dependency #updated
9 changes: 0 additions & 9 deletions core/capabilities/ccip/configs/evm/chain_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/smartcontractkit/chainlink-ccip/pkg/consts"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp"
evmrelaytypes "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/types"
Expand All @@ -21,19 +20,12 @@ var (
// ChainWriterConfigRaw returns a ChainWriterConfig that can be used to transmit commit and execute reports.
func ChainWriterConfigRaw(
fromAddress common.Address,
maxGasPrice *assets.Wei,
commitGasLimit,
execBatchGasLimit uint64,
) (evmrelaytypes.ChainWriterConfig, error) {
if fromAddress == common.HexToAddress("0x0") {
return evmrelaytypes.ChainWriterConfig{}, fmt.Errorf("fromAddress cannot be zero")
}
if maxGasPrice == nil {
return evmrelaytypes.ChainWriterConfig{}, fmt.Errorf("maxGasPrice cannot be nil")
}
if maxGasPrice.Cmp(assets.NewWeiI(0)) <= 0 {
return evmrelaytypes.ChainWriterConfig{}, fmt.Errorf("maxGasPrice must be greater than zero")
}
if commitGasLimit == 0 {
return evmrelaytypes.ChainWriterConfig{}, fmt.Errorf("commitGasLimit must be greater than zero")
}
Expand All @@ -59,7 +51,6 @@ func ChainWriterConfigRaw(
},
},
},
MaxGasPrice: maxGasPrice,
}, nil
}

Expand Down
35 changes: 1 addition & 34 deletions core/capabilities/ccip/configs/evm/chain_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,40 @@ import (

"github.com/smartcontractkit/chainlink-ccip/pkg/consts"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/configs/evm"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
)

func TestChainWriterConfigRaw(t *testing.T) {
tests := []struct {
name string
fromAddress common.Address
maxGasPrice *assets.Wei
commitGasLimit uint64
execBatchGasLimit uint64
expectedError string
}{
{
name: "valid input",
fromAddress: common.HexToAddress("0x1234567890abcdef1234567890abcdef12345678"),
maxGasPrice: assets.NewWeiI(1000000000),
commitGasLimit: 21000,
execBatchGasLimit: 42000,
expectedError: "",
},
{
name: "zero fromAddress",
fromAddress: common.HexToAddress("0x0"),
maxGasPrice: assets.NewWeiI(1000000000),
commitGasLimit: 21000,
execBatchGasLimit: 42000,
expectedError: "fromAddress cannot be zero",
},
{
name: "nil maxGasPrice",
fromAddress: common.HexToAddress("0x1234567890abcdef1234567890abcdef12345678"),
maxGasPrice: nil,
commitGasLimit: 21000,
execBatchGasLimit: 42000,
expectedError: "maxGasPrice cannot be nil",
},
{
name: "zero maxGasPrice",
fromAddress: common.HexToAddress("0x1234567890abcdef1234567890abcdef12345678"),
maxGasPrice: assets.NewWeiI(0),
commitGasLimit: 21000,
execBatchGasLimit: 42000,
expectedError: "maxGasPrice must be greater than zero",
},
{
name: "negative maxGasPrice",
fromAddress: common.HexToAddress("0x1234567890abcdef1234567890abcdef12345678"),
maxGasPrice: assets.NewWeiI(-1),
commitGasLimit: 21000,
execBatchGasLimit: 42000,
expectedError: "maxGasPrice must be greater than zero",
},
{
name: "zero commitGasLimit",
fromAddress: common.HexToAddress("0x1234567890abcdef1234567890abcdef12345678"),
maxGasPrice: assets.NewWeiI(1000000000),
commitGasLimit: 0,
execBatchGasLimit: 42000,
expectedError: "commitGasLimit must be greater than zero",
},
{
name: "zero execBatchGasLimit",
fromAddress: common.HexToAddress("0x1234567890abcdef1234567890abcdef12345678"),
maxGasPrice: assets.NewWeiI(1000000000),
commitGasLimit: 21000,
execBatchGasLimit: 0,
expectedError: "execBatchGasLimit must be greater than zero",
Expand All @@ -80,7 +50,7 @@ func TestChainWriterConfigRaw(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config, err := evm.ChainWriterConfigRaw(tt.fromAddress, tt.maxGasPrice, tt.commitGasLimit, tt.execBatchGasLimit)
config, err := evm.ChainWriterConfigRaw(tt.fromAddress, tt.commitGasLimit, tt.execBatchGasLimit)
if tt.expectedError != "" {
assert.EqualError(t, err, tt.expectedError)
} else {
Expand All @@ -94,9 +64,6 @@ func TestChainWriterConfigRaw(t *testing.T) {
assert.Equal(t,
tt.execBatchGasLimit,
config.Contracts[consts.ContractNameOffRamp].Configs[consts.MethodExecute].GasLimit)
assert.Equal(t,
tt.maxGasPrice,
config.MaxGasPrice)
}
})
}
Expand Down
1 change: 0 additions & 1 deletion core/capabilities/ccip/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) (services
bootstrapperLocators,
hcr,
cciptypes.ChainSelector(homeChainChainSelector),
d.evmConfigs,
)
} else {
oracleCreator = oraclecreator.NewBootstrapOracleCreator(
Expand Down
11 changes: 0 additions & 11 deletions core/capabilities/ccip/oraclecreator/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ type pluginOracleCreator struct {
homeChainReader ccipreaderpkg.HomeChain
homeChainSelector cciptypes.ChainSelector
relayers map[types.RelayID]loop.Relayer
evmConfigs toml.EVMConfigs
}

func NewPluginOracleCreator(
Expand All @@ -91,7 +90,6 @@ func NewPluginOracleCreator(
bootstrapperLocators []commontypes.BootstrapperLocator,
homeChainReader ccipreaderpkg.HomeChain,
homeChainSelector cciptypes.ChainSelector,
evmConfigs toml.EVMConfigs,
) cctypes.OracleCreator {
return &pluginOracleCreator{
ocrKeyBundles: ocrKeyBundles,
Expand All @@ -108,7 +106,6 @@ func NewPluginOracleCreator(
bootstrapperLocators: bootstrapperLocators,
homeChainReader: homeChainReader,
homeChainSelector: homeChainSelector,
evmConfigs: evmConfigs,
}
}

Expand Down Expand Up @@ -367,7 +364,6 @@ func (i *pluginOracleCreator) createReadersAndWriters(
cw, err1 := createChainWriter(
ctx,
chainID,
i.evmConfigs,
relayer,
i.transmitters,
execBatchGasLimit)
Expand Down Expand Up @@ -480,7 +476,6 @@ func isUSDCEnabled(ofc offChainConfig) bool {
func createChainWriter(
ctx context.Context,
chainID *big.Int,
evmConfigs toml.EVMConfigs,
relayer loop.Relayer,
transmitters map[types.RelayID][]string,
execBatchGasLimit uint64,
Expand All @@ -492,14 +487,8 @@ func createChainWriter(
fromAddress = common.HexToAddress(transmitter[0])
}

maxGasPrice := getKeySpecificMaxGasPrice(evmConfigs, chainID, fromAddress)
if maxGasPrice == nil {
return nil, fmt.Errorf("failed to find max gas price for chain %s", chainID.String())
}

chainWriterRawConfig, err := evmconfig.ChainWriterConfigRaw(
fromAddress,
maxGasPrice,
defaultCommitGasLimit,
execBatchGasLimit,
)
Expand Down
1 change: 1 addition & 0 deletions core/services/relay/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ func (r *Relayer) NewChainWriter(_ context.Context, config []byte) (commontypes.
return nil, fmt.Errorf("failed to unmarshall chain writer config err: %s", err)
}

cfg.MaxGasPrice = r.chain.Config().EVM().GasEstimator().PriceMax()
return NewChainWriterService(r.lggr, r.chain.Client(), r.chain.TxManager(), r.chain.GasEstimator(), cfg)
}

Expand Down

0 comments on commit bf9b08c

Please sign in to comment.