Skip to content
Merged
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: 4 additions & 1 deletion commit/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (p *PluginFactory) NewReportingPlugin(ctx context.Context, config ocr3types
return nil, ocr3types.ReportingPluginInfo{}, fmt.Errorf("validate ocr config: %w", err)
}

ccipReader := readerpkg.NewCCIPChainReader(
ccipReader, err := readerpkg.NewCCIPChainReader(
ctx,
logutil.WithComponent(lggr, "CCIPReader"),
readers,
Expand All @@ -186,6 +186,9 @@ func (p *PluginFactory) NewReportingPlugin(ctx context.Context, config ocr3types
p.ocrConfig.Config.OfframpAddress,
p.addrCodec,
)
if err != nil {
return nil, ocr3types.ReportingPluginInfo{}, fmt.Errorf("failed to create CCIP chain reader: %w", err)
}

// The node supports the chain that the token prices are on.
_, ok := readers[offchainConfig.PriceFeedChainSelector]
Expand Down
55 changes: 52 additions & 3 deletions commit/factory_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package commit

import (
"context"
"encoding/json"
"fmt"
"math"
"math/big"
"strings"
"testing"
"time"
Expand All @@ -13,13 +15,13 @@ import (

rmnpb "github.com/smartcontractkit/chainlink-protos/rmn/v1.6/go/serialization"

"github.com/smartcontractkit/chainlink-ccip/internal"

"github.com/smartcontractkit/chainlink-common/pkg/merklemulti"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"

"github.com/smartcontractkit/chainlink-ccip/internal"

"github.com/smartcontractkit/chainlink-ccip/commit/chainfee"
"github.com/smartcontractkit/chainlink-ccip/commit/committypes"
"github.com/smartcontractkit/chainlink-ccip/commit/merkleroot"
Expand Down Expand Up @@ -305,6 +307,7 @@ func TestPluginFactory_NewReportingPlugin(t *testing.T) {
b, err := json.Marshal(offChainConfig)
require.NoError(t, err)

chainSel := ccipocr3.ChainSelector(12922642891491394802)
mockAddrCodec := internal.NewMockAddressCodecHex(t)
p := &PluginFactory{
baseLggr: lggr,
Expand All @@ -315,9 +318,15 @@ func TestPluginFactory_NewReportingPlugin(t *testing.T) {
OfframpAddress: []byte{1, 2, 3},
OffchainConfig: b,
// Real selector pointing to chain 2337
ChainSelector: 12922642891491394802,
ChainSelector: chainSel,
},
},
contractReaders: map[ccipocr3.ChainSelector]types.ContractReader{
chainSel: types.UnimplementedContractReader{},
},
chainWriters: map[ccipocr3.ChainSelector]types.ContractWriter{
chainSel: UnimplementedTestContractWriter{},
},
addrCodec: mockAddrCodec,
}

Expand All @@ -337,3 +346,43 @@ func TestPluginFactory_NewReportingPlugin(t *testing.T) {
require.Equal(t, maxQueryLength, pluginInfo.Limits.MaxQueryLength)
})
}

type UnimplementedTestContractWriter struct{}

func (u UnimplementedTestContractWriter) Start(ctx context.Context) error {
return fmt.Errorf("ContractWriter.Start not implemented")
}

func (u UnimplementedTestContractWriter) Close() error {
return fmt.Errorf("ContractWriter.Start not implemented")
}

func (u UnimplementedTestContractWriter) Ready() error {
return fmt.Errorf("ContractWriter.Start not implemented")
}

func (u UnimplementedTestContractWriter) HealthReport() map[string]error {
return nil
}

func (u UnimplementedTestContractWriter) Name() string {
return "UnimplementedTestContractWriter"
}

func (u UnimplementedTestContractWriter) SubmitTransaction(
_ context.Context, _, _ string, _ any, _ string, _ string, _ *types.TxMeta, _ *big.Int,
) error {
return fmt.Errorf("ContractWriter.SubmitTransaction not implemented")
}

func (u UnimplementedTestContractWriter) GetTransactionStatus(
ctx context.Context, transactionID string,
) (types.TransactionStatus, error) {
return 0, fmt.Errorf("ContractWriter.GetTransactionStatus not implemented")
}

func (u UnimplementedTestContractWriter) GetFeeComponents(ctx context.Context) (*types.ChainFeeComponents, error) {
return nil, fmt.Errorf("ContractWriter.GetFeeComponents not implemented")
}

var _ types.ContractWriter = UnimplementedTestContractWriter{}
5 changes: 4 additions & 1 deletion execute/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (p PluginFactory) NewReportingPlugin(
contractreader.NewObserverReader(cr, lggr, chainID))
}

ccipReader := readerpkg.NewCCIPChainReader(
ccipReader, err := readerpkg.NewCCIPChainReader(
ctx,
logutil.WithComponent(lggr, "CCIPReader"),
readers,
Expand All @@ -152,6 +152,9 @@ func (p PluginFactory) NewReportingPlugin(
p.ocrConfig.Config.OfframpAddress,
p.addrCodec,
)
if err != nil {
return nil, ocr3types.ReportingPluginInfo{}, fmt.Errorf("failed to create ccip reader: %w", err)
}

tokenDataObserver, err := observer.NewConfigBasedCompositeObservers(
ctx,
Expand Down
175 changes: 175 additions & 0 deletions pkg/chainaccessor/legacy_accessor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package chainaccessor

import (
"context"
"time"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink-ccip/pkg/contractreader"
cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
)

// LegacyAccessor is an implementation of cciptypes.ChainAccessor that allows the CCIPReader
// to cutover and migrate away from depending directly on contract reader and contract writer.
type LegacyAccessor struct {
lggr logger.Logger
chainSelector cciptypes.ChainSelector
contractReader contractreader.Extended
contractWriter types.ContractWriter
addrCodec cciptypes.AddressCodec
}

var _ cciptypes.ChainAccessor = (*LegacyAccessor)(nil)

func NewLegacyAccessor(
lggr logger.Logger,
chainSelector cciptypes.ChainSelector,
contractReader contractreader.Extended,
contractWriter types.ContractWriter,
addrCodec cciptypes.AddressCodec,
) cciptypes.ChainAccessor {
return &LegacyAccessor{
lggr: lggr,
chainSelector: chainSelector,
contractReader: contractReader,
contractWriter: contractWriter,
addrCodec: addrCodec,
}
}

func (l *LegacyAccessor) Metadata() cciptypes.AccessorMetadata {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetContractAddress(contractName string) ([]byte, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetChainFeeComponents(
ctx context.Context,
) map[cciptypes.ChainSelector]cciptypes.ChainFeeComponents {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetDestChainFeeComponents(ctx context.Context) (types.ChainFeeComponents, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) Sync(ctx context.Context, contracts cciptypes.ContractAddresses) error {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) MsgsBetweenSeqNums(
ctx context.Context,
dest cciptypes.ChainSelector,
seqNumRange cciptypes.SeqNumRange,
) ([]cciptypes.Message, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) LatestMsgSeqNum(ctx context.Context, dest cciptypes.ChainSelector) (cciptypes.SeqNum, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetExpectedNextSequenceNumber(
ctx context.Context,
dest cciptypes.ChainSelector,
) (cciptypes.SeqNum, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetTokenPriceUSD(
ctx context.Context,
address cciptypes.UnknownAddress,
) (cciptypes.BigInt, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetFeeQuoterDestChainConfig(
ctx context.Context,
dest cciptypes.ChainSelector,
) (cciptypes.FeeQuoterDestChainConfig, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) CommitReportsGTETimestamp(
ctx context.Context,
ts time.Time,
limit int,
) ([]cciptypes.CommitPluginReportWithMeta, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) ExecutedMessages(
ctx context.Context,
ranges map[cciptypes.ChainSelector]cciptypes.SeqNumRange,
confidence cciptypes.ConfidenceLevel,
) (map[cciptypes.ChainSelector][]cciptypes.SeqNum, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) NextSeqNum(
ctx context.Context,
sources []cciptypes.ChainSelector,
) (seqNum map[cciptypes.ChainSelector]cciptypes.SeqNum, err error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) Nonces(
ctx context.Context,
addresses map[cciptypes.ChainSelector][]cciptypes.UnknownEncodedAddress,
) (map[cciptypes.ChainSelector]map[string]uint64, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetChainFeePriceUpdate(
ctx context.Context,
selectors []cciptypes.ChainSelector,
) map[cciptypes.ChainSelector]cciptypes.TimestampedBig {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetLatestPriceSeqNr(ctx context.Context) (uint64, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetOffRampConfigDigest(ctx context.Context, pluginType uint8) ([32]byte, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetOffRampSourceChainsConfig(
ctx context.Context,
sourceChains []cciptypes.ChainSelector,
) (map[cciptypes.ChainSelector]cciptypes.SourceChainConfig, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetRMNRemoteConfig(ctx context.Context) (cciptypes.RemoteConfig, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}

func (l *LegacyAccessor) GetRmnCurseInfo(ctx context.Context) (cciptypes.CurseInfo, error) {
// TODO(NONEVM-1865): implement
panic("implement me")
}
31 changes: 24 additions & 7 deletions pkg/reader/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/smartcontractkit/chainlink-ccip/internal/libs/slicelib"
"github.com/smartcontractkit/chainlink-ccip/pkg/addressbook"
"github.com/smartcontractkit/chainlink-ccip/pkg/chainaccessor"
"github.com/smartcontractkit/chainlink-ccip/pkg/consts"
"github.com/smartcontractkit/chainlink-ccip/pkg/contractreader"
"github.com/smartcontractkit/chainlink-ccip/pkg/logutil"
Expand All @@ -39,11 +40,13 @@ type ccipChainReader struct {
lggr logger.Logger
contractReaders map[cciptypes.ChainSelector]contractreader.Extended
contractWriters map[cciptypes.ChainSelector]types.ContractWriter
destChain cciptypes.ChainSelector
offrampAddress string
configPoller ConfigPoller
addrCodec cciptypes.AddressCodec
donAddressBook *addressbook.Book
accessors map[cciptypes.ChainSelector]cciptypes.ChainAccessor

destChain cciptypes.ChainSelector
offrampAddress string
configPoller ConfigPoller
addrCodec cciptypes.AddressCodec
donAddressBook *addressbook.Book
}

func newCCIPChainReaderInternal(
Expand All @@ -54,21 +57,35 @@ func newCCIPChainReaderInternal(
destChain cciptypes.ChainSelector,
offrampAddress []byte,
addrCodec cciptypes.AddressCodec,
) *ccipChainReader {
) (*ccipChainReader, error) {
var crs = make(map[cciptypes.ChainSelector]contractreader.Extended)
var cas = make(map[cciptypes.ChainSelector]cciptypes.ChainAccessor)

for chainSelector, cr := range contractReaders {
crs[chainSelector] = contractreader.NewExtendedContractReader(cr)
if contractWriters[chainSelector] == nil {
return nil, fmt.Errorf("contract writer for chain %s is not provided", chainSelector)
}
cas[chainSelector] = chainaccessor.NewLegacyAccessor(
lggr,
chainSelector,
crs[chainSelector],
contractWriters[chainSelector],
addrCodec,
)
}

offrampAddrStr, err := addrCodec.AddressBytesToString(offrampAddress, destChain)
if err != nil {
// Panic here since the entire discovery process relies on the offramp address being valid.
panic(fmt.Sprintf("failed to convert offramp address to string: %v", err))
}

reader := &ccipChainReader{
lggr: lggr,
contractReaders: crs,
contractWriters: contractWriters,
accessors: cas,
destChain: destChain,
offrampAddress: offrampAddrStr,
addrCodec: addrCodec,
Expand All @@ -95,7 +112,7 @@ func newCCIPChainReaderInternal(
lggr.Errorw("failed to start config background polling", "err", err)
}

return reader
return reader, nil
}

// WithExtendedContractReader sets the extended contract reader for the provided chain.
Expand Down
Loading
Loading