-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Solana plugin #15820
base: develop
Are you sure you want to change the base?
Solana plugin #15820
Changes from all commits
b56aae7
5bf41bf
27ce8db
bc0cda8
07ad42c
8ea3930
ec9d62b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import ( | |
"encoding/json" | ||
"fmt" | ||
"io" | ||
"math/big" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
|
@@ -20,8 +19,6 @@ import ( | |
evmconfig "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/configs/evm" | ||
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ocrimpls" | ||
cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" | ||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr3/promwrapper" | ||
|
||
"github.com/smartcontractkit/libocr/commontypes" | ||
|
@@ -36,6 +33,7 @@ import ( | |
execocr3 "github.com/smartcontractkit/chainlink-ccip/execute" | ||
"github.com/smartcontractkit/chainlink-ccip/pkg/consts" | ||
ccipreaderpkg "github.com/smartcontractkit/chainlink-ccip/pkg/reader" | ||
"github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" | ||
cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" | ||
"github.com/smartcontractkit/chainlink-ccip/pluginconfig" | ||
|
||
|
@@ -218,6 +216,39 @@ func (i *pluginOracleCreator) Create(ctx context.Context, donID uint32, config c | |
return newWrappedOracle(oracle, closers), nil | ||
} | ||
|
||
// TODO: duplicated from chainlink-ccip since it's still internal | ||
type EstimateProvider interface { | ||
CalculateMerkleTreeGas(numRequests int) uint64 | ||
CalculateMessageMaxGas(msg ccipocr3.Message) uint64 | ||
} | ||
Comment on lines
+219
to
+223
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this for you: smartcontractkit/chainlink-ccip#417 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can address this once #15860 is merged |
||
type plugin struct { | ||
CommitPluginCodec cciptypes.CommitPluginCodec | ||
ExecutePluginCodec cciptypes.ExecutePluginCodec | ||
MessageHasher func(lggr logger.Logger) cciptypes.MessageHasher | ||
TokenDataEncoder cciptypes.TokenDataEncoder | ||
GasEstimateProvider EstimateProvider | ||
RMNCrypto func(lggr logger.Logger) cciptypes.RMNCrypto | ||
} | ||
|
||
var plugins = map[string]plugin{ | ||
chainsel.FamilyEVM: { | ||
CommitPluginCodec: ccipevm.NewCommitPluginCodecV1(), | ||
ExecutePluginCodec: ccipevm.NewExecutePluginCodecV1(), | ||
MessageHasher: func(lggr logger.Logger) cciptypes.MessageHasher { return ccipevm.NewMessageHasherV1(lggr) }, | ||
TokenDataEncoder: ccipevm.NewEVMTokenDataEncoder(), | ||
GasEstimateProvider: ccipevm.NewGasEstimateProvider(), | ||
RMNCrypto: func(lggr logger.Logger) cciptypes.RMNCrypto { return ccipevm.NewEVMRMNCrypto(lggr) }, | ||
}, | ||
chainsel.FamilySolana: { | ||
CommitPluginCodec: nil, | ||
ExecutePluginCodec: nil, | ||
MessageHasher: func(lggr logger.Logger) cciptypes.MessageHasher { return nil }, | ||
TokenDataEncoder: nil, | ||
GasEstimateProvider: nil, | ||
RMNCrypto: func(lggr logger.Logger) cciptypes.RMNCrypto { return nil }, | ||
}, | ||
} | ||
|
||
func (i *pluginOracleCreator) createFactoryAndTransmitter( | ||
donID uint32, | ||
config cctypes.OCR3ConfigWithMeta, | ||
|
@@ -236,6 +267,16 @@ func (i *pluginOracleCreator) createFactoryAndTransmitter( | |
return nil, nil, fmt.Errorf("unsupported chain selector %d %w", config.Config.ChainSelector, err) | ||
} | ||
|
||
chainFamily, err := chainsel.GetSelectorFamily(uint64(config.Config.ChainSelector)) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("unsupported chain selector %d %w", config.Config.ChainSelector, err) | ||
} | ||
plugin, exists := plugins[chainFamily] | ||
if !exists { | ||
return nil, nil, fmt.Errorf("unsupported chain %v", chainFamily) | ||
} | ||
messageHasher := plugin.MessageHasher(i.lggr.Named(chainFamily + ".MessageHasherV1")) | ||
|
||
if config.Config.PluginType == uint8(cctypes.PluginTypeCCIPCommit) { | ||
if !i.peerWrapper.IsStarted() { | ||
return nil, nil, fmt.Errorf("peer wrapper is not started") | ||
|
@@ -251,7 +292,7 @@ func (i *pluginOracleCreator) createFactoryAndTransmitter( | |
publicConfig.DeltaRound, | ||
) | ||
|
||
rmnCrypto := ccipevm.NewEVMRMNCrypto(i.lggr.Named("EVMRMNCrypto")) | ||
rmnCrypto := plugin.RMNCrypto(i.lggr.Named(chainFamily + ".RMNCrypto")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm partial to using structured logging fields for this sort of thing. i.e. what do you think @mateusz-sekara @makramkd |
||
|
||
factory = commitocr3.NewPluginFactory( | ||
i.lggr. | ||
|
@@ -261,8 +302,8 @@ func (i *pluginOracleCreator) createFactoryAndTransmitter( | |
Named(hexutil.Encode(config.Config.OfframpAddress)), | ||
donID, | ||
ccipreaderpkg.OCR3ConfigWithMeta(config), | ||
ccipevm.NewCommitPluginCodecV1(), | ||
ccipevm.NewMessageHasherV1(i.lggr.Named("MessageHasherV1")), | ||
plugin.CommitPluginCodec, | ||
messageHasher, | ||
i.homeChainReader, | ||
i.homeChainSelector, | ||
contractReaders, | ||
|
@@ -283,11 +324,11 @@ func (i *pluginOracleCreator) createFactoryAndTransmitter( | |
Named(hexutil.Encode(config.Config.OfframpAddress)), | ||
donID, | ||
ccipreaderpkg.OCR3ConfigWithMeta(config), | ||
ccipevm.NewExecutePluginCodecV1(), | ||
ccipevm.NewMessageHasherV1(i.lggr.Named("MessageHasherV1")), | ||
plugin.ExecutePluginCodec, | ||
messageHasher, | ||
i.homeChainReader, | ||
ccipevm.NewEVMTokenDataEncoder(), | ||
ccipevm.NewGasEstimateProvider(), | ||
plugin.TokenDataEncoder, | ||
plugin.GasEstimateProvider, | ||
contractReaders, | ||
chainWriters, | ||
) | ||
|
@@ -328,17 +369,18 @@ func (i *pluginOracleCreator) createReadersAndWriters( | |
execBatchGasLimit = defaultExecGasLimit | ||
} | ||
|
||
homeChainID, err := i.getChainID(i.homeChainSelector) | ||
homeChainID, err := chainsel.GetChainIDFromSelector(uint64(i.homeChainSelector)) | ||
if err != nil { | ||
return nil, nil, err | ||
return nil, nil, fmt.Errorf("failed to get chain ID from chain selector %d: %w", i.homeChainSelector, err) | ||
} | ||
|
||
contractReaders := make(map[cciptypes.ChainSelector]types.ContractReader) | ||
chainWriters := make(map[cciptypes.ChainSelector]types.ContractWriter) | ||
for relayID, relayer := range i.relayers { | ||
chainID := relayID.ChainID | ||
relayChainFamily := relayID.Network | ||
chainSelector, err1 := i.getChainSelector(chainID, relayChainFamily) | ||
chainDetails, err1 := chainsel.GetChainDetailsByChainIDAndFamily(chainID, relayChainFamily) | ||
chainSelector := cciptypes.ChainSelector(chainDetails.ChainSelector) | ||
if err1 != nil { | ||
return nil, nil, fmt.Errorf("failed to get chain selector from chain ID %s: %w", chainID, err1) | ||
} | ||
|
@@ -421,22 +463,6 @@ func decodeAndValidateOffchainConfig( | |
return ofc, nil | ||
} | ||
|
||
func (i *pluginOracleCreator) getChainSelector(chainID string, chainFamily string) (cciptypes.ChainSelector, error) { | ||
chainDetails, err := chainsel.GetChainDetailsByChainIDAndFamily(chainID, chainFamily) | ||
if err != nil { | ||
return 0, fmt.Errorf("failed to get chain selector from chain ID %s and family %s", chainID, chainFamily) | ||
} | ||
return cciptypes.ChainSelector(chainDetails.ChainSelector), nil | ||
} | ||
|
||
func (i *pluginOracleCreator) getChainID(chainSelector cciptypes.ChainSelector) (string, error) { | ||
chainID, err := chainsel.GetChainIDFromSelector(uint64(chainSelector)) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to get chain ID from chain selector %d: %w", chainSelector, err) | ||
} | ||
return chainID, nil | ||
} | ||
|
||
func getChainReaderConfig( | ||
lggr logger.Logger, | ||
chainID string, | ||
|
@@ -520,33 +546,6 @@ func createChainWriter( | |
return cw, nil | ||
} | ||
|
||
func getKeySpecificMaxGasPrice(evmConfigs toml.EVMConfigs, chainID *big.Int, fromAddress common.Address) *assets.Wei { | ||
var maxGasPrice *assets.Wei | ||
|
||
// If a chain is enabled it should have some configuration in the TOML config | ||
// of the chainlink node. | ||
for _, config := range evmConfigs { | ||
if config.ChainID.ToInt().Cmp(chainID) != 0 { | ||
continue | ||
} | ||
|
||
// find the key-specific max gas price for the given fromAddress. | ||
for _, keySpecific := range config.KeySpecific { | ||
if keySpecific.Key.Address() == fromAddress { | ||
maxGasPrice = keySpecific.GasEstimator.PriceMax | ||
} | ||
} | ||
|
||
// if we didn't find a key-specific max gas price, use the one specified | ||
// in the gas estimator config, which should have a default value. | ||
if maxGasPrice == nil { | ||
maxGasPrice = config.GasEstimator.PriceMax | ||
} | ||
} | ||
|
||
return maxGasPrice | ||
} | ||
|
||
type offChainConfig struct { | ||
commitOffchainConfig *pluginconfig.CommitOffchainConfig | ||
execOffchainConfig *pluginconfig.ExecuteOffchainConfig | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check can still be performed by the oracle creator using something like
_, supported := oraclecreator.plugins[networkType]