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

Add solana support to contract transmitter #15869

Open
wants to merge 4 commits into
base: solana-offchain-plugin
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions .changeset/wise-items-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Add solana support for contract transmitter and remove evm depdendency for address encoding #added
29 changes: 23 additions & 6 deletions core/capabilities/ccip/oraclecreator/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/gagliardetto/solana-go"
"github.com/google/uuid"
"github.com/prometheus/client_golang/prometheus"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"

chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"
Expand Down Expand Up @@ -170,7 +172,7 @@ func (i *pluginOracleCreator) Create(ctx context.Context, donID uint32, config c

// TODO: Extract the correct transmitter address from the destsFromAccount
factory, transmitter, err := i.createFactoryAndTransmitter(
donID, config, destRelayID, contractReaders, chainWriters, destChainWriter, destFromAccounts, publicConfig)
donID, config, destRelayID, contractReaders, chainWriters, destChainWriter, destFromAccounts, publicConfig, destChainFamily)
if err != nil {
return nil, fmt.Errorf("failed to create factory and transmitter: %w", err)
}
Expand All @@ -188,7 +190,7 @@ func (i *pluginOracleCreator) Create(ctx context.Context, donID uint32, config c
i.lggr.
Named(fmt.Sprintf("CCIP%sOCR3", pluginType.String())).
Named(destRelayID.String()).
Named(hexutil.Encode(config.Config.OfframpAddress)),
Named(encodeOffRampAddr(config.Config.OfframpAddress, destChainFamily)),
false,
func(ctx context.Context, msg string) {}),
MetricsRegisterer: prometheus.WrapRegistererWith(map[string]string{"name": fmt.Sprintf("commit-%d", config.Config.ChainSelector)}, prometheus.DefaultRegisterer),
Expand Down Expand Up @@ -218,6 +220,20 @@ func (i *pluginOracleCreator) Create(ctx context.Context, donID uint32, config c
return newWrappedOracle(oracle, closers), nil
}

func encodeOffRampAddr(addr []byte, chainFamily string) string {
var offRampAddr string
switch chainFamily {
case relay.NetworkEVM:
offRampAddr = hexutil.Encode(addr)
case relay.NetworkSolana:
offRampAddr = solana.PublicKeyFromBytes(addr).String()
default:
panic(fmt.Errorf("unsupported chain family: %s", chainFamily))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to error or panic here if encounter an unknown family. That will make it explicit to developers to support a new family here too, instead of silently returning null string.


return offRampAddr
}

func (i *pluginOracleCreator) createFactoryAndTransmitter(
donID uint32,
config cctypes.OCR3ConfigWithMeta,
Expand All @@ -227,6 +243,7 @@ func (i *pluginOracleCreator) createFactoryAndTransmitter(
destChainWriter types.ContractWriter,
destFromAccounts []string,
publicConfig ocr3confighelper.PublicConfig,
destChainFamily string,
) (ocr3types.ReportingPluginFactory[[]byte], ocr3types.ContractTransmitter[[]byte], error) {
var factory ocr3types.ReportingPluginFactory[[]byte]
var transmitter ocr3types.ContractTransmitter[[]byte]
Expand Down Expand Up @@ -258,7 +275,7 @@ func (i *pluginOracleCreator) createFactoryAndTransmitter(
Named("CCIPCommitPlugin").
Named(destRelayID.String()).
Named(fmt.Sprintf("%d", config.Config.ChainSelector)).
Named(hexutil.Encode(config.Config.OfframpAddress)),
Named(encodeOffRampAddr(config.Config.OfframpAddress, destChainFamily)),
donID,
ccipreaderpkg.OCR3ConfigWithMeta(config),
ccipevm.NewCommitPluginCodecV1(),
Expand All @@ -273,14 +290,14 @@ func (i *pluginOracleCreator) createFactoryAndTransmitter(
factory = promwrapper.NewReportingPluginFactory[[]byte](factory, i.lggr, chainID, "CCIPCommit")
transmitter = ocrimpls.NewCommitContractTransmitter(destChainWriter,
ocrtypes.Account(destFromAccounts[0]),
hexutil.Encode(config.Config.OfframpAddress), // TODO: this works for evm only, how about non-evm?
encodeOffRampAddr(config.Config.OfframpAddress, destChainFamily),
)
} else if config.Config.PluginType == uint8(cctypes.PluginTypeCCIPExec) {
factory = execocr3.NewPluginFactory(
i.lggr.
Named("CCIPExecPlugin").
Named(destRelayID.String()).
Named(hexutil.Encode(config.Config.OfframpAddress)),
Named(encodeOffRampAddr(config.Config.OfframpAddress, destChainFamily)),
donID,
ccipreaderpkg.OCR3ConfigWithMeta(config),
ccipevm.NewExecutePluginCodecV1(),
Expand All @@ -294,7 +311,7 @@ func (i *pluginOracleCreator) createFactoryAndTransmitter(
factory = promwrapper.NewReportingPluginFactory[[]byte](factory, i.lggr, chainID, "CCIPExec")
transmitter = ocrimpls.NewExecContractTransmitter(destChainWriter,
ocrtypes.Account(destFromAccounts[0]),
hexutil.Encode(config.Config.OfframpAddress), // TODO: this works for evm only, how about non-evm?
encodeOffRampAddr(config.Config.OfframpAddress, destChainFamily),
)
} else {
return nil, nil, fmt.Errorf("unsupported plugin type %d", config.Config.PluginType)
Expand Down
Loading